:root {
  --sky1: #ffb88c; --sky2: #de6262; --sky3: #6a3093;
  --hill1: #7b4397; --hill2: #5a2a7a; --hill3: #3a1a55;
  --sun: #ffe9a8;
  --accent: #ff7a59; --accent2: #ff4f7b;
  --ink: #2b2140;
  --tile: rgba(255, 255, 255, 0.92);
  --empty: rgba(40, 20, 70, 0.22);
  --glass: rgba(255, 255, 255, 0.18);
  --glass-border: rgba(255, 255, 255, 0.35);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI", Roboto, system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: var(--font); color: #fff;
  background: var(--sky3);
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
svg { display: block; }
.hidden { display: none !important; }

/* ---------- background scene ---------- */
#scene { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
.sky {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 48%, var(--sky3) 100%);
  transition: background 1.2s ease;
}
.sun {
  position: absolute; width: 46vmin; height: 46vmin; border-radius: 50%;
  left: 50%; top: 30%; transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--sun) 0%, rgba(255,255,255,0) 68%);
  opacity: .75; animation: breathe 9s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: translate(-50%, -52%) scale(1.06); opacity: .9; } }
.bokeh { position: absolute; inset: 0; }
.bokeh i {
  position: absolute; border-radius: 50%; background: rgba(255,255,255,.22);
  filter: blur(1px); animation: float linear infinite;
}
@keyframes float {
  from { transform: translateY(10vh); opacity: 0; }
  15% { opacity: 1; } 85% { opacity: 1; }
  to { transform: translateY(-110vh); opacity: 0; }
}
.hills { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 42vh; }
.hills path { transition: fill 1.2s ease; }
.hills .h1 { fill: var(--hill1); opacity: .55; }
.hills .h2 { fill: var(--hill2); opacity: .7; }
.hills .h3 { fill: var(--hill3); opacity: .9; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: none; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 10px) 16px calc(var(--safe-b) + 12px);
  max-width: 520px; margin: 0 auto;
}
.screen.active { display: flex; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(.985); } }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.glass-strong {
  background: rgba(255,255,255,.94); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; transition: transform .15s; }
.icon-btn svg { width: 24px; height: 24px; fill: #fff; }
.icon-btn:active, .round-btn:active { transform: scale(.9); }

.coins-pill {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 6px;
  border-radius: 18px; background: rgba(0,0,0,.22); font-weight: 800; font-size: 17px;
}
.coin {
  width: 24px; height: 24px; border-radius: 50%; display: inline-block; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff6c2 0 18%, #ffd34d 40%, #f0a20a 100%);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.25);
}
.coin.sm { width: 14px; height: 14px; }
.coins-pill.bump { animation: bump .45s ease; }
@keyframes bump { 40% { transform: scale(1.18); } }

/* ---------- home ---------- */
.home-top { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.logo { margin-top: 7vh; text-align: center; }
.logo-tiles { display: flex; gap: 8px; justify-content: center; }
.logo-tiles span {
  width: 58px; height: 64px; border-radius: 14px; display: grid; place-items: center;
  font-size: 38px; font-weight: 900; color: #fff;
  background: linear-gradient(160deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 0 rgba(0,0,0,.18), 0 12px 24px rgba(0,0,0,.2);
  animation: drop .7s cubic-bezier(.3,1.6,.5,1) both; animation-delay: calc(var(--i) * .09s);
}
@keyframes drop { from { transform: translateY(-60px) rotate(-12deg); opacity: 0; } }
.logo-sub {
  margin-top: 10px; font-size: 44px; font-weight: 900; letter-spacing: 2px;
  text-shadow: 0 3px 0 rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.2);
}
.home-card { background: rgba(40,20,70,.18); margin-top: 5vh; width: 100%; max-width: 340px; border-radius: 20px; padding: 16px 18px; }
.chapter-name { font-size: 20px; font-weight: 800; text-shadow: 0 1px 4px rgba(0,0,0,.25); }
.chapter-progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-weight: 700; font-size: 14px; }
.bar { flex: 1; height: 10px; border-radius: 5px; background: rgba(0,0,0,.2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 5px; background: linear-gradient(90deg, #fff, var(--sun)); transition: width .6s; }

.play-btn {
  margin-top: 4vh; min-width: 220px; padding: 14px 30px; border-radius: 26px;
  background: linear-gradient(180deg, #ffd65c, #ff9f1c);
  color: #5a2d00; box-shadow: 0 6px 0 #c76d00, 0 14px 30px rgba(0,0,0,.25);
  display: flex; flex-direction: column; align-items: center;
  transition: transform .1s, box-shadow .1s;
  animation: pulse 2.4s ease-in-out infinite;
}
.play-btn span { font-size: 30px; font-weight: 900; line-height: 1.1; }
.play-btn small { font-size: 14px; font-weight: 800; opacity: .8; }
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c76d00, 0 6px 14px rgba(0,0,0,.25); }
.play-btn.small { min-width: 200px; margin: 22px auto 0; } /* block-level flex box: text-align won't centre it */
.play-btn.small span { font-size: 24px; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.home-links { display: flex; gap: 10px; margin-top: 22px; }
.link-btn { padding: 10px 16px; border-radius: 14px; font-weight: 800; background: rgba(0,0,0,.18); }
.promise { margin-top: auto; font-weight: 700; opacity: .85; font-size: 14px; }

/* ---------- game ---------- */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; }
.level-title { text-align: center; font-weight: 900; font-size: 20px; line-height: 1.1; text-shadow: 0 2px 6px rgba(0,0,0,.2); }
.level-title small { display: block; font-size: 13px; font-weight: 700; opacity: .85; }

#boardWrap { flex: 1 1 auto; width: 100%; min-height: 0; display: grid; place-items: center; padding: 12px 0 4px; }
#board { position: relative; }
.cell {
  position: absolute; border-radius: 22%;
  background: var(--empty); border: 1.5px solid rgba(255,255,255,.55);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.08);
  display: grid; place-items: center;
  font-weight: 900; color: #fff; text-transform: uppercase;
  transition: background .25s, transform .25s;
}
.cell.filled {
  background: linear-gradient(160deg, var(--accent), var(--accent2)); border-color: transparent;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
  animation: pop .45s cubic-bezier(.3,1.7,.5,1) both;
}
.cell.hinted { background: var(--tile); color: var(--accent2); border-color: transparent; animation: pop .45s cubic-bezier(.3,1.7,.5,1) both; }
.cell.flash { animation: flash .6s ease; }
@keyframes pop { from { transform: scale(.3); } }
@keyframes flash { 30% { transform: scale(1.2); filter: brightness(1.4); } }

#preview { height: 54px; flex: none; display: grid; place-items: center; }
#previewInner {
  min-height: 44px; padding: 0 16px; border-radius: 14px; display: flex; align-items: center; gap: 2px;
  font-size: 30px; font-weight: 900; letter-spacing: 3px; text-transform: uppercase;
  background: linear-gradient(160deg, var(--accent), var(--accent2));
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  transition: opacity .2s;
}
#previewInner:empty { opacity: 0; }
#previewInner.shake { animation: shake .4s; }
#previewInner.good { background: #2ec27e; }
#previewInner.bonus { background: linear-gradient(160deg, #ffd65c, #ff9f1c); color: #5a2d00; }
#previewInner.known { background: rgba(0,0,0,.35); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

#controls { flex: none; width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; padding-bottom: 6px; }
.side { display: flex; flex-direction: column; gap: 18px; }
.round-btn { position: relative; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; transition: transform .15s; }
.round-btn svg { width: 26px; height: 26px; fill: #fff; }
.round-btn .badge {
  position: absolute; top: -4px; right: -6px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: #ffd34d; color: #5a2d00; font-size: 12px; font-weight: 900; display: grid; place-items: center;
}
.round-btn .price {
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 3px; padding: 1px 6px; border-radius: 10px;
  background: rgba(0,0,0,.45); font-size: 11px; font-weight: 900;
}
.round-btn.disabled { opacity: .5; }
#bonusBtn.ping { animation: bump .5s ease; }

/* stuck timer: ring fills toward a free hint */
#hintBtn { --p: 0; }
#hintBtn .ring {
  position: absolute; inset: -5px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(#ffd34d calc(var(--p) * 1turn), rgba(255,255,255,.15) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
  transition: background .9s linear;
}
#hintBtn.free { background: linear-gradient(180deg, #ffd65c, #ff9f1c); border-color: #fff; animation: glow 1.6s ease-in-out infinite; }
#hintBtn.free svg { fill: #5a2d00; }
#hintBtn.free .price { background: #2ec27e; }
#hintBtn.free .price .coin { display: none; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,211,77,.7); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px rgba(255,211,77,0); transform: scale(1.08); }
}

#wheel {
  --size: min(62vw, 300px, 40vh);
  flex: none; position: relative; width: var(--size); height: var(--size); border-radius: 50%;
  background: rgba(255,255,255,.22); border: 2px solid rgba(255,255,255,.45);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0,0,0,.18), inset 0 0 30px rgba(255,255,255,.2);
  touch-action: none;
}
#wheelLine { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#wheelLine polyline { fill: none; stroke: var(--accent2); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.letter {
  position: absolute; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; color: var(--ink); text-transform: uppercase;
  background: rgba(255,255,255,.9); box-shadow: 0 4px 0 rgba(0,0,0,.08);
  transform: translate(-50%, -50%);
  transition: left .35s ease, top .35s ease, background .12s, color .12s, transform .12s;
  pointer-events: none;
}
.letter.sel { background: linear-gradient(160deg, var(--accent), var(--accent2)); color: #fff; transform: translate(-50%, -50%) scale(1.08); }

/* fly-to animations */
.flyer {
  position: fixed; z-index: 30; pointer-events: none; display: grid; place-items: center;
  border-radius: 22%; font-weight: 900; text-transform: uppercase; color: #fff;
  background: linear-gradient(160deg, var(--accent), var(--accent2));
  transition: transform .45s cubic-bezier(.5,0,.3,1), opacity .45s;
}

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(20,10,40,.45); animation: fadeIn .2s; }
.modal-card { position: relative; width: 100%; max-width: 380px; max-height: 80vh; overflow: auto; border-radius: 24px; padding: 24px 22px; }
.close-x { position: absolute; top: 10px; right: 14px; font-size: 30px; line-height: 1; color: #9a8fb0; }
.modal h2 { margin: 0 0 14px; font-size: 24px; font-weight: 900; }
.modal p { line-height: 1.45; margin: 8px 0; }
.bonus-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.bonus-list span { padding: 5px 10px; border-radius: 10px; background: #f1ecfb; font-weight: 800; text-transform: uppercase; font-size: 14px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid #eee; font-weight: 800; }
.switch { width: 52px; height: 30px; border-radius: 15px; background: #d8d2e6; position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(22px); }
.btn { display: block; width: 100%; margin-top: 14px; padding: 13px; border-radius: 14px; font-weight: 900; font-size: 16px; background: linear-gradient(160deg, var(--accent), var(--accent2)); color: #fff; }
.btn.ghost { background: #f1ecfb; color: var(--ink); }
.btn.danger { background: #ffe3e3; color: #c0392b; }
.muted { color: #7d7392; font-size: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stats div { background: #f6f3fc; border-radius: 12px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 22px; }
.stats small { color: #7d7392; font-weight: 700; }

/* ---------- win ---------- */
.win { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; background: rgba(20,10,40,.35); animation: fadeIn .3s; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-card { position: relative; text-align: center; padding: 20px; animation: rise .6s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes rise { from { transform: translateY(40px) scale(.8); opacity: 0; } }
.win-title { font-size: 52px; font-weight: 900; text-shadow: 0 4px 0 rgba(0,0,0,.15), 0 10px 30px rgba(0,0,0,.25); }
.win-sub { font-size: 18px; font-weight: 800; opacity: .9; }
.win-reward { margin: 18px auto 0; display: inline-flex; align-items: center; gap: 8px; padding: 8px 18px; border-radius: 20px; background: rgba(0,0,0,.25); font-size: 26px; font-weight: 900; }
.win-chapter { margin-top: 14px; font-weight: 800; font-size: 16px; background: rgba(255,255,255,.2); padding: 10px 14px; border-radius: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 70px); z-index: 50;
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 16px; background: rgba(20,10,40,.8); font-weight: 800;
  transition: opacity .25s, transform .25s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 640px) {
  .logo { margin-top: 3vh; }
  .logo-tiles span { width: 48px; height: 54px; font-size: 32px; }
  .side { gap: 12px; }
  .round-btn { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
