:root {
  --ink: #f4efe4;
  --muted: #b7c4bf;
  --gold: #e4c27a;
  --gold-deep: #a88445;
  --foam: #e7f7fb;
  --rose: #ff8fb3;
  --bg: #081114;
  --card: rgba(14, 28, 34, 0.92);
  --line: rgba(228, 194, 122, 0.38);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans CJK SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
button, a { font-family: inherit; }
button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
}
button:hover { border-color: var(--gold); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, #f4e3ba, #d7b36a);
  color: #2a2116;
  border-color: transparent;
  font-weight: 700;
  min-width: 168px;
  padding: 12px 22px;
  font-size: 17px;
}
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  background: #081114;
}

#fatal {
  position: fixed;
  z-index: 80;
  left: 12px;
  right: 12px;
  top: 12px;
  padding: 12px 14px;
  background: #4a1820;
  color: #fff;
  border-radius: 10px;
  white-space: pre-wrap;
}

#hud {
  position: fixed;
  z-index: 5;
  top: calc(10px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(120px, 1.4fr) minmax(120px, 1fr);
  gap: 8px;
  align-items: center;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}
body[data-screen="menu"] #hud,
body[data-screen="win"] #hud,
body[data-screen="lose"] #hud { display: none; }
.hp-block, .score-block, .stage-block {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.stage-block { flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.stage-block strong { font-size: 15px; letter-spacing: 0.06em; }
.stage-block span, .score-block span, .label { color: var(--muted); font-size: 12px; }
.score-block { justify-content: flex-end; flex-wrap: wrap; }
.score-block strong, #hp-num { color: var(--ink); font-size: 16px; }
.bar {
  width: min(180px, 28vw);
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff8fb3, #ffd0e0); }
#boss-fill { background: linear-gradient(90deg, #e4c27a, #fff1cc); }
#dash-pip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: conic-gradient(var(--gold) calc(var(--p, 1) * 360deg), transparent 0);
  display: inline-block;
}
#combo { color: var(--gold); }
#jam {
  color: #9be7ff;
  border: 1px solid rgba(155, 231, 255, 0.5);
  border-radius: 999px;
  padding: 0 8px;
}

#boss-wrap {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  width: min(440px, 86vw);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(8, 17, 20, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  pointer-events: none;
}
#boss-wrap .bar { flex: 1; }
html.touch body[data-screen="playing"] #boss-wrap { bottom: calc(168px + var(--safe-b)); }

#banner {
  position: fixed;
  z-index: 6;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  width: min(640px, 92vw);
}
#banner strong {
  display: block;
  font-size: clamp(26px, 5vw, 42px);
  letter-spacing: 0.12em;
  color: var(--gold);
  text-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}
#banner span { color: var(--foam); font-size: 15px; }
#hint {
  position: fixed;
  z-index: 5;
  bottom: 18%;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  font-size: 14px;
}

#top-actions {
  position: fixed;
  z-index: 8;
  top: calc(8px + var(--safe-t));
  right: calc(8px + var(--safe-r));
  display: flex;
  gap: 6px;
}
#top-actions button {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 17, 20, 0.55);
}
#top-actions svg { width: 18px; height: 18px; fill: currentColor; }
body[data-screen="playing"] #btn-pause,
body[data-screen="paused"] #btn-pause { display: grid; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(4, 8, 10, 0.28);
}
.screen[hidden] { display: none; }
.card {
  width: min(680px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 22px 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.card.narrow { width: min(460px, 100%); text-align: center; }
.hero { width: 100%; height: auto; display: block; }
.seal {
  width: 36px;
  height: 36px;
  margin: 8px 0 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--rose);
  color: var(--rose);
  border-radius: 4px;
  letter-spacing: 0;
  font-size: 18px;
}
h1 {
  margin: 8px 0 0;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: 0.14em;
  font-weight: 700;
}
h2 { margin: 0 0 8px; letter-spacing: 0.16em; font-size: 28px; }
.sub { color: var(--gold); margin: 8px 0; }
.flavor, .controls, .fine, .best-line { color: var(--muted); line-height: 1.55; }
.roster { margin: 8px 0 12px; padding-left: 18px; line-height: 1.7; }
.roster b { color: var(--gold); font-weight: 650; }
.controls p { margin: 4px 0; }
.best-line strong, .end-score strong { color: var(--gold); font-size: 28px; }
.end-score { font-size: 16px; }
.fine { font-size: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
#end-new {
  color: #102016;
  background: var(--gold);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}

#touch-layer { display: none; }
html.touch #touch-layer {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}
html.touch body:not([data-screen="playing"]) #touch-layer { display: none; }
.stick {
  position: absolute;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 2px solid rgba(228, 194, 122, 0.55);
  background: radial-gradient(circle, rgba(231, 247, 251, 0.08), rgba(8, 17, 20, 0.35));
  pointer-events: auto;
  touch-action: none;
}
#stick-move { left: calc(16px + var(--safe-l)); bottom: calc(18px + var(--safe-b)); }
#stick-aim { right: calc(16px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); }
.stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, #fff, #d7f4ff 42%, #8ec9d8);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}
.stick span {
  position: absolute;
  left: 0; right: 0; top: -22px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}
.touch-btn {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  pointer-events: auto;
  font-weight: 700;
  background: rgba(14, 28, 34, 0.72);
}
#btn-dash { right: calc(146px + var(--safe-r)); bottom: calc(132px + var(--safe-b)); }
#btn-fire { right: calc(28px + var(--safe-r)); bottom: calc(148px + var(--safe-b)); background: rgba(228, 194, 122, 0.88); color: #2a2116; }

@media (max-width: 720px) {
  #hud { grid-template-columns: 1fr 1fr; }
  .stage-block { grid-column: 1 / -1; order: -1; }
  .card { padding: 16px 14px; }
  .roster { padding-left: 16px; }
  .stick { width: 104px; height: 104px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
