:root {
  --bg: #fffaf0;
  --panel: #fffdf7;
  --paper: #fffaf0;
  --grid: #b9dfe0;
  --ink: #3d3832;
  --muted: #8a7c6e;
  --line: #d9cfc1;
  --mint: #9eddbd;
  --blue: #8fc9eb;
  --yellow: #f7d66c;
  --coral: #f28c78;
  --purple: #b8a7e8;
  --accent: #4b9c95;
  --shadow: #d6c8b7;
}

[data-theme="dark"] {
  --bg: #17232b;
  --panel: #20323a;
  --paper: #1b2b33;
  --grid: #38535b;
  --ink: #fff4dc;
  --muted: #a8b8b2;
  --line: #4d6668;
  --mint: #86cda9;
  --blue: #76b8de;
  --yellow: #f1ce63;
  --coral: #eb806f;
  --purple: #a99add;
  --accent: #9eddbd;
  --shadow: #0d171d;
}

* { 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(570px, 100%);
  padding: 15px 14px calc(22px + env(safe-area-inset-bottom));
}

.topbar {
  min-height: 58px;
  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: 800 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 {
  text-align: center;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(17px, 4vw, 24px);
  font-weight: 950;
  letter-spacing: .08em;
  line-height: 1;
  white-space: nowrap;
  transform: rotate(-1deg);
}

.brand span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .12em;
  white-space: nowrap;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  width: min(100%, 480px);
  margin: 0 auto 9px;
}

.stat {
  position: relative;
  overflow: hidden;
  min-width: 0;
  padding: 8px 9px 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: -12px;
  bottom: -18px;
  width: 35px;
  height: 35px;
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: .22;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .1em;
}

.stat b {
  display: block;
  margin-top: 3px;
  font-size: clamp(12px, 3.2vw, 16px);
  line-height: 1;
  letter-spacing: .04em;
}

.stat-score { color: var(--coral); }
.stat-stars { color: #d59b16; }
.stat-height { color: var(--accent); }
.stat-best { color: var(--purple); }

.screen {
  position: relative;
  width: min(100%, 480px);
  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(.25deg);
}

.screen canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  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-scribble {
  color: var(--coral);
  font-size: 40px;
  line-height: 1;
  transform: rotate(14deg);
}

.overlay b {
  color: var(--ink);
  font-size: clamp(24px, 7vw, 36px);
  font-weight: 950;
  letter-spacing: .06em;
  line-height: 1;
  transform: rotate(-2deg);
}

.overlay span {
  max-width: 260px;
  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 1fr;
  gap: 9px;
  width: min(100%, 480px);
  margin: 15px auto 0;
}

.controls button {
  min-height: 52px;
  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: .06em;
}

.controls button:hover, .controls button:focus-visible, .controls button.active {
  border-color: var(--accent);
  background: var(--mint);
  color: #25433d;
  outline: none;
}

.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 14px;
  width: min(100%, 480px);
  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: 480px) {
  .page { padding: 10px 10px max(19px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 54px; gap: 5px; }
  .brand h1 { font-size: 17px; }
  .brand span { font-size: 6px; letter-spacing: .08em; }
  .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-scribble { font-size: 31px; }
  .overlay b { font-size: 25px; }
  .overlay span { font-size: 8px; }
  .controls { margin-top: 12px; gap: 7px; }
  .controls button { min-height: 50px; font-size: 9px; box-shadow: 2px 3px 0 var(--shadow); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
