:root {
  --ink: #f6f0ff;
  --muted: #b3a8cc;
  --card: rgba(24, 18, 40, 0.92);
  --line: rgba(255, 255, 255, 0.09);
  --accent: #ffc86e;
  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120e22;
  color: var(--ink);
  color-scheme: dark;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

canvas#stage { position: fixed; inset: 0; display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; appearance: none; -webkit-appearance: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 22px; letter-spacing: 0.01em; margin-right: auto; }
.brand-name {
  background: linear-gradient(180deg, #fff 0%, #ffe3a6 60%, #f3b225 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.mode-tag {
  font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); color: var(--muted); border: 1px solid var(--line);
}
.stats { display: flex; gap: 8px; }
.stat {
  min-width: 78px; padding: 6px 12px 7px; border-radius: 12px; text-align: center;
  background: linear-gradient(180deg, rgba(60, 48, 92, 0.85), rgba(32, 25, 52, 0.85));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 6px 16px rgba(0, 0, 0, 0.3);
}
.stat .label, .over-stats .label { display: block; font-size: 10px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stat .value { display: block; font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat .value.bump { animation: bump 0.28s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); color: #ffe795; } 100% { transform: scale(1); } }

.actions { display: flex; gap: 6px; }
.chip, .icon-btn {
  height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(60, 48, 92, 0.85), rgba(32, 25, 52, 0.85));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 6px 16px rgba(0, 0, 0, 0.3);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s;
}
.icon-btn { width: 42px; }
.chip { padding: 0 10px; }
.chip:hover, .icon-btn:hover { filter: brightness(1.2); }
.chip:active, .icon-btn:active { transform: translateY(1px) scale(0.97); }
.chip:disabled { opacity: 0.45; cursor: default; filter: none; }
.chip svg, .icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .off { display: none; }
.icon-btn.muted .on { display: none; }
.icon-btn.muted .off { display: block; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }
.pips i.on { background: radial-gradient(circle at 35% 30%, #fff6c8, #f3b225 70%); box-shadow: 0 0 6px rgba(255, 201, 64, 0.8); }
.chip.flash { animation: chipflash 0.6s ease-out; }
@keyframes chipflash { 0% { box-shadow: 0 0 0 0 rgba(255, 201, 64, 0.9); } 100% { box-shadow: 0 0 0 14px rgba(255, 201, 64, 0); } }

.hint {
  position: fixed; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom));
  text-align: center; font-size: 12px; font-weight: 700; color: rgba(214, 204, 240, 0.55); z-index: 4; pointer-events: none;
}

.toast {
  position: fixed; left: 50%; top: 74px; transform: translate(-50%, -10px);
  padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: 14px;
  background: linear-gradient(180deg, #ffe795, #f3b225); color: #4a2d00;
  box-shadow: 0 8px 24px rgba(243, 178, 37, 0.35); opacity: 0; pointer-events: none; z-index: 8;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto; opacity: 0; pointer-events: none; transition: opacity 0.25s;
  touch-action: pan-y;
  background: radial-gradient(ellipse at center, rgba(10, 6, 22, 0.35), rgba(10, 6, 22, 0.7));
}
.overlay.show { opacity: 1; pointer-events: auto; }
.card {
  margin: auto; width: min(460px, 100%); padding: 24px 22px 20px; border-radius: 24px; text-align: center;
  background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform: translateY(8px) scale(0.98); transition: transform 0.3s cubic-bezier(.2, 1.4, .4, 1);
}
.overlay.show .card { transform: none; }
.small-card { width: min(360px, 100%); }
.card h2 { margin: 0 0 4px; font-size: 30px; font-weight: 900; }
.sub { margin: 0 0 14px; color: var(--muted); font-weight: 700; font-size: 14px; }

.logo { display: flex; justify-content: center; gap: 5px; margin: 2px 0 12px; }
.lt {
  --a: #fff; --b: #ddd; --s: #999; --i: #333;
  width: clamp(26px, 9vw, 50px); height: clamp(30px, 10vw, 56px);
  display: inline-flex; align-items: center; justify-content: center; padding-bottom: 4px;
  font-size: clamp(15px, 5vw, 30px); font-weight: 900; color: var(--i); border-radius: 11px;
  background: linear-gradient(180deg, rgba(255,255,255,0.45), rgba(255,255,255,0) 45%), linear-gradient(180deg, var(--a), var(--b));
  box-shadow: inset 0 -5px 0 var(--s), inset 0 1px 0 rgba(255,255,255,0.8), 0 8px 16px rgba(0,0,0,0.4);
  animation: drop 0.6s cubic-bezier(.2, 1.5, .4, 1) both;
}
.lt:nth-child(2) { animation-delay: .05s; } .lt:nth-child(3) { animation-delay: .1s; } .lt:nth-child(4) { animation-delay: .15s; }
.lt:nth-child(5) { animation-delay: .2s; } .lt:nth-child(6) { animation-delay: .25s; } .lt:nth-child(7) { animation-delay: .3s; }
@keyframes drop { from { transform: translateY(-24px) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.v2 { --a: #fffaf2; --b: #e8ddcc; --s: #bba68c; --i: #6b5847; }
.v8 { --a: #ffcaa0; --b: #f58f4e; --s: #bd5d24; --i: #fff; }
.v32 { --a: #ff93aa; --b: #e8466b; --s: #a82748; --i: #fff; }
.v128 { --a: #ffe795; --b: #f3b225; --s: #b27a0c; --i: #714400; }
.v512 { --a: #86f2c4; --b: #1cbb7b; --s: #0f8355; --i: #fff; }
.v1024 { --a: #86e9f7; --b: #17a5cc; --s: #0d7090; --i: #fff; }
.v2048 { --a: #9bb8ff; --b: #3a5ff0; --s: #2238a8; --i: #fff; }

.tagline { margin: 0 0 14px; color: var(--muted); font-weight: 700; font-size: 15px; }
.greet { margin: -6px 0 12px; font-weight: 800; color: var(--accent); }

.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.mode {
  padding: 10px 4px 8px; border-radius: 14px; border: 1px solid var(--line); font-weight: 900; font-size: 18px;
  background: rgba(255, 255, 255, 0.05); display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.mode small { font-size: 11px; font-weight: 700; color: var(--muted); }
.mode:hover { background: rgba(255, 255, 255, 0.1); }
.mode.sel { background: linear-gradient(180deg, rgba(255, 214, 120, 0.25), rgba(255, 170, 60, 0.12)); border-color: rgba(255, 201, 64, 0.7); }
.mode.daily.sel { background: linear-gradient(180deg, rgba(120, 170, 255, 0.28), rgba(80, 100, 240, 0.12)); border-color: rgba(120, 160, 255, 0.8); }
.mode-info { min-height: 20px; margin-bottom: 14px; font-size: 13px; font-weight: 700; color: var(--muted); }
.mode-info b { color: var(--ink); }

.row { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.btn {
  min-height: 48px; padding: 0 26px; border-radius: 14px; border: 0; font-weight: 900; font-size: 18px;
  transition: transform 0.1s, filter 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(2px); }
.btn.primary {
  color: #3f2600; min-width: 160px;
  background: linear-gradient(180deg, rgba(255,255,255,0.5), rgba(255,255,255,0) 50%), linear-gradient(180deg, #ffe795, #f3b225);
  box-shadow: inset 0 -4px 0 #b27a0c, 0 10px 24px rgba(243, 178, 37, 0.3);
}
.btn.gold {
  color: #fff;
  background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 50%), linear-gradient(180deg, #86e9f7, #17a5cc);
  box-shadow: inset 0 -4px 0 #0d7090, 0 10px 24px rgba(23, 165, 204, 0.3);
}
.btn.ghost { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); color: var(--ink); }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 16px; margin-top: 12px; }

.howto { list-style: none; padding: 0; margin: 0 0 12px; text-align: left; font-size: 13.5px; line-height: 1.45; color: #d9d0ee; }
.howto li { padding-left: 18px; position: relative; margin-bottom: 5px; }
.howto li::before { content: ''; position: absolute; left: 3px; top: 7px; width: 7px; height: 7px; border-radius: 2px; background: linear-gradient(180deg, #ffe795, #f3b225); }
.howto b { color: #fff; }
.keys { font-size: 12px; color: var(--muted); font-weight: 700; line-height: 1.7; }
kbd {
  display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 6px; font: inherit; font-weight: 800; font-size: 11px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line); border-bottom-width: 2px; color: var(--ink);
}

.big-score {
  font-size: 54px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff, #ffe3a6 60%, #f3b225); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.badge {
  display: inline-block; margin: 6px 0 0; padding: 4px 12px; border-radius: 999px; font-weight: 900; font-size: 13px;
  background: linear-gradient(180deg, #86f2c4, #1cbb7b); color: #fff; animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.08); } }
.over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 18px; align-items: end; }
.over-stats > div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.over-stats .value { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.mini-tile {
  min-width: 44px; height: 36px; padding: 0 8px 3px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 17px;
}

@media (max-width: 560px) {
  .hud { flex-wrap: wrap; width: min(680px, calc(100% - 16px)); row-gap: 8px; }
  .brand { order: 1; }
  .actions { order: 2; margin-left: auto; }
  .stats { order: 3; flex: 1 1 100%; justify-content: center; }
  .brand-name { display: none; }
  .stat { min-width: 88px; }
  .card { padding: 20px 16px 16px; }
  .mode { font-size: 16px; }
  .big-score { font-size: 44px; }
  .logo { gap: 4px; }
}
@media (max-width: 560px) and (max-height: 480px) {
  .stats { order: 2; flex: 0 1 auto; }
  .actions { order: 3; }
  .stat { min-width: 58px; padding: 4px 8px; }
  .stat .value { font-size: 15px; }
  .icon-btn, .chip { height: 36px; }
  .icon-btn { width: 36px; }
}
@media (max-height: 560px) {
  .howto { display: none; }
  .tagline { margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
