:root {
  color-scheme: dark;
  --ink: #f4ead2;
  --muted: #b9ad91;
  --panel: rgba(9, 18, 20, 0.88);
  --panel-soft: rgba(13, 30, 33, 0.82);
  --line: rgba(209, 178, 91, 0.44);
  --gold: #d7a94a;
  --green: #2c7b4d;
  --stone: #86785f;
  --danger: #c74747;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: auto;
  background:
    radial-gradient(circle at 50% 38%, rgba(236, 214, 132, 0.22), transparent 28%),
    linear-gradient(130deg, #213e30 0%, #0d1c22 42%, #231b28 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 42px;
  border: 1px solid rgba(214, 174, 83, 0.55);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(39, 54, 50, 0.95), rgba(8, 18, 21, 0.95));
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: rgba(255, 215, 122, 0.9);
  filter: brightness(1.1);
}

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

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(132px, 10rem) minmax(0, 1fr) minmax(156px, 12rem);
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  min-width: 0;
  min-height: 100vh;
}

.traits-panel,
.lobby-panel,
.bottom-bar,
.trace-panel {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.traits-panel {
  z-index: 2;
  grid-column: 1;
  grid-row: 1 / 3;
  padding: 16px 10px;
  border-right: 1px solid var(--line);
}

.panel-title {
  margin-bottom: 12px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.traits-list {
  display: grid;
  gap: 8px;
}

.trait-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 5px 7px;
  border: 1px solid rgba(158, 174, 154, 0.18);
  border-radius: 6px;
  background: rgba(7, 12, 15, 0.58);
}

.trait-row.active {
  border-color: rgba(255, 213, 101, 0.68);
  background: rgba(67, 57, 25, 0.64);
}

.trait-icon {
  display: grid;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(213, 188, 122, 0.5);
  border-radius: 50%;
  color: #ffe7a5;
  font-size: 12px;
  font-weight: 900;
}

.trait-copy {
  min-width: 0;
}

.trait-copy strong,
.trait-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trait-copy strong {
  font-size: 13px;
}

.trait-copy span {
  color: var(--muted);
  font-size: 12px;
}

.playfield {
  position: relative;
  display: grid;
  grid-column: 2;
  grid-row: 1;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: min(720px, calc(100vh - 178px));
  overflow: clip;
}

.top-hud {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px 8px;
}

.stage-pill,
.board-capacity {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 42px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(7, 9, 10, 0.86);
  color: #f7ddb4;
  font-weight: 850;
  white-space: nowrap;
}

.timer-ring {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 4px solid #dfb33e;
  border-radius: 50%;
  background: rgba(10, 12, 14, 0.92);
  color: #ffe7a5;
  font-size: 18px;
  font-weight: 950;
}

.arena {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  padding: 10px 36px 12px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.5), transparent 12%, transparent 88%, rgba(0, 0, 0, 0.55)),
    radial-gradient(ellipse at 50% 56%, rgba(227, 193, 107, 0.36), transparent 37%),
    linear-gradient(180deg, rgba(30, 84, 52, 0.9), rgba(116, 97, 54, 0.92) 48%, rgba(43, 74, 50, 0.95));
}

.arena::before {
  position: absolute;
  inset: 104px 36px 124px;
  content: "";
  border: 18px solid rgba(92, 82, 65, 0.9);
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 229, 149, 0.12),
    inset 0 0 54px rgba(0, 0, 0, 0.25),
    0 24px 70px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.arena::after {
  display: none;
}

.enemy-lane {
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 96px;
  place-items: end center;
}

.enemy-squad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 8px 12px;
  width: min(610px, 62vw);
  min-height: 54px;
}

.enemy-token {
  display: grid;
  justify-items: center;
  gap: 3px;
  width: 50px;
  color: rgba(244, 234, 210, 0.74);
  font-size: 10px;
  font-weight: 800;
}

.enemy-orb {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid rgba(191, 88, 83, 0.78);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 220, 165, 0.2), transparent 28%),
    linear-gradient(135deg, rgba(58, 25, 31, 0.96), rgba(9, 12, 16, 0.96));
  box-shadow: 0 0 18px rgba(191, 88, 83, 0.24);
}

.enemy-name {
  overflow: hidden;
  max-width: 64px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.enemy-gate {
  padding: 10px 18px;
  border: 1px solid rgba(213, 188, 122, 0.35);
  border-radius: 6px;
  background: rgba(11, 18, 20, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.board-stage {
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px 0;
  overflow: visible;
}

.board-grid {
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(112px, 148px));
  grid-template-rows: repeat(3, minmax(88px, 108px));
  gap: 10px 16px;
  width: min(500px, 100%);
  max-height: 100%;
  justify-content: center;
  align-content: center;
}

.hex-cell {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 1.16;
  place-items: center;
  min-height: 88px;
  overflow: visible;
}

.hex-cell::before {
  position: absolute;
  inset: 2px;
  content: "";
  border: 2px solid rgba(35, 168, 158, 0.46);
  background: rgba(31, 90, 77, 0.36);
  clip-path: polygon(14% 0, 86% 0, 100% 50%, 86% 100%, 14% 100%, 0 50%);
  box-shadow:
    inset 0 0 18px rgba(80, 211, 178, 0.14),
    0 8px 20px rgba(0, 0, 0, 0.16);
  pointer-events: none;
}

.hex-cell > * {
  z-index: 1;
}

.drop-slot {
  transition:
    border-color 120ms ease,
    filter 120ms ease,
    transform 120ms ease;
}

.drop-slot.occupied {
  cursor: grab;
}

.drop-slot.dragging {
  opacity: 0.42;
}

.drop-slot.drop-hover {
  border-color: rgba(110, 234, 190, 0.95);
  filter: brightness(1.22);
}

.hex-cell.drop-hover::before {
  border-color: rgba(110, 234, 190, 0.95);
  background: rgba(65, 188, 147, 0.24);
}

.hex-cell:nth-child(2),
.hex-cell:nth-child(5),
.hex-cell:nth-child(8) {
  transform: none;
}

.bench-dock {
  z-index: 1;
  display: grid;
  grid-template-rows: 20px minmax(0, 1fr);
  gap: 7px;
  align-self: end;
  min-height: 104px;
  padding: 8px 0 0;
  border-top: 1px solid rgba(214, 174, 83, 0.28);
  background: linear-gradient(180deg, rgba(5, 11, 13, 0.06), rgba(5, 11, 13, 0.42));
}

.bench-title {
  align-self: end;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.bench-row {
  display: grid;
  grid-template-columns: repeat(9, minmax(64px, 1fr));
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.bench-slot {
  position: relative;
  height: 68px;
  min-height: 68px;
  padding: 0;
  overflow: visible;
  background: rgba(18, 27, 28, 0.9);
}

.bench-slot.drop-hover {
  background: rgba(23, 72, 58, 0.94);
}

.bench-slot span {
  color: rgba(244, 234, 210, 0.42);
  font-size: 11px;
}

.lobby-panel {
  z-index: 2;
  grid-column: 3;
  grid-row: 1 / 3;
  padding: 16px 12px;
  border-left: 1px solid var(--line);
}

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid rgba(214, 174, 83, 0.62);
  border-radius: 6px;
  background: rgba(13, 21, 24, 0.82);
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 3px solid #dfb33e;
  border-radius: 50%;
  background: #223d4c;
  color: #ffe7a5;
  font-weight: 950;
}

.player-name {
  font-weight: 900;
}

.player-hp {
  color: var(--muted);
  font-size: 13px;
}

.scoreboard {
  display: grid;
  gap: 8px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgba(158, 174, 154, 0.16);
  border-radius: 6px;
  background: rgba(7, 12, 15, 0.54);
  font-size: 13px;
}

.score-row span {
  color: var(--muted);
}

.bottom-bar {
  z-index: 4;
  grid-column: 1 / 4;
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(118px, 140px) minmax(420px, 1fr) minmax(250px, 300px);
  gap: 12px;
  align-items: stretch;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.economy-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  height: auto;
}

.level-box {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 18, 21, 0.92);
}

.level-box span {
  font-size: 22px;
  font-weight: 950;
}

.level-box strong {
  color: #7cb9d8;
  font-size: 13px;
}

.shop-button {
  min-width: 0;
}

.center-economy {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  height: auto;
}

.gold-bank {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 18, 21, 0.95);
  color: #f7d070;
  font-size: 28px;
  font-weight: 950;
}

.gold-bank::before {
  content: "Gold";
  margin-right: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.combat-readout {
  display: grid;
  gap: 4px;
  align-content: center;
  padding: 8px;
  border: 1px solid rgba(158, 174, 154, 0.16);
  border-radius: 6px;
  background: rgba(7, 12, 15, 0.54);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.shop-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(126px, 1fr));
  gap: 10px;
  height: auto;
  min-width: 0;
}

.shop-card {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  height: 138px;
  min-height: 138px;
  padding: 0;
  overflow: hidden;
  text-align: left;
}

.shop-card.empty {
  display: grid;
  place-items: center;
}

.shop-art {
  height: 82px;
  min-height: 82px;
  background: linear-gradient(135deg, rgba(74, 83, 91, 0.7), rgba(20, 30, 35, 0.9));
}

.shop-art img {
  width: 100%;
  height: 100%;
  min-height: 82px;
  object-fit: cover;
  filter: saturate(1.05) contrast(1.08);
}

.shop-meta {
  display: grid;
  gap: 2px;
  padding: 7px 9px;
  background: rgba(6, 9, 12, 0.82);
}

.unit-name {
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff1c2;
  font-size: 15px;
  font-weight: 950;
  white-space: nowrap;
}

.unit-traits {
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.cost {
  position: absolute;
  right: 8px;
  bottom: 7px;
  color: #ffd77d;
  font-size: 14px;
  font-weight: 950;
}

.action-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  height: auto;
}

.action-panel button {
  min-height: 34px;
}

.action-panel button:nth-child(3) {
  border-color: rgba(242, 196, 73, 0.86);
  background: linear-gradient(180deg, rgba(83, 64, 22, 0.96), rgba(24, 17, 10, 0.96));
}

.action-panel button.active-toggle {
  border-color: rgba(95, 203, 156, 0.86);
  background: linear-gradient(180deg, rgba(28, 72, 57, 0.96), rgba(8, 23, 21, 0.96));
  color: #d5ffe6;
}

.trace-panel {
  position: absolute;
  z-index: 3;
  right: 12px;
  top: auto;
  bottom: 164px;
  left: auto;
  display: grid;
  grid-template-columns: 1fr;
  width: min(188px, calc(12rem - 24px));
  height: auto;
  max-height: 178px;
  gap: 8px;
  align-items: stretch;
  padding: 10px;
  border: 1px solid rgba(158, 174, 154, 0.16);
  border-radius: 6px;
  backdrop-filter: blur(6px);
}

.items-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.item-chip,
.empty-state {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 5px 9px;
  border: 1px solid rgba(158, 174, 154, 0.16);
  border-radius: 6px;
  background: rgba(7, 12, 15, 0.54);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.item-chip.component {
  border-color: rgba(89, 172, 212, 0.4);
  color: #b8d9f3;
}

.item-chip.completed {
  border-color: rgba(224, 177, 73, 0.56);
  color: #ffe3a2;
}

.item-chip.actionable {
  cursor: pointer;
}

.item-chip.actionable:hover,
.item-chip.actionable:focus {
  border-color: rgba(255, 215, 122, 0.9);
  filter: brightness(1.16);
  outline: none;
}

.log-list {
  display: grid;
  gap: 6px;
  min-width: 0;
  overflow: visible;
}

.log-line {
  max-width: none;
  min-height: 28px;
  overflow: hidden;
  padding: 6px 9px;
  border: 1px solid rgba(158, 174, 154, 0.16);
  border-radius: 6px;
  background: rgba(7, 12, 15, 0.54);
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-token {
  position: relative;
  display: grid;
  justify-items: center;
  width: 70px;
  color: #fff1c2;
  text-shadow: 0 1px 2px #000;
}

.unit-token.board {
  width: 96px;
}

.portrait {
  position: relative;
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: rgba(8, 18, 21, 0.92);
}

.unit-token.board .portrait {
  width: 58px;
  height: 58px;
  box-shadow: 0 0 24px rgba(82, 178, 230, 0.42);
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.healthbar {
  width: 62px;
  height: 7px;
  margin-top: -4px;
  border: 1px solid rgba(1, 12, 7, 0.8);
  background: rgba(0, 0, 0, 0.66);
}

.healthbar span {
  display: block;
  width: 88%;
  height: 100%;
  background: #3ed356;
}

.token-name {
  max-width: 92px;
  overflow: hidden;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stars {
  color: #ffe27a;
  font-size: 12px;
  letter-spacing: 0;
}

.cost-one {
  border-color: rgba(130, 144, 144, 0.8);
}

.cost-two {
  border-color: rgba(61, 172, 98, 0.8);
}

.cost-three {
  border-color: rgba(64, 139, 214, 0.85);
}

.cost-four {
  border-color: rgba(189, 78, 214, 0.9);
}

.cost-five {
  border-color: rgba(229, 165, 57, 0.95);
}

@media (min-width: 1101px) and (max-height: 820px) {
  button {
    min-height: 36px;
  }

  .playfield {
    min-height: calc(100vh - 140px);
  }

  .top-hud {
    padding: 10px 12px 6px;
  }

  .stage-pill,
  .board-capacity {
    min-height: 38px;
    gap: 12px;
    padding: 0 16px;
  }

  .timer-ring {
    width: 46px;
    height: 46px;
    font-size: 16px;
  }

  .arena {
    padding: 6px 32px 8px;
  }

  .arena::before {
    inset: 84px 32px 102px;
    border-width: 14px;
  }

  .enemy-lane {
    min-height: 74px;
    gap: 6px;
  }

  .enemy-squad {
    min-height: 42px;
  }

  .enemy-token {
    width: 46px;
    font-size: 10px;
  }

  .enemy-orb {
    width: 30px;
    height: 30px;
  }

  .enemy-gate {
    padding: 7px 14px;
    font-size: 12px;
  }

  .board-grid {
    grid-template-columns: repeat(3, minmax(96px, 128px));
    grid-template-rows: repeat(3, minmax(72px, 86px));
    width: min(432px, 100%);
    gap: 8px 12px;
  }

  .hex-cell {
    min-height: 72px;
  }

  .bench-dock {
    grid-template-rows: 16px minmax(0, 1fr);
    gap: 5px;
    min-height: 86px;
    padding-top: 6px;
  }

  .bench-slot {
    height: 56px;
    min-height: 56px;
  }

  .bottom-bar {
    grid-template-columns: minmax(160px, 205px) minmax(110px, 130px) minmax(390px, 1fr) minmax(235px, 285px);
    gap: 10px;
    padding: 8px 14px;
  }

  .level-box {
    min-height: 38px;
  }

  .level-box span {
    font-size: 20px;
  }

  .gold-bank {
    font-size: 24px;
  }

  .shop-card {
    height: 122px;
    min-height: 122px;
  }

  .shop-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .shop-art,
  .shop-art img {
    height: 70px;
    min-height: 70px;
  }

  .shop-meta {
    padding: 5px 8px;
  }

  .unit-name {
    font-size: 14px;
  }

  .action-panel button {
    min-height: 30px;
  }

  .trace-panel {
    bottom: 140px;
  }
}

@media (max-width: 1100px) {
  html,
  body {
    overflow: auto;
    overflow-x: hidden;
  }

  .app-shell {
    min-width: 0;
    min-height: 100vh;
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto;
  }

  .traits-panel {
    grid-column: 1;
    grid-row: 3;
    padding: 10px 7px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .playfield {
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
    overflow: visible;
  }

  .lobby-panel {
    grid-column: 1;
    grid-row: 4;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .bottom-bar {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
    height: auto;
    padding: 10px;
  }

  .economy-panel,
  .center-economy,
  .shop-row,
  .action-panel {
    height: auto;
  }

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

  .trace-panel {
    position: static;
    grid-column: 1;
    grid-row: 5;
    grid-template-columns: 1fr;
    width: auto;
    height: auto;
    max-height: none;
    border-radius: 0;
  }

  .arena {
    padding: 10px 14px 12px;
  }

  .arena::before {
    inset: 104px 14px 124px;
    border-width: 10px;
  }

  .board-grid {
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    grid-template-rows: repeat(3, minmax(66px, 78px));
    width: min(312px, 100%);
    gap: 6px;
  }

  .hex-cell {
    min-height: 66px;
  }

  .bench-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow-x: visible;
    padding-bottom: 8px;
  }

  .bench-slot {
    height: 72px;
    min-height: 72px;
  }

  .top-hud {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 8px 8px;
  }

  .stage-pill,
  .board-capacity {
    min-height: 36px;
    gap: 8px;
    padding: 0 8px;
    font-size: 12px;
  }

  .timer-ring {
    width: 42px;
    height: 42px;
    font-size: 15px;
  }
}
