:root {
  --bg: #080909;
  --panel: #171a19;
  --line: #343a37;
  --ink: #edf0ee;
  --muted: #adb5b1;
  --accent: #f0c75e;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--ink); font: 14px/1.7 -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; cursor: pointer; color: var(--ink); background: #242a27; border: 1px solid var(--line); border-radius: 6px; padding: 9px 14px; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
#previewApp { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
header {
  position: relative; z-index: 7;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(7px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 7px max(16px, env(safe-area-inset-left, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.chapter-progress { width: min(340px, 60%); line-height: 1.5; }
#previewStatus { color: var(--muted); font-size: 12px; }
progress { display: block; width: 100%; height: 3px; margin-top: 5px; border: 0; border-radius: 2px; overflow: hidden; background: var(--line); accent-color: var(--accent); }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.state-buttons { flex: none; display: flex; gap: 8px; }
.menu-wrap { position: relative; }
.gear-button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border-radius: 50%; }
.state-menu {
  position: absolute; z-index: 10; top: calc(100% + 8px); inset-inline-end: 0;
  width: 220px; max-width: calc(100vw - 20px); display: grid; gap: 2px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 20px #0009;
}
.state-menu button { padding: 9px 12px; font-size: 13px; text-align: start; background: none; border: 0; border-radius: 6px; }
.state-menu button:hover { background: #242a27; }
.volume-control { padding: 9px 12px 5px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.volume-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.volume-label output { color: var(--accent); font-variant-numeric: tabular-nums; }
#gameVolume { display: block; width: 100%; height: 36px; margin: 0; cursor: pointer; accent-color: var(--accent); }
#gameVolume:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.help-button { width: 30px; height: 30px; padding: 0; font-size: 15px; line-height: 1; border-radius: 50%; }
.game-stage { position: relative; min-height: 0; background: #000; }
#game { width: 100%; height: 100%; display: block; border: 0; background: #000; }
.loading-splash {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center;
  padding: 24px; background: #000; transition: opacity .4s ease, visibility .4s ease;
}
.splash-content { width: min(650px, 100%); text-align: center; }
.loading-splash img { display: block; width: 100%; max-height: 55vh; object-fit: contain; }
.loading-splash p { margin: 12px 0; color: var(--muted); font-size: 18px; }
.loading-splash.done { opacity: 0; visibility: hidden; pointer-events: none; }
.state-toast {
  position: absolute; z-index: 6; inset-inline: 0; bottom: max(16px, env(safe-area-inset-bottom, 0px));
  width: fit-content; max-width: calc(100% - 32px); margin: 0 auto; padding: 8px 16px;
  background: var(--panel); color: var(--accent); border: 1px solid var(--line); border-radius: 999px; text-align: center;
}
dialog { width: min(430px, calc(100% - 28px)); max-height: calc(100% - 28px); padding: 22px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
dialog::backdrop { background: #000b; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
h1 { margin: 0; font-size: 20px; }
#closeHelp { padding: 0; width: 34px; height: 34px; font-size: 23px; line-height: 1; }
.help-list { margin: 18px 0 0; padding: 0; list-style: none; }
.help-list li { padding: 10px 0; border-top: 1px solid var(--line); }
.help-list b { display: block; color: var(--accent); }
.help-list span { color: var(--muted); font-size: 13px; }
.help-note { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.game-message { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 24px; background: var(--bg); color: var(--muted); text-align: center; }
@media (max-width: 480px) {
  header { gap: 10px; padding-right: 10px; padding-left: 10px; }
  #previewStatus { font-size: 11px; }
  dialog { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) { .loading-splash { transition: none; } }
