/* Design tokens and components ported from the prototype (misha-quest-site/index.html): dark "comic night city" theme, mobile-first. */
:root {
  --bg: #0e1124;
  --panel: #171b35;
  --panel-2: #1f2446;
  --line: #2c3260;
  --fg: #eef0ff;
  --muted: #9ba1cc;
  --red: #ff3d57;
  --red-deep: #c4183a;
  --yellow: #ffd23f;
  --blue: #4a86ff;
  --good: #3ad69e;
  --bad: #ff7a7a;
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --body: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(circle at 1px 1px, rgba(74,134,255,.10) 1px, transparent 1.4px) 0 0 / 14px 14px,
    var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
.app { max-width: 560px; margin: 0 auto; padding-inline: 16px; padding-block: calc(14px + env(safe-area-inset-top, 0px)) calc(110px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; }


/* HUD */
.hud { position: relative; background: linear-gradient(135deg, var(--red-deep), var(--red) 55%, #ff6b4a); border-radius: 22px; padding: 18px; overflow: hidden; box-shadow: 0 10px 0 -4px #000a; }
.hud::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 2px 2px, rgba(0,0,0,.18) 1.2px, transparent 1.6px) 0 0 / 9px 9px; mask-image: linear-gradient(120deg, transparent 40%, #000); pointer-events: none; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; position: relative; z-index: 1; }
.lvl-badge { font-family: var(--display); font-weight: 800; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; opacity: .9; }
.player { font-family: var(--display); font-weight: 800; font-size: 28px; line-height: 1.05; margin: 4px 0 0; text-wrap: balance; }
.coins { display: flex; align-items: center; gap: 6px; background: #0007; padding: 6px 12px 6px 6px; border-radius: 999px; font-family: var(--mono); font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.coin { width: 24px; height: 24px; flex: none; }
.xp { position: relative; z-index: 1; margin-top: 16px; }
.xp-row { display: flex; justify-content: space-between; font-size: 12px; font-weight: 500; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.bar { height: 14px; background: #0006; border-radius: 999px; overflow: hidden; border: 2px solid #0004; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--yellow), #fff3b0); border-radius: 999px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.hud-stats { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: #0005; border-radius: 12px; padding: 8px 10px; }
.stat b { display: block; font-family: var(--mono); font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; opacity: .85; }

/* Sections */
h2 { font-family: var(--display); font-weight: 800; font-size: 16px; letter-spacing: .02em; margin: 6px 0 0; text-transform: uppercase; }
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }

.chest { display: flex; gap: 14px; align-items: center; background: var(--panel-2); border: 2px dashed var(--yellow); border-radius: 18px; padding: 14px; }
.chest-ico { width: 54px; height: 54px; flex: none; }
.chest-body { flex: 1; min-width: 0; }
.chest-title { font-weight: 700; }
.pips { display: flex; gap: 6px; margin-top: 8px; }
.pip { flex: 1; height: 8px; border-radius: 4px; background: var(--line); }
.pip.on { background: var(--yellow); }

.task { display: flex; gap: 12px; align-items: center; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 500; }
.task-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.pts { font-family: var(--mono); font-weight: 700; color: var(--yellow); font-size: 13px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.btn { border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 700; background: var(--fg); color: var(--bg); white-space: nowrap; transition: transform .1s; }
.btn:active { transform: translateY(2px); }
.btn.red { background: var(--red); color: #fff; box-shadow: 0 3px 0 var(--red-deep); }
.btn.yellow { background: var(--yellow); color: #231a00; box-shadow: 0 3px 0 #b8930e; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--fg); }
.btn.small { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.state { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 10px; white-space: nowrap; }
.state.wait { background: #4a86ff22; color: var(--blue); }
.state.ok { background: #3ad69e22; color: var(--good); }
.state.no { background: #ff7a7a22; color: var(--bad); }

/* Focus */
.focus { display: flex; align-items: center; gap: 16px; }
.ring { width: 92px; height: 92px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .t { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.focus-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Shop */
.shop { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.item-ico { font-size: 30px; line-height: 1; }
.item-title { font-weight: 500; flex: 1; }
.item-cost { display: flex; align-items: center; gap: 5px; font-family: var(--mono); font-weight: 700; color: var(--yellow); }
.item-cost .coin { width: 18px; height: 18px; }
.item.locked .item-ico { filter: grayscale(1); opacity: .5; }
.need { font-size: 11px; color: var(--muted); }

/* Achievements */
.ach { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.badge { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; gap: 10px; align-items: flex-start; }
.badge .medal { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 20px; background: var(--panel-2); }
.badge.on .medal { background: radial-gradient(circle at 35% 30%, #fff6c9, var(--yellow) 60%, #b8930e); box-shadow: 0 0 0 3px #ffd23f33; }
.badge:not(.on) .medal { filter: grayscale(1); opacity: .45; }
.badge b { display: block; font-size: 14px; }
.badge span { font-size: 12px; color: var(--muted); display: block; }
.badge em { font-style: normal; font-family: var(--mono); font-size: 11px; color: var(--yellow); }

/* Log */
.log { display: flex; flex-direction: column; }
.log-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.log-row:last-child { border-bottom: 0; }
.log-row .d { font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plus { color: var(--good); } .minus { color: var(--bad); }
.when { color: var(--muted); font-size: 11px; }

/* Parent */
.pending { display: flex; gap: 12px; align-items: flex-start; }
.pending img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; }
.form { display: flex; flex-direction: column; gap: 8px; }
.form input, .form textarea { background: var(--bg); border: 1px solid var(--line); color: var(--fg); border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%; }
.form-row { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 8px; }

/* Sheet (submit dialog) */
.sheet-bg { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-end; justify-content: center; z-index: 30; }
.sheet { background: var(--panel); border-top: 3px solid var(--red); border-radius: 22px 22px 0 0; width: 100%; max-width: 560px; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; }
.sheet h3 { font-family: var(--display); font-size: 17px; margin: 0; }
.photo-pick { display: flex; align-items: center; gap: 10px; }
.photo-pick img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }

/* Tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #0e1124f2; border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); backdrop-filter: blur(8px); }
.tabs-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.tab { background: none; border: 0; border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 500; color: var(--muted); position: relative; }
.tab svg { width: 22px; height: 22px; }
.tab { text-decoration: none; }
.tab[aria-current="page"] { color: var(--fg); background: var(--panel); }
.tab[aria-current="page"] svg { color: var(--red); }
.dot { position: absolute; top: 4px; right: calc(50% - 20px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

/* Toasts & level up */
.toasts { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--fg); color: var(--bg); border-radius: 14px; padding: 10px 14px; font-weight: 500; box-shadow: 0 8px 24px #0008; animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
.toast b { font-family: var(--mono); }
.lvlup { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: #000c; padding: 24px; }
.lvlup-card { text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; animation: pop .5s cubic-bezier(.2,1.4,.4,1); }
.lvlup-card .big { font-family: var(--display); font-weight: 800; font-size: clamp(34px, 11vw, 56px); line-height: 1; color: var(--yellow); text-shadow: 4px 4px 0 var(--red-deep); text-wrap: balance; }
.lvlup-card p { margin: 0; color: var(--fg); font-size: 17px; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (max-width: 380px) { .shop, .ach { grid-template-columns: 1fr; } .player { font-size: 24px; } }

/* Forms, auth pages, flash */
.narrow { max-width: 420px; width: 100%; margin: 0 auto; }
.brand { font-family: var(--display); font-weight: 800; font-size: 26px; line-height: 1.1; margin: 18px 0 4px; color: var(--yellow); text-shadow: 3px 3px 0 var(--red-deep); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 500; color: var(--muted); }
.form input:focus-visible, .form textarea:focus-visible { outline: 2px solid var(--yellow); outline-offset: 1px; }
.form .btn { width: 100%; padding-block: 12px; margin-top: 4px; }
.errors { background: #ff7a7a1a; border: 1px solid #ff7a7a55; color: var(--bad); border-radius: 12px; padding: 10px 14px; font-size: 13px; }
.errors ul { margin: 0; padding-left: 18px; }
.flash { border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 500; }
.flash.notice { background: #3ad69e1f; color: var(--good); }
.flash.alert { background: #ff7a7a1f; color: var(--bad); }
.links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; }
a { color: var(--yellow); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.button_to { margin: 0; }

/* Family, login links, child login */
.nav-card { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--fg); }
.qr-box { background: #fff; border-radius: 14px; padding: 14px; width: min(100%, 260px); margin: 0 auto; }
.qr { display: block; width: 100%; height: auto; }
.copy { display: flex; gap: 8px; }
.copy input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--fg); border-radius: 10px; padding: 8px 10px; font: 13px var(--mono); }
.form input.pin { font-family: var(--mono); font-size: 24px; letter-spacing: .4em; text-align: center; }
.banner { display: flex; justify-content: space-between; gap: 12px; align-items: center; background: #4a86ff22; color: var(--blue); border-radius: 12px; padding: 10px 14px; font-size: 13px; font-weight: 500; }
.stretch .btn { width: 100%; }

/* Stage 3: tasks, review, points */
.form select, .form input[type="date"], .form input[type="number"] { background: var(--bg); border: 1px solid var(--line); color: var(--fg); border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%; }
.form-row.even { grid-template-columns: 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: auto; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field legend { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-block; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; }
.chip input:checked + span { background: var(--yellow); color: #231a00; border-color: var(--yellow); }
.chip input:focus-visible + span { outline: 2px solid var(--yellow); outline-offset: 2px; }
.task.inactive { opacity: .55; }
.state.muted { background: var(--panel-2); color: var(--muted); font-weight: 500; }
.deadline { color: var(--yellow); }
.review-note { font-size: 12px; color: var(--bad); margin-top: 4px; }
.note { font-size: 13px; margin-top: 6px; background: var(--panel-2); border-radius: 10px; padding: 6px 10px; }
.review-actions { margin-top: 8px; align-items: flex-start; }
.reject summary { list-style: none; cursor: pointer; }
.reject summary::-webkit-details-marker { display: none; }
.reject[open] summary { display: none; }
.reject .form { flex-direction: row; flex-wrap: wrap; }
.chest-like { border: 2px dashed var(--blue); }
.privacy { text-align: center; font-size: 12px; }
.lvlup-card .big.down { color: var(--fg); text-shadow: 4px 4px 0 var(--line); }
.lvlup-card .sub { max-width: 320px; }
.coins.small { font-size: 15px; }
.grow { flex: 1; text-align: center; }
a.btn { text-decoration: none; display: inline-block; text-align: center; }
.level-row { align-items: center; }
.level-row input { width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--fg); border-radius: 8px; padding: 6px 8px; font: inherit; }
.level-row input[type="number"] { max-width: 90px; }
.log-row .d { text-align: right; }

/* Stage 4: shop */
.reward-img { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; flex: none; }
.task .reward-img { width: 36px; height: 36px; }
.task .item-ico { font-size: 26px; flex: none; }
.chip.emoji span { font-size: 20px; padding: 4px 8px; }
.shop-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.item .button_to .btn { width: 100%; }
.label { font-size: 13px; font-weight: 500; color: var(--muted); }

/* Stage 5: chest, focus, achievements */
.task .chest-ico { width: 40px; height: 40px; flex: none; }
.lvlup-card .chest-ico { width: 88px; height: 88px; }
.lvlup-card p b { color: var(--yellow); }
.badge.secret .medal { filter: none; opacity: .7; }
details > summary { list-style: none; cursor: pointer; width: fit-content; }
details > summary::-webkit-details-marker { display: none; }
.chest-form { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.ring .t { pointer-events: none; }

/* Stage 7: AI tutor */
.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.bubble p, .bubble div { margin: 0; }
.bubble div + div { margin-top: 6px; }
.bubble.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.me { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.bubble.failed { color: var(--bad); }
.chat-photo { display: block; max-width: 100%; border-radius: 10px; margin-bottom: 6px; }
.chat-form textarea { background: var(--bg); border: 1px solid var(--line); color: var(--fg); border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%; resize: vertical; }
.file-btn { position: relative; cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tutor-card { border-color: var(--blue); }
.hud-stats.plain { position: static; margin: 0; }
.hud-stats.plain .stat { background: var(--panel); border: 1px solid var(--line); }
.usage-row { align-items: center; }
.usage-bar { flex: 1; height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.usage-bar i { display: block; height: 100%; background: var(--yellow); }
.usage-row .tokens { min-width: 80px; text-align: right; }
.need.goal { color: var(--yellow); }

/* Photo gallery (PhotoSwipe): keep its buttons clear of the notch and the home indicator */
.pswp__top-bar { top: env(safe-area-inset-top, 0px); }
.pswp__counter { font-family: var(--mono); }
.pswp__button--arrow { bottom: env(safe-area-inset-bottom, 0px); }
