/* Colors as tokens so dark mode (shared/theme.js) only has to swap values. */
:root {
    --bg: #f6f8fb;
    --text: #1f2937;
    --muted: #6b7280;
    --card: #ffffff;
    --border: #dfe4ec;
    --accent: #3b82f6;
    --accent-text: #ffffff;
    --bar: #e7ebf1;
    --good: #16a34a;
    --good-soft: #e5f6ea;
    --bad: #dc2626;
    --bad-soft: #fdeaea;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.06);
}

:root[data-theme="dark"] {
    --bg: #15161a;
    --text: #e7e9ee;
    --muted: #9aa0ab;
    --card: #1f2127;
    --border: #2f323a;
    --accent: #60a5fa;
    --accent-text: #0b1220;
    --bar: #2b2e36;
    --good: #4ade80;
    --good-soft: #17301f;
    --bad: #f87171;
    --bad-soft: #3a1c1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* No double-tap zoom (pinch zoom still works) */
html {
    touch-action: manipulation;
}

/* Quick repeated taps shouldn't select text or pop up the iOS callout. That covers the whole
   app: a double tap on empty space would select the nearest text (like the Categories heading)
   and the phone would scroll down to show the selection. */
main {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}

main {
    max-width: 760px;
    margin: auto;
    padding: 64px 16px 40px;
}

header {
    text-align: center;
}

h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25em;
    margin: 0 0 6px;
    font-size: 2rem;
}

/* Pixel hourglass (hourglass.gif, from _tools/hourglass.mjs) in place of an emoji.
   It runs its sand out and flips while hovered, and toggles on tap/click/Enter/Space; see script.js */
.title-hourglass-wrap {
    display: flex;
    cursor: pointer;
    border-radius: 6px;
}

.title-hourglass-wrap:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.title-hourglass {
    height: 1.6em;
    width: auto;
    image-rendering: pixelated;
}

.tagline {
    margin: 0;
    color: var(--muted);
}

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

/* Category picker, below the game */
.picker {
    margin-top: 36px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.cats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.cat {
    padding: 7px 14px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

/* Hover styles only for real pointers: on touch screens :hover sticks to the last thing tapped */
@media (hover: hover) {
    .cat:hover {
        border-color: var(--accent);
    }
}

.cat[aria-pressed="true"] {
    color: var(--accent-text);
    background: var(--accent);
    border-color: var(--accent);
}

.cat:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.cats-heading {
    margin: 14px 0 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cats-heading + .cats {
    margin-top: 8px;
}

.cat-special {
    border-style: dashed;
}

.cat-special[aria-pressed="true"] {
    border-style: solid;
}

.special-note {
    max-width: 480px;
    margin: 0 auto 16px;
    padding: 8px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.special-note[hidden] {
    display: none;
}

.scores {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 16px 0 20px;
    color: var(--muted);
    font-size: 0.95rem;
}

.scores b {
    color: var(--text);
    font-size: 1.15rem;
    margin-left: 4px;
    font-variant-numeric: tabular-nums;
}

/* Two pairs side by side on wide screens, stacked on phones */
.pairs {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: stretch;
    align-content: start; /* any height held between rounds (script.js) stays empty below the cards */
    gap: 12px;
}

.vs {
    align-self: center;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pair {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 14px 16px 16px;
    font: inherit;
    color: inherit;
    text-align: left;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    position: relative;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, background-color 0.2s;
}

/* The hover lift moves the card up; this strip keeps its old bottom edge clickable,
   or a cursor there would fall off, drop the card back, and the click would miss. */
.pair::after {
    content: "";
    position: absolute;
    left: -2px;
    right: -2px;
    bottom: -6px;
    height: 6px;
}

@media (hover: hover) {
    .pair:not(:disabled):hover {
        border-color: var(--accent);
        transform: translateY(-2px);
    }
}

.pair:focus-visible,
.next:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

.pair:disabled {
    cursor: default;
}

.tag {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.event {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.emoji {
    flex: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    background: var(--bg);
    border-radius: 12px;
}

/* YouTube thumbnails (16:9) in place of the emoji */
.has-thumbs .emoji {
    width: 96px;
    height: 54px;
}

.has-thumbs .event-text {
    min-height: 54px;
}

.has-thumbs .link {
    margin-left: 47px;
}

.thumb {
    overflow: hidden;
    border-radius: 8px;
}

.thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.event-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 40px;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* Hidden until the answer is revealed */
.year {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--muted);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.3s, opacity 0.3s;
}

/* Dotted line joining the two events of a pair */
.link {
    width: 0;
    height: 16px;
    margin-left: 19px;
    border-left: 2px dotted var(--muted);
}

.gap {
    display: none;
    margin-top: 12px;
}

.gap-bar {
    display: block;
    height: 10px;
    background: var(--bar);
    border-radius: 999px;
    overflow: hidden;
}

.gap-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--muted);
    transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.gap-text {
    display: block;
    margin-top: 6px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.revealed .year {
    max-height: 2em;
    opacity: 1;
}

.revealed .gap {
    display: block;
}

.pair.is-closer {
    border-color: var(--good);
}

.pair.is-closer .gap-fill {
    background: var(--good);
}

.pair.is-closer .gap-text {
    color: var(--good);
}

.pair.is-picked.is-closer {
    background: var(--good-soft);
}

.pair.is-picked.is-farther {
    border-color: var(--bad);
    background: var(--bad-soft);
}

.pair.is-picked .tag::after {
    content: " · your pick";
}

.result {
    min-height: 1.5em;
    margin: 20px 0 12px;
    text-align: center;
    font-weight: 600;
}

.result.is-right {
    color: var(--good);
}

.result.is-wrong {
    color: var(--bad);
}

.next {
    display: block;
    margin: 0 auto;
    padding: 12px 32px;
    font: inherit;
    font-weight: 700;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

/* Keeps its space while hidden, so tapping Next doesn't shift what's below it */
.next[hidden] {
    display: block;
    visibility: hidden;
}

@media (max-width: 620px) {
    .cats {
        gap: 6px;
    }

    .cat {
        padding: 6px 11px;
        font-size: 0.85rem;
    }

    .pairs {
        grid-template-columns: 1fr;
    }

    .vs {
        justify-self: center;
    }

    /* Room for two lines, so a longer message doesn't push Next down */
    .result {
        min-height: 2.6em;
        line-height: 1.3;
    }

    /* The game fills the screen, so answering never has to scroll to reach Next,
       and the top of the categories peeks in below it as a hint to scroll. */
    main {
        padding-top: 14px;
    }

    .game {
        --peek: 56px;
        display: flex;
        flex-direction: column;
        min-height: calc(100vh - var(--peek));
        min-height: calc(100svh - var(--peek)); /* the screen with the browser's toolbars showing */
    }

    /* Title shares the top row with the back link and theme button */
    h1 {
        margin: 0;
        font-size: 1.4rem;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .scores {
        margin: 6px 0 10px;
        font-size: 0.85rem;
    }

    .scores b {
        font-size: 1rem;
    }

    /* A special category's note stands in for the tagline, as plain text, to save room */
    .game:has(.special-note:not([hidden])) .tagline {
        display: none;
    }

    .special-note {
        margin: -4px auto 8px;
        padding: 0;
        font-size: 0.75rem;
        line-height: 1.3;
        background: none;
        border: 0;
    }

    .pairs {
        gap: 4px;
    }

    .vs {
        font-size: 0.75rem;
    }

    .pair {
        gap: 2px;
        padding: 10px 12px 12px;
        border-radius: 14px;
    }

    .tag {
        margin-bottom: 4px;
        font-size: 0.7rem;
    }

    .event {
        gap: 10px;
        font-size: 0.95rem;
    }

    .emoji {
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
        border-radius: 10px;
    }

    .event-text {
        min-height: 32px;
    }

    .has-thumbs .emoji {
        width: 64px;
        height: 36px;
    }

    .has-thumbs .event-text {
        min-height: 36px;
    }

    .has-thumbs .link {
        margin-left: 31px;
    }

    .year {
        font-size: 0.8rem;
    }

    .link {
        height: 8px;
        margin-left: 15px;
    }

    .gap {
        margin-top: 8px;
    }

    .gap-bar {
        height: 8px;
    }

    .gap-text {
        margin-top: 4px;
        font-size: 0.9rem;
    }

    /* Result and Next follow right under the cards; any spare room is left below Next */
    .result {
        margin: 12px 0 8px;
        font-size: 0.9rem;
    }

    .next {
        padding: 10px 32px;
    }

    .picker {
        margin-top: 0;
    }

    .cats-heading {
        margin-top: 10px;
    }
}

/* Short phones (an iPhone SE with Safari's toolbars): squeeze a little more to still fit */
@media (max-width: 620px) and (max-height: 600px) {
    .game {
        --peek: 48px;
    }

    .tagline {
        font-size: 0.8rem;
    }

    .scores {
        margin: 2px 0 6px;
    }

    .vs {
        visibility: hidden;
        height: 4px;
    }

    .pair {
        padding: 8px 12px 10px;
    }

    /* Bar and gap on one line */
    .revealed .gap {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        column-gap: 10px;
        margin-top: 6px;
    }

    .gap-bar {
        flex: 1 1 80px;
    }

    .gap-text {
        margin-top: 0;
    }

    .result {
        min-height: 2.4em;
        margin: 8px 0 6px;
        font-size: 0.85rem;
        line-height: 1.2;
    }

    .next {
        padding: 8px 32px;
    }
}

/* Too narrow for the title beside the back link: drop it below */
@media (max-width: 359px) {
    main {
        padding-top: 56px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pair,
    .year,
    .gap-fill {
        transition: none;
    }
}

/* ---------- How to play ---------- */

.scores {
    align-items: center;
}

.help {
    width: 26px;
    height: 26px;
    padding: 0;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
}

@media (hover: hover) {
    .help:hover {
        color: var(--text);
        border-color: var(--accent);
    }
}

.intro {
    width: min(420px, calc(100% - 32px));
    max-height: calc(100% - 32px);
    padding: 0;
    color: var(--text);
    background: var(--card);
    border: 0;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* ::backdrop doesn't see :root's tokens in every browser, so it gets a plain color */
.intro::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.intro-body {
    padding: 20px;
}

.intro h2 {
    margin: 0 0 14px;
    font-size: 1.3rem;
    text-align: center;
}

.intro-steps {
    margin: 16px 0 0;
    padding-left: 20px;
    font-size: 0.92rem;
    line-height: 1.4;
}

.intro-steps li + li {
    margin-top: 6px;
}

.intro-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.intro-actions button {
    padding: 10px 18px;
    font: inherit;
    font-weight: 700;
    border-radius: 999px;
    cursor: pointer;
}

.intro-hide {
    color: var(--muted);
    background: transparent;
    border: 2px solid var(--border);
}

.intro-ok {
    min-width: 88px;
    color: var(--accent-text);
    background: var(--accent);
    border: 2px solid var(--accent);
}

.help:focus-visible,
.intro-actions button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* The demo: a finger taps Pair A, the years and gaps show, and the streak goes up.
   Every part runs on the same 7s loop, so the keyframe percentages line up. */
.demo {
    --loop: 7s;
    position: relative;
    padding: 12px;
    background: var(--bg);
    border-radius: 14px;
    font-size: 0.78rem;
    overflow: hidden;
}

.demo p {
    margin: 0;
    text-align: center;
}

.demo-scores {
    color: var(--muted);
}

.demo-scores b {
    color: var(--text);
    margin-left: 4px;
}

.demo-after,
.demo i,
.demo-result {
    opacity: 0;
    animation: demo-show var(--loop) infinite;
}

.demo-before {
    animation: demo-hide var(--loop) infinite;
}

/* The old and new streak share one spot */
.demo-scores b {
    display: inline-grid;
}

.demo-before,
.demo-after {
    grid-area: 1 / 1;
}

.demo-pairs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.demo-pair {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 8px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 10px;
}

.demo-closer {
    animation: demo-pick var(--loop) infinite;
}

.demo-tag {
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.demo-event {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    line-height: 1.2;
}

.demo-emoji {
    flex: none;
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    background: var(--bg);
    border-radius: 7px;
}

.demo i {
    display: block;
    font-style: normal;
    font-weight: 500;
    color: var(--muted);
}

.demo-gap {
    height: 6px;
    background: var(--bar);
    border-radius: 999px;
    overflow: hidden;
}

.demo-fill {
    display: block;
    width: 0;
    height: 100%;
    background: var(--muted);
    border-radius: inherit;
    animation: demo-fill var(--loop) infinite;
}

.demo-closer .demo-fill {
    background: var(--good);
}

.demo-gap-text {
    font-weight: 700;
    opacity: 0;
    animation: demo-show var(--loop) infinite;
}

.demo-closer .demo-gap-text,
.demo-result {
    color: var(--good);
}

.demo .demo-result {
    margin-top: 8px;
    font-weight: 600;
}

/* A fingertip: starts off to the side, moves onto Pair A and taps it */
.demo-finger {
    position: absolute;
    top: 80px;
    left: 25%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    background: rgba(255, 255, 255, 0.55);
    border: 2px solid rgba(15, 23, 42, 0.45);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    opacity: 0;
    animation: demo-finger var(--loop) infinite;
    pointer-events: none;
}

@keyframes demo-finger {
    0%, 8% { opacity: 0; transform: translate(120px, 90px); }
    14% { opacity: 1; transform: translate(120px, 90px); }
    30% { opacity: 1; transform: translate(0, 0) scale(1); }
    33% { transform: translate(0, 0) scale(0.75); }
    37% { opacity: 1; transform: translate(0, 0) scale(1); }
    48%, 100% { opacity: 0; transform: translate(0, 0); }
}

@keyframes demo-pick {
    0%, 33% { background: var(--card); border-color: var(--border); }
    35%, 88% { background: var(--good-soft); border-color: var(--good); }
    92%, 100% { background: var(--card); border-color: var(--border); }
}

@keyframes demo-show {
    0%, 34% { opacity: 0; }
    38%, 88% { opacity: 1; }
    92%, 100% { opacity: 0; }
}

@keyframes demo-hide {
    0%, 34% { opacity: 1; }
    38%, 88% { opacity: 0; }
    92%, 100% { opacity: 1; }
}

@keyframes demo-fill {
    0%, 35% { width: 0; }
    50%, 88% { width: var(--w); }
    92%, 100% { width: 0; }
}

/* No motion: hold the demo on its answered frame */
@media (prefers-reduced-motion: reduce) {
    .demo * {
        animation-delay: calc(var(--loop) * -0.7) !important;
        animation-play-state: paused !important;
    }
}

@media (max-width: 620px) {
    .help {
        width: 22px;
        height: 22px;
        font-size: 0.75rem;
    }
}
