:root {
  --ink: #2a1a12;
  --paper: #fff7e6;
  --accent: #f2b33d;
  --panel: rgba(255, 247, 230, 0.92);
  --panel-ink: #2a1a12;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  --font: 'Fredoka', system-ui, sans-serif;
  --title-font: var(--font);
  --radius: 14px;
  --hud-ink: #fff7e6;
  --hud-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #111; color: var(--hud-ink);
  font-family: var(--font);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
canvas#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }

.hud { position: fixed; pointer-events: none; text-shadow: var(--hud-shadow); }
.hud-top {
  top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; padding: max(14px, env(safe-area-inset-top)) 18px 0;
}
.brand .title { font-family: var(--title-font); font-size: clamp(22px, 4vw, 38px); line-height: 1; letter-spacing: 0.02em; }
.brand .sub { margin-top: 6px; font-size: clamp(11px, 1.6vw, 14px); opacity: 0.85; }
.stats { display: grid; grid-template-columns: repeat(4, auto); gap: 4px 16px; text-align: right; font-size: clamp(11px, 1.5vw, 14px); }
.stats b { display: block; font-size: clamp(16px, 2.4vw, 24px); font-family: var(--title-font); }

.message {
  top: clamp(70px, 13vh, 120px); left: 50%; transform: translateX(-50%);
  font-size: clamp(14px, 2.2vw, 20px); white-space: nowrap; transition: opacity 0.25s;
}

.result {
  top: clamp(64px, 11vh, 120px); left: 50%; transform: translateX(-50%);
  width: min(340px, 80vw);
  padding: 18px 20px; border-radius: var(--radius);
  background: var(--panel); color: var(--panel-ink); text-shadow: none;
  box-shadow: var(--shadow); text-align: center;
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.result[hidden] { display: none; }
.r-title { font-family: var(--title-font); font-size: 26px; line-height: 1.1; }
.r-detail { margin-top: 8px; font-size: 15px; }
.r-score { margin-top: 10px; font-family: var(--title-font); font-size: 34px; color: var(--accent); }
.r-next { margin-top: 10px; font-size: 12px; opacity: 0.7; }
@keyframes pop { from { transform: translateX(-50%) scale(0.6); opacity: 0; } }

.hint {
  left: 50%; transform: translateX(-50%); bottom: max(22px, env(safe-area-inset-bottom));
  width: max-content; max-width: calc(100vw - 150px); text-align: center;
  font-size: clamp(14px, 2vw, 18px); opacity: 0.95; transition: opacity 0.6s;
}
.hint .touch { display: none; }
body[data-style='blocky'] kbd { background: rgba(255, 255, 255, 0.55); }
@media (hover: none) { .hint .keys { display: none; } .hint .touch { display: inline; } }
kbd { font-family: inherit; padding: 1px 6px; border-radius: 5px; background: rgba(0, 0, 0, 0.35); }

/* ---------- style selector, bottom right ---------- */
.selector {
  position: fixed; right: 14px; bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px; border-radius: var(--radius);
  background: var(--panel); color: var(--panel-ink); box-shadow: var(--shadow);
}
.sel-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.7; padding: 0 2px; }
.sel-buttons { display: flex; flex-direction: column; gap: 6px; }
.sel-btn {
  display: flex; align-items: center; gap: 10px; min-width: 190px;
  padding: 7px 10px; border: 2px solid transparent; border-radius: calc(var(--radius) - 4px);
  background: rgba(0, 0, 0, 0.06); color: inherit; font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.sel-btn:hover { background: rgba(0, 0, 0, 0.12); }
.sel-btn[aria-pressed='true'] { border-color: var(--panel-ink); background: rgba(0, 0, 0, 0.14); }
.sel-btn .sw { flex: none; width: 34px; height: 34px; border-radius: 8px; overflow: hidden; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.sel-btn .sw i { display: block; }
.sel-btn .nm b { display: block; font-size: 14px; }
.sel-btn .nm small { display: block; font-size: 11px; opacity: 0.7; }
.sel-btn kbd { margin-left: auto; font-size: 11px; background: rgba(0, 0, 0, 0.1); }
.sel-mute { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 6px; background: none; color: inherit; opacity: 0.8; cursor: pointer; padding: 0; }
.sel-mute:hover, .sel-mute:focus-visible { opacity: 1; background: rgba(0, 0, 0, 0.08); }
@media (max-width: 640px) {
  .selector { flex-direction: row; align-items: center; padding: 6px; gap: 6px; }
  .sel-label { display: none; }
  .sel-buttons { flex-direction: row; }
  .sel-btn { min-width: 0; padding: 5px; flex-direction: column; gap: 4px; text-align: center; }
  .sel-btn .sw { width: 28px; height: 28px; }
  .selector { padding: 4px; }
  .sel-btn .nm small, .sel-btn kbd { display: none; }
  .sel-btn .nm b { font-size: 12px; }
  .stats { grid-template-columns: repeat(2, auto); }
  .hint { max-width: calc(100vw - 96px); font-size: 13px; left: 16px; transform: none; text-align: left; }
}

/* ---------- per-style themes ---------- */
body[data-style='pixel'] {
  --font: 'Press Start 2P', monospace; --title-font: 'Press Start 2P', monospace;
  --panel: #ded895; --panel-ink: #543847; --accent: #e86a17; --radius: 0px;
  --shadow: 0 0 0 4px #543847, 6px 6px 0 4px rgba(84, 56, 71, 0.5);
  --hud-ink: #fff; --hud-shadow: 3px 3px 0 #543847;
}
body[data-style='pixel'] .brand .title { font-size: clamp(16px, 3vw, 28px); }
body[data-style='pixel'] .brand .sub, body[data-style='pixel'] .stats { font-size: clamp(8px, 1.1vw, 11px); line-height: 1.6; }
body[data-style='pixel'] .stats b { font-size: clamp(12px, 1.8vw, 18px); }
body[data-style='pixel'] .message { font-size: clamp(10px, 1.6vw, 14px); }
body[data-style='pixel'] .sel-btn, body[data-style='pixel'] .sel-btn .nm b { font-size: 10px; }
body[data-style='pixel'] .sel-btn .nm small, body[data-style='pixel'] .sel-mute, body[data-style='pixel'] .sel-label { font-size: 8px; line-height: 1.5; }
body[data-style='pixel'] .r-title { font-size: 16px; line-height: 1.4; }
body[data-style='pixel'] .r-detail, body[data-style='pixel'] .r-next { font-size: 9px; line-height: 1.6; }
body[data-style='pixel'] .r-score { font-size: 22px; }
body[data-style='pixel'] .hint { font-size: 9px; line-height: 1.6; }

body[data-style='blocky'], body[data-style='emerald'] {
  --font: 'Lilita One', 'Fredoka', sans-serif; --title-font: 'Lilita One', sans-serif;
  --panel: #ffffff; --panel-ink: #23324a; --accent: #ff5a3c; --radius: 6px;
  --shadow: 0 6px 0 #9fb2c8, 0 10px 18px rgba(0, 0, 0, 0.18);
  --hud-ink: #1f2d44; --hud-shadow: 0 1px 0 rgba(255, 255, 255, 0.8), 0 0 8px rgba(255, 255, 255, 0.7);
}

body[data-style='storybook'], body[data-style='cliffs'] {
  --font: 'Fredoka', system-ui, sans-serif; --title-font: 'Fredoka', system-ui, sans-serif;
  --panel: rgba(255, 244, 222, 0.95); --panel-ink: #3b2414; --accent: #c2452d; --radius: 18px;
  --shadow: 0 10px 30px rgba(20, 8, 0, 0.45), inset 0 0 0 2px rgba(120, 70, 30, 0.35);
  --hud-ink: #ffeccc; --hud-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}
body[data-style='storybook'] .brand .title, body[data-style='storybook'] .stats b,
body[data-style='cliffs'] .brand .title, body[data-style='cliffs'] .stats b { font-weight: 700; color: #ffd98a; }
body[data-style='storybook'] .r-title, body[data-style='cliffs'] .r-title { font-weight: 700; color: #3b2414; }
