:root {
  --bg: #0f131b;
  --panel: #171d29;
  --panel-alt: #1f2737;
  --border: #2c374d;
  --border-hi: #4a5b7c;
  --text: #e8edf6;
  --muted: #93a1ba;
  --gold: #e7be5b;
  --gold-dim: rgba(231, 190, 91, 0.16);
  --blue: #4a90e2;
  --blue-soft: rgba(74, 144, 226, 0.2);
  --red: #e05a5a;
  --red-soft: rgba(224, 90, 90, 0.24);
  --green: #4cc38a;
  --green-soft: rgba(76, 195, 138, 0.18);
  --amber: #e69d45;
  --purple: #9f7aea;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, #182032 0%, var(--bg) 60%);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

button,
select,
input {
  font-family: inherit;
  color: inherit;
}

.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 14px 18px 40px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-crest {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #d4a33b, #8b5a19);
  display: grid;
  place-items: center;
  font-size: 18px;
  box-shadow: 0 2px 10px rgba(231, 190, 91, 0.3);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  border-color: var(--border-hi);
  color: var(--text);
}

.tab-btn.active {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold);
}

/* Common Buttons */
.btn {
  background: var(--panel-alt);
  border: 1px solid var(--border-hi);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #283349;
  border-color: var(--gold);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #c9942a, #a67218);
  border-color: var(--gold);
  color: #11151d;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #dfab3d, #bc8320);
}

.btn-danger {
  background: rgba(224, 90, 90, 0.16);
  border-color: var(--red);
  color: #ff9c9c;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-active {
  background: var(--red-soft);
  border-color: var(--red);
  color: #ffb4b4;
}

/* Cards & Layout */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.panel-title {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.battle-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 980px) {
  .battle-layout {
    grid-template-columns: 1fr;
  }
}

/* Status strip */
.run-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.strip-pills {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.pill-gold {
  border-color: rgba(231, 190, 91, 0.5);
  color: var(--gold);
}

.pill-red {
  border-color: rgba(224, 90, 90, 0.5);
  color: #ff9c9c;
}

.pill-blue {
  border-color: rgba(74, 144, 226, 0.5);
  color: #8cc4ff;
}

.pill-green {
  border-color: rgba(76, 195, 138, 0.5);
  color: #7ee4b1;
}

/* Enemy Hint Banner */
.hint-banner {
  background: linear-gradient(90deg, rgba(224, 90, 90, 0.14), rgba(31, 39, 55, 0.8));
  border: 1px solid rgba(224, 90, 90, 0.35);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.hint-title {
  font-weight: 700;
  font-size: 14px;
  color: #ffb8b8;
}

.hint-text {
  font-size: 12.5px;
  color: var(--text);
  margin-top: 2px;
}

.power-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
}

/* Tactical Grid Board */
.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.board-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.grid-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 6;
  background: #101620;
  border: 2px solid var(--border-hi);
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
}

.grid-tiles {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(6, 1fr);
  width: 100%;
  height: 100%;
}

.tile {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 3px 4px;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.tile-plain {
  background: #23302a;
}

.tile-forest {
  background: radial-gradient(circle at 50% 45%, #244732 0%, #193124 85%);
}

.tile-fort {
  background: linear-gradient(135deg, #4b473d, #36332b);
  box-shadow: inset 0 0 0 2px rgba(231, 190, 91, 0.35);
}

.tile-water {
  background: linear-gradient(135deg, #1b4b6d, #133552);
}

.tile-wall {
  background: repeating-linear-gradient(
    45deg,
    #2f3644,
    #2f3644 6px,
    #252b37 6px,
    #252b37 12px
  );
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.tile-tag {
  font-size: 9px;
  font-weight: 700;
  opacity: 0.65;
  letter-spacing: 0.03em;
  pointer-events: none;
}

.tile.deploy-zone {
  box-shadow: inset 0 0 0 2px rgba(74, 144, 226, 0.55);
  background-blend-mode: screen;
  cursor: pointer;
}

.tile.deploy-zone::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(74, 144, 226, 0.14);
  pointer-events: none;
}

.tile.deploy-zone:hover::after {
  background: rgba(74, 144, 226, 0.3);
}

.tile.danger-zone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(224, 90, 90, 0.24);
  box-shadow: inset 0 0 0 1px rgba(224, 90, 90, 0.5);
  pointer-events: none;
  z-index: 1;
}

.tile.unit-range::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(231, 190, 91, 0.25);
  box-shadow: inset 0 0 0 1px rgba(231, 190, 91, 0.6);
  pointer-events: none;
  z-index: 1;
}

.tile-slot-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 8.5px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(15, 19, 27, 0.72);
  color: #ffb8b8;
  pointer-events: none;
  z-index: 2;
}

/* Unit Layer */
.unit-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.unit-token {
  position: absolute;
  width: 12.5%;
  height: 16.6667%;
  padding: 4px;
  pointer-events: auto;
  cursor: pointer;
  transition: left 0.22s ease, top 0.22s ease, transform 0.14s ease, opacity 0.25s ease;
}

.unit-token.dead {
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}

.unit-token.active-turn .token-card {
  box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(231, 190, 91, 0.65);
}

.unit-token.selected .token-card {
  box-shadow: 0 0 0 2.5px #ffffff, 0 0 14px rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

.unit-token.hit-flash .token-card {
  animation: hitShake 0.28s ease;
}

@keyframes hitShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
    filter: brightness(1.6);
  }
  75% {
    transform: translateX(4px);
  }
}

.token-card {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 5px;
  position: relative;
  border: 2px solid transparent;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
}

.token-player {
  background: linear-gradient(180deg, #214a7f 0%, #152d4f 100%);
  border-color: #5ea5f6;
}

.token-enemy {
  background: linear-gradient(180deg, #7c242b 0%, #4b141a 100%);
  border-color: #ef6b6b;
}

.token-boss {
  border-color: var(--gold);
  background: linear-gradient(180deg, #6d1b3b 0%, #3d0f22 100%);
}

.token-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  line-height: 1;
}

.token-class {
  font-weight: 800;
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.token-lvl {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--gold);
  font-weight: 700;
}

.token-mid {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 17px;
  line-height: 1;
}

.token-name {
  font-size: 9px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.92;
  font-weight: 600;
}

.hp-track {
  width: 100%;
  height: 5px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 3px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  transition: width 0.2s ease;
}

.hp-player {
  background: linear-gradient(90deg, #3fd08e, #79f2b6);
}

.hp-enemy {
  background: linear-gradient(90deg, #e05252, #ff8b7b);
}

.hp-low {
  background: linear-gradient(90deg, #e69d45, #ffd166);
}

/* Floating battle popups */
.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.float-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 13px;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.9);
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  animation: floatUp 0.95s ease-out forwards;
}

.pop-dmg {
  color: #ffdf6b;
  background: rgba(120, 20, 20, 0.78);
}

.pop-adv {
  color: #9effc4;
  background: rgba(20, 90, 50, 0.85);
}

.pop-heal {
  color: #88f7b8;
  background: rgba(16, 78, 48, 0.8);
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translate(-50%, -40%) scale(0.95);
  }
  25% {
    opacity: 1;
    transform: translate(-50%, -75%) scale(1.08);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -145%) scale(0.95);
  }
}

/* Legend & Replay Controls */
.terrain-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.replay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Combat Log */
.combat-log {
  margin-top: 12px;
  max-height: 190px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  background: #101520;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-line {
  line-height: 1.35;
}

.log-turn {
  color: var(--gold);
  font-weight: 700;
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 4px;
}

.log-combat {
  color: #e6ecf7;
}

.log-heal {
  color: #7ee4b1;
}

.log-ko {
  color: #ff8e8e;
  font-weight: 700;
}

/* Right Side Inspector / Prep Controls */
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doctrine-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.doc-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 9px;
  text-align: left;
  cursor: pointer;
  transition: all 0.14s ease;
}

.doc-card:hover {
  border-color: var(--border-hi);
}

.doc-card.active {
  border-color: var(--gold);
  background: var(--gold-dim);
}

.doc-name {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text);
}

.doc-bonus {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

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

.stat-box {
  background: #101520;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 4px;
  text-align: center;
}

.stat-lbl {
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
}

.stat-val {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field-row label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.field-row select,
.field-row input {
  background: #101520;
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
}

.field-desc {
  font-size: 11.5px;
  color: var(--muted);
}

.roster-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.roster-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
}

.roster-item.selected {
  border-color: var(--gold);
  background: rgba(231, 190, 91, 0.1);
}

.roster-meta {
  font-size: 11px;
  color: var(--muted);
}

/* Starter / Reward Cards */
.card-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.choice-card {
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.choice-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.choice-card h3 {
  margin: 0;
  color: var(--gold);
  font-size: 16px;
}

.choice-card p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

/* Balance Lab Tables */
.lab-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-family: var(--mono);
}

.data-table th,
.data-table td {
  padding: 7px 8px;
  border: 1px solid var(--border);
  text-align: center;
}

.data-table th {
  background: var(--panel-alt);
  color: var(--gold);
  font-weight: 700;
}

.cell-win {
  background: rgba(76, 195, 138, 0.22);
  color: #93f3c4;
  font-weight: 700;
}

.cell-tie {
  background: rgba(230, 157, 69, 0.2);
  color: #ffd399;
}

.cell-loss {
  background: rgba(224, 90, 90, 0.2);
  color: #ffa5a5;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.badge-ok {
  background: var(--green-soft);
  color: #7ee4b1;
}

.badge-warn {
  background: rgba(230, 157, 69, 0.22);
  color: #ffc982;
}

.badge-bad {
  background: var(--red-soft);
  color: #ff9e9e;
}

.tuner-input {
  width: 54px;
  background: #101520;
  border: 1px solid var(--border-hi);
  border-radius: 5px;
  padding: 4px 5px;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
}

.outcome-banner {
  padding: 14px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.outcome-win {
  background: var(--green-soft);
  border: 1px solid var(--green);
}

.outcome-loss {
  background: var(--red-soft);
  border: 1px solid var(--red);
}
