/* ============================================
   TERMINAL — interactive text-adventure page
   Hooks into styles.css / premium.css design tokens, loader, dark mode, i18n
   ============================================ */

:root {
    --term-bg: #14130f;
    --term-bg-2: #1c1a14;
    --term-fg: #e9e4d6;
    --term-dim: #8d8775;
    --term-green: #9ecb6e;
    --term-gold: var(--accent-color);
    --term-red: #d98a6b;
    --term-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

/* === PAGE LAYOUT === */
.term-page {
    position: relative;
    z-index: 1;
    max-width: 980px;
    margin: 0 auto;
    padding: 14vh 6vw 12vh;
}

.term-intro {
    margin-bottom: 3.5rem;
}

.term-eyebrow {
    display: block;
    font-size: 0.7rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--accent-color);
    opacity: 0.9;
    margin-bottom: 1.4rem;
    font-weight: 600;
}

.term-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 200;
    font-size: clamp(2.6rem, 7vw, 5rem);
    line-height: 1.02;
    letter-spacing: -0.035em;
    margin: 0 0 1.6rem;
    color: var(--secondary-color);
}

.term-title em {
    font-style: normal;
    font-weight: 300;
    color: var(--accent-color);
}

.term-lead {
    max-width: 52ch;
    color: var(--text-secondary-color);
    font-size: clamp(0.95rem, 1.4vw, 1.15rem);
    font-weight: 300;
    letter-spacing: 0.02em;
    line-height: 1.7;
}

.term-lead code,
.term-hint kbd {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--secondary-color);
    color: var(--bg-color);
    padding: 0.1em 0.45em;
    border-radius: 4px;
    font-weight: 500;
}

/* === TERMINAL SHELL === */
.terminal {
    border-radius: 14px;
    overflow: hidden;
    background: var(--term-bg);
    box-shadow:
        0 2px 0 rgba(0,0,0,0.04),
        0 30px 60px -20px rgba(0,0,0,0.55),
        0 8px 20px -10px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.06);
    opacity: 0;
    transform: translateY(30px) scale(0.99);
    transition: opacity 1s var(--term-ease), transform 1s var(--term-ease);
}

body.terminal-ready .terminal {
    opacity: 1;
    transform: none;
}

.terminal-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.1rem;
    background: linear-gradient(var(--term-bg-2), #16140f);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    user-select: none;
}

.terminal-dots {
    display: flex;
    gap: 0.5rem;
}

.t-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: block;
}

.t-dot--red    { background: #ec6a5e; }
.t-dot--yellow { background: #f4bf4f; }
.t-dot--green  { background: #61c554; }

.terminal-bar-title {
    flex: 1;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--term-dim);
    letter-spacing: 0.02em;
}

.terminal-bar-meta {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--term-dim);
    opacity: 0.6;
}

/* === WINDOW === */
.terminal-window {
    font-family: var(--font-mono);
    font-size: 0.92rem;
    line-height: 1.65;
    color: var(--term-fg);
    height: min(62vh, 560px);
    overflow-y: auto;
    padding: 1.4rem 1.5rem 2rem;
    scroll-behavior: smooth;
    background:
        radial-gradient(120% 80% at 50% 0%, rgba(200,169,110,0.06), transparent 60%),
        var(--term-bg);
}

.terminal-window::-webkit-scrollbar { width: 9px; }
.terminal-window::-webkit-scrollbar-track { background: transparent; }
.terminal-window::-webkit-scrollbar-thumb {
    background: rgba(233,228,214,0.14);
    border-radius: 10px;
}
.terminal-window::-webkit-scrollbar-thumb:hover { background: rgba(233,228,214,0.25); }

/* === OUTPUT LINES === */
.terminal-output > * { white-space: pre-wrap; word-break: break-word; }

.term-line { margin: 0; }
.term-spacer { height: 0.7rem; }

.term-cmd-echo {
    color: var(--term-fg);
    margin-top: 0.4rem;
}
.term-cmd-echo .echo-prompt { color: var(--term-green); }
.term-cmd-echo .echo-path   { color: var(--term-gold); }

.term-dim     { color: var(--term-dim); }
.term-accent  { color: var(--term-gold); font-weight: 500; }
.term-green   { color: var(--term-green); }
.term-red     { color: var(--term-red); }
.term-strong  { color: #fff; font-weight: 700; }

.term-link {
    color: var(--term-gold);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: color-mix(in srgb, var(--term-gold) 40%, transparent);
}
.term-link:hover { text-decoration-color: var(--term-gold); }

.term-banner {
    color: var(--term-gold);
    font-size: 0.7rem;
    line-height: 1.25;
    letter-spacing: 0;
}

.term-cmd-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.15rem 1.5rem;
}
.term-cmd-list dt { color: var(--term-green); }
.term-cmd-list dd { color: var(--term-dim); margin: 0; }

.term-bar-vis {
    color: var(--term-gold);
    letter-spacing: -1px;
}

/* === INPUT LINE === */
.terminal-input-line {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-top: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.92rem;
}
.terminal-input-line[hidden] { display: none; }

.terminal-prompt { white-space: nowrap; }
.prompt-user  { color: var(--term-green); }
.prompt-colon { color: var(--term-dim); }
.prompt-path  { color: var(--term-gold); }
.prompt-tail  { color: var(--term-dim); margin-left: 0.15rem; }

.terminal-input-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: baseline;
}

/* real input is transparent; we render a styled mirror */
.terminal-input {
    position: absolute;
    inset: 0;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: transparent;
    caret-color: transparent;
    font: inherit;
    padding: 0;
}

.terminal-typed { color: var(--term-fg); white-space: pre; }

.terminal-caret {
    color: var(--term-gold);
    margin-left: -2px;
    animation: term-blink 1.1s steps(1) infinite;
}
@keyframes term-blink { 50% { opacity: 0; } }
.terminal-input-line.is-typing .terminal-caret { animation: none; opacity: 1; }

/* === HINT === */
.term-hint {
    margin-top: 1.6rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary-color);
}
.term-hint kbd {
    background: var(--secondary-color);
    color: var(--bg-color);
}

/* === AMBER THEME (toggled via `theme` command) === */
.term-amber {
    --term-bg: #1a1206;
    --term-bg-2: #221908;
    --term-fg: #ffb454;
    --term-dim: #b3792e;
    --term-green: #ffcb6b;
    --term-gold: #ffd479;
    --term-red: #ff8a5c;
}
.term-amber .terminal-window {
    text-shadow: 0 0 6px rgba(255, 180, 84, 0.35);
}

/* === MATRIX EASTER EGG === */
.matrix-canvas {
    position: fixed;
    inset: 0;
    z-index: 9990;
    background: #000;
}
.matrix-exit {
    position: fixed;
    bottom: 2rem; left: 50%;
    transform: translateX(-50%);
    z-index: 9991;
    font-family: var(--font-mono);
    color: #9ecb6e;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    animation: term-blink 1.4s steps(1) infinite;
}

/* === RESPONSIVE === */
@media (max-width: 640px) {
    .term-page { padding: 12vh 5vw 10vh; }
    .terminal-window { font-size: 0.8rem; height: 60vh; padding: 1.1rem 1rem 1.6rem; }
    .terminal-input-line { font-size: 0.8rem; }
    .term-banner { font-size: 0.5rem; }
    .term-cmd-list { grid-template-columns: 1fr; gap: 0.05rem; }
    .term-cmd-list dd { margin-bottom: 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    .terminal, .terminal-caret { transition: none; animation: none; }
}
