/* ========== TOKENS ========== */
:root {
    --bg-0: #07080d;
    --bg-1: #0d1018;
    --bg-2: #131826;
    --bg-3: #1a2236;
    --line: #1f2a44;
    --line-strong: #2c3a5c;
    --fg-0: #e6ecff;
    --fg-1: #aab4d4;
    --fg-2: #6b7699;
    --fg-3: #3a4570;

    --accent-in: #6ec8ff;     /* input/context */
    --accent-mid: #b48aff;    /* transformer */
    --accent-out: #5cf2c0;    /* output */
    --accent-warn: #ffb86b;
    --accent-pick: #ffe663;   /* sampled token glow */

    --grad-in: linear-gradient(135deg, #2a4d7a, #6ec8ff);
    --grad-mid: linear-gradient(135deg, #4a3a7e, #b48aff);
    --grad-out: linear-gradient(135deg, #1f6f59, #5cf2c0);

    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --font-ui: -apple-system, "Inter", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 1920px;
    height: 1080px;
    background: var(--bg-0);
    color: var(--fg-0);
    font-family: var(--font-ui);
    overflow: hidden;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

#app {
    width: 1920px;
    height: 1080px;
    position: relative;
    background: radial-gradient(ellipse at top, #0c1224 0%, var(--bg-0) 70%);
    display: grid;
    grid-template-rows: 60px 1fr 250px;
}

/* ========== HEADER ========== */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-1);
}
.header-left, .header-right { display: flex; align-items: center; gap: 16px; }
.label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.2em;
    color: var(--fg-2);
    text-transform: uppercase;
}
.prompt-text {
    font-family: var(--font-mono);
    font-size: 18px;
    color: var(--fg-0);
    max-width: 1200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.script-name {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--fg-1);
    letter-spacing: 0.1em;
}
.cycle-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent-out);
    box-shadow: 0 0 12px var(--accent-out);
    animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* ========== STAGE ========== */
#stage {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0;
    padding: 24px;
}
#stage-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.panel {
    position: relative;
    z-index: 2;
    background: rgba(13, 16, 24, 0.55);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px 20px;
    margin: 8px;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(2px);
}
.panel h2 {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.22em;
    color: var(--fg-2);
    margin-bottom: 14px;
    text-transform: uppercase;
}
.panel-meta {
    display: flex;
    gap: 18px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--fg-2);
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.panel-meta em { color: var(--fg-0); font-style: normal; }

/* Panel accents */
.panel-context { border-color: rgba(110, 200, 255, 0.18); }
.panel-process { border-color: rgba(180, 138, 255, 0.18); }
.panel-output  { border-color: rgba(92, 242, 192, 0.18); }

/* ========== TOKEN STREAMS ========== */
.token-stream {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-content: flex-start;
    flex: 1;
    overflow: hidden;
    line-height: 1.7;
}
.tok {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 14px;
    padding: 3px 8px;
    border-radius: 5px;
    background: var(--bg-3);
    color: var(--fg-0);
    border: 1px solid var(--line-strong);
    white-space: pre;
    transition: transform 0.25s ease, opacity 0.25s ease, background 0.25s, box-shadow 0.25s;
}
.tok.in { background: rgba(110, 200, 255, 0.14); border-color: rgba(110, 200, 255, 0.4); color: #d4ecff; }
.tok.gen { background: rgba(92, 242, 192, 0.14); border-color: rgba(92, 242, 192, 0.4); color: #c9fbe6; }
.tok.ws { color: var(--fg-3); letter-spacing: 0.1em; }
.tok .lead { color: var(--fg-3); margin-right: 1px; }
.tok.attended {
    background: rgba(255, 230, 99, 0.18);
    border-color: rgba(255, 230, 99, 0.7);
    box-shadow: 0 0 12px rgba(255, 230, 99, 0.45);
}
.tok.appearing {
    animation: tok-in 0.4s ease-out;
}
@keyframes tok-in {
    from { opacity: 0; transform: translateY(-8px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.tok.just-picked {
    animation: tok-pick 0.6s ease-out;
}
@keyframes tok-pick {
    0% { transform: scale(1.4); box-shadow: 0 0 24px var(--accent-pick); background: var(--accent-pick); color: #000; }
    100% { transform: scale(1); }
}

.output-stream-wrap {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.output-stream-wrap .label { display: block; margin-bottom: 8px; }
.token-stream.output { min-height: 80px; }

/* ========== TRANSFORMER PANEL ========== */
.layer-stack {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
}
.layer {
    flex: 1;
    background: linear-gradient(90deg, rgba(180,138,255,0.04), rgba(180,138,255,0.10), rgba(180,138,255,0.04));
    border: 1px solid rgba(180, 138, 255, 0.18);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
}
.layer-fill {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(110,80,200,0.0), rgba(180,138,255,0.6), rgba(110,80,200,0.0));
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
    transition: transform 0.35s ease-out, opacity 0.35s ease-out, background 0.5s;
}
.layer-label {
    position: relative;
    z-index: 2;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--fg-3);
    margin-left: 10px;
    letter-spacing: 0.1em;
}
.layer.active .layer-fill {
    transform: scaleX(1);
    opacity: 1;
    background: linear-gradient(90deg, rgba(110,80,200,0.0), rgba(220,180,255,0.85), rgba(180,138,255,0.4));
    box-shadow: 0 0 16px rgba(180, 138, 255, 0.6);
}
.layer.active .layer-label { color: #e6d5ff; }
.attention-bands {
    height: 60px;
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
}
.attn-head {
    background: var(--bg-3);
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}
.attn-head-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(180deg, var(--accent-mid), #6e4ec0);
    transition: height 0.3s ease;
}

/* ========== PROBABILITY BARS ========== */
.prob-bars {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
    justify-content: flex-start;
}
.prob-row {
    display: grid;
    grid-template-columns: 130px 1fr 70px;
    align-items: center;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 14px;
    transition: opacity 0.3s;
    min-height: 28px;
}
.prob-row .pname {
    color: var(--fg-1);
    white-space: pre;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
}
.prob-row .pbar {
    height: 22px;
    background: var(--bg-2);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}
.prob-row .pfill {
    height: 100%;
    background: linear-gradient(90deg, #2c5e7e, var(--accent-in));
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.prob-row .ppct {
    color: var(--fg-2);
    text-align: right;
}
.prob-row.picked .pname { color: var(--accent-pick); font-weight: 600; }
.prob-row.picked .pfill { background: linear-gradient(90deg, #b89a2e, var(--accent-pick)); }
.prob-row.picked .ppct { color: var(--accent-pick); }

/* ========== TECH STRIP ========== */
#tech-strip {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr 1.6fr 1fr;
    gap: 1px;
    background: var(--line);
    border-top: 1px solid var(--line-strong);
}
.tech-block {
    background: var(--bg-1);
    padding: 14px 20px;
    overflow: hidden;
}
.tech-block h3 {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.22em;
    color: var(--fg-2);
    margin-bottom: 10px;
    text-transform: uppercase;
}

#logprob-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
}
#logprob-table td {
    padding: 2px 8px 2px 0;
    color: var(--fg-1);
}
#logprob-table tr.picked td { color: var(--accent-pick); }
#logprob-table .lp-tok { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logprob-table .lp-val { text-align: right; }

.gauge {
    height: 10px;
    background: var(--bg-2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}
.gauge-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-out), var(--accent-warn), #ff6b6b);
    width: 0%;
    transition: width 0.4s ease;
}
.tech-stat {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--fg-1);
    margin-bottom: 4px;
}
.tech-stat label { color: var(--fg-2); margin-right: 8px; }
.tech-stat em { font-style: normal; color: var(--fg-0); }
.tech-stat.large { font-size: 22px; color: var(--fg-0); margin-bottom: 8px; }
.tech-stat.large em { color: var(--fg-0); }

/* attention heatmap */
.attn-heatmap {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 2px;
    height: 110px;
    align-items: end;
}
.attn-cell {
    background: rgba(110, 200, 255, 0.1);
    border-radius: 2px;
    position: relative;
    transition: background 0.3s;
    min-height: 4px;
}
.attn-cell .attn-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(180deg, var(--accent-pick), var(--accent-in));
    transition: height 0.4s ease;
}
.attn-cell .attn-lbl {
    position: absolute;
    bottom: -16px; left: 0; right: 0;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--fg-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
