*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* Slightly larger base type so UI stays readable without browser zoom */
  font-size: clamp(16px, 0.35vw + 15px, 20px);
}

body {
  margin: 0;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #1a1f2e 0%, #0d1117 45%, #151b24 100%);
  color: #e6edf3;
}

.stage {
  min-height: 100dvh;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: max(0.25rem, env(safe-area-inset-top)) max(0.25rem, env(safe-area-inset-right))
    max(0.25rem, env(safe-area-inset-bottom)) max(0.25rem, env(safe-area-inset-left));
  box-sizing: border-box;
  overflow-x: hidden;
}

.stage.stage--fs {
  min-height: 100%;
  height: 100%;
  width: 100%;
  padding: 0.5rem;
  justify-content: flex-start;
  background: linear-gradient(180deg, #1a1f2e 0%, #0d1117 45%, #151b24 100%);
}

.stage.stage--fs .hud {
  width: 100%;
  max-width: none;
  margin-bottom: 0.5rem;
}

.stage.stage--fs .game-wrap {
  flex: 1;
  width: 100%;
  max-width: none;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage.stage--fs #game {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
}

.hud:not(.hidden) {
  width: min(calc(100vw - 0.75rem), calc((100dvh - 10.5rem) * 16 / 9));
  max-width: 100%;
}

.hud {
  margin-bottom: 0.75rem;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid rgba(88, 166, 255, 0.25);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  align-items: center;
}

.hud-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.hud-row.subtle {
  flex: 1 1 100%;
  font-size: 0.8rem;
  color: #8b949e;
  margin-top: -0.25rem;
}

.label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b949e;
}

#score {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #58a6ff;
}

#combo {
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #d2a8ff;
}

/* Fills remaining column height; width capped for 16∶9. */
.game-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: min(calc(100vw - 0.75rem), calc((100dvh - 3.5rem) * 16 / 9));
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud:not(.hidden) ~ .game-wrap {
  width: min(calc(100vw - 0.75rem), calc((100dvh - 10.5rem) * 16 / 9));
}

.hidden {
  display: none !important;
}

#game {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  height: auto;
  border-radius: 8px;
  border: 2px solid #30363d;
  background: #0d1117;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  cursor: crosshair;
  vertical-align: top;
}

.overlay {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  box-sizing: border-box;
}

.overlay--select {
  z-index: 2;
  background: rgba(13, 17, 23, 0.82);
  backdrop-filter: blur(6px);
}

.choose-title {
  margin: 0 0 1.25rem;
  font-size: clamp(1.35rem, 3.5vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #e6edf3;
  text-align: center;
}

.char-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  max-width: 100%;
}

.char-option {
  padding: 0;
  border: 3px solid #30363d;
  border-radius: 10px;
  background: #161b22;
  cursor: pointer;
  overflow: hidden;
  width: clamp(6.5rem, 22vw, 10rem);
  height: clamp(6.5rem, 22vw, 10rem);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.char-option:hover,
.char-option:focus-visible {
  border-color: #58a6ff;
  transform: scale(1.04);
  outline: none;
}

.char-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.overlay--panel {
  z-index: 3;
  background: transparent;
  pointer-events: none;
}

.overlay--panel .panel-card {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 1.25rem 1.75rem;
  border-radius: 12px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid rgba(126, 231, 135, 0.35);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.overlay--panel .panel-card .btn {
  align-self: center;
}

#gameover-overlay .panel-card {
  border-color: rgba(255, 123, 114, 0.35);
}

#victory-overlay .panel-card {
  max-width: min(30rem, calc(100% - 2rem));
}

#boss-fail-overlay .panel-card--boss-fail {
  max-width: min(28rem, calc(100% - 2rem));
  border-color: rgba(210, 153, 34, 0.45);
}

.boss-fail-title {
  margin: 0 0 1rem;
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  font-weight: 700;
  line-height: 1.45;
  color: #e6edf3;
  text-align: center;
}

.victory-title {
  margin: 0 0 1rem;
  font-size: clamp(1.15rem, 3.6vw, 1.65rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: #7ee787;
  text-align: center;
}

.gameover-title {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: #ff7b72;
  text-align: center;
}

.overlay--boss-warn {
  z-index: 4;
  background: rgba(13, 17, 23, 0.52);
  backdrop-filter: blur(5px);
  pointer-events: none;
}

.overlay--boss-warn .boss-warn-card {
  padding: 1.2rem 1.65rem;
  border-radius: 12px;
  background: rgba(22, 27, 34, 0.94);
  border: 2px solid rgba(255, 166, 87, 0.7);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.45),
    0 0 28px rgba(255, 166, 87, 0.18);
  max-width: min(38rem, calc(100% - 2rem));
}

.boss-warn-title {
  margin: 0;
  font-size: clamp(1.05rem, 3.3vw, 1.5rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.35;
  color: #ffa657;
  text-align: center;
}

.btn {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.65rem 1.5rem;
  border-radius: 8px;
  border: 1px solid #58a6ff;
  background: #1f6feb;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:focus-visible {
  outline: 2px solid #58a6ff;
  outline-offset: 2px;
}

#player-hp {
  font-size: 1.15rem;
  font-weight: 600;
  color: #ff7b72;
}
