/* Neuroscope — Dark "brain scanner" theme */

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

body {
    background: #1a1a2e;
    color: #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

header {
    margin-bottom: 24px;
    border-bottom: 1px solid #333;
    padding-bottom: 12px;
}

header h1 {
    font-size: 1.8em;
    color: #7ecfff;
}

header .subtitle {
    color: #888;
    font-weight: 300;
}

.model-info {
    color: #666;
    font-size: 0.85em;
    margin-top: 4px;
}

/* Input area */
.input-area {
    margin-bottom: 20px;
}

.input-area textarea {
    width: 100%;
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 12px;
    font-size: 1em;
    font-family: "Fira Code", "Cascadia Code", monospace;
    resize: vertical;
}

.input-area textarea:focus {
    outline: none;
    border-color: #7ecfff;
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

#analyze-btn {
    background: #0f3460;
    color: #7ecfff;
    border: 1px solid #7ecfff;
    padding: 8px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.2s;
}

#analyze-btn:hover {
    background: #1a4a7a;
}

#analyze-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#status-text {
    color: #888;
    font-size: 0.9em;
}

/* Token bar */
.token-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-bottom: 16px;
    padding: 8px;
    background: #16213e;
    border-radius: 6px;
}

.token-bar .token {
    font-family: "Fira Code", "Cascadia Code", monospace;
    font-size: 0.85em;
    padding: 2px 4px;
    background: #0f3460;
    border-radius: 3px;
    color: #7ecfff;
    white-space: pre;
}

.token-bar .token-idx {
    font-size: 0.65em;
    color: #555;
    vertical-align: super;
    margin-left: 1px;
}

/* Tab navigation */
.tab-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid #333;
    padding-bottom: 0;
}

.tab {
    background: transparent;
    color: #888;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.95em;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    color: #bbb;
}

.tab.active {
    color: #7ecfff;
    border-bottom-color: #7ecfff;
}

.tab-export {
    margin-left: auto;
    background: transparent;
    color: #888;
    border: 1px solid #444;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
}

.tab-export:hover {
    color: #e0e0e0;
    border-color: #666;
}

/* Panels */
.panel {
    animation: fadeIn 0.3s ease;
}

.panel.hidden {
    display: none;
}

.panel h2 {
    color: #7ecfff;
    font-size: 1.2em;
    margin-bottom: 4px;
}

.panel h3 {
    color: #ccc;
    font-size: 1em;
    margin: 20px 0 8px;
}

.panel-desc {
    color: #777;
    font-size: 0.85em;
    margin-bottom: 12px;
}

/* Logit Lens heatmap grid */
.logit-grid {
    overflow-x: auto;
    margin: 12px 0;
}

.logit-grid table {
    border-collapse: collapse;
    font-size: 0.75em;
    font-family: "Fira Code", "Cascadia Code", monospace;
}

.logit-grid th {
    padding: 4px 6px;
    color: #888;
    font-weight: normal;
    white-space: nowrap;
    position: sticky;
    background: #1a1a2e;
}

.logit-grid th.layer-label {
    text-align: right;
    left: 0;
    z-index: 1;
}

.logit-grid th.token-label {
    writing-mode: vertical-lr;
    text-orientation: mixed;
    transform: rotate(180deg);
    max-height: 80px;
    overflow: hidden;
    top: 0;
}

.logit-grid td {
    padding: 3px 5px;
    text-align: center;
    cursor: pointer;
    white-space: nowrap;
    min-width: 50px;
    position: relative;
    transition: outline 0.1s;
}

.logit-grid td:hover {
    outline: 1px solid #7ecfff;
    z-index: 1;
}

/* Tooltip */
.cell-tooltip {
    position: fixed;
    background: #16213e;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 10px;
    font-size: 0.85em;
    z-index: 100;
    pointer-events: none;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.cell-tooltip .tt-header {
    color: #7ecfff;
    margin-bottom: 6px;
    font-weight: bold;
}

.cell-tooltip .tt-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0;
}

.cell-tooltip .tt-bar {
    height: 8px;
    background: #7ecfff;
    border-radius: 2px;
    transition: width 0.2s;
}

.cell-tooltip .tt-token {
    color: #e0e0e0;
    font-family: "Fira Code", monospace;
    min-width: 80px;
}

.cell-tooltip .tt-prob {
    color: #888;
    font-size: 0.9em;
    min-width: 40px;
    text-align: right;
}

/* Evolution chart */
.evolution-chart {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 600px;
}

.evo-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
}

.evo-layer {
    width: 50px;
    text-align: right;
    color: #888;
}

.evo-bar-wrap {
    flex: 1;
    height: 22px;
    background: #16213e;
    border-radius: 3px;
    overflow: hidden;
}

.evo-bar {
    height: 100%;
    border-radius: 3px;
    display: flex;
    align-items: center;
    padding-left: 6px;
    font-family: "Fira Code", monospace;
    font-size: 0.85em;
    color: #fff;
    white-space: nowrap;
}

.evo-prob {
    width: 45px;
    text-align: right;
    color: #888;
    font-size: 0.85em;
}

/* Final prediction */
.final-prediction {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.final-pred-item {
    background: #16213e;
    padding: 6px 12px;
    border-radius: 4px;
    font-family: "Fira Code", monospace;
    font-size: 0.9em;
}

.final-pred-item .pred-prob {
    color: #7ecfff;
    margin-left: 4px;
}

/* Attention section */
.attention-controls {
    display: flex;
    gap: 16px;
    margin: 12px 0;
}

.attention-controls label {
    color: #888;
    font-size: 0.9em;
}

.attention-controls select {
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 8px;
    margin-left: 4px;
}

.attention-layout {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 800px) {
    .attention-layout {
        grid-template-columns: 1fr;
    }
}

.attention-matrix-wrap {
    position: relative;
}

#attn-canvas {
    background: #16213e;
    border-radius: 4px;
    cursor: crosshair;
}

.attn-tooltip {
    position: fixed;
    background: #16213e;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.85em;
    font-family: "Fira Code", monospace;
    z-index: 100;
    pointer-events: none;
}

/* Head overview grid — columns set dynamically by JS for model flexibility */
.head-overview {
    display: grid;
    grid-template-columns: auto repeat(16, 1fr);
    gap: 2px;
    font-size: 0.75em;
}

.head-overview .ho-label {
    color: #888;
    padding: 4px;
    text-align: center;
}

.head-overview .ho-cell {
    width: 32px;
    height: 32px;
    border-radius: 3px;
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
}

.head-overview .ho-cell:hover {
    transform: scale(1.2);
    z-index: 1;
    outline: 1px solid #fff;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 2px;
    vertical-align: middle;
}

/* 3D Volume view */
.view3d-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 12px 0;
    flex-wrap: wrap;
}

.view3d-controls label {
    color: #888;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.view3d-controls select {
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 8px;
}

.view3d-controls input[type="range"] {
    width: 140px;
    accent-color: #7ecfff;
}

.view3d-controls span {
    color: #888;
    font-size: 0.85em;
    min-width: 80px;
}

#view3d-play-btn {
    background: #0f3460;
    color: #7ecfff;
    border: 1px solid #7ecfff;
    padding: 5px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

#view3d-play-btn:hover {
    background: #1a4a7a;
}

.view3d-container {
    width: 100%;
    height: 520px;
    background: #12121f;
    border-radius: 6px;
    overflow: hidden;
}

.view3d-container canvas {
    border-radius: 6px;
}

/* Utilities */
.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #16213e;
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ── Thinking 3D ── */

.thinking3d-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
}

.thinking3d-controls button {
    background: #0f3460;
    color: #7ecfff;
    border: 1px solid #7ecfff;
    padding: 6px 18px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.2s;
}

.thinking3d-controls button:hover {
    background: #1a4a7a;
}

.thinking3d-controls span {
    color: #888;
    font-size: 0.85em;
}

.thinking3d-container {
    width: 100%;
    height: 560px;
    background: #08081a;
    border-radius: 6px;
    overflow: hidden;
}

.thinking3d-container canvas {
    border-radius: 6px;
}

/* ── Contrastive Mode ── */

.mode-toggle {
    background: transparent;
    color: #888;
    border: 1px solid #444;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

.mode-toggle:hover {
    color: #e0e0e0;
    border-color: #666;
}

.mode-toggle.active {
    background: #0f3460;
    color: #7ecfff;
    border-color: #7ecfff;
}

/* Contrastive input area */
.contrastive-input {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px;
    background: #16213e;
    border-radius: 6px;
    border: 1px solid #333;
}

.contrastive-input textarea {
    width: 100%;
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 10px;
    font-size: 0.95em;
    font-family: "Fira Code", "Cascadia Code", monospace;
    resize: vertical;
}

.contrastive-input textarea:focus {
    outline: none;
    border-color: #7ecfff;
}

.contrastive-controls {
    grid-column: 1 / -1;
    display: flex;
    gap: 12px;
    align-items: center;
}

.contrastive-controls button {
    background: #0f3460;
    color: #7ecfff;
    border: 1px solid #7ecfff;
    padding: 8px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.2s;
}

.contrastive-controls button:hover {
    background: #1a4a7a;
}

.contrastive-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* A/B color coding */
.prompt-a-color {
    color: #00e5ff;
}

.prompt-b-color {
    color: #ff9800;
}

.contrastive-label {
    display: block;
    font-weight: bold;
    font-size: 0.85em;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Decision banner */
.decision-banner {
    background: #0a2a3e;
    border: 1px solid #00e5ff;
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.95em;
    line-height: 1.6;
}

.decision-banner strong {
    color: #00e5ff;
}

.decision-banner .dp-token-a {
    color: #00e5ff;
    font-family: "Fira Code", monospace;
}

.decision-banner .dp-token-b {
    color: #ff9800;
    font-family: "Fira Code", monospace;
}

/* Contrastive subtabs */
.contrastive-subtabs {
    display: flex;
    gap: 2px;
    margin-bottom: 16px;
    background: #16213e;
    border-radius: 6px;
    padding: 3px;
}

.contrastive-subtab {
    background: transparent;
    color: #888;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}

.contrastive-subtab:hover {
    color: #bbb;
}

.contrastive-subtab.active {
    background: #0f3460;
    color: #7ecfff;
}

/* Contrastive sub-panels */
.contrastive-subpanel.hidden {
    display: none;
}

.contrastive-subpanel h3 {
    color: #ccc;
    font-size: 1em;
    margin-bottom: 4px;
}

.contrastive-subpanel h4 {
    font-size: 0.9em;
    margin-bottom: 6px;
}

/* Attention side-by-side */
.attn-side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.attn-side-by-side canvas {
    background: #16213e;
    border-radius: 4px;
    width: 100%;
    height: auto;
}

@media (max-width: 900px) {
    .attn-side-by-side {
        grid-template-columns: 1fr;
    }
}

/* Evolution comparison */
.evolution-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 800px) {
    .evolution-comparison {
        grid-template-columns: 1fr;
    }
    .contrastive-input {
        grid-template-columns: 1fr;
    }
}
