@font-face {
  font-family: 'Hind Siliguri';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(../assets/fonts/hind-siliguri-bengali-500-normal.woff2) format('woff2');
  unicode-range: U+0951-0952, U+0964-0965, U+0980-09FE, U+1CD0, U+1CD2, U+1CD5-1CD6, U+1CD8, U+1CE1, U+1CEA, U+1CED, U+1CF2, U+1CF5-1CF7, U+200C-200D, U+20B9, U+25CC, U+A8F1;
}
@font-face {
  font-family: 'Hind Siliguri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../assets/fonts/hind-siliguri-bengali-700-normal.woff2) format('woff2');
  unicode-range: U+0951-0952, U+0964-0965, U+0980-09FE, U+1CD0, U+1CD2, U+1CD5-1CD6, U+1CD8, U+1CE1, U+1CEA, U+1CED, U+1CF2, U+1CF5-1CF7, U+200C-200D, U+20B9, U+25CC, U+A8F1;
}
@font-face {
  font-family: 'Hind Siliguri';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(../assets/fonts/hind-siliguri-latin-500-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Hind Siliguri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../assets/fonts/hind-siliguri-latin-700-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #1d1a2b;
  --paper: #fff8e7;
  --green: #0a8f5a;
  --green-dark: #066b43;
  --red: #e63946;
  --yellow: #ffd23f;
  --sky: #8fd0f7;
  --muted: #6b6478;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: 'Hind Siliguri', 'Noto Sans Bengali', 'Kalpurush', 'Vrinda', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fd0f7;
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body { position: fixed; inset: 0; }

#app { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#touch { position: absolute; inset: 0; touch-action: none; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- buttons ---------- */
button { font-family: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  min-height: 48px; padding: 0.5em 1.1em;
  font-size: 1.05rem; font-weight: 700;
  background: #fff; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer; touch-action: manipulation;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible, .icon-btn:focus-visible, .toggle:focus-visible, .seg button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.btn small { font-size: 0.7em; opacity: 0.85; letter-spacing: 0.08em; }
.btn-primary { background: var(--green); color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; }
.btn-ghost:active { transform: none; box-shadow: none; }
.btn-xl { font-size: 1.45rem; min-height: 62px; padding: 0.4em 1.6em; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btn.small { font-size: 0.9rem; min-height: 40px; }

.icon-btn {
  width: 52px; height: 52px; display: grid; place-items: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink);
  cursor: pointer; fill: var(--ink); color: var(--ink); touch-action: manipulation;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 14px 4px 8px; font-weight: 700; box-shadow: 0 3px 0 var(--ink);
}
.pill small { font-size: 0.75rem; color: var(--muted); margin-left: 6px; }
.coin {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3a6 0 18%, #ffcf2e 19% 60%, #d99a00 61%);
  border: 2px solid #8a5a00;
}

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  touch-action: manipulation;
}
.screen.center { display: flex; align-items: center; justify-content: center; overflow-y: auto; }
.screen.dim { background: rgba(29, 26, 43, 0.45); }

.panel {
  width: min(440px, 100%); max-height: 100%; overflow-y: auto;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 22px;
  box-shadow: 0 8px 0 var(--ink);
  padding: 20px; display: flex; flex-direction: column; gap: 12px; text-align: center;
  touch-action: pan-y;
}
.panel h2 { margin: 0; font-size: 1.7rem; line-height: 1.2; }
.panel h3 { margin: 6px 0 0; font-size: 1.15rem; }
.panel p { margin: 0; }

#loading { background: linear-gradient(#8fd0f7, #cfeaf8); flex-direction: column; gap: 18px; }
.logo-mark { font-size: 2.4rem; font-weight: 700; text-align: center; line-height: 1.15; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.loader { width: 200px; height: 14px; border: 3px solid var(--ink); border-radius: 99px; background: #fff; overflow: hidden; }
.loader div { height: 100%; width: 40%; background: var(--green); animation: load 1s ease-in-out infinite alternate; }
@keyframes load { from { margin-left: 0; } to { margin-left: 60%; } }

/* ---------- menu ---------- */
.menu { display: flex; flex-direction: column; justify-content: space-between; align-items: center; pointer-events: none; }
.menu > * { pointer-events: auto; }
.menu-head { text-align: center; margin-top: 4px; }
.title {
  margin: 0; font-size: clamp(2.1rem, 9vw, 3.6rem); line-height: 1.1; color: #fff;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink);
}
.title span { color: var(--yellow); }
.subtitle { margin: 8px 0 0; font-weight: 700; letter-spacing: 0.35em; font-size: 0.85rem; color: var(--ink); background: var(--yellow); display: inline-block; padding: 2px 12px; border: 3px solid var(--ink); border-radius: 8px; transform: rotate(-2deg); }
.menu-stats { display: flex; gap: 10px; margin-top: auto; margin-bottom: 14px; }
.menu-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(460px, 100%); }
.menu-actions .btn-row .btn { flex: 1 1 40%; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); display: inline-block; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-left { position: absolute; top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l)); }
.hud-right { position: absolute; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); display: flex; gap: 10px; align-items: center; }
.hud-score { font-size: 2.1rem; font-weight: 700; line-height: 1; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 3px 0 var(--ink); font-variant-numeric: tabular-nums; }
.hud-dist { margin-top: 6px; display: inline-block; background: rgba(255, 255, 255, 0.9); border: 2px solid var(--ink); border-radius: 8px; padding: 0 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.coin-pill span { font-variant-numeric: tabular-nums; min-width: 2ch; }

.hint {
  position: absolute; left: 50%; top: calc(96px + var(--safe-t)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 32px);
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 5px 0 var(--ink);
  padding: 8px 16px; font-weight: 700; font-size: 1.15rem; animation: pop 0.25s ease-out;
}
.hint-icon { font-size: 1.6rem; animation: bob 0.6s ease-in-out infinite alternate; }
.hint-key { font-size: 0.8rem; background: #fff; border: 2px solid var(--ink); border-radius: 6px; padding: 0 6px; white-space: nowrap; }
@keyframes bob { from { transform: translateY(-3px); } to { transform: translateY(3px); } }

.banner {
  position: absolute; top: calc(78px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 14px; padding: 6px 18px; text-align: center;
  animation: slidein 0.4s ease-out; max-width: calc(100% - 32px);
}
.banner b { display: block; font-size: 1.3rem; color: var(--yellow); }
.banner small { opacity: 0.8; letter-spacing: 0.1em; }
@keyframes slidein { from { transform: translate(-50%, -20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.toast {
  position: absolute; top: calc(168px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  background: #fff; border: 3px solid var(--green); border-radius: 14px; padding: 6px 14px; font-weight: 700;
  box-shadow: 0 4px 0 var(--green-dark); animation: pop 0.3s ease-out; max-width: calc(100% - 32px); text-align: center;
}
.comic {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) rotate(-6deg);
  font-size: clamp(2.6rem, 13vw, 5rem); font-weight: 700; color: var(--yellow);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 7px 0 var(--ink);
  animation: comic 0.45s cubic-bezier(.2, 1.6, .4, 1); white-space: nowrap;
}
.comic.small-word { font-size: clamp(1.8rem, 8vw, 3rem); color: #fff; }
@keyframes comic { from { transform: translate(-50%, -50%) rotate(-6deg) scale(0.2); } to { transform: translate(-50%, -50%) rotate(-6deg) scale(1); } }
@keyframes pop { from { transform: translateX(-50%) scale(0.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 7rem; font-weight: 700; color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--ink);
}

.key-guide {
  position: absolute; left: calc(12px + var(--safe-l)); bottom: calc(12px + var(--safe-b));
  display: flex; flex-wrap: wrap; gap: 6px 12px; max-width: 60%;
  background: rgba(255, 255, 255, 0.82); border: 2px solid var(--ink); border-radius: 10px; padding: 6px 10px; font-size: 0.85rem; font-weight: 700;
}
kbd { display: inline-block; min-width: 1.6em; text-align: center; background: #fff; border: 2px solid var(--ink); border-bottom-width: 3px; border-radius: 5px; padding: 0 4px; margin: 0 1px; font-family: inherit; font-size: 0.8rem; }
.fps { position: absolute; bottom: calc(6px + var(--safe-b)); right: calc(8px + var(--safe-r)); font: 700 12px/1 monospace; color: #fff; background: rgba(0, 0, 0, 0.55); padding: 4px 6px; border-radius: 4px; pointer-events: none; }

/* ---------- game over ---------- */
.gameover { gap: 14px; }
.go-badge { align-self: center; background: var(--red); color: #fff; font-weight: 700; padding: 2px 14px; border-radius: 99px; border: 3px solid var(--ink); transform: rotate(-3deg); animation: pop2 0.4s ease-out; }
@keyframes pop2 { from { transform: rotate(-3deg) scale(0.3); } to { transform: rotate(-3deg) scale(1); } }
.go-message { font-size: 1.4rem; font-weight: 700; line-height: 1.35; }
.go-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.go-stats div { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 6px 2px; display: flex; flex-direction: column; }
.go-stats small { color: var(--muted); font-size: 0.75rem; }
.go-stats b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.go-missions { display: flex; flex-direction: column; gap: 6px; }

.mission-list { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.mission { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 12px; }
.mission .row { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.mission .reward { white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.mission .reward .coin { width: 16px; height: 16px; }
.bar { height: 10px; background: #e8e1d0; border-radius: 99px; overflow: hidden; margin-top: 6px; border: 2px solid var(--ink); }
.bar div { height: 100%; background: var(--green); }
.mission small { color: var(--muted); }
.go-missions .mission { padding: 4px 10px; font-size: 0.9rem; }

/* ---------- shop ---------- */
.shop { display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.shop > * { pointer-events: auto; }
.shop-top { display: flex; align-items: center; gap: 10px; }
.shop-top h2 { flex: 1; margin: 0; font-size: 1.5rem; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 3px 0 var(--ink); }
.shop-bottom { background: var(--paper); border: 4px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink); padding: 12px; max-height: 50%; display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; touch-action: pan-x; }
.tabs button { flex: 0 0 auto; min-height: 40px; padding: 4px 14px; border: 2px solid var(--ink); border-radius: 99px; background: #fff; font-weight: 700; cursor: pointer; }
.tabs button.active { background: var(--ink); color: #fff; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; overflow-y: auto; touch-action: pan-y; }
.item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px; background: #fff; border: 2px solid var(--ink); border-radius: 14px; cursor: pointer; min-height: 112px; font-weight: 700; font-size: 0.9rem; }
.item.equipped { border-width: 3px; border-color: var(--green); background: #e8fff3; }
.item .swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--ink); }
.item .price { display: inline-flex; align-items: center; gap: 4px; font-size: 0.85rem; }
.item .price .coin { width: 14px; height: 14px; }
.item.locked .price { color: var(--red); }
.item .state { font-size: 0.75rem; color: var(--green-dark); }

/* ---------- settings ---------- */
.setting { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; font-weight: 700; }
.setting.column { flex-direction: column; align-items: stretch; }
.toggle { width: 60px; height: 34px; border-radius: 99px; border: 3px solid var(--ink); background: #ddd; position: relative; cursor: pointer; flex: 0 0 auto; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transition: left 0.15s; }
.toggle.on { background: var(--green); }
.toggle.on::after { left: 29px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; }
.seg button { min-height: 42px; border: 0; border-right: 2px solid var(--ink); background: #fff; font-weight: 700; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--ink); color: #fff; }

/* ---------- how to ---------- */
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.howto-grid div { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 2px; font-size: 0.9rem; }
.howto-grid b { font-size: 1.3rem; }
.legend { list-style: none; padding: 0; margin: 0; text-align: left; display: flex; flex-direction: column; gap: 6px; font-size: 0.95rem; }
.legend i { display: inline-block; width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--ink); margin-right: 8px; vertical-align: -3px; }

.replay-bar {
  position: absolute; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(29, 26, 43, 0.85); color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.replay-bar .rec { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--red); margin-right: 6px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

@media (max-height: 520px) and (orientation: landscape) {
  .title { font-size: 2rem; }
  .menu-stats { margin-bottom: 6px; }
  .btn-xl { min-height: 52px; font-size: 1.2rem; }
  .panel { padding: 14px; gap: 8px; }
  .shop-bottom { max-height: 60%; }
  .hint { top: calc(12px + var(--safe-t)); font-size: 1rem; }
  .menu { display: grid; grid-template-columns: 1fr minmax(280px, 360px); grid-template-rows: auto 1fr auto; gap: 8px; align-items: end; }
  .menu-head { grid-column: 1 / -1; align-self: start; }
  .menu-stats { grid-column: 2; grid-row: 2; justify-self: center; margin: 0; }
  .menu-actions { grid-column: 2; grid-row: 3; gap: 8px; }
  .menu-actions .btn { min-height: 42px; font-size: 0.95rem; }
}
@media (prefers-reduced-motion: reduce) {
  .hint, .banner, .toast, .comic, .go-badge, .loader div, .hint-icon { animation: none !important; }
}
