/* =============================================================================================
 * main.css — everything the first viewport did NOT need.
 *
 * Loaded with <link rel="preload" as="style" onload="this.rel='stylesheet'"> from inc/head.php,
 * so it never blocks the first paint; the critical rules are inlined there instead.
 *
 * Contents
 *   1. Design tokens (fallbacks only — see the note below)
 *   2. Layout primitives
 *   3. Cards
 *   4. How to play
 *   5. Features
 *   6. FAQ
 *   7. Related
 *   8. Game area
 *   9. 404
 *  10. Footer
 *  11. Breakpoints
 *  12. Reduced motion
 *  13. Print
 *
 * NOTE — why the token block below is wrapped in :where().
 * The real palette is generated by PHP from `theme` in inc/config.php and inlined in <head>.
 * This file is a LATER stylesheet, so a plain `:root{--bg:…}` here would beat that inline
 * block and every landing would come out the same colour. `:where(:root)` has a specificity
 * of zero, so these values only apply when the critical CSS is missing entirely — a CDN
 * stripping inline styles, a cached partial page — and the site still looks right instead of
 * unstyled. Change colours in inc/config.php, never here.
 * =========================================================================================== */

/* --------------------------------------------------------------------------- 1. tokens --- */

:where(:root) {
    --primary: #4f7cff;
    --accent:  #ffb545;
    --bg:      #0e1117;
    --surface: #171b26;
    --raised:  #1e222d;
    --text:    #e8ecf5;
    --muted:   #abafb7;
    --border:  #31343b;
    --on-fill: #0e1117;
    --ring:    #4f7cff;

    --wrap: 1120px;
    --gap: clamp(1rem, 3vw, 1.75rem);
    --radius: 14px;
    --radius-sm: 9px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --shadow: 0 1px 2px rgba(0, 0, 0, .28), 0 10px 30px rgba(0, 0, 0, .22);
    color-scheme: dark;
}

/* Light variant, both ways round: the explicit toggle wins over the OS preference. */
:where(:root[data-theme="light"]) {
    --bg:      #f3f3f4;
    --surface: #ffffff;
    --raised:  #fafafb;
    --text:    #1c1f25;
    --muted:   #5b5d61;
    --border:  #d8d9da;
    --primary: #3b5dbf;
    --accent:  #8c6426;
    --on-fill: #ffffff;
    --ring:    #3b5dbf;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 28px rgba(16, 24, 40, .08);
    color-scheme: light;
}

@media (prefers-color-scheme: light) {
    :where(:root:not([data-theme="dark"])) {
        --bg:      #f3f3f4;
        --surface: #ffffff;
        --raised:  #fafafb;
        --text:    #1c1f25;
        --muted:   #5b5d61;
        --border:  #d8d9da;
        --primary: #3b5dbf;
        --accent:  #8c6426;
        --on-fill: #ffffff;
        --ring:    #3b5dbf;
        --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 28px rgba(16, 24, 40, .08);
        color-scheme: light;
    }
}

/* ---------------------------------------------------------------- 2. layout primitives --- */

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1 0 auto;
}

.section + .section {
    border-top: 1px solid var(--border);
}

.section__lead {
    margin: -.35rem 0 1.9rem;
}

ul,
ol {
    margin: 0;
    padding: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.icon {
    width: 1.5rem;
    height: 1.5rem;
    flex: none;
}

.btn .icon {
    width: 1.15rem;
    height: 1.15rem;
    margin-inline-start: -.15rem;
}

.btn {
    transition: background-color .16s ease, color .16s ease, border-color .16s ease, transform .12s ease;
}

.btn:active {
    transform: translateY(1px);
}

.iconbtn {
    transition: border-color .16s ease, color .16s ease, background-color .16s ease;
}

/* ---------------------------------------------------------------------------- 3. cards --- */

.card {
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1.15rem, 2.4vw, 1.6rem);
}

.card h3 {
    margin-bottom: .45rem;
}

.card p:last-child {
    margin-bottom: 0;
}

/* --------------------------------------------------------------------- 4. how to play --- */

.howto__list {
    display: grid;
    gap: var(--gap);
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    counter-reset: howto;
}

.howto__step {
    list-style: none;
    display: flex;
    gap: .9rem;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1.15rem, 2.4vw, 1.5rem);
}

.howto__num {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-fill);
    font-weight: 800;
    font-size: .95rem;
    line-height: 1;
}

.howto__title {
    margin-bottom: .35rem;
}

.howto__body p:last-child {
    margin-bottom: 0;
}

/* ------------------------------------------------------------------------- 5. features --- */

.features__grid {
    display: grid;
    gap: var(--gap);
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.feature__icon {
    display: block;
    font-size: 1.7rem;
    line-height: 1;
    margin-bottom: .7rem;
}

.feature__text {
    color: var(--muted);
    font-size: .965rem;
}

/* ------------------------------------------------------------------------------ 6. FAQ --- */

.faq__list {
    display: grid;
    gap: .7rem;
    max-width: 68ch;
}

.faq__item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.faq__item[open] {
    border-color: var(--primary);
}

.faq__q {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem clamp(1rem, 2.4vw, 1.35rem);
    cursor: pointer;
    font-weight: 650;
    list-style: none;
}

/* Safari still paints its own triangle without this. */
.faq__q::-webkit-details-marker {
    display: none;
}

.faq__q:hover {
    color: var(--primary);
}

.faq__chev .icon {
    width: 1.2rem;
    height: 1.2rem;
    color: var(--muted);
    transform: rotate(90deg);
    transition: transform .18s ease;
}

.faq__item[open] .faq__chev .icon {
    transform: rotate(-90deg);
    color: var(--primary);
}

.faq__a {
    padding: 0 clamp(1rem, 2.4vw, 1.35rem) 1.15rem;
    color: var(--muted);
}

.faq__a p:last-child {
    margin-bottom: 0;
}

/* -------------------------------------------------------------------------- 7. related --- */

.related__grid {
    display: grid;
    gap: var(--gap);
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.related__title {
    display: flex;
    align-items: center;
    gap: .4rem;
}

.related__title a {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    text-decoration: none;
    color: var(--text);
}

.related__title a:hover {
    color: var(--primary);
}

.related__title .icon {
    width: 1.05rem;
    height: 1.05rem;
    color: var(--primary);
    transition: transform .16s ease;
}

.related__card--link:hover {
    border-color: var(--primary);
}

.related__card--link:hover .related__title .icon {
    transform: translateX(3px);
}

.related__text {
    color: var(--muted);
    font-size: .965rem;
}

/* ----------------------------------------------------------------------------- 8. game --- */

.game__facade {
    transition: background-color .16s ease;
}

.game__facade:hover .game__play,
.game__facade:focus-visible .game__play {
    background: var(--accent);
}

.game__play {
    pointer-events: none;
}

.game__ph .icon {
    width: 2.4rem;
    height: 2.4rem;
    color: var(--primary);
}

.game__ph code {
    word-break: break-word;
}

.game__note {
    color: var(--muted);
    font-size: .9rem;
    margin: .85rem 0 0;
}

/* ------------------------------------------------------------------------------ 9. 404 --- */

.notfound {
    text-align: center;
}

.notfound .hero__tagline,
.notfound .hero__actions {
    margin-inline: auto;
    justify-content: center;
}

.notfound__code {
    font-size: clamp(3.5rem, 12vw, 7rem);
    font-weight: 800;
    line-height: 1;
    margin: 0 0 .25rem;
    color: var(--primary);
    letter-spacing: -.04em;
}

/* --------------------------------------------------------------------------- 10. footer --- */

.site-footer {
    margin-top: clamp(2rem, 6vw, 4rem);
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: clamp(1.75rem, 4vw, 2.5rem) 0;
}

.site-footer__inner {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem 2rem;
    align-items: flex-start;
    justify-content: space-between;
}

.site-footer__note {
    color: var(--muted);
    font-size: .92rem;
    margin: .6rem 0 0;
    max-width: 46ch;
}

.site-footer__nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.25rem;
    list-style: none;
}

.site-footer__nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: .95rem;
}

.site-footer__nav a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.site-footer__legal {
    flex-basis: 100%;
    color: var(--muted);
    font-size: .88rem;
    margin: 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    justify-content: space-between;
}

.site-footer__top {
    color: var(--muted);
}

/* ---------------------------------------------------------------------- 11. breakpoints --- */

@media (max-width: 719px) {
    .site-footer__inner {
        flex-direction: column;
    }

    .howto__list,
    .features__grid,
    .related__grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 900px) {
    .features__grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .howto__list {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1200px) {
    .howto__list {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ------------------------------------------------------------------- 12. reduced motion --- */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ------------------------------------------------------------------------------ 13. print --- */

@media print {
    :where(:root) {
        --bg: #ffffff;
        --surface: #ffffff;
        --raised: #ffffff;
        --text: #000000;
        --muted: #333333;
        --border: #999999;
        --shadow: none;
    }

    body {
        background: #fff;
        color: #000;
        font-size: 11pt;
    }

    .site-header,
    .nav,
    .iconbtn,
    .hero__actions,
    .game__frame,
    .site-footer__nav,
    .site-footer__top,
    .skip {
        display: none !important;
    }

    /* <details> prints collapsed by default, which would lose every answer. CSS cannot
       force it open, so main.js sets [open] on beforeprint and restores it afterwards. */
    .faq__item {
        border: 0;
        break-inside: avoid;
    }

    .card,
    .howto__step {
        border: 1px solid #999;
        break-inside: avoid;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #555;
    }
}
