/* ============================================================
   GPT-2 Internals — Stylesheet
   ============================================================ */

:root {
    --bg:          #0a0e17;
    --bg2:         #111827;
    --card:        #1a1f2e;
    --border:      #2a3042;
    --border-hi:   #3b4563;
    --text:        #e2e8f0;
    --text2:       #94a3b8;
    --text3:       #64748b;
    --accent:      #6366f1;
    --accent2:     #818cf8;
    --accent-glow: rgba(99,102,241,0.25);
    --green:       #34d399;
    --green-glow:  rgba(52,211,153,0.2);
    --orange:      #fb923c;
    --red:         #f87171;
    --pink:        #f472b6;
    --cyan:        #22d3ee;
    --yellow:      #fbbf24;
    --mono:        'SF Mono','Cascadia Code','Fira Code','JetBrains Mono','Consolas',monospace;
    --sans:        'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
    --radius:      8px;
    --radius-sm:   4px;
    --radius-lg:   12px;
    --transition:  0.25s cubic-bezier(.4,0,.2,1);
}

/* ---- Reset ---- */
*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { font-size:16px; -webkit-font-smoothing:antialiased; }
body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---- Utility ---- */
.hidden { display:none !important; }
.collapsed { max-height:0; opacity:0; overflow:hidden; padding-top:0 !important; padding-bottom:0 !important; margin-bottom:0 !important; }

/* ============================================================
   LANDING PAGE
   ============================================================ */
.landing {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(99,102,241,0.12) 0%, transparent 60%),
        var(--bg);
    padding: 20px;
}
.landing-content {
    max-width: 620px;
    width: 100%;
    text-align: center;
}

/* Logo */
.logo {
    font-family: var(--mono);
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: -1px;
}
.logo-bracket { color: var(--accent2); }
.logo-text { color: var(--text); margin:0 4px; }

.landing h1 {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.tagline {
    color: var(--text2);
    font-size: 1rem;
    margin-bottom: 36px;
}

/* Input */
.input-area {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}
.input-area input {
    flex: 1;
    padding: 14px 18px;
    font-size: 1rem;
    font-family: var(--mono);
    border-radius: var(--radius);
    border: 1.5px solid var(--border);
    background: var(--bg2);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input-area input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.hint {
    color: var(--text3);
    font-size: 0.82rem;
    margin-bottom: 40px;
}

/* Specs */
.specs {
    display: flex;
    justify-content: center;
    gap: 32px;
    flex-wrap: wrap;
}
.spec {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.spec-val {
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent2);
}
.spec-label {
    font-size: 0.75rem;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 2px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--sans);
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    user-select: none;
}
.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: rgba(255,255,255,0.1);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent2);
    box-shadow: 0 0 20px var(--accent-glow);
}
.btn-secondary {
    background: var(--bg2);
    color: var(--text2);
    border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
    border-color: var(--text3);
    color: var(--text);
}
.btn-ghost {
    background: transparent;
    color: var(--text3);
    padding: 6px 12px;
    font-size: 0.82rem;
}
.btn-ghost:hover { color: var(--text); }
.btn-icon {
    background: transparent;
    color: var(--text3);
    border: 1px solid var(--border);
    width: 34px; height: 34px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}
.btn-icon:hover {
    color: var(--accent2);
    border-color: var(--accent);
}

/* ============================================================
   WALKTHROUGH LAYOUT
   ============================================================ */
.walkthrough {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 20px 20px;
}

/* Top bar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.topbar-center {
    flex: 1;
    text-align: center;
}
.step-label {
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text3);
    letter-spacing: 0.5px;
}

/* Progress */
.progress-track {
    position: relative;
    height: 32px;
    margin-bottom: 20px;
}
.progress-bar {
    position: absolute;
    top: 14px;
    left: 0;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.5s ease;
    box-shadow: 0 0 8px var(--accent-glow);
}
.progress-track::before {
    content: '';
    position: absolute;
    top: 14px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
}
.progress-dots {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    z-index: 1;
}
.dot {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--bg2);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text3);
    transition: all 0.3s;
    cursor: default;
}
.dot.active {
    border-color: var(--accent);
    color: var(--accent2);
    background: var(--bg);
    box-shadow: 0 0 12px var(--accent-glow);
}
.dot.done {
    border-color: var(--green);
    color: var(--green);
    background: rgba(52,211,153,0.08);
}

/* Stage Header */
.stage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.stage-header h2 {
    font-family: var(--mono);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text);
}

/* Explanation */
.explanation {
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.15);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text2);
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.35s ease, margin 0.35s ease;
    max-height: 400px;
    opacity: 1;
}
.explanation b, .explanation strong { color: var(--text); }

/* Stage */
.stage-wrap {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
    min-height: 340px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stage-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(42,48,66,0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(42,48,66,0.3) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
}
.stage {
    width: 100%;
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
}
.stage.col {
    flex-direction: column;
    align-items: center;
}

/* Nav bar */
.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   VISUAL TOKENS & ELEMENTS
   ============================================================ */

/* Characters (step 1) */
.char {
    display: inline-block;
    padding: 2px 1px;
    font-size: 1.3rem;
    opacity: 0;
    animation: charIn 0.08s forwards;
}
@keyframes charIn {
    from { opacity:0; transform:translateY(4px); }
    to   { opacity:1; transform:translateY(0); }
}
.char.space { color: var(--text3); }
.char.cursor {
    display: inline-block;
    width: 2px;
    height: 1.4em;
    background: var(--accent);
    vertical-align: text-bottom;
    animation: blink 0.8s step-end infinite;
    margin-left: 2px;
}
@keyframes blink { 50% { opacity:0; } }

/* Tokens */
.token {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    background: var(--card);
    border: 1px solid var(--border);
    font-size: 0.95rem;
    opacity: 0;
    animation: pop 0.3s cubic-bezier(.175,.885,.32,1.275) forwards;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: default;
    position: relative;
}
.token:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.token.highlight {
    border-color: var(--accent) !important;
    box-shadow: 0 0 12px var(--accent-glow) !important;
    z-index: 10;
}
.token.special {
    background: var(--orange);
    border-color: var(--orange);
    color: #000;
    font-weight: 600;
}

/* Token IDs */
.tid {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--green);
    font-weight: 700;
    font-size: 0.9rem;
    opacity: 0;
    animation: flip 0.35s ease forwards;
}

/* Vectors */
.vec {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
    min-width: 52px;
    align-items: center;
    opacity: 0;
    animation: pop 0.3s ease forwards;
}
.vec-cell {
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 2px;
    width: 100%;
    text-align: center;
    color: var(--text2);
}
.vec-cell.pos { background: rgba(99,102,241,0.18); color: var(--accent2); }
.vec-cell.neg { background: rgba(248,113,113,0.15); color: var(--red); }
.vec-label {
    font-size: 0.7rem;
    color: var(--text3);
    text-align: center;
    margin-bottom: 4px;
}

/* Math operator */
.op {
    font-size: 1.5rem;
    color: var(--text3);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* Status message */
.status {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--accent2);
    text-align: center;
    width: 100%;
    min-height: 1.2em;
    animation: fadeIn 0.3s;
}

/* Info box */
.info-box {
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.15);
    border-radius: var(--radius);
    padding: 14px 18px;
    font-size: 0.85rem;
    color: var(--text2);
    line-height: 1.6;
    width: 100%;
    max-width: 700px;
}
.info-box b { color: var(--text); }

/* Vocab popup */
.vocab-popup {
    position: absolute;
    background: var(--card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 8px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;
    font-family: var(--mono);
    font-size: 0.8rem;
    min-width: 180px;
    animation: slideUp 0.25s ease;
}
.vocab-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 14px;
    color: var(--text3);
}
.vocab-row.hl {
    background: rgba(99,102,241,0.12);
    color: var(--accent2);
    font-weight: 700;
}

/* Embedding matrix */
.matrix {
    display: flex;
    flex-direction: column;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    padding: 4px;
    position: relative;
}
.matrix-label {
    font-size: 0.75rem;
    color: var(--text3);
    text-align: center;
    margin-bottom: 6px;
}
.mrow {
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: 2px;
    transition: background 0.3s;
}
.mrow.hl {
    background: rgba(99,102,241,0.15);
    box-shadow: 0 0 0 1px var(--accent);
}
.mcell {
    width: 36px; height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    border-radius: 2px;
    background: var(--card);
    color: var(--text3);
}

/* Attention heatmap */
.attn-grid {
    display: grid;
    gap: 3px;
    padding: 8px;
    background: var(--bg2);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.attn-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 3px;
    transition: background 0.5s;
    position: relative;
    min-width: 28px;
    min-height: 28px;
}
.attn-label {
    font-size: 0.7rem;
    color: var(--text3);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60px;
}
.attn-label.side {
    writing-mode: horizontal-tb;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
}

/* FFN diagram */
.ffn-layer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    transition: border-color 0.3s, box-shadow 0.3s;
    min-width: 120px;
}
.ffn-layer.active {
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}
.ffn-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
}
.ffn-sub {
    font-size: 0.65rem;
    color: var(--text3);
}
.ffn-nodes {
    display: flex;
    gap: 3px;
    margin: 4px 0;
}
.ffn-node {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text3);
    transition: background 0.3s, box-shadow 0.3s;
}
.ffn-node.lit {
    background: var(--accent2);
    box-shadow: 0 0 6px var(--accent-glow);
}

/* Arrow connector */
.arrow {
    font-size: 1.6rem;
    color: var(--text3);
    display: flex;
    align-items: center;
    padding: 0 8px;
}
.arrow-down {
    font-size: 1.4rem;
    color: var(--text3);
    text-align: center;
    padding: 4px 0;
}

/* Probability bars */
.prob-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 10px;
}
.prob-word {
    width: 80px;
    text-align: right;
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--text2);
}
.prob-bar-bg {
    flex: 1;
    height: 26px;
    background: var(--card);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.prob-bar {
    height: 100%;
    border-radius: var(--radius-sm);
    width: 0%;
    transition: width 1s cubic-bezier(.4,0,.2,1);
}
.prob-bar.top { background: linear-gradient(90deg, var(--green), var(--cyan)); }
.prob-bar.other { background: var(--accent); opacity: 0.6; }
.prob-pct {
    width: 52px;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text3);
}

/* Transformer block diagram */
.block-diagram {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 500px;
}
.block-box {
    width: 100%;
    padding: 14px 20px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    text-align: center;
    font-family: var(--mono);
    font-size: 0.85rem;
    transition: all 0.4s;
    position: relative;
}
.block-box .dim {
    font-size: 0.7rem;
    color: var(--text3);
    margin-top: 2px;
}
.block-box.glow {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
    background: rgba(99,102,241,0.06);
}
.block-box.glow-green {
    border-color: var(--green);
    box-shadow: 0 0 20px var(--green-glow);
    background: rgba(52,211,153,0.04);
}
.block-repeat {
    font-size: 0.8rem;
    color: var(--accent2);
    padding: 6px 16px;
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    background: rgba(99,102,241,0.04);
}
.residual-arrow {
    position: absolute;
    right: -36px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    color: var(--text3);
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

/* Layer stack for step 8 */
.layer-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 400px;
}
.layer-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    transition: all 0.4s;
    font-size: 0.8rem;
}
.layer-bar .num {
    font-family: var(--mono);
    font-weight: 700;
    color: var(--text3);
    min-width: 24px;
}
.layer-bar .lbl {
    flex: 1;
    color: var(--text2);
}
.layer-bar .indicator {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s;
}
.layer-bar.processing {
    border-color: var(--accent);
    background: rgba(99,102,241,0.05);
}
.layer-bar.processing .indicator {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    animation: pulse 0.8s infinite;
}
.layer-bar.done {
    border-color: var(--green);
    background: rgba(52,211,153,0.03);
}
.layer-bar.done .indicator {
    background: var(--green);
}
.layer-bar.done .num {
    color: var(--green);
}

/* Generation output */
.gen-output {
    font-family: var(--mono);
    font-size: 1.1rem;
    line-height: 1.8;
    padding: 20px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 700px;
    min-height: 80px;
}
.gen-prompt { color: var(--text2); }
.gen-new { color: var(--green); }
.gen-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--green);
    vertical-align: text-bottom;
    animation: blink 0.6s step-end infinite;
    margin-left: 1px;
}

/* QKV visualization */
.qkv-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
}
.qkv-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.qkv-label {
    font-family: var(--mono);
    font-weight: 700;
    font-size: 0.9rem;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
}
.qkv-label.q { color: var(--cyan); background: rgba(34,211,238,0.1); }
.qkv-label.v { color: var(--pink); background: rgba(244,114,182,0.1); }
.qkv-label.k { color: var(--yellow); background: rgba(251,191,36,0.1); }

/* ============================================================
   TOOLTIPS
   ============================================================ */
/* Wrapper that holds the element + tooltip */
[data-tip] {
    position: relative;
    cursor: help;
}
[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: #1e2536;
    color: var(--text2);
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.5;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border-hi);
    box-shadow: 0 8px 30px rgba(0,0,0,0.45);
    white-space: normal;
    width: max-content;
    max-width: 300px;
    z-index: 500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
[data-tip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
/* Variant: tooltip below */
[data-tip].tip-below::after {
    bottom: auto;
    top: calc(100% + 8px);
    transform: translateX(-50%) translateY(-4px);
}
[data-tip].tip-below:hover::after {
    transform: translateX(-50%) translateY(0);
}
/* Variant: tooltip left-aligned */
[data-tip].tip-left::after {
    left: 0;
    transform: translateX(0) translateY(4px);
}
[data-tip].tip-left:hover::after {
    transform: translateX(0) translateY(0);
}
/* Variant: tooltip right-aligned */
[data-tip].tip-right::after {
    left: auto;
    right: 0;
    transform: translateX(0) translateY(4px);
}
[data-tip].tip-right:hover::after {
    transform: translateX(0) translateY(0);
}

/* ---- Animations ---- */
@keyframes fadeIn   { from { opacity:0; } to { opacity:1; } }
@keyframes pop      { 0%   { transform:scale(0.8); opacity:0; } 100% { transform:scale(1); opacity:1; } }
@keyframes flip     { 0%   { transform:rotateX(90deg); opacity:0; } 100% { transform:rotateX(0); opacity:1; } }
@keyframes slideUp  { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes pulse    { 0%,100% { opacity:1; } 50% { opacity:0.4; } }
@keyframes slideIn  { from { opacity:0; transform:translateX(-10px); } to { opacity:1; transform:translateX(0); } }

/* ---- Responsive ---- */
@media (max-width: 700px) {
    .walkthrough { padding: 12px 10px; }
    .stage-wrap { padding: 14px; min-height: 260px; }
    .specs { gap: 16px; }
    .qkv-container { gap: 10px; }
    .attn-cell { min-width: 20px; min-height: 20px; }
    .block-diagram { max-width: 100%; }
    .gen-output { font-size: 0.95rem; }
}
