:root {
  --bg: #07081a;
  --panel: rgba(18, 20, 44, 0.92);
  --panel-border: rgba(150, 160, 255, 0.25);
  --text: #eef0ff;
  --muted: #a6abd6;
  --accent: #ff4d6d;
  --accent-2: #ffd166;
  --chip: rgba(10, 12, 32, 0.66);
  --blood: linear-gradient(90deg, #8f0f24, #ff3b5c);
  --dawn: linear-gradient(90deg, #2b3a8f, #f7a35c);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  container-type: size;
  overflow: hidden;
  background: #111;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
}
@supports (height: 100dvh) {
  #stage { width: min(100vw, calc(100dvh * 16 / 9)); }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: max(11px, 1.35cqw);
}
.hud-top {
  position: absolute;
  top: 1.2cqh; left: 1.2cqw; right: 1.2cqw;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1cqw;
}
.hud-group { display: flex; align-items: center; gap: 0.7cqw; }
.hud-bottom {
  position: absolute;
  bottom: 1.4cqh; left: 1.2cqw;
  display: flex;
  gap: 0.7cqw;
}
.chip {
  background: var(--chip);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.35em 0.85em;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.bar {
  position: relative;
  height: 1.9em;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--panel-border);
  overflow: hidden;
}
.bar.dawn { width: 14cqw; }
.bar.blood { width: 26cqw; height: 2.2em; }
.bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.15s linear; }
.bar.dawn .fill { background: var(--dawn); opacity: 0.8; }
.bar.blood .fill { background: var(--blood); }
.bar-label {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
}
.icon-btn {
  pointer-events: auto;
  font: inherit;
  background: var(--chip);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  width: 2.3em; height: 2.3em;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(60, 64, 120, 0.8); }

/* ---------- touch controls ---------- */
#touch {
  position: absolute;
  right: 2cqw; bottom: 3cqh;
  display: flex;
  gap: 2cqw;
  align-items: flex-end;
}
.touch-btn {
  width: 13cqh; height: 13cqh;
  min-width: 64px; min-height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 22, 50, 0.6);
  color: #fff;
  font-size: max(20px, 4cqh);
  display: grid;
  place-items: center;
  align-content: center;
  touch-action: none;
}
.touch-btn span { font-size: 0.45em; font-weight: 700; }
.touch-btn.bite { width: 18cqh; height: 18cqh; background: rgba(140, 16, 40, 0.55); }
.touch-btn.on, .touch-btn:active { background: rgba(255, 209, 102, 0.45); }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 5, 16, 0.55);
  backdrop-filter: blur(3px);
  overflow: auto;
  padding: 2cqh 2cqw;
}
.panel {
  width: min(92%, 760px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: clamp(14px, 3cqh, 32px) clamp(16px, 3cqw, 40px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  font-size: max(12px, 1.4cqw);
  text-align: center;
}
.panel.small { width: min(92%, 460px); }
.panel h1 { margin: 0 0 0.2em; font-size: 2.6em; letter-spacing: 0.02em; }
.panel h2 { margin: 0 0 0.6em; font-size: 1.8em; }
.sub { color: var(--muted); margin: 0 0 1em; line-height: 1.5; }
.rules {
  text-align: left;
  margin: 0 0 1em;
  padding: 0;
  list-style: none;
  line-height: 1.55;
}
.rules li { margin: 0.35em 0; }
.rules b { color: var(--accent-2); }
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4em 1em;
  text-align: left;
  font-size: 0.88em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 0.8em 1em;
  margin-bottom: 1.2em;
}
.controls b { color: var(--text); }
.stats { list-style: none; padding: 0; margin: 0 0 1.2em; line-height: 1.9; }
.stats b { color: var(--accent-2); }
button.primary, button.secondary {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 999px;
  padding: 0.7em 2.2em;
  cursor: pointer;
  margin: 0.25em;
}
button.primary { background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(255, 77, 109, 0.4); }
button.primary:hover { filter: brightness(1.1); }
button.secondary { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.best { color: var(--muted); margin: 0.8em 0 0; font-size: 0.9em; }
.panel a { color: var(--muted); }

/* title: choose a mode */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1em;
  margin: 0.4em 0 0.4em;
}
.mode-card {
  font: inherit;
  color: var(--text);
  text-decoration: none;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  padding: 1em;
  cursor: pointer;
  display: grid;
  gap: 0.3em;
  justify-items: center;
  text-align: center;
}
.panel a.mode-card { color: var(--text); }
.mode-card:hover, .mode-card:focus-visible { border-color: var(--accent-2); outline: none; }
.mode-card .emoji { font-size: 2.4em; }
.mode-card b { font-size: 1.25em; }
.mode-card small { color: var(--muted); line-height: 1.4; }
.howto { text-align: left; margin-top: 0.8em; }
.howto summary { cursor: pointer; color: var(--muted); }
.howto .rules { margin-top: 0.6em; }

#rotate-hint {
  display: none;
  position: absolute;
  left: 50%; bottom: 4px;
  transform: translateX(-50%);
  font-size: 12px;
  background: var(--chip);
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
}
@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint { display: block; }
  .controls { grid-template-columns: 1fr; }
  .modes { grid-template-columns: 1fr; }
}
