:root {
    --ink: #243047;
    --muted: #5c6b82;
    --paper: rgba(255, 255, 255, 0.94);
    --coral: #ff7a59;
    --coral-d: #e25b3a;
    --sun: #ffd166;
    --sky: #7ec8ff;
    --mint: #2fbf8f;
    --shadow: 0 14px 34px rgba(80, 50, 20, 0.08);
    color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
    font-size: clamp(16px, 0.4vw + 15px, 18px);
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--ink);
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    background: linear-gradient(180deg, #fff6ea 0%, #e7f6ff 100%);
    overflow-x: clip;
    -webkit-tap-highlight-color: transparent;
}

img, object, video { max-width: 100%; }

body::before {
    content: "";
    position: fixed;
    inset: -25%;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 18% 22%, rgba(255, 122, 89, 0.38), transparent 26%),
        radial-gradient(circle at 82% 12%, rgba(126, 200, 255, 0.5), transparent 24%),
        radial-gradient(circle at 74% 78%, rgba(177, 151, 252, 0.38), transparent 26%),
        radial-gradient(circle at 12% 82%, rgba(255, 209, 102, 0.46), transparent 22%);
    filter: blur(6px);
    animation: drift 16s ease-in-out infinite alternate;
}

button, input { font: inherit; color: inherit; }
button, .btn, .choice, .mem-card, .age span, .staff-option { touch-action: manipulation; }

a:focus-visible, button:focus-visible, input:focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 3px;
}

.top {
    display: grid;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 6;
    width: min(1040px, calc(100% - 20px));
    margin: 0 auto;
    padding: calc(14px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.95);
    border-radius: 0 0 22px 22px;
    box-shadow: 0 10px 28px rgba(80, 50, 20, 0.08);
    backdrop-filter: blur(16px);
    isolation: isolate;
}

.top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px 16px;
    min-width: 0;
    width: 100%;
}

.head-tools {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    justify-self: end;
    max-width: 100%;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    text-decoration: none;
    color: inherit;
}

.brand-text {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.brand strong {
    display: block;
    font-size: clamp(0.95rem, 2.8vw, 1.15rem);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand small {
    display: block;
    color: var(--muted);
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand-logo {
    height: 48px;
    width: auto;
    max-width: min(168px, 42vw);
    object-fit: contain;
    object-position: left center;
    flex-shrink: 0;
    display: block;
    filter: drop-shadow(0 6px 8px rgba(36, 48, 71, 0.16));
}

.sky {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.wrap, .foot { position: relative; z-index: 1; }

.top-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding-top: 12px;
    border-top: 1px solid rgba(36, 48, 71, 0.08);
}

.top-meta-end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.top-nav {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    min-width: 0;
}

.top-nav a {
    color: var(--ink);
    font-weight: 800;
    text-decoration: none;
    background: #fff;
    border: 1px solid rgba(36, 48, 71, 0.1);
    border-radius: 999px;
    padding: 8px 14px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.top-nav a:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(80, 50, 20, 0.1);
}

.chip {
    background: #fff7ef;
    border: 1px solid rgba(255, 122, 89, 0.22);
    border-radius: 999px;
    padding: 8px 14px;
    font-weight: 800;
    font-size: 0.88rem;
    max-width: 100%;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.chip-name {
    max-width: 12ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chip-sep { opacity: 0.45; font-weight: 700; }
.chip-score { color: var(--coral, #ff7a59); }

.top-nav form,
.top-meta-end form { margin: 0; }

.nav-out,
.tool-btn,
.theme-toggle,
.music-toggle {
    background: #fff;
    border: 1px solid rgba(36, 48, 71, 0.12);
    color: var(--ink);
    font-weight: 800;
    cursor: pointer;
    border-radius: 999px;
    padding: 8px 12px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    box-shadow: 0 3px 0 rgba(36, 48, 71, 0.08);
}

.tool-btn {
    min-width: 4.5rem;
    font-size: 0.88rem;
}

.family-chip {
    display: inline-flex;
    flex-shrink: 0;
}

.family-chip img,
.family-photo {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 50%;
    display: block;
    background: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(36, 48, 71, 0.12);
}

.family-photo {
    width: 140px;
    height: 140px;
    border-radius: 28px;
    margin: 8px auto;
}

.family-hero {
    display: block;
    width: min(100%, 520px);
    max-height: 280px;
    object-fit: cover;
    border-radius: 28px;
    margin: 8px auto 14px;
    background: #fff;
}

.camera-view {
    display: block;
    width: min(100%, 520px);
    border-radius: 28px;
    margin: 8px 0 12px;
    background: #1c2433;
}

.child-list { display: grid; gap: 10px; }

.child-play {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: left;
    background: #fff;
    border: 0;
    border-radius: 18px;
    padding: 14px 16px;
    cursor: pointer;
    box-shadow: inset 0 0 0 3px #ffe0c2;
}

.child-play span { color: var(--muted); font-weight: 700; }

.count-grid { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); margin-bottom: 8px; }

.wrap {
    width: min(1040px, calc(100% - 28px));
    margin: 18px auto 32px;
}

.hero { padding: 8px 4px 4px; }
.kicker { margin: 0 0 6px; font-weight: 800; color: #d45d78; }
h1 { font-size: clamp(1.55rem, 4vw, 2.2rem); line-height: 1.15; margin: 0 0 8px; overflow-wrap: anywhere; }
h2 { margin: 0 0 10px; }
.lead { font-size: 1.12rem; line-height: 1.45; margin-top: 0; color: #3d4c63; }

.panel {
    background: rgba(255, 255, 255, 0.82);
    border-radius: 28px;
    padding: 22px;
    box-shadow: var(--shadow);
    margin: 14px 0;
    border: 1px solid rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
}

.alert {
    background: #fff3d6;
    border-radius: 16px;
    padding: 12px 14px;
    font-weight: 700;
}

.field { display: block; font-weight: 800; margin: 14px 0 8px; }

input[type="text"],
input[type="file"] {
    width: 100%;
    font-size: 1.15rem;
    padding: 14px 16px;
    border-radius: 16px;
    border: 3px solid #ffd7a8;
    background: #fff;
}

input[type="text"]:focus,
input[type="file"]:focus {
    outline: none;
    border-color: var(--coral);
    box-shadow: 0 0 0 4px rgba(255, 122, 89, 0.18);
}

input[type="file"] {
    border-style: dashed;
    background: #fffaf4;
}

.start-form .btn { margin-top: 18px; }

.staff-pick { position: relative; }
.staff-menu {
    position: absolute;
    z-index: 5;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    margin: 0;
    padding: 6px;
    list-style: none;
    max-height: min(280px, 46dvh);
    overflow: auto;
    background: #fff;
    border: 3px solid #ffd7a8;
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.staff-option {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 800;
    cursor: pointer;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.staff-option:hover,
.staff-option.is-active { background: #fff1e4; }

.age-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
    gap: 10px;
}

.age input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.age span {
    display: grid;
    place-items: center;
    height: 72px;
    border-radius: 18px;
    background: #fff;
    font-size: 1.5rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.age.b1 span { box-shadow: inset 0 0 0 3px #ff9db1; }
.age.b2 span { box-shadow: inset 0 0 0 3px #ffd166; }
.age.b3 span { box-shadow: inset 0 0 0 3px #7ec8ff; }
.age.b4 span { box-shadow: inset 0 0 0 3px #7ddeb8; }
.age.b5 span { box-shadow: inset 0 0 0 3px #b197fc; }
.age.b6 span { box-shadow: inset 0 0 0 3px #ffa94d; }
.age.b7 span { box-shadow: inset 0 0 0 3px #69db7c; }

.age input:checked + span,
.age input:focus-visible + span {
    background: var(--coral);
    color: white;
    box-shadow: 0 4px 0 var(--coral-d);
    transform: scale(1.06);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 0;
    margin: 14px 0 18px;
    list-style: none;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 700;
}

.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.s1 { background: #ff9db1; }
.s2 { background: #ffd166; }
.s3 { background: #7ec8ff; }
.s4 { background: #7ddeb8; }
.s5 { background: #b197fc; }
.s6 { background: #ffa94d; }
.s7 { background: #69db7c; }

.btn {
    display: inline-block;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, #ff8d70, var(--coral));
    color: white;
    border: 0;
    border-radius: 999px;
    padding: 14px 22px;
    font-size: 1.15rem;
    font-weight: 800;
    text-decoration: none;
    text-align: center;
    box-shadow: 0 6px 0 var(--coral-d), 0 12px 24px rgba(255, 122, 89, 0.28);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.55) 48%, transparent 62%);
    transform: translateX(-130%);
    animation: sheen 3.8s ease-in-out infinite;
    pointer-events: none;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--coral-d); }

.btn-ghost {
    background: white;
    color: var(--ink);
    box-shadow: 0 6px 0 #eadfce;
}

.btn-ghost::after { display: none; }

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 14px;
}

.row-actions form { margin: 0; }

.rule-table {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 12px;
}

.rule {
    background: #fff;
    border-radius: 18px;
    padding: 14px 16px;
    border: 3px solid #ffe7c8;
    height: 100%;
}

.rule h3 { margin: 0 0 4px; }
.rule p { margin: 4px 0; }
.rule-games, .rule-split { font-weight: 800; }
.muted { color: var(--muted); font-size: 0.9rem; }

.meter {
    height: 22px;
    background: #ffe7c8;
    border-radius: 999px;
    overflow: hidden;
}

.meter span {
    display: block;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, #ffd166, #ff7a59);
    border-radius: inherit;
    transition: width 0.7s ease;
}

.meter span::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
    animation: shine 2.4s linear infinite;
}

.meter-label { font-weight: 800; }

.gcards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.gcard {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 28px;
    padding: 18px 18px 16px;
    box-shadow: var(--shadow);
    border: 3px solid transparent;
    min-height: 100%;
}

a.gcard {
    display: flex;
    text-decoration: none;
    color: inherit;
}

a.gcard { transition: transform 0.22s ease, box-shadow 0.22s ease; }
a.gcard:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 22px 36px rgba(255, 122, 89, 0.16);
}
.gcards .gcard:nth-child(1) { background: linear-gradient(180deg, #fff 30%, #ffe8e2); }
.gcards .gcard:nth-child(2) { background: linear-gradient(180deg, #fff 30%, #fff4cc); }
.gcards .gcard:nth-child(3) { background: linear-gradient(180deg, #fff 30%, #e7fbee); }
.gcards .gcard:nth-child(4) { background: linear-gradient(180deg, #fff 30%, #f3e9ff); }
.gcards .gcard:nth-child(5) { background: linear-gradient(180deg, #fff 30%, #e7f4ff); }
.gcard.is-done { border-color: #7ddeb8; }
.gcard.is-locked { opacity: 0.72; }
.gcard-emoji {
    font-size: 2.6rem;
    margin: 0;
    display: inline-block;
    animation: floaty 2.6s ease-in-out infinite;
}
.gcard h2 { margin-bottom: 4px; }
.pill, .score-line, .play-label { font-weight: 800; }
.play-label { color: var(--coral-d); margin: auto 0 0; padding-top: 8px; }
.pill {
    display: inline-block;
    background: #fff6ea;
    border-radius: 999px;
    padding: 4px 10px;
}

.game-panel {
    min-height: 420px;
    background:
        radial-gradient(circle at 12% 0%, rgba(255, 209, 102, 0.45), transparent 28%),
        radial-gradient(circle at 90% 10%, rgba(126, 200, 255, 0.4), transparent 26%),
        rgba(255, 255, 255, 0.94);
    border: 4px solid #fff;
    box-shadow: 0 18px 0 rgba(255, 183, 140, 0.35), var(--shadow);
}
.back { font-weight: 800; color: var(--muted); text-decoration: none; }
.game-kicker { font-weight: 800; margin-bottom: 0; }
.worth { font-weight: 800; color: var(--muted); }

.buddy {
    display: flex;
    gap: 12px;
    align-items: center;
    background: #fff8ee;
    border-radius: 24px;
    padding: 12px 14px;
    margin: 8px 0 12px;
    box-shadow: inset 0 0 0 3px #ffe1c4;
}
.buddy-face {
    width: 64px;
    height: 64px;
    flex: 0 0 64px;
    display: grid;
    place-items: center;
    font-size: 2.2rem;
    background: white;
    border-radius: 50%;
    box-shadow: 0 6px 0 #ffd166;
    animation: floaty 2.8s ease-in-out infinite;
}
.buddy > div { min-width: 0; }
.buddy-name { margin: 0; font-weight: 800; color: var(--coral-d); }
.buddy-say { margin: 2px 0 0; font-weight: 800; font-size: 1.15rem; overflow-wrap: anywhere; }

.dots { display: flex; gap: 6px; margin: 4px 0 14px; flex-wrap: wrap; }
.dots i {
    width: auto;
    height: auto;
    border-radius: 0;
    background: transparent;
    display: block;
    font-style: normal;
    font-size: 1.35rem;
    line-height: 1;
    color: #f0c9a0;
}
.dots i.did { color: #f0b429; background: transparent; }
.dots i.now { color: var(--coral); background: transparent; transform: scale(1.15); }

.pair-pill {
    display: inline-block;
    margin: 0 0 12px;
    padding: 6px 12px;
    border-radius: 999px;
    background: #e7fbee;
    font-weight: 800;
}

.game-top {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.game-top .buddy {
    flex: 1 1 auto;
    margin-bottom: 0;
}
.game-clock {
    flex: 0 0 auto;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 4px;
    min-width: 72px;
    padding: 8px 10px;
    border-radius: 18px;
    background: linear-gradient(160deg, #fff7e8, #ffe3c2);
    box-shadow: inset 0 0 0 3px #f0c9a0;
}
.clock-face {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 50%, #fff 58%, transparent 59%),
        conic-gradient(from 0deg, #ffd7a8, #fff3e0 40%, #ffc48a 70%, #ffd7a8);
    box-shadow: inset 0 0 0 2px #e8a86a, 0 2px 0 #e8a86a;
}
.clock-mark {
    position: absolute;
    left: 50%;
    top: 5px;
    width: 2px;
    height: 5px;
    margin-left: -1px;
    background: #c57a3a;
    border-radius: 1px;
    transform-origin: 50% 17px;
}
.clock-mark:nth-child(2) { transform: rotate(90deg); }
.clock-mark:nth-child(3) { transform: rotate(180deg); }
.clock-mark:nth-child(4) { transform: rotate(270deg); }
.clock-hand {
    position: absolute;
    left: 50%;
    bottom: 50%;
    width: 2px;
    margin-left: -1px;
    transform-origin: 50% 100%;
    border-radius: 2px;
    background: #5a3a24;
}
.clock-hand-min { height: 12px; }
.clock-hand-sec { height: 15px; width: 1.5px; background: var(--coral); }
.clock-dot {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 6px;
    height: 6px;
    margin: -3px 0 0 -3px;
    border-radius: 50%;
    background: #5a3a24;
}
.clock-digits {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
    color: var(--coral-d);
    letter-spacing: 0.02em;
}
.result-clock {
    display: grid;
    justify-items: center;
    gap: 6px;
    margin: 12px 0;
}
.result-clock .game-clock {
    min-width: 88px;
    padding: 12px 14px;
}
.result-clock .clock-face {
    width: 56px;
    height: 56px;
}
.clock-mark { transform-origin: 50% 17px; }
.result-clock .clock-mark { transform-origin: 50% 23px; top: 6px; height: 6px; }
.result-clock .clock-hand-min { height: 16px; }
.result-clock .clock-hand-sec { height: 20px; }
.speed-bonus {
    margin: 0;
    font-weight: 800;
    color: #c45c14;
}

.prompt-wrap { display: grid; place-items: center; min-height: 150px; margin-bottom: 8px; }
.prompt-label { font-weight: 800; margin: 0; }
.quiz-q { font-size: clamp(1.15rem, 3.4vw, 1.45rem); text-align: center; margin: 10px 0 18px; overflow-wrap: anywhere; white-space: normal; }
.fill-answer {
    display: grid;
    gap: 10px;
    margin: 8px 0 14px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}
.fill-input {
    width: 100%;
    min-height: 56px;
    border: 3px solid #7ec8ff;
    border-radius: 16px;
    padding: 10px 14px;
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: 800;
    text-align: center;
    background: #fff;
    color: inherit;
    box-sizing: border-box;
}
.fill-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px #ffd166;
}
.fill-answer .btn { width: 100%; }

.choice-grid { display: grid; gap: 12px; }
.choice-grid.colors { grid-template-columns: repeat(2, 1fr); }
.choice-grid.nums { grid-template-columns: 1fr 1fr; }
.choice-grid.quiz { grid-template-columns: 1fr; }
.choice-grid.odds { grid-template-columns: 1fr 1fr; }
.choice-grid.odds-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-grid.odds-6 .big-emoji { font-size: 2.4rem; }
.big-emoji { font-size: 3rem; line-height: 1; }

.pattern-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}
.pattern-item {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 6px 0 #ffe1c4;
}
.pattern-item.is-blank {
    color: var(--coral-d);
    font-weight: 800;
    border: 3px dashed #ffbf9e;
    box-shadow: none;
}

.scramble-hint {
    margin: 4px 0 12px;
    padding: 12px 14px;
    border-radius: 16px;
    background: linear-gradient(180deg, #fff8e8, #ffe9c8);
    border: 2px solid #ffd7a8;
    text-align: center;
}
.scramble-hint .prompt-label {
    margin-bottom: 4px;
    color: #9a6230;
}
.scramble-hint-text {
    margin: 0 0 8px;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
}
.scramble-hint .pair-pill {
    display: inline-block;
    margin: 0;
}
.scramble-tiles,
.scramble-word {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 8px 0 14px;
}
.scramble-tile {
    min-width: 52px;
    min-height: 52px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(180deg, #fff6df, #ffe1c4);
    box-shadow: 0 5px 0 #e8c49a;
    font-size: 1.35rem;
    font-weight: 800;
    cursor: pointer;
}
.scramble-tile.is-used {
    opacity: 0.35;
    box-shadow: none;
    cursor: default;
}
.scramble-slot {
    min-width: 42px;
    min-height: 48px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #fff;
    border: 3px solid #ffd7a8;
    font-size: 1.3rem;
    font-weight: 800;
}
.scramble-slot.is-empty { color: #d8c3a8; }

.diff-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 8px 0 14px;
}
.diff-panel {
    background: #fff8ee;
    border-radius: 20px;
    padding: 12px;
    box-shadow: inset 0 0 0 3px #ffe1c4;
}
.diff-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.diff-cell {
    min-height: 64px;
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    border: 0;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 5px 0 #ffe1c4;
    cursor: pointer;
}
.diff-cell.is-locked {
    cursor: default;
    box-shadow: 0 5px 0 #eadfce;
}
.diff-cell.is-selected {
    background: #e7fbee;
    box-shadow: 0 5px 0 #8ed7b4, 0 0 0 3px #37d67a;
}

.diff-photo-wrap {
    width: 100%;
    margin: 8px 0 12px;
    border-radius: 22px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 10px 0 #eadfce;
    touch-action: manipulation;
    cursor: crosshair;
}
.diff-photo-stage {
    position: relative;
    display: block;
    width: 100%;
    line-height: 0;
}
.diff-photo {
    display: block;
    width: 100%;
    height: auto;
    vertical-align: middle;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}
.diff-left-lock {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 50%;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(20, 16, 24, 0.22), rgba(20, 16, 24, 0.08) 70%, transparent);
    display: grid;
    align-content: end;
    justify-items: center;
    padding: 10px;
}
.diff-left-lock span {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.88);
    color: #333;
    font-size: 0.78rem;
    font-weight: 800;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}
.diff-mark-layer {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}
.diff-mark {
    position: absolute;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 0;
    border-radius: 50%;
    background: #fffef8;
    color: #1a1a1a;
    font-weight: 900;
    font-size: 0.72rem;
    line-height: 1;
    box-shadow:
        0 0 0 2px #1a1a1a,
        0 2px 6px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    pointer-events: auto;
    animation: mark-pop 0.35s ease;
}
@keyframes mark-pop {
    from { transform: scale(0.4); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.xword-sheet {
    margin: 4px 0 10px;
    padding: clamp(10px, 2.5vw, 16px);
    background: #fffdf6;
    border: 3px solid #222;
    border-radius: 8px;
    box-shadow: 0 8px 0 #d6b84a;
    max-width: 100%;
}
.xword-heading {
    margin: 0 0 12px;
    text-align: center;
    font-weight: 900;
    font-size: clamp(1.35rem, 5vw, 1.9rem);
    letter-spacing: 0.04em;
    color: #111;
    text-transform: uppercase;
}
.xword-board {
    position: relative;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    container-type: inline-size;
    container-name: xword;
}
.xword-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: #f2c400;
    min-width: 100%;
}
.xword-table td {
    border: 2px solid #111;
    padding: 0;
    width: calc(100% / 12);
    vertical-align: middle;
}
.xword-block {
    background: #f2c400;
}
.xword-block::after {
    content: "";
    display: block;
    padding-top: 100%;
}
.xword-cell {
    background: #fff !important;
    position: relative;
}
.xword-cell button {
    width: 100%;
    aspect-ratio: 1 / 1;
    min-height: 0;
    border: 0;
    background: #fff;
    padding: 0;
    margin: 0;
    cursor: pointer;
    position: relative;
    font: inherit;
    color: #111;
    display: grid;
    place-items: center;
    touch-action: manipulation;
}
.xword-cell.is-active {
    background: #fff4a8 !important;
}
.xword-cell.is-active button {
    background: #fff4a8;
}
.xword-cell.is-cursor {
    background: #ffe8d8 !important;
    box-shadow: inset 0 0 0 2px #ff7a59;
}
.xword-cell.is-cursor button {
    background: #ffe8d8;
}
.xword-cell-num {
    position: absolute;
    top: 2px;
    left: 3px;
    z-index: 1;
    font-size: clamp(0.65rem, 2.2cqi, 0.9rem);
    font-weight: 900;
    line-height: 1;
    color: #222;
}
.xword-cell-letter {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-weight: 900;
    font-size: clamp(1.2rem, 6.5cqi, 2.2rem);
    line-height: 1;
    text-transform: uppercase;
    color: #111;
    font-family: Arial, Helvetica, sans-serif;
}
/* Small blinking underscore cursor — does not cover the letter. */
.xword-cell.is-cursor .xword-cell-letter::after {
    content: "_";
    position: absolute;
    left: 50%;
    bottom: 4%;
    transform: translateX(-50%);
    font-size: 0.55em;
    font-weight: 900;
    line-height: 1;
    color: #ff5a2f;
    pointer-events: none;
    animation: xword-caret-blink 1s steps(1, end) infinite;
}
@keyframes xword-caret-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}
.xword-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 8px 0 12px;
}
.xword-col {
    display: grid;
    gap: 8px;
    align-content: start;
}
.xword-clue {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 4px 8px;
    text-align: left;
    border: 0;
    border-radius: 16px;
    padding: 12px;
    background: #fff8ee;
    box-shadow: 0 4px 0 #eadfce;
    cursor: pointer;
    color: inherit;
    font: inherit;
    touch-action: manipulation;
}
.xword-clue.is-active {
    background: #e7f6ff;
    box-shadow: 0 4px 0 #9ec9e8, 0 0 0 3px #7ec8ff;
}
.xword-clue.is-done {
    background: #e7fbee;
}
.xword-clue em {
    font-style: normal;
    color: #6a7383;
    font-weight: 700;
}
.xword-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #ff7a59;
    color: #fff;
    font-weight: 800;
    font-size: 0.95rem;
}
.xword-text {
    font-weight: 700;
    font-size: clamp(0.95rem, 2.8vw, 1.05rem);
    line-height: 1.35;
}
/* Focus target for the phone keyboard — no visible native caret/blob. */
.xword-type {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 5;
    width: 2.5rem;
    height: 2.5rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    font-size: 1px;
    font-weight: 400;
    font-family: Arial, Helvetica, sans-serif;
    text-align: center;
    text-transform: uppercase;
    line-height: 1;
    outline: none;
    box-shadow: none;
    opacity: 0.01;
    -webkit-text-fill-color: transparent;
    -webkit-caret-color: transparent;
    touch-action: manipulation;
}
.xword-type:focus {
    outline: none;
    box-shadow: none;
    caret-color: transparent;
}
@media (max-width: 700px) {
    .xword-wrap { grid-template-columns: 1fr; }
    .xword-sheet {
        margin-left: 0;
        margin-right: 0;
        padding: 10px 8px 12px;
    }
    .xword-table {
        width: 100%;
        min-width: 100%;
    }
    .xword-table td {
        border-width: 1.5px;
    }
    .xword-cell-letter {
        font-size: clamp(1.05rem, 7cqi, 1.7rem);
    }
    .xword-cell-num {
        font-size: clamp(0.6rem, 2.4cqi, 0.8rem);
    }
}
@media (max-width: 420px) {
    .game-panel:has(.xword-sheet) {
        padding: 12px 8px;
    }
    .xword-cell-letter {
        font-size: clamp(1rem, 6.5cqi, 1.45rem);
    }
}
@supports not (font-size: 1cqi) {
    .xword-cell-letter {
        font-size: clamp(1.15rem, 5.2vw, 2.1rem);
    }
    .xword-cell-num {
        font-size: clamp(0.6rem, 2.2vw, 0.85rem);
    }
}

.staff-list { margin: 0; }
.staff-list div {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 2px solid #fff0df;
}
.staff-list dt { font-weight: 800; }
.staff-list dd { margin: 0; font-weight: 700; }

.kid-board { display: grid; gap: 12px; }
.kid-card {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 12px;
    align-items: center;
    background: #fff;
    border-radius: 18px;
    padding: 12px;
}
.kid-card img {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 16px;
}
.kid-card h3 { margin: 0 0 4px; }
.child-papers {
    background: #fff;
    border-radius: 18px;
    padding: 14px;
}
input[type="file"] { font-weight: 700; }

.choice {
    background: white;
    border: 3px solid #ffe1c4;
    border-radius: 22px;
    padding: 12px;
    cursor: pointer;
    min-height: 92px;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.15rem;
    transition: transform 0.12s ease, border-color 0.12s ease;
}
.choice-grid.colors .balloon { animation: floaty 2.4s ease-in-out infinite; }
.choice-grid.colors .choice:nth-child(2) .balloon { animation-delay: 0.2s; }
.choice-grid.colors .choice:nth-child(3) .balloon { animation-delay: 0.4s; }
.choice-grid.colors .choice:nth-child(4) .balloon { animation-delay: 0.15s; }

.choice:hover {
    border-color: #ffbf9e;
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 22px rgba(255, 122, 89, 0.16);
}
.choice:active { transform: scale(0.96); }
.choice .big-num { font-size: 2.4rem; font-weight: 800; }

.count-stage {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    min-height: 110px;
    padding: 8px;
}
.friend {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    font-size: 2.6rem;
    background: white;
    border-radius: 22px;
    box-shadow: 0 8px 0 #d7ecff;
    animation: friend-bob 1.6s ease-in-out infinite;
}
.star-row { font-size: 2rem; letter-spacing: 4px; margin: 4px 0 8px; }

.balloon {
    --c: #ff5a5a;
    width: min(92px, 34vw);
    height: auto;
    aspect-ratio: 92 / 108;
    margin: 0 auto 26px;
    border-radius: 50% 50% 48% 48%;
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.85) 0 7px, transparent 9px),
        var(--c);
    display: grid;
    place-items: center;
    position: relative;
    box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.08);
}

.balloon::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -24px;
    width: 2px;
    height: 24px;
    background: #8d6a5a;
}

.balloon.is-large {
    width: min(150px, 46vw);
    height: auto;
    aspect-ratio: 130 / 150;
    animation: floaty 2.4s ease-in-out infinite;
}
.balloon.is-large::after { height: 28px; bottom: -28px; }

.shape {
    width: 34px;
    height: 34px;
    background: white;
    display: block;
}
.balloon.is-large .shape { width: 48px; height: 48px; }
.shape-circle { border-radius: 50%; }
.shape-square { border-radius: 8px; }
.shape-triangle { clip-path: polygon(50% 6%, 96% 94%, 4% 94%); }
.shape-star { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }

.mem-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.mem-grid-hard {
    gap: 8px;
}
.mem-grid-hard .mem-card,
.mem-grid-hard .mem-inner {
    min-height: 88px;
}
.mem-grid-hard .symbol {
    font-size: 1.85rem;
}

.mem-card {
    min-height: 112px;
    border: 0;
    border-radius: 18px;
    background: transparent;
    padding: 0;
    cursor: pointer;
    perspective: 700px;
}

.mem-inner {
    position: relative;
    display: block;
    min-height: 112px;
    transform-style: preserve-3d;
    transition: transform 0.45s ease;
}

.mem-card.is-up .mem-inner { transform: rotateY(180deg); }

.mem-face {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 18px;
    backface-visibility: hidden;
    font-size: 2.4rem;
}

.mem-front {
    background:
        radial-gradient(circle at 30% 30%, #fff 0 8px, transparent 9px),
        linear-gradient(160deg, #ffb7d5, #7ec8ff 55%, #b7f0c8);
    color: white;
    box-shadow: 0 6px 0 #7eb6e0;
}
.mem-mark { font-size: 2rem; }

.mem-back {
    background: white;
    transform: rotateY(180deg);
    box-shadow: 0 6px 0 #eadfce;
}

.mem-card.is-matched .mem-back {
    box-shadow: 0 6px 0 #8ed7b4, 0 0 18px rgba(55, 214, 122, 0.45);
    animation: matchpop 0.45s ease;
}

.feedback, .result, .locked-reward { text-align: center; }
.feedback { position: relative; border-radius: 24px; padding: 18px; overflow: hidden; }
.sparks { position: absolute; inset: 0; pointer-events: none; }
.sparks i {
    position: absolute;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ffd166;
    animation: spark 0.85s ease-out forwards;
}
.sparks i:nth-child(1) { left: 18%; top: 46%; background: #ff7a59; }
.sparks i:nth-child(2) { left: 30%; top: 28%; animation-delay: 0.05s; }
.sparks i:nth-child(3) { left: 72%; top: 30%; background: #7ec8ff; }
.sparks i:nth-child(4) { left: 80%; top: 52%; background: #37d67a; animation-delay: 0.08s; }
.sparks i:nth-child(5) { left: 48%; top: 18%; background: #b197fc; }
.sparks i:nth-child(6) { left: 58%; top: 62%; }
.feedback.ok { background: #e7fbee; animation: pop 0.45s ease; }
.feedback.try { background: #fff6df; animation: shake 0.42s ease; }
.feedback-emoji, .result-emoji, .cert-emoji { font-size: 3rem; margin: 0; }
.feedback-answer { margin: 10px 0; }
.big-num { font-size: 2.6rem; font-weight: 800; }
.game-error { color: #b42318; font-weight: 800; }
.result-total { font-size: 1.3rem; font-weight: 800; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.certificate {
    background: white;
    border-radius: 28px;
    padding: 28px 22px;
    text-align: center;
    border: 8px solid #ffd166;
    box-shadow: var(--shadow);
    animation: rise 0.55s ease both, halo 3s ease-in-out 0.4s infinite;
}

.stars { animation: twinkle 1.8s ease-in-out infinite; }

.tier-gold { border-color: #f0c14a; }
.tier-silver { border-color: #c5d0dc; }
.tier-bronze { border-color: #e0a36a; }
.tier-friend { border-color: #b9a7ff; }
.cert-kicker { font-weight: 800; letter-spacing: 0.04em; }
.cert-name { font-size: clamp(1.6rem, 5vw, 2.4rem); font-weight: 800; margin: 6px 0; overflow-wrap: anywhere; }
.cert-points { font-size: 3rem; font-weight: 800; margin: 8px 0; }
.cert-points span { font-size: 1.3rem; color: var(--muted); }
.cert-reward { font-size: 1.4rem; font-weight: 800; }
.stars { font-size: 1.8rem; letter-spacing: 4px; color: #e2a100; margin: 0; }
.cert-date { color: var(--muted); }

.breakdown, .board { list-style: none; padding: 0; margin: 0; }
.breakdown li, .board li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 0;
    border-bottom: 2px solid #fff0df;
    font-weight: 700;
}
.total-row { font-size: 1.15rem; }
.board { counter-reset: star; }
.board li { counter-increment: star; }
.board li::before {
    content: counter(star);
    font-weight: 800;
    margin-right: 8px;
}
.board .is-me { background: #fff6df; border-radius: 12px; padding-left: 8px; padding-right: 8px; }
.board small { color: var(--muted); font-weight: 700; }

.foot {
    text-align: center;
    font-weight: 800;
    color: #d45d78;
    padding: 8px 16px calc(28px + env(safe-area-inset-bottom));
}

.confetti {
    pointer-events: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 4;
}

.confetti i {
    position: absolute;
    top: -16px;
    left: var(--x);
    width: 10px;
    height: 14px;
    background: var(--c);
    border-radius: 2px;
    animation: fall 3.8s linear infinite;
    animation-delay: var(--d);
}

@keyframes fall {
    to { transform: translateY(105vh) rotate(220deg); }
}

.show {
    margin: 8px 0 16px;
    background: #243047;
    border-radius: 28px;
    padding: 12px 12px 8px;
    box-shadow: 0 12px 0 #1a2436;
    animation: rise 0.6s ease both;
}

.show-film {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: min(42vh, 320px);
    border: 0;
    border-radius: 18px;
    background: #9fd6ff;
    pointer-events: none;
}
.show-video {
    object-fit: contain;
    background: #1a2436;
    pointer-events: auto;
}

.show figcaption {
    color: white;
    font-weight: 800;
    text-align: center;
    margin: 8px 4px 4px;
}

.panel, .gcard, .hero, .certificate {
    animation: rise 0.55s ease both;
}

.gcards .gcard:nth-child(2) { animation-delay: 0.08s; }
.gcards .gcard:nth-child(3) { animation-delay: 0.16s; }
.gcards .gcard:nth-child(4) { animation-delay: 0.24s; }
.gcards .gcard:nth-child(5) { animation-delay: 0.32s; }

.dots i.now { animation: pulse 1s ease-in-out infinite; }
.count-stage { animation: pop 0.4s ease; }
.family-hero, .family-photo { animation: rise 0.5s ease both; }
.child-play { transition: transform 0.15s ease; }
.child-play:hover { transform: translateY(-2px); }
.result-emoji, .feedback-emoji, .cert-emoji { display: inline-block; animation: pop 0.5s ease; }

@keyframes friend-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes floaty {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes pop {
    0% { transform: scale(0.86); }
    70% { transform: scale(1.06); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@keyframes shine {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.25); }
}

@keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes drift {
    from { transform: translate3d(-2%, -1%, 0) scale(1); }
    to { transform: translate3d(2%, 2%, 0) scale(1.06); }
}

@keyframes sheen {
    0%, 55% { transform: translateX(-130%); }
    80%, 100% { transform: translateX(130%); }
}

@keyframes spark {
    to { transform: translateY(-46px) scale(0.2); opacity: 0; }
}

@keyframes matchpop {
    0% { transform: rotateY(180deg) scale(0.92); }
    60% { transform: rotateY(180deg) scale(1.06); }
    100% { transform: rotateY(180deg) scale(1); }
}

@keyframes halo {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0); }
    50% { box-shadow: 0 0 28px 6px rgba(255, 209, 102, 0.55); }
}

@keyframes twinkle {
    0%, 100% { opacity: 1; filter: brightness(1); }
    50% { opacity: 0.72; filter: brightness(1.25); }
}

@media (max-width: 900px) {
    .top, .wrap { width: min(1040px, calc(100% - 16px)); }
    .gcards { grid-template-columns: 1fr 1fr; }
    .choice-grid.odds { grid-template-columns: 1fr 1fr; }
    .choice-grid.odds-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .top-nav a, .nav-out, .theme-toggle, .music-toggle, .chip {
        min-height: 44px;
    }
    .mem-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
}

@media (max-width: 720px) {
    .top { gap: 10px; }
    .top-bar {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .brand {
        width: 100%;
    }
    .brand-logo {
        height: 40px;
        max-width: min(150px, 46vw);
    }
    .head-tools {
        width: 100%;
        justify-content: flex-start;
        justify-self: stretch;
        padding-top: 2px;
    }
    .tool-btn,
    .theme-toggle,
    .music-toggle {
        flex: 0 1 auto;
        min-width: 0;
        padding: 8px 12px;
    }
    .top-meta {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .top-nav { justify-content: flex-start; }
    .top-meta-end { width: 100%; }
    .chip {
        width: 100%;
        max-width: 100%;
        justify-content: center;
        text-align: center;
    }
    .chip-name { max-width: 40vw; }
    .panel, .game-panel { padding: 16px; border-radius: 22px; }
    .game-panel { min-height: 0; }
    .staff-list div, .kid-card { grid-template-columns: 1fr; }
    .kid-card img { width: 100%; height: 180px; }
    .choice-grid.colors, .choice-grid.nums { grid-template-columns: 1fr 1fr; }
    .choice { min-height: 72px; }
    .mem-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
    .show-film, .show-video {
        max-height: min(38vh, 240px);
    }
    .friend { width: 64px; height: 64px; font-size: 2.1rem; }
    .start-form .btn,
    .row-actions,
    .row-actions .btn,
    .row-actions form,
    .result-actions .btn,
    .search-again .btn { width: 100%; }
    .certificate { padding: 20px 14px; border-width: 6px; }
    .camera-view {
        width: 100%;
        max-height: min(50vh, 320px);
        object-fit: cover;
    }
    .age-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
    }
    .age span { height: 56px; font-size: 1.25rem; }
    .age input:checked + span,
    .age input:focus-visible + span { transform: none; }
    .diff-mark {
        width: 22px;
        height: 22px;
        margin: -11px 0 0 -11px;
        font-size: 0.75rem;
    }
    .scramble-slot,
    .scramble-tile {
        min-width: 44px;
        min-height: 44px;
    }
    .fill-input { min-height: 52px; font-size: 1.2rem; }
}

@media (max-width: 480px) {
    .top, .wrap { width: calc(100% - 12px); }
    .gcards,
    .choice-grid.colors,
    .choice-grid.nums,
    .choice-grid.odds { grid-template-columns: 1fr; }
    .choice-grid.odds-6 { grid-template-columns: 1fr 1fr; }
    .mem-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mem-grid-hard { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .mem-card, .mem-inner { min-height: 96px; }
    .mem-grid-hard .mem-card,
    .mem-grid-hard .mem-inner { min-height: 72px; }
    .buddy { align-items: flex-start; }
    .buddy-face { width: 52px; height: 52px; flex-basis: 52px; font-size: 1.7rem; }
    .game-top { flex-wrap: wrap; }
    .game-clock { margin-left: auto; }
    .brand strong { font-size: 0.95rem; }
    .brand small { font-size: 0.75rem; }
    .brand-logo { max-width: min(132px, 40vw); height: 36px; }
    .head-tools { gap: 6px; }
    .tool-btn,
    .theme-toggle,
    .music-toggle {
        padding: 7px 10px;
        font-size: 0.82rem;
        min-height: 38px;
        min-width: 0;
    }
    .show { box-shadow: 0 8px 0 #1a2436; }
    .game-panel { box-shadow: var(--shadow); min-height: 0; }
    .pattern-item { width: 48px; height: 48px; font-size: 1.45rem; }
    .diff-board { grid-template-columns: 1fr; }
    .diff-cell { min-height: 56px; font-size: 1.55rem; }
    .certificate { padding: 14px 10px; border-width: 4px; }
    .certificate .family-photo { width: 96px; height: 96px; }
    .cert-points { font-size: clamp(1.8rem, 10vw, 2.4rem); }
    .legend { font-size: 0.85rem; gap: 6px 10px; }
}

@media (max-width: 420px) {
    .age-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-height: 520px) and (orientation: landscape) {
    .show-film, .show-video {
        max-height: min(40vh, 180px);
    }
    .brand-logo { height: 36px; }
    .panel { padding: 14px; }
    .game-panel { min-height: 0; }
}

@media (min-width: 1200px) {
    .top, .wrap { width: min(1100px, calc(100% - 48px)); }
    .gcards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media print {
    body { background: white; color: #243047; }
    .top, .foot, .no-print, .confetti, .panel, .row-actions, .sky, .show, .theme-toggle, .music-toggle { display: none !important; }
    .certificate { display: block; box-shadow: none; animation: none; color: #243047; background: white; }
    .wrap { width: auto; }
}

html[data-theme="dark"] {
    --ink: #f6efe6;
    --muted: #cbbba8;
    --paper: rgba(42, 34, 48, 0.94);
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
}

html[data-theme="dark"] body {
    background: linear-gradient(180deg, #1c1622 0%, #121820 100%);
}

html[data-theme="dark"] body::before { opacity: 0.35; }

html[data-theme="dark"] .top,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .gcard,
html[data-theme="dark"] .top-nav a,
html[data-theme="dark"] .chip,
html[data-theme="dark"] .nav-out,
html[data-theme="dark"] .tool-btn,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .music-toggle,
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .age span,
html[data-theme="dark"] .rule,
html[data-theme="dark"] .child-play,
html[data-theme="dark"] .child-papers,
html[data-theme="dark"] .choice,
html[data-theme="dark"] .mem-back,
html[data-theme="dark"] .kid-card,
html[data-theme="dark"] .certificate,
html[data-theme="dark"] .staff-menu { background: #2a2232; border-color: #6a5044; }
html[data-theme="dark"] .staff-option { color: var(--ink); }
html[data-theme="dark"] .staff-option:hover,
html[data-theme="dark"] .staff-option.is-active { background: #3a2e28; }

html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="file"] {
    background: #2a2232;
    color: var(--ink);
}

html[data-theme="dark"] .age input:checked + span,
html[data-theme="dark"] .age input:focus-visible + span {
    background: var(--coral);
    color: white;
}

html[data-theme="dark"] .gcard.is-done { border-color: #7ddeb8; }
html[data-theme="dark"] .tier-gold { border-color: #f0c14a; }
html[data-theme="dark"] .tier-silver { border-color: #c5d0dc; }
html[data-theme="dark"] .tier-bronze { border-color: #e0a36a; }
html[data-theme="dark"] .tier-friend { border-color: #b9a7ff; }

html[data-theme="dark"] .top {
    background: rgba(28, 22, 34, 0.94);
    border-color: rgba(138, 106, 88, 0.35);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
html[data-theme="dark"] .top-meta {
    border-top-color: rgba(255, 255, 255, 0.08);
}
html[data-theme="dark"] .top-nav a,
html[data-theme="dark"] .chip,
html[data-theme="dark"] .nav-out,
html[data-theme="dark"] .tool-btn,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .music-toggle {
    background: #342a3c;
    border: 1px solid #6a5044;
    color: var(--ink);
    box-shadow: 0 3px 0 #1c1622;
}
html[data-theme="dark"] .chip {
    background: #3a2e28;
    border-color: rgba(255, 157, 134, 0.35);
}
html[data-theme="dark"] .chip-score { color: #ff9d86; }
html[data-theme="dark"] ::placeholder {
    color: #b5a090;
    opacity: 1;
}
html[data-theme="dark"] input[type="file"] {
    border-color: #6a5044;
    background: #2a2232;
}

html[data-theme="dark"] .panel {
    background: rgba(36, 28, 44, 0.88);
}

html[data-theme="dark"] .lead,
html[data-theme="dark"] .back,
html[data-theme="dark"] .worth { color: var(--muted); }

html[data-theme="dark"] .kicker,
html[data-theme="dark"] .foot { color: #ff9db1; }

html[data-theme="dark"] .alert { background: #4a3820; color: #ffe7c2; }
html[data-theme="dark"] .feedback.ok { background: #1c3b2c; }
html[data-theme="dark"] .feedback.try { background: #3d3424; }
html[data-theme="dark"] .pill,
html[data-theme="dark"] .board .is-me { background: #3a2e28; color: var(--ink); }
html[data-theme="dark"] .meter { background: #4a3828; }

html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .nav-out,
html[data-theme="dark"] .tool-btn,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .music-toggle {
    box-shadow: 0 3px 0 #1c1622;
}

html[data-theme="dark"] .child-play { box-shadow: inset 0 0 0 3px #6a5044; }
html[data-theme="dark"] .choice { border-color: #6a5044; }
html[data-theme="dark"] .dots i { color: #6a5344; background: transparent; }
html[data-theme="dark"] .dots i.did { color: #f0c14a; }
html[data-theme="dark"] .dots i.now { color: #ff9d86; }
html[data-theme="dark"] .buddy { background: #3a2e28; box-shadow: inset 0 0 0 3px #5a4638; }
html[data-theme="dark"] .buddy-face,
html[data-theme="dark"] .friend {
    background: #2a2232;
    color: inherit;
    box-shadow: 0 6px 0 #1c1622;
}
html[data-theme="dark"] .scramble-slot.is-empty { color: #8a7a6c; }
html[data-theme="dark"] .pair-pill { background: #1c3b2c; }
html[data-theme="dark"] .game-clock {
    background: linear-gradient(160deg, #3a2e28, #4a382c);
    box-shadow: inset 0 0 0 3px #5a4638;
}
html[data-theme="dark"] .clock-face {
    background:
        radial-gradient(circle at 50% 50%, #2a221c 58%, transparent 59%),
        conic-gradient(from 0deg, #6a4a32, #4a3428 40%, #7a5538 70%, #6a4a32);
    box-shadow: inset 0 0 0 2px #8a6540, 0 2px 0 #8a6540;
}
html[data-theme="dark"] .clock-digits,
html[data-theme="dark"] .speed-bonus { color: #ffc48a; }
html[data-theme="dark"] .game-panel {
    background:
        radial-gradient(circle at 12% 0%, rgba(255, 183, 140, 0.16), transparent 28%),
        #2a2232;
    border-color: #3d3344;
    box-shadow: var(--shadow);
}
html[data-theme="dark"] .diff-photo-wrap {
    background: #2a2232;
    box-shadow: 0 10px 0 #1c1622;
}
html[data-theme="dark"] .diff-left-lock span {
    background: rgba(42, 34, 48, 0.92);
    color: #fff8ee;
}
html[data-theme="dark"] .diff-mark {
    background: #fffef8;
    color: #111;
    box-shadow:
        0 0 0 2px #111,
        0 2px 6px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .diff-panel { background: #3a2e28; box-shadow: inset 0 0 0 3px #5a4638; }
html[data-theme="dark"] .diff-cell {
    background: #2a2232;
    box-shadow: 0 5px 0 #1c1622;
    color: inherit;
}
html[data-theme="dark"] .diff-cell.is-selected {
    background: #1c3b2c;
    box-shadow: 0 5px 0 #0f281b, 0 0 0 3px #37d67a;
}

html[data-theme="dark"] .pattern-item,
html[data-theme="dark"] .scramble-slot { background: #2a2232; border-color: #6a5044; }
html[data-theme="dark"] .scramble-hint {
    background: linear-gradient(180deg, #3a2e28, #2a2232);
    border-color: #6a5044;
}
html[data-theme="dark"] .scramble-hint .prompt-label { color: #ffc98a; }
html[data-theme="dark"] .scramble-tile {
    background: linear-gradient(180deg, #3a2e28, #2a2232);
    box-shadow: 0 5px 0 #1c1622;
    color: var(--ink);
}
html[data-theme="dark"] .pattern-item.is-blank { border-color: #6a5044; }

html[data-theme="dark"] .breakdown li,
html[data-theme="dark"] .board li,
html[data-theme="dark"] .staff-list div { border-bottom-color: #3d3344; }
html[data-theme="dark"] .game-error { color: #ffb4a8; }
html[data-theme="dark"] .show figcaption { color: #f6efe6; }

/* Game cards keep readable dark gradients (override light nth-child fills). */
html[data-theme="dark"] .gcards .gcard:nth-child(1) { background: linear-gradient(180deg, #2a2232 28%, #3a2826); }
html[data-theme="dark"] .gcards .gcard:nth-child(2) { background: linear-gradient(180deg, #2a2232 28%, #3a3224); }
html[data-theme="dark"] .gcards .gcard:nth-child(3) { background: linear-gradient(180deg, #2a2232 28%, #24362c); }
html[data-theme="dark"] .gcards .gcard:nth-child(4) { background: linear-gradient(180deg, #2a2232 28%, #322840); }
html[data-theme="dark"] .gcards .gcard:nth-child(5),
html[data-theme="dark"] .gcards .gcard:nth-child(n+6) { background: linear-gradient(180deg, #2a2232 28%, #243040); }
html[data-theme="dark"] .gcard { color: var(--ink); box-shadow: 0 10px 0 #1c1622; }
html[data-theme="dark"] a.gcard:hover { box-shadow: 0 14px 0 #1c1622; }
html[data-theme="dark"] .play-label { color: #ff9d86; }
html[data-theme="dark"] .score-line,
html[data-theme="dark"] .legend,
html[data-theme="dark"] .meter-label,
html[data-theme="dark"] .prompt-label,
html[data-theme="dark"] .field { color: var(--muted); }

html[data-theme="dark"] .btn {
    box-shadow: 0 6px 0 #8a3f2c;
}
html[data-theme="dark"] .btn:active { box-shadow: 0 3px 0 #8a3f2c; }

html[data-theme="dark"] .family-hero,
html[data-theme="dark"] .camera-view,
html[data-theme="dark"] .family-photo {
    background: #1c1622;
    border-color: #6a5044;
    box-shadow: 0 8px 0 #121018;
}

html[data-theme="dark"] .locked-reward,
html[data-theme="dark"] .intro .meter + .meter-label { color: var(--ink); }
html[data-theme="dark"] .locked-reward { background: #2a2232; }

html[data-theme="dark"] .rule-table,
html[data-theme="dark"] .rule {
    background: #2a2232;
    border-color: #6a5044;
    color: var(--ink);
}
html[data-theme="dark"] .rule-table th {
    background: #3a2e28;
    color: var(--ink);
}
html[data-theme="dark"] .rule-table td { border-color: #3d3344; }

html[data-theme="dark"] .mem-front {
    background: #3a2e28;
    color: var(--ink);
}
html[data-theme="dark"] .mem-card {
    box-shadow: 0 6px 0 #1c1622;
}
html[data-theme="dark"] .mem-card.is-matched .mem-front {
    background: #1c3b2c;
}

html[data-theme="dark"] .big-num,
html[data-theme="dark"] .big-emoji,
html[data-theme="dark"] .quiz-q,
html[data-theme="dark"] .buddy-name,
html[data-theme="dark"] .buddy-say { color: var(--ink); }

html[data-theme="dark"] .feedback-answer {
    background: #3a2e28;
    color: var(--ink);
}

html[data-theme="dark"] .fill-input {
    background: #1c1622;
    color: var(--ink);
    border-color: #ff9d86;
}
html[data-theme="dark"] .fill-input:focus {
    box-shadow: 0 0 0 3px #7ec8ff;
}
html[data-theme="dark"] .fill-answer .field { color: var(--muted); }

html[data-theme="dark"] .xword-type {
    caret-color: transparent;
}
html[data-theme="dark"] .xword-cell.is-cursor .xword-cell-letter::after {
    color: #ff7a59;
}
/* Keep the puzzle sheet light so letters stay easy to read. */
html[data-theme="dark"] .xword-sheet {
    background: #fffdf6;
    border-color: #222;
    box-shadow: 0 8px 0 #5a4520;
}
html[data-theme="dark"] .xword-heading {
    color: #111;
}
html[data-theme="dark"] .xword-table {
    background: #ffe600;
}
html[data-theme="dark"] .xword-table td {
    border-color: #222;
}
html[data-theme="dark"] .xword-block {
    background: #ffe600;
}
html[data-theme="dark"] .xword-cell {
    background: #fffef5 !important;
}
html[data-theme="dark"] .xword-cell button {
    background: #fffef5;
    color: #111;
}
html[data-theme="dark"] .xword-cell.is-active,
html[data-theme="dark"] .xword-cell.is-active button {
    background: #fff3b0 !important;
}
html[data-theme="dark"] .xword-cell.is-cursor,
html[data-theme="dark"] .xword-cell.is-cursor button {
    background: #ffd7c2 !important;
}
html[data-theme="dark"] .xword-cell-num { color: #444; }
html[data-theme="dark"] .xword-cell-letter { color: #111; }
html[data-theme="dark"] .xword-clue {
    background: #3a2e28;
    box-shadow: 0 4px 0 #1c1622;
    color: var(--ink);
}
html[data-theme="dark"] .xword-clue.is-active {
    background: #243848;
    box-shadow: 0 4px 0 #1a2834, 0 0 0 3px #7ec8ff;
}
html[data-theme="dark"] .xword-clue.is-done {
    background: #1c3b2c;
}
html[data-theme="dark"] .xword-clue em { color: #cbbba8; }
html[data-theme="dark"] .xword-text { color: var(--ink); }

html[data-theme="dark"] .certificate {
    color: var(--ink);
    background: #2a2232;
}
html[data-theme="dark"] .cert-kicker,
html[data-theme="dark"] .cert-date { color: #ff9db1; }
html[data-theme="dark"] .cert-name { color: #ffe7c2; }
html[data-theme="dark"] .stars { color: #f0c14a; }

html[data-theme="dark"] .child-play,
html[data-theme="dark"] .child-papers {
    color: var(--ink);
}
html[data-theme="dark"] .staff-list dt,
html[data-theme="dark"] .staff-list dd { color: var(--ink); }

html[data-theme="dark"] .show {
    background: #2a2232;
    box-shadow: 0 10px 0 #1c1622;
}

html[data-theme="dark"] .result-actions .btn-ghost {
    color: var(--ink);
}

html[data-theme="dark"] .age span {
    color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
    .confetti, .sky { display: none; }
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
