/* Nunito (SIL OFL 1.1, src/fonts/OFL.txt): static 800 + 900 — variable fonts render hairline-thin on some WebViews */
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 800; font-display: swap;
  src: url(src/fonts/nunito-800-cyrillic-ext.woff2) format('woff2'); unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 800; font-display: swap;
  src: url(src/fonts/nunito-800-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 800; font-display: swap;
  src: url(src/fonts/nunito-800-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 900; font-display: swap;
  src: url(src/fonts/nunito-900-cyrillic-ext.woff2) format('woff2'); unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 900; font-display: swap;
  src: url(src/fonts/nunito-900-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 900; font-display: swap;
  src: url(src/fonts/nunito-900-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --ink: #1b1e2b;
  --ink-soft: rgba(27, 30, 43, 0.66);
  --glass: rgba(255, 255, 255, 0.74);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --line: rgba(27, 30, 43, 0.1);
  --gold: #f5b301;
  --accent: #e9893a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --host-top: 0px;
  --host-side: 0px;
  --top: calc(var(--safe-top) + var(--host-top) + 10px);
  --ease: cubic-bezier(0.2, 0.9, 0.25, 1.05);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #f6b46b;
  color: var(--ink);
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-weight: 800;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
#ui > .hud, #ui > .toasts, #ui > .ready, #ui > .pause { pointer-events: none; }
.ready > *, .pause > * { pointer-events: auto; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
svg { display: block; width: 100%; height: 100%; }

/* ---------------------------------------------------------------- shared bits */
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; padding: 12px;
  background: var(--glass); color: var(--ink);
  box-shadow: 0 6px 18px rgba(30, 20, 40, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform 0.18s var(--ease), opacity 0.2s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn:disabled { opacity: 0; pointer-events: none; }
.coin { display: inline-block; width: 22px; height: 22px; flex: none; }
.coin.small { width: 18px; height: 18px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 18px;
  font-size: 17px; font-weight: 900; letter-spacing: 0.01em;
  transition: transform 0.16s var(--ease), background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--ink); color: #fff; box-shadow: 0 10px 24px rgba(20, 22, 34, 0.28); }
.btn.primary:disabled { background: rgba(27, 30, 43, 0.45); box-shadow: none; cursor: default; }
.btn.secondary { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.ghost { background: var(--glass); color: var(--ink); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.btn.big { min-height: 60px; font-size: 20px; border-radius: 20px; width: 100%; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 15px; border-radius: 14px; }
.btn-ico { width: 20px; height: 20px; }
.link-btn { color: var(--ink); text-decoration: underline; font-weight: 900; padding: 6px 4px; }

.pop { animation: pop 0.42s var(--ease); }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.22); } 100% { transform: scale(1); } }
.shake { animation: shake 0.42s ease; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

/* ---------------------------------------------------------------- top bar (ready) */
.topbar {
  position: absolute; top: var(--top); left: calc(12px + var(--host-side)); right: calc(12px + var(--host-side));
  display: flex; justify-content: space-between; align-items: center; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.wallet {
  display: flex; align-items: center; gap: 7px; height: 44px; padding: 0 16px 0 10px; border-radius: 22px;
  background: var(--glass); font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 18px rgba(30, 20, 40, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform 0.18s var(--ease);
}
.wallet:active { transform: scale(0.94); }

/* ---------------------------------------------------------------- HUD (playing) */
.hud {
  position: absolute; top: var(--top); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
}
.hud-time {
  font-size: 46px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  color: var(--ink); text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55), 0 0 18px rgba(255, 255, 255, 0.65);
}
.hud-points {
  display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px 0 8px; border-radius: 17px;
  background: var(--glass); font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 14px rgba(30, 20, 40, 0.12); transition: background 0.25s, color 0.25s;
}
.hud-badge {
  margin-left: 2px; padding: 2px 8px; border-radius: 10px; font-size: 14px; font-weight: 900;
  background: var(--ink); color: #fff;
}
.hud.perfect .hud-points { background: #fff4c2; color: #8a5a00; box-shadow: 0 0 0 2px #ffd34d, 0 6px 18px rgba(245, 179, 1, 0.45); }
.hud.perfect .hud-badge { background: var(--gold); color: #3b2600; }
.hud.record .hud-points-num { color: #b37400; }
.hud-stars { display: flex; gap: 4px; margin-top: 4px; }
.hud-star { width: 18px; height: 18px; fill: rgba(255, 255, 255, 0.55); stroke: rgba(27, 30, 43, 0.35); stroke-width: 1.6; transition: fill 0.2s; }
.hud-star.on { fill: var(--gold); stroke: #9a6a00; }

.pause-btn { position: absolute; top: var(--top); left: calc(12px + var(--host-side)); }
.control-row .seg { width: 210px; }

/* first-time tilt film */
.intro { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(15, 16, 26, 0.45);
  opacity: 0; transition: opacity 0.25s; }
.intro.in { opacity: 1; }
.intro-card { width: min(100%, 360px); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 20px 14px;
  border-radius: 28px; background: #fff; box-shadow: 0 24px 60px rgba(20, 16, 40, 0.3); text-align: center;
  transform: translateY(16px) scale(0.98); transition: transform 0.35s var(--ease-out); }
.intro.in .intro-card { transform: none; }
.intro-art { width: 280px; height: 290px; max-width: 100%; }
.intro-title { margin: 0; font-size: 26px; font-weight: 900; }
.intro-body { margin: 0 0 6px; font-size: 16px; line-height: 1.35; color: var(--ink-soft); font-weight: 800; }
.intro-note { margin: 0 0 4px; font-size: 13.5px; line-height: 1.35; color: var(--ink-soft); font-weight: 700; opacity: 0.85; }
.intro-finger { font-size: 15px; color: var(--ink-soft); text-decoration: none; padding: 8px; }
@media (max-height: 640px) { .intro-art { height: 220px; } }

.toasts { position: absolute; top: calc(var(--top) + 118px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.toast {
  padding: 9px 16px; border-radius: 18px; background: rgba(27, 30, 43, 0.86); color: #fff; font-size: 16px; font-weight: 900;
  box-shadow: 0 10px 26px rgba(20, 20, 30, 0.25); opacity: 0; transform: translateY(-8px) scale(0.96);
  transition: opacity 0.22s, transform 0.3s var(--ease);
}
.toast.in { opacity: 1; transform: none; }
.toast.out { opacity: 0; transform: translateY(-6px); }
.toast.star, .toast.record { background: #fff4c2; color: #6b4600; box-shadow: 0 0 0 2px #ffd34d, 0 10px 26px rgba(245, 179, 1, 0.35); }
.toast.clutch { background: #dffbff; color: #0b5563; box-shadow: 0 0 0 2px #7fe3f2, 0 10px 26px rgba(40, 180, 210, 0.3); }
.toast.unlock { background: var(--ink); }

/* ---------------------------------------------------------------- ready: object panel, arrows, hint */
.ready { position: absolute; inset: 0; }
.obj-panel {
  position: absolute; top: calc(var(--top) + 58px); left: 50%; transform: translateX(-50%);
  width: min(92vw, 420px); display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  pointer-events: none;
}
.obj-panel > * { pointer-events: auto; }
.obj-name {
  margin: 0; font-size: clamp(26px, 8vw, 34px); font-weight: 900; line-height: 1.1; letter-spacing: -0.01em;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}
.pips { display: flex; gap: 4px; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: rgba(27, 30, 43, 0.16); }
.pip.on { background: var(--ink); }
.obj-meta { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; font-size: 15px; color: var(--ink-soft); font-weight: 800; }
.obj-stars { display: flex; gap: 3px; }
.obj-stars .star { width: 20px; height: 20px; fill: rgba(255, 255, 255, 0.6); stroke: rgba(27, 30, 43, 0.3); stroke-width: 1.6; }
.obj-stars .star.on { fill: var(--gold); stroke: #9a6a00; }
.lock-row { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 900; color: var(--ink-soft); }
.lock-ico { width: 18px; height: 18px; }
.unlock-bar { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 2.2vh); display: flex; justify-content: center; padding: 0 20px; pointer-events: none; }
.unlock-btn { min-width: min(320px, 86vw); min-height: 56px; font-size: 18px; pointer-events: auto; }
.unlock-btn.ready { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { box-shadow: 0 10px 24px rgba(20, 22, 34, 0.28); } 50% { box-shadow: 0 10px 30px rgba(20, 22, 34, 0.42), 0 0 0 6px rgba(255, 255, 255, 0.45); } }

.arrow { position: absolute; top: 50%; width: 52px; height: 52px; margin-top: -26px; }
.arrow.prev { left: max(28px, calc(var(--host-side) + 8px)); }
.arrow.next { right: max(28px, calc(var(--host-side) + 8px)); }

.hint {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 2.6vh); transform: translateX(-50%);
  margin: 0; padding: 10px 18px; border-radius: 20px; background: var(--glass-strong); font-size: 17px; font-weight: 900;
  white-space: nowrap; box-shadow: 0 8px 20px rgba(30, 20, 40, 0.16);
  animation: float 2.4s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -4px); } }

.pause { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 2.2vh); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pause-text {
  margin: 0; padding: 12px 20px; border-radius: 22px; background: var(--glass-strong); font-size: 19px; font-weight: 900;
  box-shadow: 0 10px 26px rgba(30, 20, 40, 0.18); animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.end-run { font-size: 14px; }

/* ---------------------------------------------------------------- sheets */
.scrim { position: absolute; inset: 0; background: rgba(15, 16, 26, 0.36); opacity: 0; transition: opacity 0.25s; }
.scrim.in { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; width: min(100%, 520px);
  max-height: min(84vh, calc(100vh - var(--top) - 12px)); display: flex; flex-direction: column;
  background: #fff; border-radius: 28px 28px 0 0; box-shadow: 0 -16px 50px rgba(20, 16, 40, 0.22);
  transform: translateY(105%); transition: transform 0.34s var(--ease-out);
  padding-bottom: var(--safe-bottom);
}
.sheet.in { transform: none; }
.grab { width: 44px; height: 5px; border-radius: 3px; background: rgba(27, 30, 43, 0.15); margin: 10px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 16px 6px 22px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 900; }
.sheet-close { width: 42px; height: 42px; padding: 11px; box-shadow: none; background: rgba(27, 30, 43, 0.06); }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 6px 20px 22px; }

/* result */
.result .sheet-body { display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding-top: 4px; }
.res-points { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 52px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.res-points .coin { width: 40px; height: 40px; }
.res-points .plus { opacity: 0.55; margin-right: -2px; }
.res-time { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 18px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.res-time .ico { width: 20px; height: 20px; }
.res-stars { display: flex; justify-content: center; gap: 8px; }
.res-stars .star { width: 34px; height: 34px; fill: #eef0f4; stroke: #c8ccd6; stroke-width: 1.4; }
.res-stars .star.on { fill: var(--gold); stroke: #9a6a00; }
.res-stars .star.fresh { animation: starIn 0.6s var(--ease) both; animation-delay: var(--d, 0ms); }
@keyframes starIn { 0% { transform: scale(0.2) rotate(-40deg); opacity: 0; } 60% { transform: scale(1.3) rotate(8deg); opacity: 1; } 100% { transform: none; } }
.res-badge {
  align-self: center; padding: 6px 14px; border-radius: 14px; background: #fff4c2; color: #6b4600; font-weight: 900; font-size: 16px;
  box-shadow: 0 0 0 2px #ffd34d; animation: pop 0.5s var(--ease) 0.5s both;
}
.res-next { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 18px; background: #f5f6f9; }
.res-next.ready { background: #fff8db; box-shadow: inset 0 0 0 2px #ffd34d; }
.next-thumb { flex: none; width: 54px; height: 64px; }
.next-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.next-label { font-size: 15px; font-weight: 800; color: var(--ink-soft); }
.bar { height: 8px; border-radius: 4px; background: rgba(27, 30, 43, 0.1); overflow: hidden; }
.bar .fill { display: block; height: 100%; border-radius: 4px; background: var(--ink); transition: width 0.8s var(--ease-out); }
.res-done { margin: 0; font-size: 15px; color: var(--ink-soft); }
.res-row { display: flex; gap: 10px; }
.res-row .btn { flex: 1; }
.res-save { min-height: 18px; text-align: center; font-size: 14px; color: var(--ink-soft); font-weight: 800; }
.res-save.saved { color: #1f8a4c; }
.res-save.failed { color: #b42318; }

.records { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.seg { display: flex; padding: 4px; border-radius: 14px; background: #f1f2f6; }
.seg-btn { flex: 1; min-height: 40px; border-radius: 11px; font-size: 15px; font-weight: 900; color: var(--ink-soft); transition: background 0.2s, color 0.2s; }
.seg-btn.on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(20, 20, 40, 0.1); }
.rec-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rec-row, .rec-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 4px 8px; border-radius: 14px; text-align: left; }
.rec-row.tap { padding: 0; }
.rec-btn:active { background: #f3f4f7; }
.rec-row.me { background: #fff8db; box-shadow: inset 0 0 0 1.5px #ffd34d; }
.rank { width: 26px; text-align: center; font-weight: 900; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.av { width: 34px; height: 34px; border-radius: 50%; flex: none; object-fit: cover; display: grid; place-items: center; background: #e9ebf1; font-weight: 900; color: var(--ink-soft); }
.who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.score { font-weight: 900; font-variant-numeric: tabular-nums; }
.rec-msg { padding: 14px 8px; text-align: center; color: var(--ink-soft); font-size: 15px; }
.rec-msg.loading { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

/* collection */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 10px; border-radius: 18px;
  background: linear-gradient(180deg, var(--card-top), var(--card)); box-shadow: 0 6px 16px rgba(30, 20, 40, 0.1);
  transition: transform 0.16s var(--ease);
}
.card:active { transform: scale(0.95); }
.card.current { box-shadow: 0 0 0 3px var(--ink), 0 6px 16px rgba(30, 20, 40, 0.14); }
.card.locked { filter: saturate(0.25) brightness(0.98); }
.card-art { width: 78px; height: 92px; }
.card-name { font-size: 14px; font-weight: 900; line-height: 1.15; min-height: 2.3em; display: flex; align-items: center; text-align: center; }
.card-stars { display: flex; gap: 2px; }
.card-stars .star { width: 15px; height: 15px; fill: rgba(255, 255, 255, 0.65); stroke: rgba(27, 30, 43, 0.3); stroke-width: 1.6; }
.card-stars .star.on { fill: var(--gold); stroke: #9a6a00; }
.card-price { display: flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 900; padding: 2px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.8); font-variant-numeric: tabular-nums; }
.card-price.ready { background: var(--ink); color: #fff; }

/* settings */
.set-row { display: flex; align-items: center; justify-content: space-between; min-height: 60px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-label { font-size: 18px; font-weight: 800; }
.switch { position: relative; width: 58px; height: 34px; border-radius: 17px; background: #d5d8e0; transition: background 0.22s; flex: none; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22); transition: transform 0.25s var(--ease); }
.switch[aria-checked="true"] { background: var(--ink); }
.switch[aria-checked="true"] .knob { transform: translateX(24px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
@media (min-width: 700px) and (orientation: landscape) {
  .obj-panel { top: calc(var(--top) + 30px); }
  .hud-time { font-size: 52px; }
}
