:root {
  --ink: #1f2c4a;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #ff6a3d;
  --accent-2: #3a8dff;
  --good: #2fb36a;
  --gold: #ffc21f;
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8ccbff; color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* HUD */
.hud {
  position: fixed; top: calc(10px + var(--sat)); left: calc(12px + var(--sal)); right: calc(12px + var(--sar));
  display: flex; gap: 10px; align-items: center; pointer-events: none;
}
.hud button { pointer-events: auto; }
.pill {
  background: var(--panel); border-radius: 999px; padding: 8px 16px; font-weight: 800; font-size: 18px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12); border: 0; color: var(--ink); font-family: inherit; white-space: nowrap;
}
.pill.grow { flex: 1; padding-bottom: 12px; position: relative; }
.bar { position: absolute; left: 16px; right: 16px; bottom: 5px; height: 5px; background: #d9e3f2; border-radius: 3px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--good); }
.hint {
  position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%);
  background: var(--panel); padding: 10px 20px; border-radius: 16px; font-weight: 800; font-size: 18px; text-align: center;
  pointer-events: none; max-width: 90vw; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

/* Screens */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(14px + var(--sat)) calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
  background: rgba(20, 40, 80, 0.28); touch-action: pan-y;
}
.screen.clear { background: transparent; }
.panel {
  background: var(--panel); border-radius: 28px; padding: 22px 26px; width: min(720px, 100%);
  max-height: 100%; overflow-y: auto; box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12), 0 20px 50px rgba(0, 0, 0, 0.25);
  text-align: center; -webkit-overflow-scrolling: touch;
}
.panel.narrow { width: min(460px, 100%); }
h1 { margin: 0 0 4px; font-size: clamp(32px, 7vw, 54px); line-height: 1; letter-spacing: -1px; }
h1 span { color: var(--accent); }
h2 { margin: 0 0 10px; font-size: 28px; }
p { margin: 6px 0; font-weight: 600; }
.sub { color: #5d6b88; margin-bottom: 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; margin-top: 12px; }

.btn {
  font: inherit; font-weight: 800; font-size: 22px; padding: 14px 26px; border-radius: 18px; border: 0;
  background: var(--accent); color: #fff; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2); cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); }
.btn.blue { background: var(--accent-2); }
.btn.green { background: var(--good); }
.btn.gray { background: #8d99b0; }
.btn.small { font-size: 16px; padding: 9px 16px; border-radius: 14px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.coins { font-weight: 900; font-size: 22px; }
.tabs { display: flex; gap: 8px; justify-content: center; margin: 10px 0; }
.tab { font: inherit; font-weight: 800; font-size: 16px; padding: 8px 16px; border-radius: 14px; border: 0; background: #e3eaf6; color: var(--ink); }
.tab.on { background: var(--accent-2); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 8px; }
.card {
  background: #f1f5fc; border-radius: 20px; padding: 10px; font-weight: 800; display: flex; flex-direction: column;
  align-items: center; gap: 6px; border: 3px solid transparent;
}
.card.sel { border-color: var(--good); background: #e5f8ee; }
.card.locked { opacity: 0.6; }
.card canvas { position: static; width: 120px; height: 90px; }
.card small { font-weight: 700; color: #5d6b88; }
.card .btn { width: 100%; }
.pips { display: flex; gap: 4px; justify-content: center; }
.pip { width: 14px; height: 14px; border-radius: 50%; background: #d3dcec; }
.pip.on { background: var(--gold); }
.theme-dot { width: 100%; height: 56px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 28px; }

.stat { display: flex; justify-content: space-between; font-size: 22px; font-weight: 800; padding: 6px 4px; border-bottom: 2px dashed #d3dcec; }
.stat:last-of-type { border: 0; }
.big { font-size: clamp(26px, 6vw, 40px); }
.good { color: var(--good); }
.gold { color: #c98a00; }

@media (max-height: 460px) {
  .panel { padding: 12px 18px; border-radius: 22px; }
  .btn { font-size: 18px; padding: 10px 20px; }
  h1 { font-size: 34px; } h2 { font-size: 22px; }
  .sub { margin-bottom: 8px; } .stack { margin-top: 8px; gap: 8px; }
  .panel.narrow { width: min(640px, 100%); }
  .panel.narrow .stack { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .stat { font-size: 17px; padding: 3px 4px; }
  .big { font-size: 24px; }
}
