/* ===== МатемаГически игри — стил „Светло приключение" =====
   Light, high-contrast (sun-readable), bold & kid-friendly, with quest/rune motifs. */
:root {
  --paper:#fdf4e0; --card:#fffaf0; --ink:#2c2114; --line:#2c2114; --muted:#8a755a;
  --gold:#f6a823; --gold-d:#e0890f; --teal:#0f8f8a; --teal-d:#0b6f6b;
  --coral:#ef5a4f; --coral-ink:#c23320; --sky:#cfe9f2; --green:#3fae5a;
  --shadow-soft: rgba(44,33,20,.18); --trail:#c9b48e;
  --r-md:10px; --r-lg:16px; --r-xl:22px; --r-pill:999px;
  --display:'Fredoka', system-ui, sans-serif;
  --body:'Poppins', ui-sans-serif, system-ui, sans-serif;
  --rune:'Noto Sans Runic','Segoe UI Historic','Segoe UI Symbol',serif;
  --spring:cubic-bezier(0.34,1.56,0.64,1); --ease:cubic-bezier(0.22,0.61,0.36,1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { font-family: var(--body); color: var(--ink); -webkit-font-smoothing: antialiased; }
/* gradient on the ROOT so it paints the whole canvas (full screen on iOS, incl. notch/toolbar/overscroll).
   NOT background-attachment:fixed — that bands white on iOS Safari. */
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; background: transparent; }

.doodles { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.doodle { position: absolute; font-family: var(--rune); color: rgba(44,33,20,.06); user-select: none; animation: drift 18s ease-in-out infinite; }
@keyframes drift { 0%,100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-26px) rotate(8deg); } }

.app { position: relative; z-index: 1; width: 100%; max-width: 460px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: transparent; display: flex; flex-direction: column; }
.screen { display: none; flex-direction: column; flex: 1; min-height: 0; }
.screen.active { display: flex; animation: screenIn 0.4s var(--ease) both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes blink { 50% { opacity: 0.25; } }

/* topbar */
.topbar { display: flex; align-items: center; gap: 9px; padding: 16px 18px 10px; }
.logo { display: flex; align-items: center; gap: 9px; }
.logo-mark { width: 30px; height: 34px; object-fit: contain; }
.logo-text { display: flex; flex-direction: column; line-height: 1.02; font-family: var(--display); font-weight: 700; font-size: 16px; color: var(--teal-d); }
.logo-text small { font-family: var(--body); font-weight: 600; font-size: 8.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-top: 1px; }
.live-pill { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; background: var(--coral); color: #fff; font-weight: 700; font-size: 11.5px; padding: 5px 11px; border-radius: var(--r-pill); border: 2.5px solid var(--line); box-shadow: 2px 2px 0 var(--line); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: blink 1s steps(2) infinite; }

.body { padding: 4px 20px 24px; flex: 1; display: flex; flex-direction: column; overflow-y: auto; }

/* hero */
.hero-mark { text-align: center; margin-top: 6px; }
.kicker { display: inline-block; font-family: var(--display); font-weight: 700; font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--coral-ink); margin-bottom: 6px; }
.hero-title { font-family: var(--display); font-weight: 700; font-size: 37px; line-height: 0.95; color: var(--teal-d); letter-spacing: -0.01em; }
.hero-title em { font-style: normal; color: var(--gold-d); }
.hero-sub { color: var(--ink); opacity: .85; font-size: 13px; font-weight: 500; margin-top: 7px; }

/* countdown */
.clock-wrap { margin: 18px auto 4px; background: linear-gradient(180deg, #15a09a, var(--teal-d)); border: 3px solid var(--line); border-radius: var(--r-xl); box-shadow: 4px 5px 0 var(--line); padding: 15px; text-align: center; }
.clock-label { color: #cfeee9; font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
.clock-digits { font-family: var(--display); font-weight: 700; color: #fff; font-size: 50px; line-height: 1; margin-top: 3px; font-variant-numeric: tabular-nums; text-shadow: 0 3px 0 rgba(0,0,0,.18); }
.clock-digits .sep { color: #ffd86b; animation: blink 1s steps(2) infinite; }
.clock-foot { color: #d7efec; font-size: 12px; font-weight: 500; margin-top: 5px; }

/* inputs + buttons */
.reg { margin-top: 16px; }
.field-label { font-weight: 600; font-size: 13px; color: var(--ink); margin: 0 0 7px 3px; display: block; }
.name-input { width: 100%; font-family: var(--body); font-size: 16px; font-weight: 600; color: var(--ink); padding: 14px 15px; background: #fff; border: 3px solid var(--line); border-radius: var(--r-lg); outline: none; transition: box-shadow 0.18s var(--ease); }
.name-input::placeholder { color: #b6a484; font-weight: 500; }
.name-input:focus { box-shadow: 0 0 0 4px rgba(246,168,35,0.4); }
.btn { font-family: var(--display); font-weight: 700; font-size: 17px; border: 3px solid var(--line); cursor: pointer; border-radius: var(--r-lg); padding: 14px 16px; transition: transform 0.12s var(--spring), box-shadow 0.12s var(--ease); display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; color: var(--ink); box-shadow: 4px 5px 0 var(--line); }
.btn:active { transform: translate(3px,3px); box-shadow: 1px 2px 0 var(--line); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(#ffc24a, var(--gold)); }
.btn-brand { background: var(--teal); color: #fff; }
.btn-ghost { background: var(--card); color: var(--teal-d); }
.btn-mint { background: var(--teal-d); color: #fff; }
.reg .btn { margin-top: 11px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* card primitive */
.card, .clock-card { background: var(--card); border: 3px solid var(--line); border-radius: var(--r-lg); box-shadow: 4px 5px 0 var(--line); padding: 13px 14px; }

/* waiting room */
.waitlist { margin-top: 16px; background: var(--card); border: 3px solid var(--line); border-radius: var(--r-lg); box-shadow: 4px 5px 0 var(--line); padding: 13px 14px; }
.wl-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.wl-head b { font-family: var(--display); font-size: 14px; color: var(--ink); }
.wl-count { background: var(--gold); border: 2px solid var(--line); border-radius: var(--r-pill); font-family: var(--display); font-weight: 700; font-size: 12px; padding: 1px 10px; box-shadow: 1.5px 1.5px 0 var(--line); color: var(--ink); }
.wl-row { display: flex; align-items: center; gap: 9px; padding: 5px 2px; font-weight: 600; font-size: 13.5px; color: var(--ink); }
.wl-row + .wl-row { border-top: 1.5px dashed #e3d4b3; }
.wl-av { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-family: var(--display); font-weight: 700; font-size: 13px; border: 2px solid var(--line); flex: 0 0 auto; }
.wl-more { font-size: 12px; color: var(--muted); font-weight: 600; text-align: center; margin-top: 7px; }
.wl-empty { font-size: 12.5px; color: var(--muted); font-weight: 500; text-align: center; padding: 8px 0 4px; }

/* profile */
.prof-hero { text-align: center; margin-top: 10px; }
.prof-av { width: 80px; height: 80px; border-radius: 24px; margin: 0 auto 10px; display: grid; place-items: center; background: var(--teal-d); color: #fff; font-family: var(--display); font-weight: 700; font-size: 36px; border: 3px solid var(--line); box-shadow: 5px 6px 0 var(--line); }
.prof-name { font-family: var(--display); font-weight: 700; font-size: 26px; color: var(--ink); }
.prof-tag { display: inline-flex; align-items: center; gap: 6px; margin-top: 9px; background: #e7f8ec; border: 2.5px solid var(--line); box-shadow: 2.5px 2.5px 0 var(--line); border-radius: var(--r-pill); padding: 5px 13px; font-weight: 700; font-size: 12px; color: #127a36; }
.prof-clock { margin: 15px auto 0; text-align: center; color: var(--muted); font-size: 13px; font-weight: 600; }
.prof-clock b { font-family: var(--display); color: var(--teal-d); font-size: 18px; font-variant-numeric: tabular-nums; }
.prof-actions { margin-top: 18px; display: flex; flex-direction: column; gap: 11px; }
.prof-switch { text-align: center; margin-top: 14px; }
.prof-switch a { font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }

/* game */
.game-top { display: flex; align-items: center; gap: 12px; padding: 16px 20px 8px; }
.timer-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--ink); color: #fff; font-family: var(--display); font-weight: 700; font-size: 18px; padding: 6px 13px; border-radius: var(--r-pill); border: 2.5px solid var(--line); box-shadow: 2.5px 2.5px 0 var(--line); font-variant-numeric: tabular-nums; }
.timer-chip .ic { animation: tick 1s steps(8) infinite; }
@keyframes tick { to { transform: rotate(360deg); } }
.qcount { margin-left: auto; font-weight: 700; font-size: 13px; color: var(--muted); }
/* adventure trail */
.progress { display: flex; align-items: center; gap: 0; padding: 0 20px 6px; }
.progress i { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 12px; border: 2.5px solid var(--line); background: var(--card); color: var(--ink); flex: 0 0 auto; }
.progress i.done { background: var(--green); color: #fff; }
.progress i.cur { background: var(--gold); color: var(--ink); }
.progress .seg { flex: 1; height: 0; border-top: 3px dashed var(--trail); }

.q-body { padding: 8px 20px 20px; flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.clue-name { font-family: var(--display); font-weight: 700; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--coral-ink); margin-bottom: 4px; }
.loc-hint { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 2.5px solid var(--line); box-shadow: 2px 2px 0 var(--line); border-radius: var(--r-pill); padding: 5px 12px; font-size: 12.5px; font-weight: 700; color: var(--teal-d); margin-bottom: 10px; }
.instructions { font-size: 13.5px; font-weight: 500; color: var(--ink); line-height: 1.4; background: var(--card); border: 3px solid var(--line); border-radius: var(--r-lg); box-shadow: 4px 5px 0 var(--line); padding: 11px 13px; margin-bottom: 12px; }
.q-task { font-weight: 600; font-size: 14px; color: var(--ink); margin-bottom: 7px; }
.q-prompt { font-family: var(--display); font-weight: 600; font-size: 19px; line-height: 1.22; color: var(--ink); background: var(--card); border: 3px solid var(--line); border-radius: var(--r-lg); box-shadow: 4px 5px 0 var(--line); padding: 13px 15px; margin-bottom: 14px; }
.q-image { border: 3px solid var(--line); border-radius: var(--r-xl); box-shadow: 4px 5px 0 var(--line); background: linear-gradient(160deg, #fff7e6, #ffeede); padding: 12px; display: grid; place-items: center; margin-bottom: 14px; min-height: 124px; }
.q-image img { max-width: 100%; max-height: 300px; border-radius: var(--r-md); }
.q-image .noimg { font-family: var(--display); color: var(--teal-d); font-size: 22px; }

.answer-display { min-height: 60px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; background: #fff; border: 3px solid var(--line); border-radius: var(--r-lg); overflow-x: auto; }
.answer-display.wrong { border-color: var(--coral); animation: shake 0.4s; }
@keyframes shake { 10%,90%{transform:translateX(-2px);} 30%,70%{transform:translateX(4px);} 50%{transform:translateX(-6px);} }
.rune { font-family: var(--rune); line-height: 1; }
.answer-display .rune { font-size: 32px; color: var(--teal-d); }
.answer-display .ph { color: #c9b48e; font-family: var(--display); font-size: 26px; font-weight: 600; }
.caret { width: 3px; height: 30px; background: var(--gold); border-radius: 2px; flex-shrink: 0; animation: blink 1s steps(2) infinite; }

.q-feedback { margin-top: 12px; background: #fff1ee; border: 3px solid var(--line); border-radius: var(--r-lg); box-shadow: 4px 5px 0 var(--line); padding: 12px 14px; animation: screenIn 0.25s var(--ease) both; }
.fb-head { font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--coral-ink); display: flex; align-items: center; gap: 8px; }
.fb-hint { margin-top: 9px; font-size: 13px; font-weight: 600; color: var(--ink); background: #fff7e6; border: 2px solid var(--line); border-radius: var(--r-md); padding: 9px 11px; line-height: 1.35; }

.kbd { margin-top: 14px; }
.kbd-modes { display: flex; gap: 8px; margin-bottom: 12px; }
.kbd-mode { flex: 1; font-family: var(--display); font-weight: 600; font-size: 14px; padding: 9px; border-radius: var(--r-pill); border: 2.5px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; box-shadow: 2.5px 2.5px 0 var(--line); }
.kbd-mode.active { background: var(--teal-d); color: #fff; }
.kbd-grid { display: grid; gap: 7px; }
.kbd-grid.digits { grid-template-columns: repeat(5, 1fr); }
.kbd-grid.letters { grid-template-columns: repeat(6, 1fr); }
.kbd-key { aspect-ratio: 1 / 1; display: grid; place-items: center; font-family: var(--rune); font-size: 22px; color: var(--ink); background: #fff; border: 2.5px solid var(--line); border-radius: 9px; box-shadow: 2px 3px 0 var(--line); cursor: pointer; transition: transform 0.1s var(--spring), box-shadow 0.1s var(--ease); }
.kbd-key:active { transform: translate(2px, 3px); box-shadow: 0 0 0 var(--line); background: var(--teal-d); color: #fff; }
.kbd-utils { display: flex; gap: 8px; margin-top: 10px; }
.kbd-util { flex: 1; font-family: var(--display); font-weight: 700; font-size: 15px; padding: 12px; border-radius: var(--r-lg); border: 3px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; box-shadow: 3px 4px 0 var(--line); display: flex; align-items: center; justify-content: center; gap: 7px; }
.kbd-util:active { transform: translate(2px, 3px); box-shadow: 0 0 0 var(--line); }
.q-actions { padding-top: 14px; }

/* success */
.success { padding: 30px 24px; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.success-badge { width: 84px; height: 84px; border-radius: 50%; background: var(--green); border: 3px solid var(--line); box-shadow: 5px 6px 0 var(--line); display: grid; place-items: center; color: #fff; font-size: 42px; font-weight: 700; margin-bottom: 8px; animation: pop 0.55s var(--spring) both; }
.success h2 { font-family: var(--display); font-size: 26px; color: var(--teal-d); margin-top: 10px; }
.success p { color: var(--ink); opacity: .9; font-size: 14px; font-weight: 500; line-height: 1.45; margin: 10px 0 24px; max-width: 340px; }
.success .btn { width: 100%; max-width: 320px; }

/* result */
.result { padding: 26px 24px; flex: 1; display: flex; flex-direction: column; text-align: center; position: relative; overflow: hidden; }
.result h2 { font-family: var(--display); font-size: 28px; color: var(--teal-d); margin-top: 8px; }
.result .place { display: inline-flex; align-items: baseline; gap: 6px; font-family: var(--display); font-weight: 700; margin-top: 6px; }
.result .place .big { font-size: 50px; color: var(--coral-ink); line-height: 1; }
.result .place .small { font-size: 16px; color: var(--muted); }
.stat-row { display: flex; gap: 12px; margin: 20px 0 8px; }
.stat { flex: 1; background: var(--card); border: 3px solid var(--line); border-radius: var(--r-lg); box-shadow: 4px 5px 0 var(--line); padding: 13px 6px; }
.stat .v { font-family: var(--display); font-weight: 700; font-size: 23px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat.rec .v { color: var(--teal); }
.stat .l { font-size: 10.5px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.result .actions { margin-top: auto; display: flex; flex-direction: column; gap: 11px; }
.confetti { position: absolute; top: -12px; width: 11px; height: 16px; border-radius: 2px; opacity: 0; }
.pop-confetti .confetti { animation: fall 1.5s var(--ease) forwards; }
@keyframes fall { 0% { opacity: 1; transform: translateY(0) rotate(0); } 100% { opacity: 0; transform: translateY(520px) rotate(540deg); } }

/* leaderboards */
.lb-head { padding: 14px 20px 6px; }
.lb-tabs { display: flex; gap: 8px; padding: 0 20px 12px; }
.lb-tab { flex: 1; font-family: var(--display); font-weight: 600; font-size: 13px; padding: 11px 8px; border-radius: var(--r-pill); border: 2.5px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; text-align: center; box-shadow: 2.5px 2.5px 0 var(--line); }
.lb-tab.active { background: var(--teal-d); color: #fff; }
.lb-title { font-family: var(--display); font-size: 21px; color: var(--teal-d); }
.lb-title .ic { font-size: 20px; }
.lb-sub { color: var(--muted); font-size: 12.5px; font-weight: 500; margin-top: 2px; }
.lb-list { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; flex: 1; }
.lb-row { display: flex; align-items: center; gap: 11px; background: var(--card); border: 2.5px solid var(--line); border-radius: var(--r-lg); box-shadow: 3px 3px 0 var(--line); padding: 10px 12px; animation: rowIn 0.4s var(--spring) both; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
.lb-row.me { background: #fff3d6; border-color: var(--gold-d); box-shadow: 3px 3px 0 var(--gold-d); }
.rank { font-family: var(--display); font-weight: 700; font-size: 16px; width: 26px; text-align: center; color: var(--muted); flex-shrink: 0; }
.rank.gold { color: var(--gold-d); } .rank.silver { color: #8a92a8; } .rank.bronze { color: #b06a32; }
.lb-av { width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0; display: grid; place-items: center; color: #fff; font-family: var(--display); font-weight: 700; font-size: 16px; border: 2.5px solid var(--line); }
.lb-meta { flex: 1; min-width: 0; }
.lb-meta b { font-family: var(--display); font-weight: 600; font-size: 15px; display: block; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-meta span { font-size: 12px; color: var(--muted); font-weight: 500; }
.lb-score { text-align: right; flex-shrink: 0; }
.lb-score b { font-family: var(--display); font-weight: 700; font-size: 16px; color: var(--teal); font-variant-numeric: tabular-nums; }
.lb-score span { display: block; font-size: 10.5px; color: var(--muted); font-weight: 600; }
.lb-empty { text-align: center; color: var(--muted); font-weight: 600; padding: 30px 10px; }
.lb-foot { padding: 12px 20px 22px; }

/* loading / error */
.center-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 30px; text-align: center; }
.spinner { width: 44px; height: 44px; border: 5px solid #e7dcc2; border-top-color: var(--teal-d); border-radius: 50%; animation: spin 0.8s linear infinite; }
.muted { color: var(--muted); font-size: 13px; font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
