/**
 * Public quiz site — standalone styling (docs/PLAN.md §11.3).
 *
 * Deliberately self-contained (own custom properties, own class names) like
 * games/flash-anzan/game.css, rather than depending on app.css's design
 * tokens: this site is meant to work standalone on its own future domain,
 * with no guarantee the rest of the app's CSS even ships there one day.
 * Respects the host page's dark/light preference the same way every other
 * layout in this app does: prefers-color-scheme first, then a
 * [data-theme="dark"]/[data-theme="light"] ancestor override (the public
 * layout's theme toggle stamps this attribute on <html>).
 *
 * Mobile-first, no webfonts (system stack only — nothing to block first
 * paint), big touch targets, minimal rules. Logical (inline/block) spacing
 * properties are used throughout so the whole site mirrors correctly under
 * RTL (Kurdish/Arabic) without a single direction-specific override; the
 * few genuinely direction-fixed bits (numbers, expressions) get an explicit
 * dir="ltr" in the markup instead of a CSS trick.
 */

.quiz-app {
    --quiz-bg: #fffdf9;
    --quiz-card: #ffffff;
    --quiz-text: #241c47;
    --quiz-muted: #6b6483;
    --quiz-accent: #06d6a0;
    --quiz-accent-2: #ffd166;
    --quiz-danger: #ef476f;
    --quiz-border: rgba(36, 28, 71, 0.12);
    --quiz-radius: 20px;
    --quiz-shadow: 0 8px 24px rgba(36, 28, 71, 0.10);

    color: var(--quiz-text);
    max-width: 640px;
    margin-inline: auto;
    padding-block: .25rem .5rem;
}

@media (prefers-color-scheme: dark) {
    .quiz-app {
        --quiz-bg: #1c1638;
        --quiz-card: #241c47;
        --quiz-text: #f4f0ff;
        --quiz-muted: #b7aede;
        --quiz-border: rgba(244, 240, 255, 0.14);
        --quiz-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    }
}
[data-theme="dark"] .quiz-app {
    --quiz-bg: #1c1638;
    --quiz-card: #241c47;
    --quiz-text: #f4f0ff;
    --quiz-muted: #b7aede;
    --quiz-border: rgba(244, 240, 255, 0.14);
    --quiz-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
[data-theme="light"] .quiz-app {
    --quiz-bg: #fffdf9;
    --quiz-card: #ffffff;
    --quiz-text: #241c47;
    --quiz-muted: #6b6483;
    --quiz-border: rgba(36, 28, 71, 0.12);
    --quiz-shadow: 0 8px 24px rgba(36, 28, 71, 0.10);
}

.quiz-h1 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 800;
    margin: .25rem 0 .1rem;
    text-align: center;
}

.quiz-sub {
    color: var(--quiz-muted);
    text-align: center;
    margin: 0 0 1.25rem;
    font-size: 1rem;
}

/* ---------------------------------------------------------------- Home */

.quiz-tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .9rem;
}

.quiz-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    aspect-ratio: 1 / 1;
    background: var(--quiz-card);
    border: 1px solid var(--quiz-border);
    border-radius: var(--quiz-radius);
    box-shadow: var(--quiz-shadow);
    text-decoration: none;
    color: var(--quiz-text);
    font-weight: 700;
    font-size: 1.05rem;
    text-align: center;
    padding: 1rem;
    box-sizing: border-box;
    transition: transform .12s ease;
}
.quiz-tile:active { transform: scale(.96); }
.quiz-tile:focus-visible { outline: 3px solid var(--quiz-accent); outline-offset: 2px; }

.quiz-tile-icon {
    font-size: clamp(2.25rem, 10vw, 3rem);
    line-height: 1;
}

.quiz-tiles-loading,
.quiz-tiles-empty {
    text-align: center;
    color: var(--quiz-muted);
    padding: 2rem 1rem;
}

/* --------------------------------------------------------------- Setup */

.quiz-setup-game {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--quiz-muted);
}
.quiz-setup-game-icon { font-size: 1.6rem; }

.quiz-field {
    background: var(--quiz-card);
    border: 1px solid var(--quiz-border);
    border-radius: var(--quiz-radius);
    box-shadow: var(--quiz-shadow);
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
}

.quiz-field-label {
    display: block;
    font-weight: 700;
    margin-bottom: .35rem;
}

.quiz-field-hint {
    color: var(--quiz-muted);
    font-size: .85rem;
    margin: 0 0 .5rem;
}

.quiz-speed-row {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.quiz-range {
    flex: 1 1 auto;
    accent-color: var(--quiz-accent);
    height: 2rem;
}

.quiz-speed-readout {
    direction: ltr;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    font-size: 1.1rem;
    min-width: 3.5em;
    text-align: center;
    background: var(--quiz-bg);
    border-radius: 999px;
    padding: .3rem .6rem;
}

.quiz-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.quiz-chip {
    position: relative;
}
.quiz-chip input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.quiz-chip span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 3.25rem;
    min-height: 3.25rem;
    padding: .4rem .9rem;
    border-radius: 999px;
    border: 2px solid var(--quiz-border);
    font-size: 1.4rem;
    font-weight: 800;
    direction: ltr;
    background: var(--quiz-bg);
    transition: background .1s ease, border-color .1s ease, color .1s ease;
}
.quiz-chip input:checked + span {
    background: var(--quiz-accent);
    border-color: var(--quiz-accent);
    color: #05261e;
}
.quiz-chip input:focus-visible + span {
    outline: 3px solid var(--quiz-accent);
    outline-offset: 2px;
}

.quiz-choice-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.quiz-choice {
    position: relative;
}
.quiz-choice input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.quiz-choice span {
    display: block;
    padding: .6rem 1rem;
    border-radius: 14px;
    border: 2px solid var(--quiz-border);
    background: var(--quiz-bg);
    font-weight: 600;
    font-size: .95rem;
    transition: background .1s ease, border-color .1s ease, color .1s ease;
}
.quiz-choice input:checked + span {
    background: var(--quiz-accent-2);
    border-color: var(--quiz-accent-2);
    color: #402d00;
    font-weight: 800;
}
.quiz-choice input:focus-visible + span {
    outline: 3px solid var(--quiz-accent);
    outline-offset: 2px;
}

.quiz-count-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1.4rem;
    font-weight: 800;
    text-align: center;
    direction: ltr;
    padding: .6rem;
    border-radius: 14px;
    border: 2px solid var(--quiz-border);
    background: var(--quiz-bg);
    color: var(--quiz-text);
}

.quiz-start-btn {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 1.4rem;
    font-weight: 800;
    padding: 1rem;
    border: none;
    border-radius: var(--quiz-radius);
    background: var(--quiz-accent);
    color: #05261e;
    cursor: pointer;
    box-shadow: var(--quiz-shadow);
}
.quiz-start-btn:active { transform: scale(.98); }

.quiz-back-link {
    display: block;
    text-align: center;
    margin-top: 1rem;
    color: var(--quiz-muted);
    text-decoration: none;
    font-weight: 600;
}
.quiz-back-link:hover,
.quiz-back-link:focus-visible { text-decoration: underline; }

/* ---------------------------------------------------------------- Play */

.quiz-progress-wrap {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--quiz-bg);
    padding-block: .5rem;
    margin-bottom: 1rem;
}

.quiz-progress-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    margin-bottom: .35rem;
    direction: ltr;
    text-align: start;
}

.quiz-progress-track {
    height: .6rem;
    border-radius: 999px;
    background: var(--quiz-border);
    overflow: hidden;
}
.quiz-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--quiz-accent);
    border-radius: 999px;
    transition: width .25s ease;
}

.quiz-stage {
    background: var(--quiz-card);
    border-radius: var(--quiz-radius);
    box-shadow: var(--quiz-shadow);
    padding: 1rem;
    min-height: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.quiz-watch-label {
    color: var(--quiz-muted);
    font-weight: 700;
    margin: 0;
}

.quiz-answer-display {
    direction: ltr;
    font-variant-numeric: tabular-nums;
    font-size: clamp(2rem, 10vw, 3rem);
    font-weight: 800;
    min-height: 1.2em;
    color: var(--quiz-text);
}

.quiz-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
    width: 100%;
    max-width: 320px;
}

.quiz-key {
    font-size: 1.5rem;
    font-weight: 800;
    padding: .9rem 0;
    border-radius: 14px;
    border: 2px solid var(--quiz-border);
    background: var(--quiz-bg);
    color: var(--quiz-text);
    cursor: pointer;
}
.quiz-key:active { transform: scale(.95); }
.quiz-key-submit { background: var(--quiz-accent); border-color: var(--quiz-accent); color: #05261e; }
.quiz-key:disabled { opacity: .5; cursor: default; }

.quiz-feedback {
    font-weight: 800;
    font-size: 1.1rem;
    border-radius: 14px;
    padding: .6rem 1rem;
    text-align: center;
}
.quiz-feedback-correct { background: rgba(6, 214, 160, .18); color: #05885f; }
.quiz-feedback-incorrect { background: rgba(239, 71, 111, .16); color: #b0264a; }
@media (prefers-color-scheme: dark) {
    .quiz-feedback-correct { color: #7CF0CE; }
    .quiz-feedback-incorrect { color: #ff9db4; }
}
[data-theme="dark"] .quiz-feedback-correct { color: #7CF0CE; }
[data-theme="dark"] .quiz-feedback-incorrect { color: #ff9db4; }

.quiz-score-pill {
    direction: ltr;
    font-weight: 800;
    background: var(--quiz-bg);
    border-radius: 999px;
    padding: .3rem .8rem;
    font-variant-numeric: tabular-nums;
}

.quiz-unavailable {
    text-align: center;
    color: var(--quiz-muted);
    padding: 2rem 1rem;
}

/* -------------------------------------------------------------- Finish */

.quiz-finish-heading {
    text-align: center;
    font-size: 1.6rem;
    font-weight: 800;
    margin: .25rem 0;
}
.quiz-finish-message {
    text-align: center;
    color: var(--quiz-muted);
    margin: 0 0 .75rem;
}
.quiz-finish-score {
    text-align: center;
    font-size: 1.8rem;
    font-weight: 800;
    direction: ltr;
    margin: 0 0 1.25rem;
}

.quiz-review-list {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    margin: 0 0 1.25rem;
}

.quiz-review-item {
    background: var(--quiz-card);
    border: 1px solid var(--quiz-border);
    border-radius: 14px;
    padding: .75rem .9rem;
}
.quiz-review-item.is-correct { border-inline-start: 5px solid var(--quiz-accent); }
.quiz-review-item.is-incorrect { border-inline-start: 5px solid var(--quiz-danger); }

.quiz-review-expr {
    direction: ltr;
    font-weight: 800;
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
    margin-bottom: .35rem;
}

.quiz-review-row {
    display: flex;
    justify-content: space-between;
    gap: .5rem;
    font-size: .9rem;
    color: var(--quiz-muted);
}
.quiz-review-row b {
    direction: ltr;
    color: var(--quiz-text);
    font-variant-numeric: tabular-nums;
}

.quiz-finish-actions {
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

@media (min-width: 420px) {
    .quiz-finish-actions { flex-direction: row; }
    .quiz-finish-actions > * { flex: 1 1 0; }
}

/* -------------------------------------------------------------- Confetti */

.quiz-confetti-holder {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 50;
}
.quiz-confetti-piece {
    position: absolute;
    top: -10px;
    width: 8px;
    height: 14px;
    opacity: .9;
    animation-name: quiz-confetti-fall;
    animation-timing-function: ease-in;
    animation-fill-mode: forwards;
}
@keyframes quiz-confetti-fall {
    from { transform: translateY(0) rotate(0deg); opacity: .95; }
    to   { transform: translateY(105vh) rotate(340deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .quiz-confetti-piece { animation: none; display: none; }
    .quiz-progress-fill { transition: none; }
}

/* ---------------------------------------------------------------------------
 * Difficulty presets + the collapsible rules
 *
 * The rules live inside a <details> so the setup screen opens as three
 * buttons and a Start, not a form. `[hidden]` needs the explicit rule below:
 * .quiz-field sets `display`, which would otherwise win over the browser's
 * default `[hidden] { display: none }` and leave a field that is supposed to
 * be irrelevant to this game sitting on screen anyway.
 * ------------------------------------------------------------------------ */

.quiz-field[hidden] {
    display: none;
}

.quiz-rules {
    margin-bottom: 1rem;
}

.quiz-rules-summary {
    background: var(--quiz-card);
    border: 1px solid var(--quiz-border);
    border-radius: var(--quiz-radius);
    box-shadow: var(--quiz-shadow);
    padding: .85rem 1.1rem;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.quiz-rules-summary::-webkit-details-marker {
    display: none;
}

.quiz-rules-summary::after {
    content: '+';
    float: inline-end;
    font-weight: 700;
    color: var(--quiz-muted);
}

.quiz-rules[open] .quiz-rules-summary {
    margin-bottom: 1rem;
}

.quiz-rules[open] .quiz-rules-summary::after {
    content: '−';   /* a real minus sign, not a hyphen */
}

/* ---------------------------------------------------------------------------
 * Tile hover: underline the words, never the icon
 *
 * app.css has a global `a:hover { text-decoration: underline }`, which beats
 * .quiz-tile's own `text-decoration: none` on specificity — and a text
 * decoration set on an ancestor is DRAWN THROUGH its descendants, so the
 * emoji got a line through it too. A descendant cannot opt out: writing
 * `text-decoration: none` on the icon does nothing, and the usual escape
 * (`display: inline-block`) is unavailable here because the tile is a flex
 * container, which blockifies its children straight back.
 *
 * So the decoration is cancelled on the tile and applied to the label
 * instead, where it belongs. Scoped through .quiz-tiles so this wins on
 * specificity rather than on stylesheet order.
 * ------------------------------------------------------------------------ */

.quiz-tiles .quiz-tile:hover,
.quiz-tiles .quiz-tile:focus-visible {
    text-decoration: none;
}

.quiz-tiles .quiz-tile:hover .quiz-tile-label,
.quiz-tiles .quiz-tile:focus-visible .quiz-tile-label {
    text-decoration: underline;
}

/* ===========================================================================
 * PLAY SCREEN — a game, not a document
 * ===========================================================================
 * Measured before this block, on a 390x664 viewport: the document was 761px
 * tall, so the page scrolled and the confirm key sat 8px past the fold —
 * under the phone browser's bottom toolbar. Four padded surfaces were nested
 * inside each other (.public-card > .quiz-stage > module root > module stage)
 * beneath a 73px header carrying a brand, a language switcher and a theme
 * toggle, none of which a child answering a question uses.
 *
 * The layout drops the header and the card for this screen (see the
 * $bareShell branch in app/views/layouts/public.php). What is left is sized
 * to the viewport rather than allowed to flow past it.
 *
 * Scoped to [data-screen="play"] throughout: the quiz home and setup screens,
 * /verify and every other public page keep the normal shell.
 * ======================================================================== */

body.layout-bare {
    /* The screen is exactly one viewport, so there is nothing to scroll to.
       Without this, a stray overflowing child would reintroduce the same
       "keypad below the fold" symptom this block exists to remove. */
    overflow: hidden;
}

body.layout-bare .public-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

body.layout-bare .public-content {
    /*
     * The default is a padded flex ROW that centres its child. On the main
     * axis that sizes the child to its content, so the app came out 244px
     * wide inside a 390px screen — a column of keys down the middle with
     * dead space either side. Block layout lets it take the full width, and
     * .quiz-app keeps its own max-width so desktop still gets a column.
     */
    display: block;
    padding: 0;
    min-height: 0;
}

.quiz-app[data-screen="play"] {
    /* dvh is the whole point: it tracks the phone browser's toolbar sliding
       in and out, which vh does not — vh reports the LARGEST viewport, so a
       vh-sized app is exactly one toolbar too tall for most of its life.
       The vh line stays first as the fallback for anything without dvh. */
    height: 100vh;
    height: 100dvh;

    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: .5rem;

    padding-inline: .75rem;
    padding-block: .5rem;
    padding-block-end: calc(.5rem + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

/* ---- the slim bar that replaces the site header --------------------- */

.quiz-topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.quiz-topbar .quiz-progress-wrap {
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
}

.quiz-topbar .quiz-progress-wrap[hidden] {
    display: none;
}

.quiz-exit {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 40px;
    block-size: 40px;
    border-radius: 999px;
    color: var(--quiz-muted);
    text-decoration: none;
    background: rgba(127, 127, 127, .12);
}

.quiz-exit svg {
    inline-size: 20px;
    block-size: 20px;
}

.quiz-exit:hover {
    color: var(--quiz-text);
    text-decoration: none;
}

/* ---- one surface, not four ------------------------------------------ */

.quiz-app[data-screen="play"] .quiz-stage {
    /* The module inside draws its own surface. Two cards on a 390px screen
       cost ~64px of horizontal padding and stack two shadows for nothing. */
    background: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    min-height: 0;
    block-size: 100%;
    /* clip, not hidden: the celebration overlay is deliberately bigger than
       its box and must not be cut in half by it. */
    overflow: clip;
    overflow-clip-margin: 4rem;
}

/* The mounted module fills the row it was given rather than setting its own
   height — a fixed min-height is what pushed the keypad off-screen. */
.quiz-app[data-screen="play"] .quiz-stage > *:not(.quiz-cheer) {
    inline-size: 100%;
    block-size: 100%;
    min-block-size: 0;
}

.quiz-app[data-screen="play"] .quiz-finish {
    overflow-y: auto;
}

/* Desktop keeps a centred column rather than a full-width sprawl. */
@media (min-width: 700px) {
    .quiz-app[data-screen="play"] {
        max-width: 640px;
        padding-inline: 1rem;
    }
}

/* The answer display takes whatever height is left between the question and
   the keypad, so the number sits in the middle of that space rather than
   under the question with a gap below it. */
.quiz-app[data-screen="play"] :is(.aq-answer, .sq-answer, .mq-answer, .dq-answer) {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-block-size: 0;
}

/* ---------------------------------------------------------------------------
 * Saying "yes" to a child
 *
 * An emoji lands instantly and in every language, which matters on a page
 * aimed at children who may still be learning to read. It sits ON TOP of the
 * stage rather than in the flow, so nothing reflows mid-answer and the game
 * below stays exactly where the child's thumb left it.
 * ------------------------------------------------------------------------ */

.quiz-stage {
    position: relative;   /* the anchor the cheer is positioned against */
}

.quiz-cheer {
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(4rem, 22vw, 8rem);
    line-height: 1;
    pointer-events: none;   /* never intercept the next tap */
    z-index: 5;
    animation: quiz-cheer-pop 1.1s ease-out forwards;
}

@keyframes quiz-cheer-pop {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
    25%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    45%  { transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -75%) scale(1); }
}

/* A wrong answer gets a smaller, calmer mark. Missing one should not feel
   like being shouted at. */
.quiz-cheer.is-wrong {
    font-size: clamp(3rem, 15vw, 5.5rem);
    animation-duration: .9s;
}

@media (prefers-reduced-motion: reduce) {
    .quiz-cheer {
        animation: quiz-cheer-fade 1.1s ease-out forwards;
    }
    @keyframes quiz-cheer-fade {
        0%   { opacity: 0; }
        20%  { opacity: 1; }
        100% { opacity: 0; }
    }
}

.quiz-mute {
    flex: 0 0 auto;
    inline-size: 40px;
    block-size: 40px;
    border: 0;
    border-radius: 999px;
    background: rgba(127, 127, 127, .12);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}
