/* ===== Theme Variables (shared vocabulary with ../venn-in-doubt) ===== */
:root {
    --bg: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-raised: #f1f3f5;
    --text: #333;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --border-hover: #adb5bd;
    --accent: #339af0;
    --good: #2b8a3e;
    --good-bg: #d3f9d8;
    --bad: #c92a2a;
    --bad-bg: #ffe3e3;
    --shadow-sm: rgba(0, 0, 0, 0.08);
    --shadow-md: rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --bg-surface: #16213e;
    --bg-raised: #1e2a4a;
    --text: #eee;
    --text-muted: #a3adc2;
    --border: #2a3a5e;
    --border-hover: #3a4a6e;
    --accent: #4dabf7;
    --good: #8ce99a;
    --good-bg: #1c3b23;
    --bad: #ffa8a8;
    --bad-bg: #45201f;
    --shadow-sm: rgba(0, 0, 0, 0.3);
    --shadow-md: rgba(0, 0, 0, 0.45);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: 16px 20px 48px;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 100;
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    line-height: 0;
    cursor: pointer;
}

.theme-toggle:hover { color: var(--text); border-color: var(--border-hover); }
.theme-toggle .icon { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ===== Top bar ===== */
.topbar {
    max-width: 1080px;
    margin: 0 auto 18px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-right: 44px;
}

.topbar h1 {
    font-size: 1.5rem;
    letter-spacing: -0.02em;
}

/* Title and instruction read as one line, divided by a rule; the stats stay on the far side. */
.title-group {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 14px;
}

.stats { display: flex; gap: 18px; }

.stat {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.stat-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.negative { color: var(--bad); }

/* Progress through the level's three tasks. Dots have no baseline of their own to sit on. */
.dots {
    display: flex;
    align-self: center;
    gap: 7px;
}

.dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.25s ease;
}

.dot.solved { background: var(--good); }

/* Which task is in hand — a skipped one stays grey, so the dots alone would not say. */
.dot.current { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--border-hover); }
.dot.current.solved { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--good); }

main {
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ===== Diagram ===== */
.stage {
    position: relative;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    aspect-ratio: 1.45;
    /* 100px off the 690 the ratio gives at full width. A cap rather than a taller ratio: below
       856px the ratio already yields less than this, and shrinking there crowds the captions. */
    max-height: 590px;
}

#venn { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.labels { position: absolute; inset: 0; pointer-events: none; }

/* Captions are pinned to a point on their ellipse's rim; JS sets left/top/transform. */
.set-label {
    position: absolute;
    max-width: min(172px, var(--gutter-x, 172px));
    font-size: 0.78rem;
    line-height: 1.25;
    font-weight: 600;
    color: hsl(var(--hue), 68%, 34%);
    text-wrap: balance;
}

/* Above and below the diagram there is the whole stage width to spread into. */
.set-label.wide { max-width: 260px; }

[data-theme="dark"] .set-label { color: hsl(var(--hue), 72%, 70%); }

.none-label {
    position: absolute;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text);
}

/* ===== Prompt ===== */
/* The instruction leads the page; the running commentary stays down by the words it is about. */
.prompt-line {
    font-size: 1.05rem;
    color: var(--text);
}

.prompt-line::before {
    content: '|';
    margin-right: 14px;
    color: var(--border);
    font-weight: 400;
}

.highlight-word {
    color: #3a2a00;
    background: rgba(255, 186, 8, 0.9);
    box-shadow: inset 0 0 0 1px rgba(163, 91, 0, 0.7);
    padding: 1px 6px;
    border-radius: 4px;
}

.feedback {
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    min-height: 1.4em;
}

.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

/* ===== Word board ===== */
.board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.word {
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 11px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-surface);
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 1px 2px var(--shadow-sm);
    transition: transform 0.08s, border-color 0.12s, background 0.12s;
}

.word:hover:not(:disabled) { border-color: var(--border-hover); transform: translateY(-1px); }
.word:active:not(:disabled) { transform: translateY(0); }

.word.wrong {
    background: var(--bad-bg);
    border-color: var(--bad);
    color: var(--bad);
    animation: shake 0.3s;
}

.word.used {
    background: var(--good-bg);
    border-color: var(--good);
    color: var(--good);
    cursor: default;
    box-shadow: none;
}

.word.revealed {
    background: var(--bg-raised);
    border-style: dashed;
    color: var(--text-muted);
    cursor: default;
}

.word.just-solved { animation: pop 0.3s; }

@keyframes shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@keyframes pop {
    50% { transform: scale(1.08); }
}

/* ===== Actions ===== */
.actions { display: flex; gap: 10px; }

button.ghost {
    font: inherit;
    font-size: 0.88rem;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

button.ghost:hover { color: var(--text); border-color: var(--border-hover); }

/* ===== Overlay ===== */
/* Shown for a beat between levels; never waits on a click, so it must not swallow one. */
.level-banner {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    pointer-events: none;
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
    /* Duration comes from LEVEL_BANNER_MS so the fade can't outlast the banner, or stop short. */
    animation: level-banner var(--banner-ms, 2000ms) ease-in-out forwards;
}

.level-banner[hidden] { display: none; }

.level-banner span {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 44px;
    box-shadow: 0 12px 40px var(--shadow-md);
}

@keyframes level-banner {
    0% { opacity: 0; transform: scale(0.94); }
    10%, 75% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: scale(0.98); }
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.45);
}

.overlay[hidden] { display: none; }

.overlay-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 32px;
    text-align: center;
    max-width: 380px;
    box-shadow: 0 12px 40px var(--shadow-md);
}

.overlay-card h2 { font-size: 1.35rem; margin-bottom: 8px; }
.overlay-card p { color: var(--text-muted); margin-bottom: 20px; }

.overlay-card button {
    font: inherit;
    font-weight: 600;
    padding: 10px 22px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}

@media (max-width: 720px) {
    /* The instruction drops under the title here, so the divider would lead a line of its own. */
    .title-group { gap: 2px 14px; }
    .prompt-line { font-size: 0.95rem; }
    .prompt-line::before { display: none; }
    .stage { aspect-ratio: 1.15; }
    .set-label { font-size: 0.68rem; }
    .set-label.wide { max-width: 200px; }
    .board { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

/* On a phone the gutter is what runs out first, so trade diagram width for caption room. */
@media (max-width: 480px) {
    body { padding: 12px 12px 40px; }
    .stage { aspect-ratio: 1; }
    .set-label { font-size: 0.62rem; }
    .set-label.wide { max-width: 150px; }
}
