:root {
  color-scheme: dark;
  --bg: #0e120f;
  --panel: #171c17;
  --panel-2: #20271f;
  --panel-3: #252d25;
  --ink: #f4efe4;
  --muted: #b8b09d;
  --faint: #827a6b;
  --line: #384033;
  --line-bright: #56614f;
  --gold: #e1b35b;
  --jade: #77c6a8;
  --red: #d7655c;
  --blue: #72aee8;
  --violet: #a784db;
  --shadow: rgba(0, 0, 0, 0.32);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body.phaser-entry {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.phaser-entry__bar {
  align-items: center;
  background:
    linear-gradient(90deg, rgba(10, 15, 12, 0.96), rgba(26, 34, 26, 0.92)),
    repeating-linear-gradient(135deg, rgba(225, 179, 91, 0.055) 0 1px, transparent 1px 22px);
  border-bottom: 1px solid rgba(86, 97, 79, 0.86);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  min-width: 0;
  padding: 10px 18px;
  position: relative;
  z-index: 2;
}

body.phaser-entry .phaser-entry__bar {
  display: none;
}

.phaser-entry__bar h1 {
  font-size: 26px;
  line-height: 1;
}

.phaser-entry__bar p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 7px;
}

.phaser-entry__actions {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
}

.phaser-entry__link {
  align-items: center;
  background:
    linear-gradient(180deg, rgba(44, 36, 20, 0.96), rgba(23, 24, 18, 0.96)),
    var(--panel-2);
  border: 1px solid rgba(225, 179, 91, 0.7);
  border-radius: 6px;
  color: var(--gold);
  display: inline-flex;
  font-size: 13px;
  font-weight: 760;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  text-decoration: none;
}

.phaser-entry__link:focus-visible {
  outline: 2px solid rgba(225, 179, 91, 0.72);
  outline-offset: 2px;
}

.phaser-entry__stage {
  background: #030605;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.phaser-entry__game {
  border: 0;
  display: block;
  height: 100%;
  width: 100%;
}

.phaser-entry__loader {
  align-items: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(119, 198, 168, 0.14), transparent 290px),
    rgba(3, 6, 5, 0.94);
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 1;
  pointer-events: auto;
  position: absolute;
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
  visibility: visible;
  z-index: 2;
}

.phaser-entry__loader.is-loaded {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.phaser-entry__loader-panel {
  align-items: center;
  background:
    linear-gradient(180deg, rgba(23, 28, 23, 0.96), rgba(9, 14, 11, 0.96)),
    var(--panel);
  border: 1px solid rgba(86, 97, 79, 0.86);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  justify-items: center;
  min-width: min(320px, calc(100vw - 40px));
  padding: 22px 24px;
  text-align: center;
}

.phaser-entry__loader-panel strong {
  color: var(--ink);
  font-size: 20px;
}

.phaser-entry__loader-panel span {
  color: var(--muted);
  font-size: 13px;
}

.phaser-entry__progress {
  background: rgba(3, 6, 5, 0.82);
  border: 1px solid rgba(86, 97, 79, 0.76);
  border-radius: 999px;
  height: 8px;
  margin-top: 6px;
  overflow: hidden;
  width: min(248px, calc(100vw - 96px));
}

.phaser-entry__progress-fill {
  background:
    linear-gradient(90deg, rgba(119, 198, 168, 0.92), rgba(225, 179, 91, 0.96)),
    var(--jade);
  box-shadow: 0 0 18px rgba(119, 198, 168, 0.34);
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 160ms ease-out;
  width: 100%;
}

.phaser-entry__progress-text {
  color: var(--gold) !important;
  font-size: 12px !important;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.phaser-entry__fallback {
  border: 1px solid rgba(225, 179, 91, 0.68);
  border-radius: 6px;
  color: var(--gold);
  display: none;
  font-size: 13px;
  font-weight: 760;
  margin-top: 6px;
  min-height: 34px;
  padding: 8px 12px;
  text-decoration: none;
}

.phaser-entry__fallback.is-visible {
  display: inline-flex;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(14, 18, 15, 0.72), rgba(14, 18, 15, 1)),
    radial-gradient(circle at 26% 0%, rgba(119, 198, 168, 0.16), transparent 34%),
    radial-gradient(circle at 80% 18%, rgba(225, 179, 91, 0.09), transparent 32%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 80px),
    #0e120f;
  color: var(--ink);
  overflow: hidden;
  overflow-x: hidden;
}

body::before {
  background:
    linear-gradient(90deg, rgba(225, 179, 91, 0.08), transparent 18%, transparent 82%, rgba(119, 198, 168, 0.08)),
    repeating-linear-gradient(0deg, rgba(244, 239, 228, 0.018) 0 1px, transparent 1px 42px);
  content: "";
  inset: 0;
  pointer-events: none;
  position: fixed;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  min-height: 42px;
  padding: 0 14px;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(225, 179, 91, 0.62);
}

button:focus-visible {
  outline: 2px solid rgba(225, 179, 91, 0.72);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.shell {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 310px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding: 18px;
}

.game-area,
.side-panel {
  background:
    linear-gradient(180deg, rgba(33, 39, 31, 0.94), rgba(20, 25, 20, 0.96)),
    var(--panel);
  border: 1px solid rgba(86, 97, 79, 0.8);
  border-radius: 8px;
  box-shadow:
    0 18px 44px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.game-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.topbar {
  align-items: center;
  background:
    linear-gradient(90deg, rgba(47, 57, 44, 0.72), rgba(23, 28, 23, 0.42)),
    repeating-linear-gradient(135deg, rgba(225, 179, 91, 0.045) 0 1px, transparent 1px 18px);
  border-bottom: 1px solid rgba(86, 97, 79, 0.8);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 14px 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--ink);
  font-size: 30px;
  font-weight: 760;
  letter-spacing: 0;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

h2 {
  color: #ded4bd;
  font-size: 15px;
  font-weight: 720;
  letter-spacing: 0;
}

.topbar p,
.selection p,
.wave-preview p,
.codex li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.stats span {
  background:
    linear-gradient(180deg, rgba(44, 52, 42, 0.92), rgba(28, 34, 28, 0.92)),
    var(--panel-2);
  border: 1px solid rgba(86, 97, 79, 0.78);
  border-radius: 6px;
  min-width: 84px;
  padding: 7px 10px;
  text-align: center;
}

.stats strong {
  color: var(--gold);
}

.canvas-wrap {
  min-height: 0;
  padding: 16px;
  position: relative;
}

.combat-hud {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 300px);
  left: 28px;
  pointer-events: none;
  position: absolute;
  right: 28px;
  top: 28px;
  z-index: 2;
}

.combat-hud > div {
  background:
    linear-gradient(180deg, rgba(20, 25, 20, 0.82), rgba(10, 14, 11, 0.72)),
    rgba(14, 18, 15, 0.72);
  border: 1px solid rgba(86, 97, 79, 0.72);
  border-radius: 6px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  padding: 8px 10px;
}

.pressure-text,
.boss-meter span {
  color: #efe6d0;
  display: block;
  font-size: 12px;
  font-weight: 720;
  line-height: 1;
  margin-bottom: 7px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.46);
}

.wave-meter,
.boss-bar {
  background: rgba(6, 9, 7, 0.78);
  border: 1px solid rgba(244, 239, 228, 0.08);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.wave-meter span,
.boss-bar span {
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 0;
}

.wave-meter span {
  background: linear-gradient(90deg, var(--jade), var(--gold));
}

.boss-meter {
  border-color: rgba(215, 101, 92, 0.7) !important;
}

.boss-bar span {
  background: linear-gradient(90deg, #d7655c, #e1b35b);
}

.combat-notice {
  background:
    linear-gradient(90deg, transparent, rgba(75, 26, 22, 0.92), transparent),
    rgba(8, 10, 8, 0.58);
  color: #f8e2bb;
  font-size: 22px;
  font-weight: 800;
  left: 50%;
  letter-spacing: 0;
  padding: 10px 80px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.52);
  top: 78px;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 3;
}

canvas {
  aspect-ratio: 3 / 2;
  background: #151a14;
  border: 1px solid rgba(86, 97, 79, 0.9);
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.025),
    0 12px 32px rgba(0, 0, 0, 0.24);
  display: block;
  height: auto;
  max-height: calc(100vh - 126px);
  width: 100%;
  touch-action: manipulation;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.side-panel section {
  min-width: 0;
}

.tower-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.tower-card {
  background:
    linear-gradient(180deg, rgba(39, 48, 38, 0.96), rgba(28, 35, 28, 0.96)),
    var(--panel-2);
  border: 1px solid rgba(72, 84, 68, 0.86);
  border-radius: 8px;
  cursor: pointer;
  padding: 11px;
  position: relative;
  text-align: left;
  width: 100%;
}

.tower-card::before {
  background: linear-gradient(180deg, rgba(225, 179, 91, 0.65), rgba(119, 198, 168, 0.2));
  border-radius: 2px;
  content: "";
  inset: 11px auto 11px 8px;
  opacity: 0.42;
  position: absolute;
  width: 3px;
}

.tower-card.active {
  border-color: var(--gold);
  background:
    linear-gradient(180deg, rgba(58, 52, 35, 0.92), rgba(31, 39, 31, 0.96)),
    var(--panel-2);
  outline: 2px solid rgba(225, 179, 91, 0.2);
}

.tower-card strong {
  display: flex;
  font-size: 14px;
  gap: 8px;
  justify-content: space-between;
  padding-left: 8px;
}

.tower-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 5px;
  padding-left: 8px;
}

.selection,
.controls,
.tools,
.progression,
.wave-preview,
.codex,
.records {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

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

.controls {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

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

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

.mode-buttons,
.talent-list {
  display: grid;
  gap: 8px;
}

.mode-buttons {
  grid-template-columns: 1fr 1fr;
}

.mode-buttons button,
.talent-list button {
  background:
    linear-gradient(180deg, rgba(39, 48, 38, 0.92), rgba(25, 31, 25, 0.96)),
    var(--panel-2);
  border-color: rgba(86, 97, 79, 0.76);
  min-height: 0;
  padding: 9px 10px;
  text-align: left;
}

.mode-buttons button.active {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(225, 179, 91, 0.2);
}

.mode-buttons strong,
.talent-list strong {
  display: block;
  font-size: 12px;
  line-height: 1.25;
}

.mode-buttons span,
.talent-list span,
.scroll-text {
  color: var(--muted);
  display: block;
  font-size: 11px;
  line-height: 1.35;
  margin-top: 3px;
}

.scroll-text {
  background: rgba(225, 179, 91, 0.08);
  border: 1px solid rgba(225, 179, 91, 0.2);
  border-radius: 6px;
  color: var(--gold);
  margin: 0;
  padding: 7px 9px;
}

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

.primary {
  background:
    linear-gradient(180deg, #c48a3e, #98652c);
  border-color: #d1a358;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.secondary {
  background:
    linear-gradient(180deg, #315448, #243b35);
  border-color: #4f836f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.ghost {
  background: rgba(255, 255, 255, 0.025);
  border-color: rgba(86, 97, 79, 0.7);
}

.wave-preview {
  display: grid;
  gap: 8px;
}

.codex ul {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.codex li,
.records li {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(86, 97, 79, 0.72);
  border-radius: 6px;
  padding: 8px 10px;
}

.records ol {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.records li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.records li strong {
  color: var(--gold);
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.record-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.recap-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.recap-row {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(86, 97, 79, 0.72);
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 3px;
  padding: 9px 10px;
}

.recap-row strong {
  color: var(--ink);
  font-size: 13px;
}

.codex .rarity-rare,
.choice-card.rarity-rare {
  border-color: rgba(109, 168, 232, 0.72);
}

.codex .rarity-epic,
.choice-card.rarity-epic {
  border-color: rgba(167, 132, 219, 0.72);
}

.codex .rarity-legendary,
.choice-card.rarity-legendary {
  border-color: rgba(231, 184, 90, 0.82);
}

.codex .rarity-forbidden,
.choice-card.rarity-forbidden {
  border-color: rgba(221, 105, 95, 0.86);
}

.overlay {
  align-items: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(225, 179, 91, 0.08), transparent 32%),
    rgba(8, 10, 8, 0.78);
  backdrop-filter: blur(3px);
  display: flex;
  inset: 14px;
  justify-content: center;
  position: absolute;
  z-index: 10;
}

.overlay.hidden,
.hidden {
  display: none;
}

.overlay-panel {
  background:
    linear-gradient(180deg, rgba(39, 46, 37, 0.98), rgba(24, 29, 23, 0.98)),
    #1d211b;
  border: 1px solid rgba(116, 109, 84, 0.72);
  border-radius: 8px;
  box-shadow: 0 22px 52px rgba(0, 0, 0, 0.45);
  max-width: 760px;
  padding: 18px;
  width: min(92%, 760px);
}

.overlay-text {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-top: 6px;
}

.card-choices {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 16px;
}

.choice-card {
  background:
    linear-gradient(180deg, rgba(41, 49, 39, 0.98), rgba(29, 35, 28, 0.98)),
    var(--panel-2);
  border: 1px solid rgba(86, 97, 79, 0.82);
  border-radius: 8px;
  color: var(--ink);
  min-height: 150px;
  padding: 14px;
  text-align: left;
}

.choice-card em {
  color: var(--gold);
  display: block;
  font-size: 12px;
  font-style: normal;
  margin-bottom: 7px;
}

.choice-card strong {
  display: block;
  font-size: 16px;
  margin-bottom: 8px;
}

.choice-card span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  line-height: 1.5;
}

.choice-card:hover {
  border-color: var(--gold);
  background:
    linear-gradient(180deg, rgba(51, 55, 39, 0.98), rgba(32, 39, 31, 0.98)),
    var(--panel-2);
}

.branch-card {
  min-height: 132px;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  body.phaser-entry {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .side-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
  }

  canvas {
    max-height: none;
  }
}

@media (max-width: 680px) {
  body.phaser-entry {
    grid-template-rows: 62px minmax(0, 1fr);
  }

  .phaser-entry__bar {
    gap: 10px;
    padding: 8px 10px;
  }

  .phaser-entry__bar h1 {
    font-size: 20px;
  }

  .phaser-entry__bar p {
    font-size: 11px;
    margin-top: 5px;
  }

  .phaser-entry__link {
    font-size: 12px;
    min-height: 34px;
    padding: 0 10px;
    white-space: nowrap;
  }

  .shell {
    gap: 10px;
    padding: 8px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  h1 {
    font-size: 26px;
  }

  .stats {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .stats span {
    min-width: 0;
    padding: 7px 6px;
  }

  .canvas-wrap {
    display: grid;
    gap: 8px;
    padding: 8px;
  }

  .side-panel {
    gap: 14px;
    padding: 12px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  .side-panel,
  .card-choices {
    grid-template-columns: 1fr;
  }

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

  .side-panel > section:first-child {
    order: 2;
  }

  .selection {
    order: 3;
  }

  .tools {
    order: 4;
  }

  .wave-preview {
    order: 5;
  }

  .progression {
    order: 6;
  }

  .codex {
    order: 7;
  }

  .records {
    order: 8;
  }

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

  .tower-card {
    min-height: 104px;
    padding: 10px;
  }

  .tower-card strong {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .tower-card p {
    font-size: 11px;
  }

  .combat-hud {
    grid-template-columns: 1fr;
    left: auto;
    position: static;
    right: auto;
    top: auto;
    z-index: auto;
  }

  .combat-hud > div {
    box-shadow: none;
    padding: 7px 8px;
  }

  .combat-notice {
    font-size: 16px;
    padding: 8px 28px;
    top: 92px;
  }

  .overlay {
    align-items: flex-start;
    inset: 0;
    padding: 12px;
    position: fixed;
  }

  .overlay-panel {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 14px;
    width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .card-choices {
    gap: 8px;
    margin-top: 12px;
  }

  .choice-card {
    min-height: 0;
    padding: 12px;
  }

  .choice-card strong {
    font-size: 15px;
  }

  .choice-card span {
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .tower-list,
  .stats {
    grid-template-columns: 1fr;
  }
}
