* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg-1: #06131a;
  --bg-2: #0d2831;
  --panel: rgba(10, 25, 34, 0.72);
  --panel-strong: rgba(9, 20, 29, 0.9);
  --line: rgba(255, 255, 255, 0.1);
  --text: #eff7f5;
  --muted: #9fc0b7;
  --accent: #ff9f54;
  --accent-2: #6ae7c8;
  --accent-3: #8eb5ff;
  --danger: #ff7262;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 167, 94, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(106, 231, 200, 0.14), transparent 28%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 22px;
  font-family: "Trebuchet MS", "Microsoft YaHei", "PingFang SC", sans-serif;
  overflow-x: hidden;
}

.game-shell {
  width: min(1380px, 100%);
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  grid-template-areas:
    "hud hud"
    "stage side";
  position: relative;
}

.hud,
.info-card,
.stage-frame {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.hud {
  grid-area: hud;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(260px, 1fr) minmax(420px, 1.1fr);
  padding: 18px;
  border-radius: 28px;
}

.hud-intro,
.hud-panel {
  min-width: 0;
}

.eyebrow,
.card-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.brand-row strong {
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1;
  letter-spacing: -0.04em;
}

.player-chip,
.panel-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.life-block {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.life-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.life-icons {
  display: flex;
  gap: 8px;
  min-height: 24px;
}

.life-icon {
  display: inline-flex;
  font-size: 20px;
  color: rgba(255, 255, 255, 0.22);
}

.life-icon.is-full {
  color: var(--danger);
  text-shadow: 0 0 14px rgba(255, 114, 98, 0.35);
}

.life-icon.is-empty {
  opacity: 0.4;
}

.hud-tip {
  max-width: 580px;
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  justify-content: space-between;
}

.scoreboard {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.scoreboard span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  text-align: center;
  font: 700 15px/1.2 "Courier New", monospace;
}

#timer {
  background: rgba(142, 181, 255, 0.14);
  color: #dbe5ff;
}

#combo {
  background: rgba(255, 159, 84, 0.16);
  color: #ffe0c3;
}

#mode {
  background: rgba(106, 231, 200, 0.14);
  color: #d6fff4;
}

.audio-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  min-height: 44px;
  min-width: 100px;
  padding: 0 18px;
  cursor: pointer;
  color: #041118;
  background: linear-gradient(180deg, #87f2d5, #56d4b3);
  box-shadow: 0 10px 28px rgba(86, 212, 179, 0.24);
  font: 700 15px/1 "Trebuchet MS", "Microsoft YaHei", sans-serif;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

button:hover {
  filter: brightness(1.03);
  box-shadow: 0 14px 32px rgba(86, 212, 179, 0.28);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.volume-control input {
  width: 130px;
  accent-color: var(--accent);
}

.volume-control output {
  min-width: 42px;
  color: var(--text);
  font-family: "Courier New", monospace;
}

.stage-wrap {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.stage-frame {
  position: relative;
  overflow: hidden;
  border-radius: 32px;
  padding: 12px;
}

.stage-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 25%),
    radial-gradient(circle at bottom right, rgba(255, 159, 84, 0.12), transparent 24%);
  pointer-events: none;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 22px;
  background: #f7fbff;
  touch-action: manipulation;
}

.touch-controls {
  display: none;
  gap: 10px;
}

.touch-button {
  flex: 1;
  min-width: 0;
  min-height: 54px;
  font-size: 17px;
}

.touch-button-secondary {
  background: linear-gradient(180deg, #ffb16e, #ff9151);
  color: #1d0b00;
  box-shadow: 0 10px 28px rgba(255, 145, 81, 0.26);
}

.touch-button-ghost {
  background: linear-gradient(180deg, #eef5f3, #cfded8);
  color: #102028;
  box-shadow: 0 10px 28px rgba(8, 17, 24, 0.15);
}

.side-panels {
  grid-area: side;
  display: grid;
  gap: 18px;
  align-content: start;
}

.info-card {
  border-radius: 28px;
  padding: 22px;
}

.card-head h2,
.panel-head h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.05;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tutorial-list,
.leaderboard ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.7;
}

.tutorial-list {
  display: grid;
  gap: 10px;
}

.tutorial-keys {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  color: var(--muted);
}

kbd {
  min-width: 40px;
  padding: 6px 9px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  font: 700 13px/1 "Courier New", monospace;
  text-align: center;
}

.leaderboard ol {
  max-height: 360px;
  overflow-y: auto;
}

.leaderboard li {
  margin-bottom: 10px;
  word-break: break-word;
}

.panel-status[data-state="online"] {
  background: rgba(106, 231, 200, 0.14);
  color: #d3fff5;
}

.panel-status[data-state="offline"] {
  background: rgba(255, 114, 98, 0.16);
  color: #ffd7d2;
}

.overlay {
  position: absolute;
  inset: 0;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(4, 14, 22, 0.78), rgba(5, 16, 24, 0.9)),
    radial-gradient(circle at top, rgba(255, 159, 84, 0.18), transparent 26%);
  display: flex;
  overflow-y: auto;
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

.overlay-body {
  width: min(940px, 100%);
  margin: auto;
  padding: 32px;
  border-radius: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.overlay h1 {
  margin: 0;
  font-size: clamp(44px, 8vw, 84px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.overlay-copy {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.7;
  font-size: clamp(17px, 2.2vw, 22px);
}

.result-badge {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  background: rgba(255, 159, 84, 0.18);
  color: #ffe0c6;
  border: 1px solid rgba(255, 159, 84, 0.26);
  font-size: 14px;
  font-weight: 700;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.result-stats span {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.start-setup {
  width: min(100%, 620px);
  padding: 18px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.09);
  display: grid;
  gap: 12px;
}

.name-field {
  display: grid;
  gap: 8px;
  text-align: left;
}

.name-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.name-field input {
  width: 100%;
  min-height: 50px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.96);
  color: #102028;
  outline: none;
  padding: 0 14px;
  font: 600 16px/1.2 "Trebuchet MS", "Microsoft YaHei", sans-serif;
}

.name-field input:focus {
  border-color: rgba(106, 231, 200, 0.7);
  box-shadow: 0 0 0 4px rgba(106, 231, 200, 0.14);
}

.form-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

#startButton {
  min-width: 180px;
  min-height: 54px;
  font-size: 17px;
}

@media (max-width: 1080px) {
  .game-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "hud"
      "stage"
      "side";
  }

  .side-panels {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  body {
    padding: 6px;
  }

  .game-shell {
    gap: 12px;
    width: 100%;
  }

  .hud {
    grid-template-columns: 1fr;
    padding: 14px;
    border-radius: 22px;
  }

  .brand-row strong {
    font-size: 28px;
  }

  .scoreboard {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .scoreboard span {
    min-height: 38px;
    font-size: 13px;
    padding: 6px 8px;
  }

  .audio-controls {
    justify-content: flex-start;
  }

  .stage-frame,
  .info-card {
    border-radius: 22px;
  }

  .side-panels {
    grid-template-columns: 1fr;
  }

  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1fr 0.9fr 0.9fr;
  }

  .overlay {
    padding: 10px;
  }

  .overlay-body {
    padding: 22px 16px;
    border-radius: 24px;
  }
}

@media (max-width: 760px) {
  .game-shell.is-playing {
    gap: 0;
    width: 100vw;
  }

  .game-shell.is-playing .stage-wrap {
    position: relative;
  }

  .game-shell.is-playing .hud {
    display: none;
  }

  .game-shell.is-playing .side-panels {
    display: none;
  }

  .game-shell.is-playing .stage-frame {
    border-radius: 0;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .game-shell.is-playing canvas {
    border-radius: 0;
    width: 100vw;
  }

  .game-shell.is-playing .touch-controls {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 8;
  }
}

@media (max-width: 520px) {
  body {
    padding: 4px;
  }

  .hud {
    padding: 12px;
    gap: 12px;
  }

  .eyebrow,
  .card-kicker {
    font-size: 11px;
  }

  .brand-row strong {
    font-size: 24px;
  }

  .player-chip {
    font-size: 11px;
    padding: 0 10px;
  }

  .hud-tip {
    font-size: 12px;
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }

  .audio-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: stretch;
  }

  button {
    min-width: 0;
    width: 100%;
  }

  .volume-control {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  .volume-control input {
    width: 92px;
  }

  .touch-controls {
    grid-template-columns: 1fr 1fr 0.95fr 0.95fr;
  }

  .touch-button {
    min-height: 48px;
    font-size: 15px;
  }

  .result-stats {
    justify-content: stretch;
  }

  .result-stats span {
    width: 100%;
    justify-content: center;
  }

  .game-shell.is-playing {
    width: 100vw;
  }

  .game-shell.is-playing .touch-controls {
    left: 8px;
    right: 8px;
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  .game-shell.is-playing .touch-button {
    min-height: 44px;
    font-size: 14px;
    padding-left: 8px;
    padding-right: 8px;
  }
}
