:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --line: #d5d9e4;
  --text: #0f1b3d;
  --muted: #747a92;
  --navy: #0f1b3d;
  --navy-soft: #e7e9f0;
  --shadow: 0 1px 2px rgba(30, 33, 53, 0.04), 0 8px 24px rgba(30, 33, 53, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: radial-gradient(ellipse at 50% 35%, #ffffff, var(--bg) 70%);
  background-color: var(--bg);
}

body { display: flex; flex-direction: column; }
button { font: inherit; }

/* ── HUD ── */
.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.hud-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.title-line { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#level-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-stats { display: flex; gap: 16px; font-variant-numeric: tabular-nums; }
.hud-stats span { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.hud-stats small, .score small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.hud-stats b { font-size: 18px; }
.hud-actions { display: flex; gap: 6px; }

.tier {
  align-self: flex-start;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.btn {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(30, 33, 53, 0.04);
}
.btn:hover { border-color: var(--navy); }
.btn.icon { width: 38px; height: 38px; padding: 0; font-size: 17px; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }

/* ── Stage ── */
#stage { position: relative; flex: 1; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.tip {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  width: max-content;
  max-width: min(600px, calc(100% - 32px));
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.toast {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 0;
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}

/* On-screen controls: shown on touch devices */
.dpad {
  position: absolute;
  right: 16px;
  bottom: calc(52px + env(safe-area-inset-bottom));
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 6px;
  transform: rotate(-12deg);
}
.dpad button {
  font-size: 18px;
  color: var(--navy);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: var(--shadow);
}
.dpad button:active { background: var(--navy); color: #fff; }
.dpad [data-dir="up"] { grid-area: 1 / 2; }
.dpad [data-dir="left"] { grid-area: 2 / 1; }
.dpad [data-dir="swap"] { grid-area: 2 / 2; font-size: 16px; visibility: hidden; }
.dpad.has-split [data-dir="swap"] { visibility: visible; }
.dpad [data-dir="right"] { grid-area: 2 / 3; }
.dpad [data-dir="down"] { grid-area: 3 / 2; }
@media (pointer: coarse) {
  .dpad { display: grid; }
  .tip { bottom: calc(232px + env(safe-area-inset-bottom)); }
}

/* ── Overlays ── */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(246, 247, 251, 0.72);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.overlay[hidden] { display: none; }
.panel {
  width: min(980px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 24px;
  border-radius: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.panel.small { width: min(380px, 100%); text-align: center; }
.panel h1 { margin: 0 0 2px; font-size: 26px; letter-spacing: -0.01em; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.sub, .muted { color: var(--muted); margin: 0; }
.keys { margin: 20px 0 0; font-size: 12.5px; color: var(--muted); }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.eyebrow { margin: 0 0 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--navy); }

.stars { font-size: 30px; letter-spacing: 6px; margin: 4px 0 0; color: var(--navy); }
.stars .off { color: var(--navy-soft); }
.points { margin: 2px 0 6px; font-size: 28px; font-weight: 750; color: var(--navy); }
.unlock { margin: 10px 0 0; font-weight: 650; color: var(--navy); }
.unlock:empty { display: none; }

.menu-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.score { display: flex; flex-direction: column; align-items: flex-end; }
.score b { font-size: 24px; color: var(--navy); white-space: nowrap; font-variant-numeric: tabular-nums; }

#tiers { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.tier-col {
  padding: 14px;
  border-radius: 0;
  border: 1px solid var(--line);
  background: var(--surface);
}
.tier-col header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tier-col h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--navy); }
.tier-col .count { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.tier-col p { margin: 2px 0 10px; color: var(--muted); font-size: 12.5px; }
.tier-col.locked { opacity: 0.55; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.lvl {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
}
.lvl:hover:not(:disabled) { border-color: var(--navy); }
.lvl:disabled { cursor: not-allowed; }
.lvl.done { background: var(--navy); border-color: var(--navy); color: #fff; }
.lvl.current { outline: 2px solid var(--navy); outline-offset: 2px; }
.lvl .n { font-weight: 650; font-size: 13px; font-variant-numeric: tabular-nums; }
.lvl .st { font-size: 8px; line-height: 1; color: inherit; min-height: 8px; letter-spacing: 1px; }

@media (max-width: 640px) {
  .hud { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .hud-stats { gap: 10px; }
  .btn.icon { width: 34px; height: 34px; }
  .panel { padding: 18px; }
  .menu-head h1 { font-size: 22px; }
}
.btn[hidden] { display: none; }

/* Ads (js/ads.js): one small banner on the menu / level-complete card only. */
.ad-slot { display: flex; justify-content: center; margin-top: 16px; min-height: 50px; }
.ad-slot[hidden] { display: none; }
.ad-demo-banner { width: 320px; max-width: 100%; height: 50px; display: grid; place-items: center; border: 1px dashed var(--line); color: var(--muted); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.ad-demo-full { position: fixed; inset: 0; z-index: 100; background: rgba(15, 27, 61, 0.92); display: grid; place-items: center; color: #fff; text-align: center; }
.ad-demo-full > div { background: var(--navy, #0f1b3d); border: 1px solid rgba(255, 255, 255, 0.2); padding: 28px; border-radius: 12px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
