:root {
  --cream: #FBF4E6;
  --paper: #FFFDF8;
  --ink: #3A2A1B;
  --ink-2: #7A6553;
  --ink-3: #B8A897;
  --line: #EADFCB;
  --capy: #96683F;
  --melon: #E5484D;
  --city-a: #2AB0E6;
  --city-b: #FFD166;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(58, 42, 27, .10), 0 2px 6px rgba(58, 42, 27, .06);
  --font-display: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(1200px 600px at 50% -200px, color-mix(in srgb, var(--city-a) 22%, transparent), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .2 0 0 0 0 .1 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
b, strong { font-weight: 800; }

.screen {
  max-width: 520px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Home */
.home { align-items: center; text-align: center; justify-content: center; }
.hero { position: relative; padding: 24px 0 4px; }
.hero-blob {
  position: absolute; inset: -20px -60px auto; height: 220px; z-index: -1;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--city-b) 55%, transparent), transparent);
  filter: blur(10px);
}
.hero-capy { width: 132px; height: 132px; animation: bob 3.2s ease-in-out infinite; filter: drop-shadow(0 10px 14px rgba(58,42,27,.18)); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
h1 {
  font-family: var(--font-display); font-weight: 800; font-size: 56px; line-height: 1; margin: 4px 0 6px;
  letter-spacing: -.02em; color: var(--ink);
}
.tag { margin: 0; color: var(--ink-2); font-weight: 600; font-size: 15px; line-height: 1.4; }

.city-card {
  width: 100%; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; text-align: left;
  border: 1px solid var(--line);
}
.city-card .em { font-size: 40px; grid-row: span 2; line-height: 1; }
.city-card .name { font-family: var(--font-display); font-weight: 800; font-size: 22px; line-height: 1.05; }
.city-card .name small { color: var(--ink-2); font-family: var(--font-body); font-size: 13px; font-weight: 700; margin-left: 6px; }
.city-card .fact { color: var(--ink-2); font-size: 13.5px; line-height: 1.35; }
.dots { grid-column: 1 / -1; display: flex; gap: 6px; margin-top: 6px; }
.dots i { flex: 1; height: 8px; border-radius: 6px; background: var(--line); }
.dots i.done { background: linear-gradient(90deg, var(--city-a), var(--city-b)); }
.dots i.cur { background: var(--capy); animation: pulse 1.4s ease-in-out infinite; }
.dots i.boss { border: 2px solid var(--ink-3); }
.dots i.boss.done { border-color: transparent; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.stats { display: flex; gap: 10px; width: 100%; }
.stat {
  flex: 1; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 10px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat em { font-style: normal; font-size: 20px; }
.stat .ico { width: 22px; height: 22px; }
.stat b { font-family: var(--font-display); font-size: 22px; line-height: 1; }
.stat small { color: var(--ink-2); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

.btn-primary {
  width: 100%; padding: 18px; border-radius: 18px;
  background: var(--ink); color: var(--cream);
  font-family: var(--font-display); font-weight: 800; font-size: 22px;
  box-shadow: 0 8px 0 #22170d, 0 14px 24px rgba(58,42,27,.25);
  transition: transform .08s, box-shadow .08s;
}
.btn-primary:active { transform: translateY(5px); box-shadow: 0 3px 0 #22170d, 0 6px 12px rgba(58,42,27,.25); }
.btn-secondary {
  padding: 12px 22px; border-radius: 14px; background: var(--ink); color: var(--cream);
  font-family: var(--font-display); font-weight: 800; font-size: 17px; box-shadow: 0 4px 0 #22170d;
}
.btn-secondary:active { transform: translateY(3px); box-shadow: 0 1px 0 #22170d; }
.btn-ghost { padding: 10px 16px; border-radius: 12px; border: 2px solid var(--line); font-weight: 800; color: var(--ink-2); }
.links { margin: 0; color: var(--ink-3); display: flex; gap: 10px; }
.link { color: var(--ink-2); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Game */
.game { gap: 10px; }
.topbar { display: flex; align-items: center; gap: 10px; }
.title { flex: 1; text-align: center; line-height: 1.05; }
.title span { font-family: var(--font-display); font-weight: 800; font-size: 22px; display: block; }
.title small { color: var(--ink-2); font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; }
.title small.boss { color: var(--melon); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--paper); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 20px; display: grid; place-items: center; color: var(--ink-2);
}

.status { display: flex; justify-content: center; gap: 8px; }
.pill {
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  font-weight: 800; font-size: 15px; display: inline-flex; align-items: center; gap: 5px; box-shadow: var(--shadow);
}
.pill .ico { width: 20px; height: 20px; }
.pill b { font-family: var(--font-display); font-size: 17px; }
.lives span { display: inline-block; transition: transform .25s, opacity .25s, filter .25s; }
.lives span.lost { opacity: .22; filter: grayscale(1); transform: scale(.8); }
.lives span.pop { animation: lifepop .45s ease; }
@keyframes lifepop { 0% { transform: scale(1); } 40% { transform: scale(1.5) rotate(-12deg); } 100% { transform: scale(.8); } }

.rules { display: flex; gap: 6px; }
.rule {
  flex: 1; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 7px 8px;
  display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 800; color: var(--ink-2); line-height: 1.15;
}
.rule svg { width: 30px; height: 30px; flex: none; }

.board-wrap { position: relative; }
.board {
  --n: 8;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  aspect-ratio: 1;
}
.cell {
  position: relative; aspect-ratio: 1; border-radius: 22%;
  background: var(--c); color: #fff;
  display: grid; place-items: center;
  transition: transform .12s, filter .2s, box-shadow .2s;
  animation: tilein .45s cubic-bezier(.2,.9,.3,1.4) both; animation-delay: calc(var(--d) * 14ms);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.09);
}
@keyframes tilein { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.cell:active { transform: scale(.9); }
.cell svg { width: 66%; height: 66%; pointer-events: none; }
.cell .x { color: #fff; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); animation: popin .18s cubic-bezier(.2,.9,.3,1.5); }
.cell.auto .x { opacity: .55; }
.cell .capy { width: 84%; height: 84%; animation: capyin .5s cubic-bezier(.2,.9,.3,1.6); filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
@keyframes popin { from { transform: scale(.3); } to { transform: scale(1); } }
@keyframes capyin { 0% { transform: scale(.2) rotate(-20deg); } 60% { transform: scale(1.15) rotate(6deg); } 100% { transform: scale(1) rotate(0); } }
.cell.wrong { animation: shake .45s; background: var(--melon) !important; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.cell.hl { filter: brightness(1.12) saturate(1.2); box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink); z-index: 2; animation: none; }
.cell.dim { filter: saturate(.35) brightness(1.05); }
.cell.target { animation: target 1s ease-in-out infinite; z-index: 3; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--capy); }
@keyframes target { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.cell.wave { animation: wave .6s ease both; animation-delay: calc(var(--w) * 40ms); }
@keyframes wave { 0% { transform: translateY(0); } 40% { transform: translateY(-10px) scale(1.06); } 100% { transform: translateY(0); } }

.cheer {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: var(--font-display); font-weight: 800; font-size: clamp(40px, 12vw, 64px);
  color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink), 0 12px 24px rgba(0,0,0,.25);
  animation: cheer .95s cubic-bezier(.2,.9,.3,1.4) both;
}
@keyframes cheer { 0% { transform: scale(.2) rotate(-8deg); opacity: 0; } 25% { transform: scale(1.15) rotate(3deg); opacity: 1; } 70% { transform: scale(1) rotate(0); opacity: 1; } 100% { transform: scale(1.1) translateY(-30px); opacity: 0; } }

.busy {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px;
  background: rgba(255,253,248,.85); border-radius: var(--radius); font-weight: 800; color: var(--ink-2);
}
.busy .ico { width: 56px; height: 56px; animation: bob 1.2s ease-in-out infinite; }

.helpers { display: flex; justify-content: center; gap: 22px; padding: 6px 0 0; }
.helper {
  position: relative; width: 74px; height: 74px; border-radius: 50%; background: var(--paper);
  border: 1px solid var(--line); box-shadow: var(--shadow); display: grid; place-items: center;
  font-size: 34px; transition: transform .1s;
}
.helper svg { width: 48px; height: 48px; }
.helper.small { width: 54px; height: 54px; font-size: 24px; align-self: center; }
.helper:active { transform: scale(.92); }
.helper i {
  position: absolute; top: -4px; right: -6px; min-width: 28px; height: 28px; padding: 0 7px; border-radius: 999px;
  background: var(--melon); color: #fff; font-style: normal; font-family: var(--font-display); font-weight: 800; font-size: 16px;
  display: grid; place-items: center; border: 3px solid var(--cream);
}
.helper.empty { opacity: .55; }
.helper.empty i { background: var(--ink-3); }

.sheet {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(94vw, 500px); background: var(--ink); color: var(--cream); border-radius: 20px; padding: 16px 18px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 20px 40px rgba(0,0,0,.3); z-index: 20;
  animation: sheetin .35s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes sheetin { from { transform: translate(-50%, 40px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet p { margin: 0; flex: 1; font-weight: 600; font-size: 15px; line-height: 1.4; }
.sheet .btn-secondary { background: var(--cream); color: var(--ink); box-shadow: 0 4px 0 #c9b9a0; flex: none; }
.sw { display: inline-block; padding: 1px 8px; border-radius: 8px; background: var(--c); color: var(--ink); font-weight: 800; }

/* ---------- Modal / toast */
.modal {
  position: fixed; inset: 0; background: rgba(58,42,27,.45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 30; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(100%, 420px); background: var(--paper); border-radius: 26px; padding: 26px 22px 22px; text-align: center;
  box-shadow: 0 30px 60px rgba(0,0,0,.3); animation: cardin .4s cubic-bezier(.2,.9,.3,1.3);
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
@keyframes cardin { from { transform: scale(.7) translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h2 { font-family: var(--font-display); font-weight: 800; font-size: 34px; line-height: 1; margin: 0; }
.modal-card .big { font-size: 64px; line-height: 1; }
.modal-card .big.ico { width: 96px; height: 96px; }
.modal-card p { margin: 0; color: var(--ink-2); font-weight: 600; line-height: 1.45; }
.modal-card .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; }
.modal-card .row .btn-secondary { flex: 1; }
.modal-card .kpi { display: flex; gap: 18px; font-family: var(--font-display); font-size: 20px; color: var(--ink); }
.modal-card .kpi small { display: block; font-family: var(--font-body); font-size: 11px; font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.modal-card .badge { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--melon); color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.modal-card .city-emoji { font-size: 72px; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.setting { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); font-weight: 700; text-align: left; }
.toggle { width: 52px; height: 30px; border-radius: 999px; background: var(--line); position: relative; transition: background .2s; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.toggle.on { background: #3DA36B; }
.toggle.on::after { transform: translateX(22px); }
.danger { color: var(--melon); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 29; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear both; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .6; } }

.toast {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--cream); padding: 12px 18px; border-radius: 14px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 40; animation: toastin .3s cubic-bezier(.2,.9,.3,1.3); max-width: 92vw; text-align: center;
}
@keyframes toastin { from { transform: translate(-50%, -20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (min-width: 600px) {
  .screen { padding-top: 28px; }
  .cell:hover { filter: brightness(1.06); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
