:root {
  color-scheme: light;
  --paper: #fffdfa;
  --paper-deep: #f4f0e5;
  --ink: #18202e;
  --muted: #6a7180;
  --line: #c7d7dd;
  --accent: #d84545;
  --accent-2: #2c7f74;
  --accent-3: #3868a8;
  --shadow: 0 22px 60px rgba(24, 32, 46, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    "Trebuchet MS",
    "Microsoft YaHei",
    Arial,
    sans-serif;
  background:
    linear-gradient(90deg, rgba(56, 104, 168, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(216, 69, 69, 0.08) 1px, transparent 1px),
    #eaf4f2;
  background-size: 34px 34px, 34px 34px, auto;
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  line-height: 1;
  min-height: 42px;
  padding: 0 16px;
  box-shadow: 4px 5px 0 rgba(24, 32, 46, 0.18);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
  touch-action: manipulation;
}

button:hover {
  background: #f9ffd9;
  transform: translate(-1px, -1px);
  box-shadow: 5px 6px 0 rgba(24, 32, 46, 0.18);
}

button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 3px 0 rgba(24, 32, 46, 0.18);
}

button:disabled {
  cursor: not-allowed;
  color: rgba(24, 32, 46, 0.48);
  background: #ece8dd;
  border-color: rgba(24, 32, 46, 0.36);
  box-shadow: 2px 3px 0 rgba(24, 32, 46, 0.1);
  transform: none;
}

.game-shell {
  width: min(1180px, calc(100vw - 28px));
  height: min(780px, calc(100vh - 28px));
  margin: 14px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(410px, 1fr);
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background:
    radial-gradient(circle at 14px 16px, rgba(56, 104, 168, 0.12) 0 2px, transparent 3px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(244, 240, 229, 0.92));
  box-shadow: var(--shadow);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 34px;
  flex: 0 0 auto;
  position: relative;
  transform: rotate(-8deg);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 54%, 100% 0, 74% 56%, 100% 100%);
  background: #ffffff;
  border: 2px solid var(--ink);
}

.brand-mark::after {
  inset: 10px 7px 8px 11px;
  clip-path: polygon(0 46%, 100% 0, 54% 100%);
  background: rgba(56, 104, 168, 0.18);
  border-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2.1vw, 1.75rem);
  letter-spacing: 0;
  white-space: nowrap;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(5, minmax(74px, 1fr));
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.stat {
  min-width: 0;
  padding: 7px 10px;
  border: 2px dashed rgba(24, 32, 46, 0.38);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.78);
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 1.1rem;
  letter-spacing: 0;
}

.stage-stat {
  min-width: 96px;
}

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

.admin-button {
  position: absolute;
  z-index: 5;
  top: 24px;
  left: 68px;
  width: 26px;
  min-height: 22px;
  padding: 0;
  border-width: 1px;
  background: rgba(255, 244, 243, 0.72);
  border-color: rgba(216, 69, 69, 0.5);
  color: rgba(24, 32, 46, 0.58);
  font-size: 0.68rem;
  box-shadow: 2px 2px 0 rgba(24, 32, 46, 0.08);
  opacity: 0.42;
}

.admin-button:hover,
.admin-button:focus-visible {
  opacity: 1;
  color: var(--ink);
  background: #fff4f3;
}

.arena {
  position: relative;
  min-height: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(56, 104, 168, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(44, 127, 116, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 48px 48px, 48px 48px, auto;
  box-shadow: var(--shadow);
}

.arena::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 48%, rgba(24, 32, 46, 0.06) 49%, transparent 51%),
    radial-gradient(circle at 18% 20%, rgba(216, 69, 69, 0.09), transparent 15%),
    radial-gradient(circle at 82% 74%, rgba(44, 127, 116, 0.1), transparent 18%);
  opacity: 0.85;
}

#gameCanvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.boss-meter {
  position: absolute;
  z-index: 3;
  top: 12px;
  left: 50%;
  width: min(440px, calc(100% - 32px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.92);
  box-shadow: 4px 6px 0 rgba(24, 32, 46, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.boss-meter.is-active {
  opacity: 1;
}

.boss-meter span {
  color: var(--accent);
  font-weight: 900;
  white-space: nowrap;
}

.boss-track {
  height: 14px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #ffffff;
}

.boss-track i {
  display: block;
  width: 100%;
  height: 100%;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.35) 0 6px, transparent 6px 12px),
    var(--accent);
  transform-origin: left center;
  transition: transform 120ms ease;
}

.overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: rgba(255, 253, 250, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.overlay.is-visible {
  opacity: 1;
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 0.84rem;
  font-weight: 900;
  text-transform: uppercase;
}

.overlay h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(2rem, 7vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 4px 5px 0 rgba(216, 69, 69, 0.16);
}

.overlay p:last-child {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 800;
}

.level-select {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(255, 253, 250, 0.86);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.level-select.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.level-select-panel {
  width: min(680px, 100%);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 18px;
  background: var(--paper);
  box-shadow: 8px 10px 0 rgba(24, 32, 46, 0.16);
  text-align: center;
}

.level-select-panel h2 {
  margin: 0 0 14px;
  font-size: clamp(1.7rem, 4vw, 3rem);
  letter-spacing: 0;
}

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

.level-choice {
  min-height: 112px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 10px;
  white-space: normal;
}

.level-choice span {
  font-size: 1.1rem;
}

.level-choice small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.25;
}

.level-choice.is-final {
  background: #fff4f3;
  border-color: var(--accent);
}

.level-close {
  margin-top: 14px;
  min-width: 120px;
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .game-shell {
    height: calc(100svh - 16px);
    min-height: 0;
    width: min(100vw - 12px, 680px);
    margin: 8px auto;
    gap: 8px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .scoreboard,
  .controls {
    justify-content: stretch;
  }

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

  .stat {
    padding: 5px 4px;
  }

  .stat-label {
    font-size: 0.64rem;
  }

  .stat strong {
    font-size: 0.88rem;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
  }

  .controls button {
    width: 100%;
    min-height: 38px;
    padding: 0 8px;
  }

  .admin-button {
    top: 18px;
    left: 54px;
  }

  .arena {
    height: auto;
    min-height: 0;
  }

  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
  }

  .level-choice {
    min-height: 92px;
    padding: 8px 4px;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 1.05rem;
  }

  .brand-mark {
    width: 34px;
    height: 27px;
  }

  .topbar {
    padding: 8px;
    gap: 8px;
  }

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

  .stage-stat {
    grid-column: span 2;
  }

  .overlay {
    padding: 16px;
  }

  .overlay p:last-child {
    font-size: 0.92rem;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .level-select {
    padding: 12px;
  }

  .level-select-panel {
    padding: 14px;
  }

  .level-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .level-choice {
    min-height: 72px;
  }
}
