@font-face { font-family: "Lilita One"; src: url(../fonts/lilita.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Nunito"; src: url(../fonts/nunito.woff2) format("woff2"); font-weight: 200 1000; font-display: swap; }

:root {
  --board: min(calc(100vw - 32px), 420px);
  --ui-font: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  --display: "Lilita One", "Arial Rounded MT Bold", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #1a2a6c linear-gradient(180deg, #1A2A6C 0%, #2B3F8F 100%) fixed;
  color: #fff; font-family: var(--ui-font);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
body::before { /* subtle pattern */
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .07;
  background-image: radial-gradient(#ffffff 1.2px, transparent 1.3px);
  background-size: 26px 26px;
}
button { font-family: inherit; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 5; }
#topbar { position: absolute; left: 0; top: 0; display: flex; align-items: center; justify-content: space-between; }
#bestWrap { display: flex; align-items: center; gap: calc(var(--B) * .02); font: 900 calc(var(--B) * .052)/1.1 var(--ui-font); color: #FFE9A6; text-shadow: 0 2px 2px #08133b80; }
#crown { width: calc(var(--B) * .07); height: auto; filter: drop-shadow(0 2px 2px #08133b80); transition: transform .3s; }
#crown.bump { animation: crownBump .7s cubic-bezier(.22,1,.36,1); }
@keyframes crownBump { 0% { transform: scale(1) rotate(0) } 30% { transform: scale(1.45) rotate(-12deg) } 60% { transform: scale(.95) rotate(6deg) } 100% { transform: scale(1) } }
#levelLabel { font: 400 calc(var(--B) * .055)/1 var(--display); color: #fff; text-shadow: 0 2px 0 #26306B; letter-spacing: .02em; }
.icon-btn { pointer-events: auto; width: 48px; height: 48px; border: 0; padding: 10px; background: transparent; cursor: pointer; border-radius: 14px; display: grid; place-items: center; touch-action: manipulation; }
.icon-btn svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 2px #08133b80); }
.icon-btn:active { transform: scale(.92); }
.icon-btn:focus-visible { outline: 3px solid #FFF1A0; outline-offset: 2px; }
#scoreWrap { position: absolute; left: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#score {
  font: 400 calc(var(--B) * .145)/1 var(--display); font-variant-numeric: tabular-nums; color: #fff;
  text-shadow: 0 calc(var(--B) * .008) calc(var(--B) * .012) #08133b80, 0 3px 0 #26306B;
  will-change: transform;
}
#score.pulse { animation: pulse 220ms cubic-bezier(.16,1,.3,1); }
@keyframes pulse { 0% { transform: scale(1) } 32% { transform: scale(1.09) } 100% { transform: scale(1) } }
#goals { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.goal { display: flex; align-items: center; gap: 6px; background: #13234FCC; border-radius: 18px; padding: 5px 12px 5px 6px; font: 900 20px/1 var(--ui-font); transition: transform .2s; }
.goal canvas { width: 28px; height: 28px; }
.goal.done { color: #ACFF93; }
.goal.bump { animation: pulse 260ms ease; }
.goal .check { color: #ACFF93; font-size: 20px; }
.goal-score { padding: 7px 14px; font-size: 16px; }
#comboChip { margin-top: 4px; min-height: calc(var(--B) * .05); display: flex; align-items: center; gap: 8px; font: 400 calc(var(--B) * .045)/1 var(--display); color: #FFF0A1; text-shadow: 0 2px 0 #39276F; }
#comboDots { display: flex; gap: 4px; }
#comboDots i { width: 8px; height: 8px; border-radius: 50%; background: #FFF0A1; box-shadow: 0 1px 0 #39276F; transition: opacity .2s, transform .2s; }
#comboDots i.off { opacity: .2; transform: scale(.7); }

#toast {
  position: fixed; left: 50%; top: 18%; z-index: 30; pointer-events: none;
  transform: translateX(-50%); padding: 10px 22px; border-radius: 999px;
  background: linear-gradient(#FFE88A, #FFB840); color: #5A2D00; border: 2px solid #FFF5BC;
  font: 400 calc(var(--board) * .07)/1 var(--display); box-shadow: 0 8px 24px #030A2D80;
  animation: toast 1.8s cubic-bezier(.16,1,.3,1) forwards; white-space: nowrap;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.6) } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08) } 25% { transform: translate(-50%, 0) scale(1) } 80% { opacity: 1 } 100% { opacity: 0; transform: translate(-50%, -20px) } }

/* ---------- buttons ---------- */
.button {
  position: relative; box-sizing: border-box; width: 100%; min-height: 56px; padding: 12px 24px;
  border: 2px solid #ffffff66; border-radius: 18px;
  font: 900 max(18px, calc(var(--board) * .052))/1.1 var(--ui-font); color: #fff;
  text-shadow: 0 2px 2px #12342755; touch-action: manipulation; cursor: pointer;
  transition: transform 90ms ease, filter 90ms ease;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.button small { font-size: .62em; font-weight: 800; opacity: .9; }
.button--primary { background: linear-gradient(#A0EC69 0%, #63D34C 42%, #37AF43 100%); box-shadow: 0 5px 0 #23763C, 0 9px 16px #06133240, inset 0 2px 0 #DBFFAD99; }
.button--secondary { background: linear-gradient(#729FF4 0%, #4779DC 45%, #345FC0 100%); box-shadow: 0 5px 0 #243D88, 0 9px 16px #06133240, inset 0 2px 0 #C2D8FF88; }
.button--ghost { background: #ffffff14; border-color: #ffffff33; box-shadow: none; min-height: 48px; font-size: max(16px, calc(var(--board) * .044)); }
.button:active { transform: translateY(3px); filter: brightness(.94); }
.button:disabled { filter: grayscale(1); opacity: .55; cursor: default; }
.button:focus-visible, .switch input:focus-visible + .track { outline: 3px solid #FFF1A0; outline-offset: 4px; }
.link-btn { background: none; border: 0; color: #C9D8FF; font: 800 16px var(--ui-font); padding: 12px 20px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 10; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#home { display: grid; place-items: center; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px); }
.home-inner { width: var(--board); display: flex; flex-direction: column; align-items: center; }
#logo { width: calc(var(--board) * .95); height: auto; filter: drop-shadow(0 10px 18px #050d2e99); animation: logoIn .7s cubic-bezier(.16,1,.3,1), float 4s ease-in-out .7s infinite; pointer-events: none; }
@keyframes logoIn { from { opacity: 0; transform: scale(.7) translateY(-20px) } }
@keyframes float { 50% { transform: translateY(-6px) } }
.home-buttons { width: calc(var(--board) * .78); display: grid; gap: 20px; margin-top: calc(var(--board) * .1); }
.home-buttons .button { min-height: 64px; animation: btnIn .5s cubic-bezier(.16,1,.3,1) backwards; }
.home-buttons .button:nth-child(2) { animation-delay: .08s; }
@keyframes btnIn { from { opacity: 0; transform: translateY(16px) } }
.home-gear { position: fixed; top: calc(env(safe-area-inset-top) + 10px); right: 12px; width: 52px; height: 52px; background: #13234FAA; border: 2px solid #ffffff22; }
.home-best { display: flex; align-items: center; gap: 8px; margin-top: 24px; font: 800 18px var(--ui-font); color: #DCE6FF; }
.home-best svg { width: 26px; }
.home-best b { font-weight: 900; color: #FFE9A6; }

/* ---------- map ---------- */
#map { padding: 0 0 calc(env(safe-area-inset-bottom) + 24px); }
.map-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 12px 10px; background: linear-gradient(#1A2A6Cf2, #1A2A6Cd0 80%, #1A2A6C00); }
.map-head h1 { flex: 1; margin: 0; font: 400 28px/1 var(--display); text-shadow: 0 3px 0 #26306B; }
.map-progress { font: 900 16px var(--ui-font); background: #13234FCC; border-radius: 18px; padding: 8px 14px; }
#mapList { width: min(calc(100vw - 24px), 440px); margin: 0 auto; }
.chapter { padding: 18px; border-radius: 24px; background: #243F80; border: 2px solid #668BD066; margin: 10px 0 22px; box-shadow: 0 10px 24px #06133240; }
.chapter.locked { filter: saturate(.6); opacity: .8; }
.chapter-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chapter-head canvas { width: 40px; height: 40px; flex: none; }
.chapter-title { font: 400 24px/1.05 var(--display); text-shadow: 0 2px 0 #1A2A6C; }
.chapter-sub { font: 800 13px var(--ui-font); color: #BFD0F5; margin-top: 2px; }
.pic { position: relative; width: 100%; aspect-ratio: 1; border-radius: 16px; overflow: hidden; clip-path: inset(0 round 16px); isolation: isolate; background-size: cover; background-position: center; box-shadow: inset 0 0 0 2px #ffffff30, 0 6px 16px #06133260; }
.pic .tiles { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.pic .tile { background: linear-gradient(135deg, #2B4A8E, #1A2F68); border: 1px solid #0f1d4a; display: grid; place-items: center; font: 400 26px var(--display); color: #ffffff38; transition: opacity .6s ease, transform .6s ease; }
.pic .tile.open { opacity: 0; transform: scale(1.15); }
.pic .tile.reveal { animation: tileReveal .9s cubic-bezier(.16,1,.3,1) .35s forwards; }
@keyframes tileReveal { 0% { opacity: 1; transform: scale(1) } 40% { opacity: 1; transform: scale(1.08); filter: brightness(2) } 100% { opacity: 0; transform: scale(1.2) } }
.nodes { position: relative; margin-top: 14px; }
.nodes svg.path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.node {
  position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; cursor: pointer; touch-action: manipulation;
  border: 4px solid #8594B2; background: linear-gradient(#67799F, #435779); box-shadow: 0 5px 8px #08133380;
  font: 400 26px/1 var(--display); color: #fff; text-shadow: 0 2px 0 #00000040; display: grid; place-items: center; padding: 0;
}
.node.done { border-color: #BEF3A5; background: linear-gradient(#84DF71, #39A954); }
.node.current { border-color: #FFF5BC; background: linear-gradient(#FFE68A, #FFB840); color: #7A3E00; text-shadow: none; animation: halo 1.2s ease-in-out infinite; }
@keyframes halo { 0%, 100% { transform: scale(1); box-shadow: 0 5px 8px #08133380, 0 0 0 0 #FFE89666 } 50% { transform: scale(1.1); box-shadow: 0 5px 8px #08133380, 0 0 18px 6px #FFE89666 } }
.node.locked { cursor: default; color: #BAC5DA; }
.node.locked svg { width: 24px; height: 24px; }
.node .stars { position: absolute; bottom: -9px; font-size: 12px; color: #FFE478; text-shadow: 0 1px 0 #6b4b00; }
.node:focus-visible { outline: 3px solid #FFF1A0; outline-offset: 3px; }

/* ---------- modals ---------- */
.backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: #060D2BB8; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fadeIn 220ms ease; }
@keyframes fadeIn { from { opacity: 0 } }
.modal { box-sizing: border-box; width: min(100%, 360px); max-height: calc(100vh - 40px); overflow-y: auto; padding: 26px 24px 28px; border: 2px solid #98B5FF66; border-radius: 28px; color: #fff; text-align: center; background: linear-gradient(180deg, #3558A6, #203A7B); box-shadow: 0 18px 48px #030A2D99, inset 0 2px 0 #B9D1FF44; animation: modalIn 220ms cubic-bezier(.16,1,.3,1); }
@keyframes modalIn { from { opacity: 0; transform: scale(.9) } }
.modal-title { margin: 0 0 6px; font: 400 calc(var(--board) * .085)/1.1 var(--display); text-shadow: 0 3px 0 #26306B; }
.modal-title.small { font-size: calc(var(--board) * .07); }
.modal-label { font: 800 max(15px, calc(var(--board) * .04))/1.4 var(--ui-font); color: #DCE6FF; }
.modal-label b { color: #FFE9A6; font-weight: 900; }
.modal-score { font: 400 calc(var(--board) * .12)/1.1 var(--display); text-shadow: 0 3px 0 #26306B; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.modal-crown svg { width: 48px; animation: crownWin 1.2s cubic-bezier(.22,1,.36,1); filter: drop-shadow(0 0 12px #FFD95Baa); }
@keyframes crownWin { 0% { transform: scale(0) rotate(-30deg) } 50% { transform: scale(1.4) rotate(8deg) } 100% { transform: scale(1) } }
.new-best { color: #FFE478; font: 400 calc(var(--board) * .06)/1 var(--display); text-shadow: 0 2px 0 #6b3b00; margin-bottom: 6px; animation: pulse 1s ease-in-out infinite; }
.modal-actions, .sheet-actions { display: grid; gap: 16px; margin-top: 22px; }
#winPic { margin: 12px 0 10px; }

/* ---------- settings sheet ---------- */
.sheet-backdrop { place-items: end center; padding: 0; }
.settings-sheet { box-sizing: border-box; width: min(100%, 460px); padding: 12px 24px calc(20px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; background: linear-gradient(#3558A6, #203A7B); box-shadow: 0 -8px 32px #030A2D66; color: #fff; animation: sheetIn 260ms cubic-bezier(.16,1,.3,1); text-align: center; }
@keyframes sheetIn { from { transform: translateY(100%) } }
.handle { width: 40px; height: 5px; border-radius: 3px; background: #FFFFFF55; margin: 0 auto 12px; }
.sheet-title { margin: 0 0 6px; font: 400 26px var(--display); text-shadow: 0 2px 0 #26306B; }
.setting-row { display: flex; align-items: center; justify-content: space-between; min-height: 64px; font: 800 20px/1.2 var(--ui-font); border-bottom: 1px solid #FFFFFF18; cursor: pointer; text-align: left; }
.switch { position: relative; display: inline-block; width: 58px; height: 44px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.track { position: absolute; top: 6px; left: 0; width: 58px; height: 32px; border-radius: 16px; background: #142858; box-shadow: inset 0 2px 4px #050D2B99; pointer-events: none; transition: background 160ms ease; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(#FFFFFF, #DCE8FF); box-shadow: 0 2px 4px #06133166; transition: transform 160ms cubic-bezier(.22,1,.36,1); }
.switch input:checked + .track { background: #53CF60; }
.switch input:checked + .track::after { transform: translateX(26px); }

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