:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --ink: #182230;
  --muted: #667085;
  --line: #d8dee9;
  --panel: #ffffff;
  --blue: #2563eb;
  --blue-quiet: #dbeafe;
  --red: #dc2626;
  --red-quiet: #fee2e2;
  --green: #15803d;
  --green-quiet: #dcfce7;
  --yellow-quiet: #fef3c7;
  --shadow: 0 14px 32px rgba(24, 34, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

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

.ghost,
.danger,
.primary,
.chip {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 700;
}

.ghost {
  background: #edf2f7;
  color: #263445;
}

.danger {
  background: var(--red-quiet);
  color: #991b1b;
}

.primary {
  background: var(--blue);
  color: #fff;
  width: 100%;
  min-height: 46px;
  margin-top: 12px;
}

.shell {
  width: min(1220px, calc(100% - 32px));
  margin: 22px auto 48px;
}

.summary-band {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 18px;
  align-items: center;
  padding: 24px;
  min-height: 180px;
  background: linear-gradient(135deg, #ffffff 0%, #eef6ff 48%, #f8fff1 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-band p {
  color: var(--muted);
  max-width: 760px;
  line-height: 1.65;
}

.battle-crest {
  height: 132px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
}

.battle-crest span {
  height: 100%;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.92), rgba(21, 128, 61, 0.7)),
    repeating-linear-gradient(45deg, transparent, transparent 8px, rgba(255,255,255,.22) 8px, rgba(255,255,255,.22) 14px);
}

.battle-crest span:last-child {
  background:
    linear-gradient(135deg, rgba(220, 38, 38, 0.92), rgba(245, 158, 11, 0.7)),
    repeating-linear-gradient(135deg, transparent, transparent 8px, rgba(255,255,255,.22) 8px, rgba(255,255,255,.22) 14px);
}

.battle-crest b {
  font-size: 28px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  overflow-x: auto;
}

.tab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 8px;
  background: #e5eaf2;
  color: #334155;
  font-weight: 800;
}

.tab.is-active {
  background: #111827;
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.panel.compact {
  margin-bottom: 0;
}

.section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stat-table,
.troop-list,
.hero-list {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: center;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 13px;
}

td:first-child,
th:first-child {
  text-align: left;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  color: var(--ink);
}

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

.chip {
  background: var(--blue-quiet);
  color: #1d4ed8;
}

.remove {
  background: transparent;
  color: var(--red);
  font-weight: 800;
}

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

.side-title input {
  max-width: 240px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  margin-bottom: 12px;
}

.toggle-row input {
  width: auto;
}

.battle-grid {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.control-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.result-card {
  margin-bottom: 0;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.metrics,
.comparison {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.metrics div,
.comparison div {
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics span,
.comparison b {
  display: block;
  font-size: 24px;
  font-weight: 900;
}

.metrics small,
.comparison small {
  color: var(--muted);
}

.battle-log {
  margin: 0;
  padding-left: 22px;
  line-height: 1.7;
}

.table-wrap {
  overflow-x: auto;
}

.muted {
  color: var(--muted);
}

@media (max-width: 920px) {
  .topbar,
  .summary-band,
  .section-grid,
  .battle-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
    align-items: stretch;
  }

  .metrics,
  .comparison,
  .control-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1220px);
  }

  h1 {
    font-size: 20px;
  }

  .panel,
  .summary-band {
    padding: 14px;
  }

  .metrics,
  .comparison,
  .control-row {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 7px 6px;
    font-size: 13px;
  }
}
