:root {
  --bg: #fff5df;
  --panel: #fffdf7;
  --paper: #fff7e7;
  --ink: #3c302a;
  --muted: #8d7868;
  --line: #dfcbb4;
  --accent: #d86d4d;
  --mint: #8fcfa9;
  --blue: #8dc9df;
  --yellow: #f7cd5c;
  --coral: #e9785e;
  --purple: #ad9bdf;
  --shadow: #d7bfa5;
}

[data-theme="dark"] {
  --bg: #111b23;
  --panel: #1c2b34;
  --paper: #17252e;
  --ink: #fff1d4;
  --muted: #a8b6ae;
  --line: #40545b;
  --accent: #ff9a70;
  --mint: #83caa3;
  --blue: #78b9d5;
  --yellow: #f4cd63;
  --coral: #ed8065;
  --purple: #ad9cde;
  --shadow: #071117;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 12px ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
}
body { display: flex; justify-content: center; }
button, a { -webkit-tap-highlight-color: transparent; }
.page { width: min(760px, 100%); padding: 15px 14px calc(22px + env(safe-area-inset-bottom)); }
.topbar {
  min-height: 60px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  border-bottom: 2px dashed var(--line);
  margin-bottom: 12px;
}
.back-link, .topbar > button {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font: 900 10px inherit;
  letter-spacing: .08em;
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 8px 0;
}
.topbar > button { justify-content: flex-end; }
.back-link:hover, .back-link:focus-visible, .topbar > button:hover, .topbar > button:focus-visible { color: var(--accent); outline: none; }
.brand { min-width: 0; text-align: center; }
.brand h1 { margin: 0; color: var(--ink); font-size: clamp(17px, 4vw, 25px); font-weight: 950; letter-spacing: .07em; line-height: 1; white-space: nowrap; transform: rotate(-1deg); }
.brand span { display: block; margin-top: 5px; color: var(--muted); font-size: 8px; font-weight: 900; letter-spacing: .12em; white-space: nowrap; }
.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; width: min(100%, 720px); margin: 0 auto 9px; }
.stat { position: relative; overflow: hidden; min-width: 0; padding: 8px 10px 9px; border: 2px solid var(--ink); border-radius: 13px 11px 14px 10px; background: var(--panel); box-shadow: 2px 3px 0 var(--shadow); }
.stat::after { content: ""; position: absolute; right: -11px; bottom: -17px; width: 34px; height: 34px; border: 2px solid currentColor; border-radius: 50%; opacity: .2; }
.stat span { display: block; color: var(--muted); font-size: 8px; font-weight: 900; letter-spacing: .1em; }
.stat b { display: block; margin-top: 3px; color: var(--ink); font-size: clamp(13px, 3.2vw, 17px); line-height: 1; letter-spacing: .04em; }
.stat-world { color: var(--accent); }
.stat-coins { color: #c08a0e; }
.stat-lives { color: var(--coral); }
.stat-score { color: var(--purple); }
.screen { position: relative; width: min(100%, 720px); margin: 0 auto; padding: 5px; border: 3px solid var(--ink); border-radius: 23px 20px 27px 19px; background: var(--paper); box-shadow: 7px 8px 0 var(--shadow); transform: rotate(.18deg); }
.screen canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 15px 13px 19px 14px; background: var(--paper); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.overlay { position: absolute; inset: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 13px; padding: 24px; border-radius: 15px 13px 19px 14px; background: color-mix(in srgb, var(--paper) 91%, transparent); text-align: center; }
.overlay.hidden { display: none; }
.overlay-mark { color: var(--coral); font-size: 40px; line-height: 1; transform: rotate(14deg); }
.overlay b { color: var(--ink); font-size: clamp(24px, 6vw, 39px); font-weight: 950; letter-spacing: .06em; line-height: 1; transform: rotate(-2deg); }
.overlay span { max-width: 320px; color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .1em; line-height: 1.5; }
.overlay button { min-height: 48px; padding: 12px 21px; border: 2px solid var(--ink); border-radius: 15px 12px 17px 11px; background: var(--yellow); color: var(--ink); box-shadow: 3px 4px 0 var(--ink); cursor: pointer; font: 950 11px inherit; letter-spacing: .08em; }
.overlay button:hover, .overlay button:focus-visible { background: var(--mint); outline: none; transform: translate(-1px, -1px); box-shadow: 4px 5px 0 var(--ink); }
.overlay button:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 var(--ink); }
.controls { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 9px; width: min(100%, 720px); margin: 15px auto 0; }
.controls button { min-height: 54px; border: 2px solid var(--ink); border-radius: 15px 11px 16px 12px; background: var(--panel); color: var(--ink); box-shadow: 3px 4px 0 var(--shadow); cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; font: 950 11px inherit; letter-spacing: .08em; }
.controls button:hover, .controls button:focus-visible, .controls button.active { border-color: var(--accent); background: var(--mint); color: #25433d; outline: none; }
.controls button:nth-child(2) { background: var(--yellow); }
.controls button:nth-child(2):hover, .controls button:nth-child(2):focus-visible, .controls button:nth-child(2).active { background: var(--coral); color: var(--ink); }
.controls button:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 var(--shadow); }
.tips { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 16px; width: min(100%, 720px); margin: 12px auto 0; color: var(--muted); font-size: 8px; font-weight: 900; letter-spacing: .08em; line-height: 1.4; }
.tips span::before { content: "✦"; margin-right: 4px; color: var(--coral); }
footer { margin-top: 12px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; line-height: 1.5; text-align: center; }
@media (max-width: 520px) {
  .page { padding: 10px 10px max(19px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 54px; gap: 5px; }
  .brand h1 { font-size: 16px; }
  .brand span { font-size: 6px; letter-spacing: .07em; }
  .back-link, .topbar > button { font-size: 8px; }
  .hud { gap: 5px; }
  .stat { padding: 7px 6px 8px; border-width: 1.5px; box-shadow: 1px 2px 0 var(--shadow); }
  .stat span { font-size: 7px; }
  .stat b { font-size: 11px; }
  .screen { border-width: 2px; border-radius: 18px 16px 21px 15px; box-shadow: 5px 6px 0 var(--shadow); }
  .screen canvas, .overlay { border-radius: 11px 10px 14px 10px; }
  .overlay { inset: 4px; gap: 10px; }
  .overlay-mark { font-size: 31px; }
  .overlay b { font-size: 24px; }
  .overlay span { font-size: 8px; }
  .controls { margin-top: 12px; gap: 7px; }
  .controls button { min-height: 52px; font-size: 10px; box-shadow: 2px 3px 0 var(--shadow); }
  footer { font-size: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
