:root {
  --sky-top: #8fd8f8;
  --sky-mid: #b9ebfb;
  --sky-bot: #d9f5f5;
  --sand: #f6e2a6;
  --sand-dark: #e9cc85;
  --sun: #ffe45c;
  --sun-deep: #f5c518;
  --sponge-hole: rgba(196, 150, 20, .28);
  --brown: #9a6232;
  --brown-dark: #6e4220;
  --pink: #ff9cc2;
  --pink-soft: #ffd6e6;
  --lilac: #c9b5ff;
  --teal: #5fd3c4;
  --teal-soft: #d4f6f0;
  --coral: #ff8a7a;
  --ink: #2d3a5a;
  --ink-soft: #5d6a88;
  --card: rgba(255, 253, 244, .94);
  --card-border: #fff;
  --ok: #3cbf7c;
  --ok-soft: #d9f7e6;
  --bad: #f2647a;
  --bad-soft: #ffe0e5;
  --shadow: 0 6px 0 rgba(110, 66, 32, .18), 0 12px 28px rgba(45, 58, 90, .12);
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #2d7fdc;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Фон ---------- */
.scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; background: linear-gradient(180deg, #1660c4 0%, #2d7fdc 30%, #5aa6ea 55%, #5aa6ea 100%); }
#sceneArt, .floaters, .ground { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.skyfl, .jelly { position: absolute; transform: translate(-50%, -50%); will-change: transform; }
.skyfl svg, .jelly svg { width: 100%; height: 100%; display: block; overflow: visible; }
.brand-logo svg { --pf: #fff; --pc: var(--pink); }
.skyfl { animation: drift 24s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(calc(-50% - 14px), calc(-50% - 6px)) rotate(-7deg); }
  to   { transform: translate(calc(-50% + 18px), calc(-50% + 8px)) rotate(8deg); }
}
.jelly { animation: bob 6s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translate(-50%, -50%) rotate(-4deg); } to { transform: translate(calc(-50% + 10px), calc(-50% - 22px)) rotate(4deg); } }
.w-dark { fill: none; stroke: #2a8a1e; stroke-linecap: round; stroke-linejoin: round; }
.w-light { fill: none; stroke: #6ee03f; stroke-linecap: round; stroke-linejoin: round; }
.sway { transform-box: fill-box; transform-origin: bottom center; animation: sway 5s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(5deg); } }
.bubbles i {
  position: absolute; bottom: -30px; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.8); background: rgba(255,255,255,.18);
  animation: rise 14s linear infinite;
}
.bubbles i:nth-child(1) { left: 6%;  animation-delay: 0s;  }
.bubbles i:nth-child(2) { left: 18%; animation-delay: 5s; width: 9px; height: 9px; }
.bubbles i:nth-child(3) { left: 33%; animation-delay: 9s; }
.bubbles i:nth-child(4) { left: 52%; animation-delay: 2s; width: 20px; height: 20px; }
.bubbles i:nth-child(5) { left: 67%; animation-delay: 7s; width: 10px; height: 10px; }
.bubbles i:nth-child(6) { left: 79%; animation-delay: 11s; }
.bubbles i:nth-child(7) { left: 90%; animation-delay: 4s; width: 8px; height: 8px; }
.bubbles i:nth-child(8) { left: 44%; animation-delay: 13s; width: 12px; height: 12px; }
@keyframes rise {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: 1; }
  50% { transform: translate(14px, -50vh); }
  100% { transform: translate(-10px, -105vh); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skyfl, .jelly, .sway, .bubbles i { animation: none !important; }
  .bubbles { display: none; }
}

/* ---------- Верхня панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: linear-gradient(180deg, rgba(22,96,196,.92), rgba(22,96,196,0));
}
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px; }
.brand-logo { width: 38px; height: 38px; display: grid; place-items: center; background: var(--sun); border-radius: 12px; box-shadow: 0 3px 0 var(--sun-deep); }
.brand-logo svg { width: 30px; height: 30px; }
.brand-text { font-weight: 900; font-size: 20px; letter-spacing: .3px; color: #fff; text-shadow: 0 2px 0 #0d3f8a, 0 0 1px #0d3f8a; }
.audio { display: flex; gap: 6px; }
.round-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 3px solid #fff;
  background: var(--sun); box-shadow: 0 3px 0 var(--sun-deep); font-size: 18px;
  display: grid; place-items: center; transition: transform .1s;
}
.round-btn.small { width: 36px; height: 36px; font-size: 14px; margin-top: 3px; }
.round-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sun-deep); }
.round-btn.off { background: #e9eef5; box-shadow: 0 3px 0 #c6cfdb; filter: grayscale(1); opacity: .75; }
.track-name {
  position: sticky; top: 58px; z-index: 19; margin: 0 auto; width: max-content; max-width: calc(100% - 32px);
  font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 99px;
  background: rgba(255,255,255,.75); color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Каркас ---------- */
.app {
  position: relative; z-index: 1;
  max-width: 820px; margin: 0 auto;
  padding: 8px 16px calc(140px + var(--safe-b));
}
.card {
  background: var(--card); border: 3px solid var(--card-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
h1, h2, h3 { margin: 0 0 10px; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 900; }
h2 { font-size: 20px; font-weight: 900; }
h3 { font-size: 16px; font-weight: 800; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.screen-title {
  font-size: 26px; font-weight: 900; color: #fff; margin: 6px 0 14px;
  text-shadow: 0 3px 0 #0d3f8a, 0 0 2px #0d3f8a;
}

/* ---------- Кнопки «губка» ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 22px; border-radius: 18px;
  border: 3px solid var(--brown); font-weight: 900; font-size: 17px; color: var(--brown-dark);
  background:
    radial-gradient(circle at 14% 30%, var(--sponge-hole) 0 5px, transparent 6px),
    radial-gradient(circle at 82% 70%, var(--sponge-hole) 0 6px, transparent 7px),
    radial-gradient(circle at 62% 22%, var(--sponge-hole) 0 3px, transparent 4px),
    radial-gradient(circle at 34% 78%, var(--sponge-hole) 0 3px, transparent 4px),
    var(--sun);
  box-shadow: 0 5px 0 var(--brown);
  transition: transform .08s, box-shadow .08s;
  text-decoration: none; user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--brown); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 0 5px 0 var(--brown); }
.btn.pink { background-color: var(--pink-soft); border-color: #d9709b; color: #8e2f58; box-shadow: 0 5px 0 #d9709b;
  background-image: radial-gradient(circle at 14% 30%, rgba(217,112,155,.25) 0 5px, transparent 6px), radial-gradient(circle at 82% 70%, rgba(217,112,155,.25) 0 6px, transparent 7px); }
.btn.teal { background-color: var(--teal-soft); border-color: #2fa596; color: #17665c; box-shadow: 0 5px 0 #2fa596;
  background-image: radial-gradient(circle at 14% 30%, rgba(47,165,150,.22) 0 5px, transparent 6px), radial-gradient(circle at 82% 70%, rgba(47,165,150,.22) 0 6px, transparent 7px); }
.btn.ghost { background: rgba(255,255,255,.85); border-color: #b8c6dc; color: var(--ink-soft); box-shadow: 0 4px 0 #b8c6dc; }
.btn.block { width: 100%; }
.btn .ico { font-size: 22px; }

/* ---------- Головна ---------- */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.ring { width: 118px; height: 118px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: #f0e6c4; stroke-width: 12; }
.ring .val { fill: none; stroke: var(--teal); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .8s; }
.ring .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 900; font-size: 26px; line-height: 1; }
.ring .lbl small { display: block; font-size: 11px; font-weight: 700; color: var(--ink-soft); margin-top: 3px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: #fff; border-radius: 16px; padding: 10px 8px; text-align: center; border: 2px solid #f1e8cb; }
.kpi b { display: block; font-size: 22px; font-weight: 900; }
.kpi span { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.mode-btn { flex-direction: column; min-height: 120px; text-align: center; font-size: 19px; border-radius: 26px; }
.mode-btn .ico { font-size: 38px; }
.mode-btn small { font-size: 12px; font-weight: 700; opacity: .8; }
.mode-btn.wide { grid-column: 1 / -1; min-height: 70px; flex-direction: row; }
.mode-btn.wide .ico { font-size: 28px; }
.badge { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 13px; font-weight: 900; }
.sec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sec-box { border-radius: 18px; padding: 12px; }
.sec-box.best { background: var(--ok-soft); }
.sec-box.worst { background: var(--bad-soft); }
.sec-box h3 { font-size: 14px; }
.sec-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 14px; padding: 5px 0; border-top: 1px dashed rgba(45,58,90,.15); }
.sec-row:first-of-type { border-top: 0; }
.sec-row span { overflow: hidden; text-overflow: ellipsis; }
.sec-row b { white-space: nowrap; }
.bar { height: 8px; border-radius: 99px; background: #f0e6c4; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--teal); border-radius: 99px; }
details.all-secs summary { cursor: pointer; font-weight: 800; color: var(--ink-soft); padding: 6px 0; }
.sec-line { padding: 8px 0; border-top: 1px dashed rgba(45,58,90,.15); font-size: 14px; }
.sec-line .top { display: flex; justify-content: space-between; gap: 10px; }

/* ---------- Налаштування вибірки ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #f3ecd2; padding: 5px; border-radius: 18px; margin-bottom: 14px; }
.seg button { border: 0; background: transparent; border-radius: 14px; padding: 12px 6px; font-weight: 800; font-size: 15px; color: var(--ink-soft); }
.seg button.on { background: var(--sun); color: var(--brown-dark); box-shadow: 0 3px 0 var(--sun-deep); }
.field-label { font-weight: 800; margin: 14px 0 8px; display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid #e4d6a6; background: #fff; border-radius: 99px; padding: 8px 14px; font-weight: 800; font-size: 14px;
}
.chip.on { background: var(--pink-soft); border-color: #e27fa8; color: #8e2f58; }
.sec-list { display: grid; gap: 8px; }
.sec-item {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; text-align: left;
  border: 2px solid #ece0b8; background: #fff; border-radius: 16px; padding: 10px 12px;
}
.sec-item .num { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: #f3ecd2; font-weight: 900; font-size: 13px; }
.sec-item .ttl { font-weight: 700; font-size: 14px; line-height: 1.25; }
.sec-item .cnt { font-size: 12px; color: var(--ink-soft); font-weight: 800; white-space: nowrap; }
.sec-item.on { border-color: var(--teal); background: var(--teal-soft); }
.sec-item.on .num { background: var(--teal); color: #fff; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.num-input {
  width: 110px; padding: 10px 12px; border-radius: 14px; border: 2px solid #e4d6a6; background: #fff; font-weight: 800; font-size: 16px;
}
.num-input:focus { outline: 3px solid var(--pink); outline-offset: 1px; }
.summary-line { margin-top: 14px; padding: 10px 14px; border-radius: 14px; background: #fff7d1; font-weight: 800; }
.sticky-cta {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(0deg, rgba(35,28,94,.85) 55%, rgba(35,28,94,0));
}
.sticky-cta .inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; }
.sticky-cta .btn { flex: 1; }

/* ---------- Тест ---------- */
.quiz-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.quiz-head .close { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; background: rgba(255,255,255,.8); font-weight: 900; flex: none; }
.progress { flex: 1; height: 16px; border-radius: 99px; background: rgba(255,255,255,.75); border: 3px solid #fff; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(45deg, var(--sun) 0 10px, #ffd23a 10px 20px); transition: width .3s; }
.quiz-count { font-weight: 900; color: #fff; text-shadow: 0 2px 0 #0d3f8a; white-space: nowrap; }
.streak-pill { display: inline-flex; gap: 4px; align-items: center; font-weight: 900; font-size: 13px; padding: 3px 10px; border-radius: 99px; background: #fff3b8; color: var(--brown-dark); }
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 99px; background: #eaf7ff; color: #2a7bb0; }
.tag.num { background: var(--sun); color: var(--brown-dark); }
.q-text { font-size: 19px; font-weight: 800; line-height: 1.4; white-space: pre-line; margin-bottom: 12px; }
.q-hint { font-size: 13px; font-weight: 800; color: #8e2f58; background: var(--pink-soft); display: inline-block; padding: 4px 10px; border-radius: 10px; margin-bottom: 12px; }
.q-imgs { display: grid; gap: 10px; margin-bottom: 14px; }
.q-imgs img { width: 100%; height: auto; border-radius: 14px; border: 3px solid #fff; background: #fff; cursor: zoom-in; box-shadow: 0 3px 10px rgba(0,0,0,.08); }
.q-imgs .zoom-hint { font-size: 12px; color: var(--ink-soft); text-align: center; margin-top: -4px; }
.opts { display: grid; gap: 10px; }
.opt {
  display: grid; grid-template-columns: 36px 1fr 26px; gap: 10px; align-items: center; text-align: left;
  width: 100%; min-height: 56px; padding: 10px 12px; border-radius: 18px;
  border: 3px solid #eadfbc; background: #fff; font-weight: 700; font-size: 16px; line-height: 1.35;
  box-shadow: 0 3px 0 #eadfbc; transition: transform .08s, background .15s, border-color .15s;
}
.opt:active { transform: translateY(2px); }
.opt .n { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: #f3ecd2; font-weight: 900; }
.opt .mark { font-size: 20px; text-align: center; }
.opt.multi .n { border-radius: 8px; }
.opt.sel { border-color: #6fb7e6; background: #eaf7ff; box-shadow: 0 3px 0 #6fb7e6; }
.opt.sel .n { background: #6fb7e6; color: #fff; }
.opt.ok { border-color: var(--ok); background: var(--ok-soft); box-shadow: 0 3px 0 var(--ok); }
.opt.ok .n { background: var(--ok); color: #fff; }
.opt.bad { border-color: var(--bad); background: var(--bad-soft); box-shadow: 0 3px 0 var(--bad); }
.opt.bad .n { background: var(--bad); color: #fff; }
.opt.missed { border-color: var(--ok); border-style: dashed; }
.opt[disabled] { cursor: default; }
.verdict { margin-top: 14px; padding: 12px 14px; border-radius: 16px; font-weight: 800; }
.verdict.ok { background: var(--ok-soft); color: #1d7a4b; }
.verdict.bad { background: var(--bad-soft); color: #a62a3e; }

/* ---------- Результати / помилки ---------- */
.result-hero { text-align: center; }
.result-hero .big { font-size: 56px; font-weight: 900; line-height: 1; margin: 6px 0; }
.result-hero .mascot { width: 120px; height: 120px; margin: 0 auto; }
.mist { border-top: 2px dashed #ecdfb6; padding: 14px 0; }
.mist:first-child { border-top: 0; padding-top: 0; }
.mist .q-text { font-size: 16px; margin-bottom: 8px; }
.mist .ans { font-size: 14px; line-height: 1.45; margin-top: 4px; }
.mist .ans b { display: inline-block; min-width: 0; }
.ans.ok { color: #1d7a4b; }
.ans.bad { color: #a62a3e; }
.mist .q-imgs img { max-height: 260px; object-fit: contain; }
.mist-actions { display: flex; gap: 8px; margin-top: 8px; }
.link-btn { border: 0; background: none; color: #2a7bb0; font-weight: 800; padding: 4px 0; text-decoration: underline; }
#resetStats, #clearM { background: rgba(255,255,255,.85); padding: 6px 14px; border-radius: 99px; }
.empty { text-align: center; padding: 26px 10px; }
.empty .mascot { width: 110px; height: 110px; margin: 0 auto 8px; }

/* ---------- Похвала за серію ---------- */
.cheer {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); z-index: 40;
  transform: translate(-50%, 140%); opacity: 0;
  width: min(460px, calc(100% - 24px));
  display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center;
  padding: 10px 14px 10px 8px; border-radius: 24px;
  background: #fffdf2; border: 4px solid var(--sun); box-shadow: 0 10px 30px rgba(45,58,90,.25);
  transition: transform .45s cubic-bezier(.2,1.4,.4,1), opacity .3s;
}
.cheer.show { transform: translate(-50%, 0); opacity: 1; }
.cheer .mascot { width: 96px; height: 96px; animation: bounce 1s ease-in-out infinite alternate; }
.cheer .msg b { display: block; font-size: 22px; font-weight: 900; color: var(--brown-dark); }
.cheer .msg span { font-weight: 800; font-size: 15px; }
@keyframes bounce { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-6px) rotate(4deg); } }
.mascot svg, .mascot img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Збільшення зображень ---------- */
.zoom { position: fixed; inset: 0; z-index: 60; background: rgba(20, 40, 70, .88); display: grid; place-items: center; padding: 12px; overflow: auto; }
.zoom img { max-width: none; width: min(1400px, 200vw); background: #fff; border-radius: 10px; touch-action: pinch-zoom pan-x pan-y; }
@media (min-width: 900px) { .zoom img { width: auto; max-width: 96vw; max-height: 92vh; } }
.zoom-close { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; width: 46px; height: 46px; border-radius: 50%; border: 3px solid #fff; background: var(--bad); color: #fff; font-size: 20px; font-weight: 900; }

/* ---------- Телефон ---------- */
@media (max-width: 600px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px; border-radius: 20px; }
  .brand-text { font-size: 18px; }
  .hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .kpis { width: 100%; }
  .modes { gap: 10px; }
  .mode-btn { min-height: 108px; font-size: 17px; padding: 10px; }
  .sec-grid { grid-template-columns: 1fr; }
  .q-text { font-size: 17px; }
  .num-input { width: 88px; }
  .row { gap: 8px; }
  .opt { font-size: 15px; grid-template-columns: 32px 1fr 22px; padding: 9px 10px; }
  .opt .n { width: 32px; height: 32px; }
  .screen-title { font-size: 22px; }
  .cheer { grid-template-columns: 76px 1fr; bottom: calc(84px + var(--safe-b)); }
  .cheer .mascot { width: 76px; height: 76px; }
  .cheer .msg b { font-size: 19px; }
  .cheer .msg span { font-size: 14px; }
}
@media (min-width: 900px) {
  .q-imgs img { max-height: 520px; object-fit: contain; }
}
