/* Layout: full-bleed canvas battlefield, DOM HUD strip on top, glass panels floating over the live scene.
   Single committed look: moonlit night with torch-amber accents. */
:root {
  --night: #0d1330;
  --deep: #161d45;
  --panel: rgba(14, 19, 48, 0.86);
  --line: #34407a;
  --ink: #eef1ff;
  --muted: #9aa3cc;
  --amber: #ffb547;
  --amber-ink: #2a1a02;
  --ember: #ff6b4a;
  --frost: #7fe0ff;
  --heal: #ff7aa8;
  --good: #8be38b;
  --f-display: "Silkscreen", "JetBrains Mono", ui-monospace, monospace;
  --f-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: 15px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

#app {
  position: relative;
  height: 100%;
  overflow: hidden;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
#kb {
  position: absolute; left: 0; bottom: 0; width: 1px; height: 1px;
  opacity: 0; border: 0; padding: 0; font-size: 16px; pointer-events: none;
}

kbd {
  font-family: var(--f-mono); font-size: 0.78em; font-weight: 700;
  padding: 1px 6px; border-radius: 4px;
  border: 1px solid currentColor; opacity: 0.85;
}

/* ---------- HUD ---------- */
#hud {
  position: relative; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px 20px; padding-block: max(10px, env(safe-area-inset-top, 0px)) 8px;
  pointer-events: none;
}
.hud-group { display: flex; align-items: center; gap: 16px; min-width: 0; }
.hearts { font-size: 22px; letter-spacing: 2px; line-height: 1; white-space: nowrap; }
.hearts .on { color: var(--heal); text-shadow: 0 0 10px rgba(255, 122, 168, 0.6); }
.hearts .off { color: rgba(238, 241, 255, 0.18); }
.hearts.hit { animation: shakeX 0.35s; }
.stage-info { display: flex; flex-direction: column; gap: 5px; min-width: 120px; }
.stage-name { font-weight: 700; font-size: 14px; letter-spacing: 0.04em; white-space: nowrap; }
.prog { height: 6px; width: 160px; max-width: 30vw; background: rgba(255, 255, 255, 0.12); border-radius: 3px; overflow: hidden; }
.prog-fill { height: 100%; width: 0%; background: var(--amber); transition: width 0.25s; }
.stats { gap: 18px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat-k { font-family: var(--f-display); font-size: 10px; letter-spacing: 0.12em; color: var(--muted); }
.stat-v { font-family: var(--f-mono); font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
#combo.hot { color: var(--amber); text-shadow: 0 0 12px rgba(255, 181, 71, 0.7); }
#combo.bump { animation: bump 0.18s; }
.icon-btn {
  pointer-events: auto; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(14, 19, 48, 0.6); color: var(--ink);
  font-size: 14px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--amber); }
.icon-btn.muted { opacity: 0.4; }

#bossbar {
  position: absolute; z-index: 3; left: 50%; transform: translateX(-50%);
  top: calc(max(10px, env(safe-area-inset-top, 0px)) + 62px);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.boss-name { font-family: var(--f-display); font-size: 13px; letter-spacing: 0.2em; color: var(--ember); text-shadow: 0 0 10px rgba(255, 107, 74, 0.6); }
.boss-pips { display: flex; gap: 6px; }
.boss-pips i { width: 34px; height: 10px; border-radius: 2px; background: var(--ember); box-shadow: 0 0 8px rgba(255, 107, 74, 0.6); transition: background 0.3s, box-shadow 0.3s; }
.boss-pips i.gone { background: rgba(255, 255, 255, 0.12); box-shadow: none; }

/* ---------- Banner & toast ---------- */
#banner {
  position: absolute; z-index: 4; left: 0; right: 0; top: 30%;
  text-align: center; pointer-events: none;
  animation: bannerIn 2.2s ease forwards;
  padding-inline: 16px;
}
.b-eyebrow { font-family: var(--f-display); font-size: 14px; letter-spacing: 0.35em; color: var(--amber); }
.b-title { font-weight: 900; font-size: clamp(34px, 7vw, 64px); line-height: 1.15; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 30px rgba(255, 181, 71, 0.35); text-wrap: balance; }
.b-sub { font-family: var(--f-display); font-size: clamp(12px, 2vw, 16px); letter-spacing: 0.25em; color: var(--muted); margin-top: 4px; }
#banner.boss .b-eyebrow { color: var(--ember); }
#banner.boss .b-title { text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 30px rgba(255, 107, 74, 0.5); }

#toast {
  position: absolute; z-index: 6; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--amber); color: var(--amber-ink); font-weight: 700;
  padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  text-align: center;
}
#tapHint {
  position: absolute; z-index: 5; left: 50%; bottom: max(20px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: rgba(14, 19, 48, 0.85); color: var(--ink); border: 1px solid var(--amber);
  padding: 10px 18px; border-radius: 999px; font: 700 14px var(--f-ui); cursor: pointer;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(13, 19, 48, 0.25), rgba(13, 19, 48, 0.7));
}
#menu { background: linear-gradient(90deg, rgba(13, 19, 48, 0.1), rgba(13, 19, 48, 0.55) 50%, rgba(13, 19, 48, 0.1)); }
.panel {
  width: 100%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 26px 26px 22px;
  display: flex; flex-direction: column; gap: 16px;
  animation: rise 0.35s ease;
}
.menu-panel { max-width: 500px; }
.small-panel { max-width: 460px; text-align: center; }

.logo { display: flex; flex-direction: column; gap: 2px; }
.logo-en { font-family: var(--f-display); font-weight: 700; font-size: clamp(34px, 8vw, 48px); line-height: 1; letter-spacing: 0.02em; color: var(--ink); }
.logo-en span { color: var(--amber); margin-left: 0.3em; text-shadow: 0 0 18px rgba(255, 181, 71, 0.45); }
.logo-zh { font-weight: 900; font-size: 20px; letter-spacing: 0.5em; color: var(--muted); }
.tagline { margin: 6px 0 0; color: var(--muted); line-height: 1.6; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-k { font-size: 12px; font-weight: 700; letter-spacing: 0.15em; color: var(--muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-3 { grid-template-columns: repeat(3, 1fr); }
.seg button, .chips button {
  font-family: var(--f-ui); color: var(--ink); cursor: pointer;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; text-align: left; display: flex; flex-direction: column; gap: 2px;
  transition: border-color 0.15s, background 0.15s;
}
.seg button b { font-size: 15px; }
.seg button small { font-size: 12px; color: var(--muted); }
.seg button:hover, .chips button:hover:not(:disabled) { border-color: var(--muted); }
.seg button[aria-checked="true"], .chips button[aria-checked="true"] {
  border-color: var(--amber); background: rgba(255, 181, 71, 0.12);
}
.seg button[aria-checked="true"] b { color: var(--amber); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { flex-direction: row; align-items: center; gap: 6px; padding: 7px 11px; font-size: 13px; }
.chips button .n { font-family: var(--f-display); color: var(--amber); }
.chips button:disabled { opacity: 0.35; cursor: not-allowed; }

.toggles { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink); }
.toggle input { width: 18px; height: 18px; accent-color: var(--amber); }

.btn-primary, .btn-ghost {
  font-family: var(--f-ui); font-weight: 900; font-size: 17px; cursor: pointer;
  border-radius: 10px; padding: 13px 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-primary { background: var(--amber); color: var(--amber-ink); border: 0; box-shadow: 0 4px 0 #b97614; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #b97614; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 700; font-size: 15px; }
.btn-ghost:hover { border-color: var(--muted); }
button:focus-visible, .toggle input:focus-visible { outline: 2px solid var(--frost); outline-offset: 2px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btn-row .btn-primary { flex: 1 1 100%; }

.best-line { font-size: 13px; color: var(--muted); text-align: center; min-height: 1em; font-variant-numeric: tabular-nums; }
.best-line b { color: var(--ink); font-family: var(--f-mono); }

.howto { margin: 0; padding: 14px 0 0; list-style: none; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.c-heal { color: var(--heal); font-weight: 700; }
.c-frost { color: var(--frost); font-weight: 700; }
.c-bomb { color: var(--ember); font-weight: 700; }

.res-eyebrow { font-family: var(--f-display); letter-spacing: 0.35em; color: var(--amber); font-size: 13px; }
.res-title { margin: 0; font-weight: 900; font-size: clamp(28px, 6vw, 40px); text-wrap: balance; }
.stars { font-size: 36px; letter-spacing: 6px; min-height: 0; }
.stars:empty { display: none; }
.stars .on { color: var(--amber); text-shadow: 0 0 14px rgba(255, 181, 71, 0.6); }
.stars .off { color: rgba(255, 255, 255, 0.15); }
.stars span { display: inline-block; animation: pop 0.4s both; }
.stars span:nth-child(2) { animation-delay: 0.15s; }
.stars span:nth-child(3) { animation-delay: 0.3s; }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.badges:empty { display: none; }
.badges span { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--amber); color: var(--amber); }
.res-grid { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.res-grid div { background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 10px 6px; }
.res-grid dt { font-size: 12px; color: var(--muted); }
.res-grid dd { margin: 2px 0 0; font-family: var(--f-mono); font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; }
.weak { font-size: 14px; color: var(--muted); line-height: 1.6; }
.weak:empty { display: none; }
.weak kbd { color: var(--ember); margin: 0 2px; }

@keyframes bannerIn {
  0% { opacity: 0; transform: translateY(16px) scale(0.96); }
  15% { opacity: 1; transform: none; }
  80% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-10px); }
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes bump { 50% { transform: scale(1.25); } }
@keyframes shakeX { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

@media (max-width: 640px) {
  #hud { gap: 8px 12px; }
  .stats { gap: 12px; }
  .stat-v { font-size: 16px; }
  .hearts { font-size: 18px; }
  .prog { width: 110px; }
  .panel { padding: 20px 18px 18px; gap: 14px; }
  .seg-3 button small { display: none; }
  #bossbar { top: calc(max(10px, env(safe-area-inset-top, 0px)) + 96px); }
  .boss-pips i { width: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  #banner { animation: none; }
}
