:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111417;
  color: #f4efe4;
  --bg: #111417;
  --surface: #191d21;
  --surface-strong: #20262b;
  --line: #343a40;
  --text-dim: #b9b0a3;
  --accent: #cda85d;
  --good: #68b984;
  --bad: #d06a5f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(17, 20, 23, 0.96), rgba(17, 20, 23, 0.78)),
    url("https://images.unsplash.com/photo-1533134486753-c833f0ed4866?auto=format&fit=crop&w=1800&q=80") center/cover fixed;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 0 24px;
  border-bottom: 1px solid rgba(244, 239, 228, 0.14);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 15px;
  color: #efe6d5;
  background: rgba(25, 29, 33, 0.88);
  border: 1px solid rgba(244, 239, 228, 0.16);
  text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
  color: #141414;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.3rem, 6vw, 5.8rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.controls {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin: 22px 0;
}

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

.tab,
.player-chip {
  min-height: 40px;
  padding: 0 15px;
  color: #efe6d5;
  background: rgba(25, 29, 33, 0.88);
  border: 1px solid rgba(244, 239, 228, 0.16);
  cursor: pointer;
}

.tab.active,
.player-chip.active {
  color: #141414;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 800;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid rgba(244, 239, 228, 0.14);
  background: rgba(17, 20, 23, 0.7);
}

.cachebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 12px 14px;
  color: var(--text-dim);
  background: rgba(25, 29, 33, 0.78);
  border: 1px solid rgba(244, 239, 228, 0.12);
  font-size: 0.9rem;
}

.report-view .controls,
.report-view .cachebar {
  display: none;
}

.refresh-button {
  min-height: 36px;
  padding: 0 12px;
  color: #f4efe4;
  background: rgba(32, 38, 43, 0.9);
  border: 1px solid rgba(205, 168, 93, 0.42);
  cursor: pointer;
}

.refresh-button:hover {
  border-color: var(--accent);
}

.refresh-button:disabled {
  cursor: progress;
  opacity: 0.62;
}

.analysis-panel {
  margin: 0 14px 14px;
  padding: 18px;
  background: rgba(17, 20, 23, 0.82);
  border-top: 1px solid rgba(205, 168, 93, 0.42);
}

.analysis-panel.hidden {
  display: none;
}

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

.panel-close {
  min-height: 32px;
  padding: 0 10px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid rgba(244, 239, 228, 0.16);
  cursor: pointer;
}

.analysis-panel p {
  margin: 8px 0 12px;
  max-width: 860px;
  line-height: 1.5;
}

.analysis-panel ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

.analysis-panel li {
  margin: 6px 0;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 900;
}

.analysis-section {
  margin: 14px 0;
}

.analysis-label {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric {
  min-width: 0;
  padding: 16px;
  border-right: 1px solid rgba(244, 239, 228, 0.12);
}

.metric:last-child {
  border-right: 0;
}

.metric-label {
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 6px;
  font-size: 1.25rem;
  font-weight: 800;
}

.games {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.history-header,
.game-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) 150px 78px minmax(220px, 1.1fr) 72px 42px 72px minmax(220px, 1.1fr);
  gap: 14px;
  align-items: center;
}

.history-header {
  padding: 0 14px 7px;
  color: rgba(244, 239, 228, 0.52);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.game-card {
  background: rgba(25, 29, 33, 0.9);
  border: 1px solid rgba(244, 239, 228, 0.13);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.game-row {
  min-height: 104px;
  padding: 12px 14px;
  transition: transform 140ms ease;
}

.game-card:hover {
  background: rgba(32, 38, 43, 0.96);
  border-color: rgba(205, 168, 93, 0.72);
}

.game-row:hover {
  transform: translateY(-1px);
}

.map-cell {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.map-thumb {
  display: block;
  width: 58px;
  height: 58px;
  overflow: hidden;
  color: rgba(244, 239, 228, 0.82);
  background:
    linear-gradient(145deg, rgba(205, 168, 93, 0.18), rgba(54, 75, 85, 0.68)),
    repeating-linear-gradient(45deg, rgba(244, 239, 228, 0.06) 0 4px, transparent 4px 9px);
  border: 2px solid rgba(90, 117, 143, 0.72);
  border-radius: 8px;
  object-fit: cover;
}

.map-fallback {
  display: grid;
  place-items: center;
  font-size: 0.88rem;
  font-weight: 900;
  text-transform: uppercase;
}

.map-thumb.win {
  border-color: rgba(104, 185, 132, 0.78);
}

.map-thumb.loss {
  border-color: rgba(208, 106, 95, 0.82);
}

.meta {
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.45;
}

.map {
  font-size: 1.16rem;
  font-weight: 900;
}

.map-copy,
.player-stack {
  min-width: 0;
}

.date-cell {
  color: var(--text-dim);
  font-size: 0.98rem;
  line-height: 1.45;
}

.world-button {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 6px;
  background: rgba(17, 20, 23, 0.72);
  border: 1px solid rgba(244, 239, 228, 0.16);
  border-radius: 5px;
  opacity: 0.76;
  transition: border-color 140ms ease, opacity 140ms ease, transform 140ms ease;
}

.world-button:hover {
  border-color: var(--accent);
  opacity: 1;
  transform: translateY(-1px);
}

.world-button img {
  width: 16px;
  height: 16px;
}

.rating-delta {
  font-size: 1.08rem;
  font-weight: 900;
  text-align: center;
}

.rating-delta.positive {
  color: var(--good);
}

.rating-delta.negative {
  color: #f1675f;
}

.rating-delta.neutral {
  color: var(--text-dim);
}

.player-stack,
.rating-stack {
  display: grid;
  gap: 7px;
}

.player-entry {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 24px;
}

.player-name {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #f05e58;
  font-size: 1.02rem;
  font-weight: 750;
  line-height: 1.15;
}

.player-entry.opponent .player-name {
  color: #5ed675;
}

.civ-flag {
  display: block;
  width: 42px;
  height: 24px;
  overflow: hidden;
  object-fit: cover;
  background: rgba(17, 20, 23, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.24);
}

.civ-fallback {
  display: inline-grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.66rem;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.42);
}

.rating-stack {
  color: rgba(244, 239, 228, 0.62);
  font-size: 0.98rem;
  line-height: 1.15;
  text-align: right;
}

.rating-line {
  min-height: 24px;
}

.versus {
  color: #f4efe4;
  font-size: 0.92rem;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.report-page {
  padding: 18px;
  background: rgba(25, 29, 33, 0.92);
  border: 1px solid rgba(244, 239, 228, 0.13);
}

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

.report-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: end;
  gap: 10px;
}

.back-button,
.debug-timeline-button,
.regenerate-button,
.report-link {
  min-height: 36px;
  padding: 0 12px;
  color: #f4efe4;
  background: rgba(32, 38, 43, 0.9);
  border: 1px solid rgba(205, 168, 93, 0.42);
  cursor: pointer;
  text-decoration: none;
}

.report-link {
  display: inline-flex;
  align-items: center;
}

.back-button:hover,
.debug-timeline-button:hover,
.regenerate-button:hover,
.report-link:hover {
  border-color: var(--accent);
}

.debug-timeline-button:disabled,
.regenerate-button:disabled {
  cursor: progress;
  opacity: 0.62;
}

.report-hero {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(244, 239, 228, 0.12);
}

.report-hero .map-thumb {
  width: 72px;
  height: 72px;
}

.report-kicker {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h2 {
  margin: 3px 0 4px;
  font-size: clamp(1.9rem, 4vw, 3.3rem);
  line-height: 1;
  letter-spacing: 0;
}

.verdict-block,
.report-section {
  max-width: 980px;
  margin: 0;
  padding: 18px 0;
  border-bottom: 1px solid rgba(244, 239, 228, 0.1);
}

.verdict-block p,
.report-section p {
  margin: 8px 0 0;
  color: #f4efe4;
  font-size: 1.05rem;
  line-height: 1.58;
}

.report-section ol {
  display: grid;
  gap: 12px;
  margin: 12px 0 0;
  padding-left: 22px;
}

.report-section li {
  padding-left: 4px;
  line-height: 1.5;
}

.report-section li strong {
  display: block;
  color: #f4efe4;
  font-weight: 900;
}

.report-section li span {
  display: block;
  margin-top: 2px;
  color: var(--text-dim);
}

.report-section.drill {
  border-bottom: 0;
}

.report-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 30px;
  align-items: start;
}

.report-main {
  min-width: 0;
}

.debug-panel {
  margin-bottom: 22px;
  padding: 14px;
  background: rgba(17, 20, 23, 0.82);
  border: 1px solid rgba(205, 168, 93, 0.28);
}

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

.debug-head p {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 0.86rem;
}

.debug-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 6px;
  max-width: 420px;
}

.debug-counts span,
.debug-note {
  color: #111417;
  background: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
}

.debug-counts span {
  padding: 4px 6px;
}

.debug-note {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 7px;
}

.debug-table-wrap {
  max-height: 420px;
  margin-top: 12px;
  overflow: auto;
  border: 1px solid rgba(244, 239, 228, 0.1);
}

.debug-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.debug-table th,
.debug-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(244, 239, 228, 0.08);
  text-align: left;
  vertical-align: top;
}

.debug-table th {
  position: sticky;
  top: 0;
  color: #f4efe4;
  background: #15191d;
  font-size: 0.68rem;
  text-transform: uppercase;
}

.debug-table td {
  color: var(--text-dim);
}

.debug-table td strong {
  display: block;
  color: #f4efe4;
}

.debug-table td span {
  display: block;
  margin-top: 2px;
  color: rgba(244, 239, 228, 0.48);
}

.data-rail {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 18px;
}

.data-card {
  padding: 14px;
  background: rgba(17, 20, 23, 0.72);
  border: 1px solid rgba(244, 239, 228, 0.12);
}

.data-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.data-legend,
.chart-caption,
.timing-key {
  color: var(--text-dim);
  font-size: 0.76rem;
}

.data-legend {
  white-space: nowrap;
}

.legend-friendly,
.legend-enemy {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: 0 4px 0 8px;
  border-radius: 999px;
}

.legend-friendly {
  background: #f05e58;
}

.legend-enemy {
  background: #5ed675;
}

.line-chart {
  display: block;
  width: 100%;
  margin: 8px 0 4px;
}

.chart-grid {
  stroke: rgba(244, 239, 228, 0.14);
  stroke-width: 1;
}

.chart-marker {
  stroke: rgba(205, 168, 93, 0.42);
  stroke-dasharray: 3 4;
  stroke-width: 1;
}

.line-friendly,
.line-enemy {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.line-friendly {
  stroke: #f05e58;
}

.line-enemy {
  stroke: #5ed675;
}

.timing-key {
  margin-top: 8px;
}

.timing-key span {
  display: inline-grid;
  width: 18px;
  height: 18px;
  margin: 0 3px 0 8px;
  place-items: center;
  color: #111417;
  background: var(--accent);
  font-size: 0.66rem;
  font-weight: 900;
}

.timing-chart,
.bar-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.timing-row,
.bar-row {
  display: grid;
  gap: 5px;
}

.timing-name,
.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #f4efe4;
  font-size: 0.82rem;
  font-weight: 800;
}

.timing-row.enemy .timing-name,
.bar-row.enemy .bar-label span {
  color: #5ed675;
}

.timing-row.friendly .timing-name,
.bar-row.friendly .bar-label span {
  color: #f05e58;
}

.timing-track,
.bar-track {
  position: relative;
  height: 8px;
  overflow: visible;
  background: rgba(244, 239, 228, 0.1);
}

.timing-marker {
  position: absolute;
  top: 50%;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  transform: translate(-50%, -50%);
  color: #111417;
  background: var(--accent);
  border: 1px solid rgba(17, 20, 23, 0.5);
  font-size: 0.62rem;
  font-weight: 950;
}

.timing-marker.imperial {
  background: #f4efe4;
}

.timing-marker.nd-tc {
  color: #f4efe4;
  background: #5b6e86;
}

.bar-label b {
  color: var(--text-dim);
  font-weight: 700;
}

.bar-track {
  height: 9px;
  overflow: hidden;
}

.bar-track span {
  display: block;
  height: 100%;
  background: #f05e58;
}

.bar-row.enemy .bar-track span {
  background: #5ed675;
}

.loading,
.empty,
.error {
  padding: 28px;
  background: rgba(25, 29, 33, 0.9);
  border: 1px solid rgba(244, 239, 228, 0.13);
  color: var(--text-dim);
}

@media (max-width: 820px) {
  .app-shell {
    width: calc(100vw - 20px);
    padding-top: 18px;
  }

  .topbar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .topnav {
    align-items: stretch;
  }

  .nav-link {
    width: 100%;
  }

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

  .metric {
    border-bottom: 1px solid rgba(244, 239, 228, 0.12);
  }

  .history-header {
    display: none;
  }

  .game-row {
    grid-template-columns: 1fr;
    gap: 10px;
    min-height: 0;
  }

  .cachebar {
    align-items: stretch;
    flex-direction: column;
  }

  .report-toolbar,
  .report-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .report-hero {
    grid-template-columns: 1fr;
  }

  .report-layout {
    grid-template-columns: 1fr;
  }

  .data-rail {
    position: static;
  }

  .date-cell,
  .rating-stack,
  .rating-delta,
  .versus {
    text-align: left;
  }

  .player-entry {
    grid-template-columns: 42px minmax(0, 1fr);
  }
}
