/* ── Theme Variables ─────────────────────────────────────────── */
:root {
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --max-width: 1100px;
    --radius: 8px;
}

[data-theme="dark"] {
    --bg: #0d1117;
    --bg-card: #161b22;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --border: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --nav-bg: #010409;
}

[data-theme="light"] {
    --bg: #f6f8fa;
    --bg-card: #ffffff;
    --text: #1f2328;
    --text-muted: #656d76;
    --border: #d0d7de;
    --accent: #0969da;
    --accent-hover: #0550ae;
    --nav-bg: #ffffff;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Nav ─────────────────────────────────────────────────────── */
nav {
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}
.nav-brand:hover { text-decoration: none; color: var(--accent); }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.nav-links a { font-size: 0.9rem; }

/* ── Nav Models Dropdown ─────────────────────────────────────── */
.nav-models-dropdown { position: relative; }

.nav-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.25rem 0.65rem;
    cursor: pointer;
    font-family: var(--font);
    transition: color 0.12s, border-color 0.12s;
    white-space: nowrap;
}
.nav-dropdown-btn:hover { color: var(--accent); border-color: var(--accent); }
.nav-dropdown-arrow { font-size: 0.7rem; }

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    min-width: 220px;
    max-height: 380px;
    overflow-y: auto;
    background: var(--nav-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    z-index: 200;
    padding: 0.35rem 0;
}
.nav-dropdown-menu[hidden] { display: none; }
.nav-dropdown-menu a {
    display: block;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.nav-dropdown-menu a:hover {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
    text-decoration: none;
}

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
}

/* ── Main ────────────────────────────────────────────────────── */
main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

h1 { font-size: 1.8rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.3rem; margin-bottom: 1rem; color: var(--text); }
h3 { font-size: 1.1rem; margin: 1rem 0 0.5rem; color: var(--text-muted); }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    position: relative;
    max-width: 960px;
    margin: 1rem auto 0;
    padding: 0 0.5rem;
}

/* Heatmap container — wider so all columns fit comfortably */
.heatmap-container {
    max-width: 1100px;
    overflow-x: auto;
    padding: 0 0.5rem;
    margin: 1rem auto;
}
.heatmap-container canvas {
    display: block;
    margin: 0 auto;
}

/* Toggle to swap between heatmap and grouped-bar view */
details.heatmap-toggle {
    max-width: 960px;
    margin: 0.5rem auto;
    padding: 0 0.5rem;
}
details.heatmap-toggle > summary {
    cursor: pointer;
    color: #555;
    font-size: 0.85rem;
    padding: 0.3rem 0;
    user-select: none;
}
details.heatmap-toggle > summary:hover {
    color: #0366d6;
}

/* ── Temperature toggle ───────────────────────────────────── */
.temperature-toggle-bar {
    max-width: 1100px;
    margin: 1.2rem auto 0.8rem;
    padding: 0.7rem 1rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.7rem;
    background: #f5f7fa;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    font-size: 0.9rem;
}
.temp-toggle-label {
    color: #444;
    font-weight: 500;
}
.temp-toggle-group {
    display: inline-flex;
    border: 1px solid #d0d4d8;
    border-radius: 6px;
    overflow: hidden;
    background: white;
}
.temp-toggle {
    padding: 0.35rem 0.85rem;
    border: none;
    background: white;
    color: #555;
    cursor: pointer;
    font-size: 0.85rem;
    border-right: 1px solid #d0d4d8;
}
.temp-toggle:last-child { border-right: none; }
.temp-toggle:hover { background: #f0f3f6; }
.temp-toggle.active {
    background: #0366d6;
    color: white;
}
.temp-toggle-note {
    margin-left: auto;
    color: #777;
    font-size: 0.8rem;
    font-style: italic;
}

/* ── Temperature comparison section ───────────────────────── */
.temperature-card .subheading {
    margin: 1.4rem 0.5rem 0.3rem;
    font-size: 1.0rem;
    color: #222;
    font-weight: 600;
}
.temperature-card .card-description-inline {
    margin: 0 0.5rem 0.8rem;
    color: #666;
    font-size: 0.85rem;
}
.notable-flips-table .item-text {
    text-align: left;
    font-style: italic;
    color: #444;
    max-width: 32em;
}
.notable-flips-table .runs-cell .ans {
    display: inline-block;
    min-width: 1.5em;
    padding: 0.05em 0.4em;
    background: #eef2f6;
    border-radius: 3px;
    font-family: -apple-system-ui-monospace, ui-monospace, Menlo, monospace;
    font-size: 0.85em;
}
.notable-flips-table .pending {
    color: #999;
    font-size: 0.8em;
    font-style: italic;
}
.notable-flips-table .row-pending {
    opacity: 0.55;
}
.score-table .delta {
    font-family: -apple-system-ui-monospace, ui-monospace, Menlo, monospace;
}
.score-table .delta.delta-up { color: #c0392b; }
.score-table .delta.delta-down { color: #27ae60; }
.score-table .subheader-row th {
    font-weight: 400;
    color: #777;
    font-size: 0.85em;
    background: #fafafa;
}

/* ── Expandable Descriptions ────────────────────────────────── */
details.card-description {
    margin-bottom: 1.5rem;
    max-width: 800px;
}

details.card-description > summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 600;
    user-select: none;
    padding: 0.3rem 0;
    list-style: none;
}

details.card-description > summary::-webkit-details-marker { display: none; }

details.card-description > summary::before {
    content: '▸  ';
    color: var(--accent);
}

details.card-description[open] > summary::before {
    content: '▾  ';
}

details.card-description[open] > summary {
    margin-bottom: 0.75rem;
}

/* ── Card Descriptions ──────────────────────────────────────── */
.card-description {
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    max-width: 800px;
}

.card-description p {
    margin-bottom: 0.75rem;
}

.card-description ul {
    margin: 0.5rem 0 0.75rem 1.25rem;
    list-style: disc;
}

.card-description ol {
    margin: 0.5rem 0 0.75rem 1.25rem;
    list-style: decimal;
}

.card-description li {
    margin-bottom: 0.4rem;
}

.cdri-footnotes { max-width: none; margin-top: 1.5rem; }
.cdri-footnotes ol li { margin-bottom: 0.85rem; }

.card-description strong {
    color: var(--text);
}

.card-description em {
    font-style: italic;
}

.card-references {
    font-size: 0.82rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 0.6rem;
    margin-top: 0.75rem;
}

.card-references a {
    font-size: 0.82rem;
}

/* ── Personality Summary ─────────────────────────────────────── */
.summary-grid {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.summary-item .label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.summary-item .value.big {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

/* ── MBTI Grid ───────────────────────────────────────────────── */
.mbti-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.mbti-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.mbti-card h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.mbti-type {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.1em;
}

.mbti-runs {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:hover { background: var(--bg); }

tr.human-baseline {
    background: var(--accent-hover);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    font-style: italic;
}

tr.human-baseline td { color: var(--text-muted); }

code {
    font-size: 0.8rem;
    background: var(--bg);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    word-break: break-all;
}

/* ── Chart Data Tables ───────────────────────────────────────── */
details.chart-table {
    margin-top: 1.25rem;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}

details.chart-table > summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    user-select: none;
    padding: 0.3rem 0;
    list-style: none;
}

details.chart-table > summary::-webkit-details-marker { display: none; }

details.chart-table > summary::before {
    content: '▸  ';
    color: var(--accent);
}

details.chart-table[open] > summary::before { content: '▾  '; }

details.chart-table[open] > summary { margin-bottom: 0.5rem; }

table.score-table th {
    text-align: center;
    padding-top: 0.75rem;
    min-width: 90px;
}

table.score-table td { text-align: center; }

table.score-table td:first-child { text-align: left; }

.cell-mean {
    font-weight: 600;
    font-size: 0.95rem;
}

.cell-range {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Card Header (h2 + action button row) ────────────────────── */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.card-header h2 { margin-bottom: 0; }

.q-trigger {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.78rem;
    padding: 0.2rem 0.65rem;
    cursor: pointer;
    font-family: var(--font);
    white-space: nowrap;
    transition: background 0.12s;
}
.q-trigger:hover {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ── Model Filter Bar ────────────────────────────────────────── */
.filter-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 0.65rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filter-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.filter-pills {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.filter-pill {
    background: none;
    border: 1px solid var(--border);
    border-radius: 2rem;
    padding: 0.2rem 0.7rem;
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--text-muted);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    font-family: var(--font);
}

.filter-pill[data-action="all"] { border-color: var(--text-muted); }
.filter-pill[data-action="all"].active {
    background: var(--text-muted);
    color: var(--bg);
}

.filter-pill[data-slug] { border-color: var(--mc, var(--border)); }
.filter-pill[data-slug].active {
    background: color-mix(in srgb, var(--mc, var(--accent)) 18%, transparent);
    color: var(--text);
    border-color: var(--mc, var(--accent));
}

.filter-pill-deselect {
    border-color: var(--text-muted);
    opacity: 0.7;
}
.filter-pill-deselect:hover { opacity: 1; }

/* ── Question Viewer Modal ───────────────────────────────────── */
.q-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.q-modal-overlay[hidden] { display: none; }

.q-modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 720px;
    width: 100%;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

.q-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.q-modal-header h3 { margin: 0; font-size: 1rem; }

#q-modal-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    line-height: 1;
}
#q-modal-close:hover { color: var(--text); background: var(--bg); }

.q-modal-body {
    overflow-y: auto;
    padding: 1rem 1.25rem;
    flex: 1;
}

/* Question list */
.q-list { display: flex; flex-direction: column; gap: 0; }

.q-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}
.q-item:last-child { border-bottom: none; }
.q-item-sub { padding: 0.45rem 0; }

.q-num {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 1.6rem;
    text-align: right;
    padding-top: 0.15rem;
    flex-shrink: 0;
}

.q-body { flex: 1; min-width: 0; }

.q-preamble {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 0.3rem;
}

.q-text {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    line-height: 1.5;
}

.q-choices {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.4rem;
}

.q-choice {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}
.q-biased { color: var(--text); }

.q-letter {
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--accent);
    min-width: 1rem;
    flex-shrink: 0;
}

.q-arrow {
    color: var(--accent);
    font-size: 0.75rem;
    font-style: italic;
}

.q-bias-tag {
    font-size: 0.68rem;
    background: color-mix(in srgb, #f97583 15%, transparent);
    color: #f97583;
    border: 1px solid #f97583;
    border-radius: 3px;
    padding: 0.05rem 0.3rem;
    white-space: nowrap;
}

.q-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 0.3rem;
}

.q-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.2rem;
}

.q-tag {
    font-size: 0.7rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.1rem 0.4rem;
    color: var(--text-muted);
}

/* Self-consistency pairs */
.q-pair {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    overflow: hidden;
}
.q-pair-header {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.q-pair .q-item { padding: 0.45rem 0.75rem; }
.q-pair .q-item:last-child { border-bottom: none; }

/* ── MBTI Dimension Bars ─────────────────────────────────────── */
.mbti-dims {
    margin-top: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    text-align: left;
}

.mbti-dim-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
}

.mbti-pole {
    font-weight: 700;
    font-size: 0.72rem;
    min-width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

.mbti-pole-pref { color: var(--accent); }
.mbti-pole-other { color: var(--text-muted); }

.mbti-bar-track {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    min-width: 0;
}

.mbti-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.mbti-pct-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    min-width: 2.4rem;
    text-align: right;
    flex-shrink: 0;
}

/* ── Heatmap cells ───────────────────────────────────────────── */
.steer-cell, .cdri-cell {
    font-variant-numeric: tabular-nums;
    transition: background 0.2s;
}

/* ── CDRI Section ────────────────────────────────────────────── */
.cdri-entry td:nth-child(3) { font-variant-numeric: tabular-nums; }

/* ── Footer ──────────────────────────────────────────────────── */
footer {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* ── Primer Conversation Chat UI ─────────────────────────────── */
.primer-block {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    overflow: hidden;
}
.primer-block[open] .primer-summary {
    border-bottom: 1px solid var(--border);
}
.primer-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: var(--bg);
}
.primer-summary::-webkit-details-marker { display: none; }
.primer-summary:hover { background: color-mix(in srgb, var(--accent) 6%, var(--bg)); }
.primer-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.primer-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.primer-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
.primer-convo {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
}
.chat-turn {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}
.chat-turn--user {
    align-self: flex-end;
    align-items: flex-end;
}
.chat-turn--assistant {
    align-self: flex-start;
    align-items: flex-start;
}
.chat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
.chat-bubble {
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-turn--user .chat-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 3px;
}
.chat-turn--assistant .chat-bubble {
    background: color-mix(in srgb, var(--border) 60%, var(--bg));
    border-bottom-left-radius: 3px;
}
.primer-length-marker {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.4rem 0;
    border-top: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    margin: 0.25rem 0;
}

/* ── Acquiescence Flag ───────────────────────────────────────── */
.acquiescence-flag {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    color: #f85149;
    background: color-mix(in srgb, #f85149 12%, transparent);
    border: 1px solid #f85149;
    border-radius: 3px;
    padding: 0.05rem 0.35rem;
    cursor: help;
    white-space: nowrap;
    letter-spacing: 0.03em;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 640px) {
    main { padding: 1rem; }
    .card { padding: 1rem; }
    .summary-grid { gap: 1rem; }
    .summary-item .value.big { font-size: 1.5rem; }
    h1 { font-size: 1.4rem; }
}
