* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #111319;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overscroll-behavior: none;
  touch-action: none;
}

button {
  font: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

#app {
  display: grid;
  width: 100vw;
  height: 100dvh;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.03)),
    #111319;
}

#gameShell {
  position: relative;
  width: min(100vw, 56.25dvh);
  height: min(100dvh, 177.7778vw);
  overflow: hidden;
  background: #20242c;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 26px 80px rgba(0, 0, 0, 0.45);
}

#gameCanvas,
#particleCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#particleCanvas {
  pointer-events: none;
  mix-blend-mode: screen;
}

#hud {
  position: absolute;
  inset: env(safe-area-inset-top) 0 0 0;
  padding: 14px 14px 14px;
  pointer-events: none;
  transition: opacity 160ms ease;
}

html[data-game-mode="loading"] #hud,
html[data-game-mode="ready"] #hud {
  opacity: 0;
}

.topRow,
.meterRow,
.scoreRow {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topRow {
  position: relative;
  justify-content: center;
}

.iconButton {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(17, 19, 25, 0.42);
  color: #fff;
  font-weight: 800;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

.centerMenuButton {
  position: absolute;
  right: 0;
  top: 0;
}

.stageReadout {
  display: grid;
  min-width: 0;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.stageReadout strong {
  font-size: 20px;
  line-height: 1.1;
}

.stageReadout span {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}

.meterRow {
  margin-top: 12px;
}

.healthTrack {
  flex: 1;
  height: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
}

#healthFill {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff4e67, #ffd15c, #6ee57e);
  transform-origin: left center;
}

#healthText,
#scoreText,
#leftText {
  min-width: 44px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

.scoreRow {
  justify-content: space-between;
  margin-top: 7px;
  font-size: 13px;
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

.buffRow {
  display: inline-grid;
  margin-top: 8px;
  min-height: 26px;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid rgba(255, 226, 120, 0.72);
  border-radius: 8px;
  background: rgba(42, 31, 9, 0.54);
  color: #ffe278;
  font-size: 12px;
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.62);
}

.bossHud {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  padding: 7px 9px 8px;
  border: 1px solid rgba(255, 220, 92, 0.82);
  border-radius: 8px;
  background: rgba(58, 7, 13, 0.78);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.bossHudTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff3b0;
  font-size: 11px;
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.72);
}

.bossHudTop strong {
  color: #fff;
  font-size: 12px;
}

.bossHpTrack {
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  background: rgba(10, 10, 14, 0.66);
}

#bossHpFill {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff315d, #ff844e, #ffe05c);
  transform-origin: left center;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(9, 11, 16, 0.04), rgba(9, 11, 16, 0.24));
}

.overlay.active {
  display: flex;
}

.overlayPanel {
  width: min(100%, 360px);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  backdrop-filter: none;
}

.overlayPanel h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.62), 0 1px 2px rgba(0, 0, 0, 0.65);
}

#overlayText {
  margin: 12px 0 18px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 15px;
  line-height: 1.5;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.72), 0 1px 2px rgba(0, 0, 0, 0.68);
}

.menuPanel,
.settingsPanel,
.helpPanel,
.leaderboardPanel {
  display: grid;
  gap: 10px;
}

.menuButton {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: rgba(18, 22, 30, 0.5);
  color: #fff;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 8px 22px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px);
}

.menuButton.primary {
  position: relative;
  overflow: hidden;
  background: #ff4e67;
  box-shadow: 0 10px 28px rgba(255, 78, 103, 0.35);
}

.menuButton.primary.counting::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.64);
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left center;
  animation: stageClearFill 5s linear forwards;
}

@keyframes stageClearFill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.privacyLink {
  justify-self: center;
  color: rgba(255, 255, 255, 0.74);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.58);
}

.privacyLink:focus-visible {
  outline: 2px solid #ffd15c;
  outline-offset: 4px;
}

.rangeControl,
.toggleControl {
  display: grid;
  grid-template-columns: 72px 1fr 38px;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 11px;
  border-radius: 8px;
  background: rgba(18, 22, 30, 0.48);
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

.rangeControl input {
  width: 100%;
  accent-color: #ffca4e;
}

.rangeControl strong {
  text-align: right;
}

.toggleControl {
  grid-template-columns: 1fr auto;
}

.toggleControl input {
  width: 22px;
  height: 22px;
  accent-color: #ff4e67;
}

.helpPanel ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 0 18px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}

.leaderboardPanel {
  max-height: min(66dvh, 560px);
}

.leaderboardList {
  display: grid;
  gap: 6px;
  max-height: min(42dvh, 360px);
  margin: 0;
  overflow: auto;
  padding: 0;
  list-style: none;
}

.resultSummary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  min-height: 58px;
  padding: 11px 12px;
  border-radius: 8px;
  background: rgba(18, 22, 30, 0.5);
  color: #fff;
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.resultSummary strong {
  font-size: 16px;
  font-weight: 900;
}

.resultSummary span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 800;
}

.resultSummary span:first-of-type {
  justify-self: end;
  color: #ffd15c;
  font-size: 15px;
}

.leaderboardList li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(18, 22, 30, 0.48);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.leaderboardRank {
  color: #ffd15c;
}

.leaderboardMeta {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 11px;
  font-weight: 700;
}

.nameEntryPanel {
  display: grid;
  gap: 10px;
}

.nameEntryScore {
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(18, 22, 30, 0.5);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  color: #ffd15c;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.4;
  text-align: center;
}

.nameInputControl {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(18, 22, 30, 0.48);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.88);
  cursor: text;
  font-size: 13px;
  font-weight: 800;
}

.nameInputControl input[type="text"] {
  background: transparent;
  border: none;
  border-bottom: 2px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  font: 900 15px system-ui, -apple-system, sans-serif;
  outline: none;
  padding: 3px 6px;
  text-align: right;
  transition: border-color 120ms;
  width: 100%;
}

.nameInputControl input[type="text"]::placeholder {
  color: rgba(255, 255, 255, 0.36);
  font-weight: 700;
}

.nameInputControl input[type="text"]:focus {
  border-bottom-color: #ff4e67;
}

/* Stage clear overlay: hide title, enlarge result text, hide privacy link */
html[data-game-mode="stageClear"] .overlayPanel h1 {
  display: none;
}

html[data-game-mode="stageClear"] #overlayText {
  margin: 0 0 24px;
  color: #fff;
  font-size: 32px;
  font-weight: 900;
  line-height: 1.15;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.72), 0 1px 3px rgba(0, 0, 0, 0.75);
}

html[data-game-mode="stageClear"] .privacyLink {
  display: none;
}

.helpSectionHeader {
  list-style: none;
  margin: 2px 0 0 -18px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(255, 78, 103, 0.15);
  color: #ff8090;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
