:root {
  color-scheme: dark;
  --ink: #f8f4e8;
  --muted: #b7c2c9;
  --glass: rgba(9, 13, 19, 0.72);
  --stroke: rgba(255, 255, 255, 0.16);
  --hot: #ff5f68;
  --gold: #f7c948;
  --aqua: #49d6d1;
  --leaf: #84d65a;
  --violet: #a98cff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0b0e12;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 0 18px;
  background: #f4c84a;
  color: #14110a;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(247, 201, 72, 0.18);
}

input {
  accent-color: var(--gold);
  font: inherit;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

input[type="color"] {
  width: 56px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  filter: brightness(1.08);
  outline: none;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.topbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(170px, 1fr) 86px 86px 96px 92px;
  gap: 10px;
  align-items: stretch;
}

.meter,
.stat {
  min-width: 0;
  height: 48px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(10px);
}

.meter {
  display: grid;
  grid-template-columns: auto minmax(48px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 0 12px;
}

.meter span,
.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.meter b,
.stat b {
  font-size: 14px;
  white-space: nowrap;
}

.bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hot), #ff9f58);
  transition: width 120ms linear;
}

.xp .bar i {
  background: linear-gradient(90deg, var(--aqua), var(--leaf));
}

.stat {
  display: grid;
  place-items: center;
  padding: 5px 8px;
  text-align: center;
}

.stat span,
.stat b {
  display: block;
}

.admin-open {
  width: 92px;
  height: 48px;
  min-height: 48px;
  padding: 0 12px;
  pointer-events: auto;
}

.effect-tray {
  position: absolute;
  top: 74px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.effect-chip {
  min-width: 92px;
  height: 34px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 7px;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--effect-color), white 24%);
  border-radius: 8px;
  padding: 0 9px 0 5px;
  background: rgba(9, 13, 19, 0.74);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--effect-color), transparent 72%);
  backdrop-filter: blur(10px);
}

.effect-chip i {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--effect-color), transparent 28%);
  color: #0b0e12;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.effect-chip span {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.effect-chip b {
  color: var(--effect-color);
  font-size: 12px;
  font-weight: 900;
}

.boss-hud {
  position: absolute;
  top: 74px;
  left: 50%;
  z-index: 21;
  width: min(560px, calc(100vw - 36px));
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(9, 13, 19, 0.82);
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.26);
  pointer-events: none;
}

.boss-hud-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.boss-hud-head b {
  color: var(--gold);
}

.boss-hp-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.boss-hp-bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hot), var(--gold));
  transition: width 120ms linear;
}

.toast-tray {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  border: 1px solid color-mix(in srgb, var(--accent, var(--gold)), transparent 45%);
  border-radius: 8px;
  padding: 12px;
  background: rgba(9, 13, 19, 0.92);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  animation: toast-in 220ms ease-out;
}

.toast span {
  display: block;
  color: var(--accent, var(--gold));
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.toast b {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 15px;
}

.toast p {
  max-width: none;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: auto;
}

.overlay.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

#adminOverlay {
  z-index: 40;
}

#metaOverlay {
  z-index: 45;
}

#infoOverlay {
  z-index: 50;
}

.panel {
  width: min(540px, 100%);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 28px;
  background: rgba(12, 16, 23, 0.86);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(14px);
  text-align: center;
}

.panel.wide {
  width: min(980px, 100%);
}

.character-panel {
  width: min(1040px, 100%);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(40px, 7vw, 76px);
  line-height: 0.95;
}

h2 {
  font-size: clamp(28px, 5vw, 48px);
}

p {
  margin: 16px auto 22px;
  max-width: 42rem;
  color: var(--muted);
  line-height: 1.55;
}

.cards {
  display: grid;
  grid-template-columns: repeat(var(--card-count, 4), minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.card-wrap {
  position: relative;
  min-height: 190px;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 190px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 18px 18px 52px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--rarity-color, transparent), transparent 64%);
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, color-mix(in srgb, var(--rarity-color, transparent), transparent 82%), transparent 56%);
  pointer-events: none;
}

.card kbd {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--gold);
  font: inherit;
  font-weight: 900;
}

.info-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  padding: 0;
  border-color: rgba(73, 214, 209, 0.64);
  background: rgba(73, 214, 209, 0.22);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  box-shadow: none;
}

.card:hover,
.card:focus-visible {
  border-color: rgba(247, 201, 72, 0.74);
  background: rgba(247, 201, 72, 0.12);
  outline: none;
}

.card h3 {
  margin: 0;
  font-size: 18px;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.card strong {
  padding-right: 42px;
  color: var(--gold);
  font-size: 13px;
}

.card .rarity-label {
  color: var(--rarity-color, var(--gold));
}

.upgrade-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.upgrade-actions button {
  min-height: 42px;
}

.upgrade-actions button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.5);
  opacity: 0.48;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.character-card {
  min-height: 260px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.character-card i {
  width: 44px;
  height: 44px;
  display: block;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 28px color-mix(in srgb, var(--accent), transparent 55%);
}

.character-card h3 {
  margin: 0;
  font-size: 20px;
}

.character-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.character-card ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

.character-card.locked {
  cursor: not-allowed;
  filter: grayscale(0.45);
  opacity: 0.68;
}

.character-card.locked strong {
  color: var(--gold);
  font-size: 13px;
}

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

.panel-head h2 {
  font-size: 34px;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  box-shadow: none;
}

.admin-panel {
  width: min(860px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  text-align: left;
}

.meta-panel {
  width: min(820px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  text-align: left;
}

.info-panel {
  width: min(720px, 100%);
  text-align: left;
}

.achievements-panel {
  width: min(860px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  text-align: left;
}

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.achievement-card {
  min-height: 142px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.achievement-card.done {
  border-color: rgba(132, 214, 90, 0.55);
  background: rgba(132, 214, 90, 0.09);
}

.achievement-card span {
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.achievement-card h3,
.achievement-card p {
  margin: 8px 0 0;
}

.achievement-card p {
  color: var(--muted);
  font-size: 14px;
}

.achievement-card strong {
  display: block;
  margin-top: 10px;
  color: var(--ink);
  font-size: 13px;
}

.info-tag {
  width: max-content;
  max-width: 100%;
  margin: 0 0 14px;
  border: 1px solid rgba(247, 201, 72, 0.42);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
}

.info-body {
  display: grid;
  gap: 10px;
  color: var(--muted);
  line-height: 1.55;
}

.info-body p {
  max-width: none;
  margin: 0;
}

.info-body ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 19px;
}

.meta-currency {
  max-width: none;
  margin: 0 0 16px;
  color: var(--gold);
  font-weight: 900;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meta-upgrade {
  min-height: 150px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.meta-upgrade h3,
.meta-upgrade p {
  margin: 0;
}

.meta-upgrade p {
  color: var(--muted);
  font-size: 14px;
}

.meta-upgrade strong {
  color: var(--gold);
  font-size: 13px;
}

.admin-login,
.admin-controls {
  display: grid;
  gap: 14px;
}

.admin-login label,
.admin-controls label,
.admin-choice {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto;
  gap: 8px 14px;
  align-items: center;
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.admin-login input,
.admin-controls input[type="range"],
.admin-choice .choice-row,
.admin-choice .leaderboard {
  grid-column: 1 / -1;
}

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

.choice-row button {
  min-height: 38px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  box-shadow: none;
}

.choice-row button.active {
  border-color: rgba(247, 201, 72, 0.86);
  background: rgba(247, 201, 72, 0.2);
  color: var(--gold);
}

.admin-controls label span {
  color: var(--ink);
  font-size: 13px;
}

.admin-controls input[type="range"] {
  width: 100%;
}

.admin-status {
  min-height: 20px;
  margin: 0;
  color: var(--gold);
  font-size: 13px;
}

.check-row {
  grid-template-columns: auto 1fr;
  justify-content: start;
}

.check-row input {
  width: 20px;
  height: 20px;
}

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

.pause-panel,
.game-over-panel {
  width: min(760px, 100%);
}

.run-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
  text-align: left;
}

.run-card {
  min-height: 84px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.run-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.run-card b {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-size: 18px;
}

.run-card p {
  max-width: none;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.stats-grid div {
  min-height: 70px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.stats-grid .pause-card {
  grid-column: 1 / -1;
  min-height: 0;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.stats-grid b {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-size: 18px;
}

.pause-list {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.pause-list li::marker {
  color: var(--gold);
}

.score-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin: 18px 0;
  text-align: left;
}

.score-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.game-over-panel h3 {
  margin: 18px 0 8px;
  text-align: left;
}

.leaderboard {
  display: grid;
  gap: 6px;
  max-height: 190px;
  margin: 0 0 18px;
  padding: 0;
  list-style-position: inside;
  overflow: auto;
  text-align: left;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
}

.leaderboard strong {
  color: var(--ink);
}

.admin-leaderboard {
  max-height: 230px;
  margin: 0;
}

.admin-leaderboard li {
  grid-template-columns: 34px 1fr auto auto;
}

.admin-leaderboard button {
  min-height: 32px;
  padding: 0 10px;
  background: rgba(255, 95, 104, 0.16);
  color: var(--ink);
  box-shadow: none;
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 1fr 1fr;
  }

  .effect-tray {
    top: 244px;
  }

  .boss-hud {
    top: 180px;
  }

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

  .upgrade-actions,
  .meta-grid,
  .achievements-grid {
    grid-template-columns: 1fr;
  }

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

  .panel {
    padding: 22px;
  }

  .admin-open {
    width: auto;
  }

  .admin-actions {
    grid-template-columns: 1fr;
  }

  .choice-row {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .score-form,
  .run-details {
    grid-template-columns: 1fr;
  }
}
