:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #1b1d23;
  --muted: #69717f;
  --line: #d8dde5;
  --red: #b82932;
  --blue: #2667a5;
  --green: #2f7d5c;
  --amber: #c77b1b;
  --soft-blue: #e6eef7;
  --soft-green: #e5f1eb;
  --shadow: 0 12px 30px rgba(27, 29, 35, 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,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto 18px;
  padding: 14px 18px;
  background: #11151d;
  color: #ffffff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 72px;
  height: 52px;
  object-fit: contain;
}

.topbar h1,
.panel h2,
.panel h3,
.eyebrow {
  margin: 0;
}

.topbar h1 {
  font-size: 1.55rem;
  line-height: 1.15;
}

.eyebrow {
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
  transition: transform 120ms ease, background 120ms ease;
}

.primary-button {
  background: var(--red);
  color: #ffffff;
}

.secondary-button {
  background: #e5e9ef;
  color: var(--ink);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled:hover,
.secondary-button:disabled:hover {
  transform: none;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(520px, 1.4fr);
  grid-template-areas:
    "deck results"
    "matchup matchup"
    "tournaments tournaments"
    "rules rules";
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

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

.deck-panel {
  grid-area: deck;
}

.results-panel {
  grid-area: results;
}

.matchup-panel {
  grid-area: matchup;
}

.tournament-panel {
  grid-area: tournaments;
}

.rules-panel {
  grid-area: rules;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 1.15rem;
}

.panel h3 {
  margin: 14px 0 10px;
  font-size: 0.9rem;
}

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

.score-chip,
.stat-pill {
  min-height: 28px;
  border-radius: 6px;
  padding: 5px 9px;
  background: var(--soft-blue);
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
}

.field-label,
.control-grid span,
.matchup-controls > label > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

textarea {
  width: 100%;
  height: 372px;
  min-height: 300px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  color: var(--ink);
  background: #fbfcfe;
  line-height: 1.45;
}

textarea:focus,
input:focus,
select:focus {
  outline: 3px solid rgba(38, 103, 165, 0.18);
  border-color: var(--blue);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fbfcfe;
  color: var(--ink);
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fbfcfe;
  color: var(--ink);
}

.status-box,
.status-line {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.status-box.error {
  color: var(--red);
}

.status-box.ok {
  color: var(--green);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric-strip.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.matchup-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(110px, 0.35fr) auto;
  align-items: end;
  gap: 12px;
}

.matchup-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.segmented-control {
  display: inline-flex;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f2f4f7;
}

.segmented-control button {
  min-height: 34px;
  padding: 0 12px;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active {
  background: var(--ink);
  color: #ffffff;
}

.bo3-rules-link {
  font-size: 0.8rem;
}

.matchup-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  margin-top: 14px;
}

.matchup-face,
.matchup-score {
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 12px;
}

.matchup-face {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.matchup-face img {
  width: 68px;
  height: 96px;
  border-radius: 6px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #e5e9ef;
}

.matchup-name {
  display: block;
  font-size: 1rem;
  font-weight: 900;
}

.matchup-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.matchup-chip {
  min-height: 24px;
  border-radius: 6px;
  padding: 4px 7px;
  background: var(--soft-green);
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 900;
}

.matchup-score {
  min-width: 210px;
  display: grid;
  place-items: center;
  text-align: center;
}

.edge-value {
  display: block;
  color: var(--red);
  font-size: 2.2rem;
  line-height: 1;
  font-weight: 950;
}

.edge-label {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.matchup-comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.comparison-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 11px;
}

.comparison-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.comparison-name,
.comparison-values {
  font-size: 0.82rem;
  font-weight: 900;
}

.comparison-values {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.comparison-bars {
  display: grid;
  gap: 6px;
}

.comparison-bar {
  height: 8px;
  border-radius: 999px;
  background: #e3e8ef;
  overflow: hidden;
}

.comparison-bar span {
  display: block;
  height: 100%;
  background: var(--blue);
}

.comparison-bar.opponent span {
  background: var(--amber);
}

.duel-details {
  margin-top: 16px;
}

.battle-replay {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.replay-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.replay-head h3 {
  margin: 0;
}

.replay-game-tabs button {
  min-width: 72px;
}

.replay-board {
  overflow: hidden;
  border: 1px solid #bfc6d0;
  border-radius: 8px;
  background: #f4f6f8;
}

.replay-player {
  min-width: 0;
  padding: 12px;
  transition: background 160ms ease;
}

.replay-player.opponent {
  background: #faf6ed;
}

.replay-player.pilot {
  background: #edf4f8;
}

.replay-player.is-active.opponent {
  background: #f7edd9;
}

.replay-player.is-active.pilot {
  background: #dfedf5;
}

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

.replay-player-head > div:first-child {
  min-width: 0;
}

.replay-player-head > div:first-child strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.86rem;
}

.replay-side-label {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
}

.replay-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.replay-counts > span {
  min-height: 26px;
  border: 1px solid rgba(105, 113, 127, 0.24);
  border-radius: 5px;
  padding: 4px 7px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.replay-counts strong {
  color: var(--ink);
}

.replay-units {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 140px));
  justify-content: center;
  gap: 7px;
  min-height: 132px;
  margin: 9px 0;
}

.replay-empty-lane {
  grid-column: 1 / -1;
  align-self: center;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.replay-unit {
  position: relative;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr);
  min-width: 0;
  height: 132px;
  overflow: hidden;
  border: 2px solid #8d98a7;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 4px 10px rgba(27, 29, 35, 0.12);
  transform-origin: center;
}

.replay-unit > img {
  width: 100%;
  height: 68px;
  object-fit: cover;
  object-position: center 18%;
  background: #dfe4ea;
}

.replay-unit-copy {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: 5px 6px;
}

.replay-unit-copy strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.66rem;
  line-height: 1.15;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.replay-unit-copy span,
.replay-unit-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.61rem;
  font-weight: 800;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replay-unit.is-rested {
  border-style: dashed;
  filter: saturate(0.55);
  opacity: 0.78;
}

.replay-unit.is-target {
  animation: replay-target 360ms ease-out 1;
}

.replay-player.pilot .replay-unit.is-actor {
  animation: replay-attack-up 360ms ease-out 1;
}

.replay-player.opponent .replay-unit.is-actor {
  animation: replay-attack-down 360ms ease-out 1;
}

.replay-zones {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.replay-base,
.replay-shields {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 4px 12px;
  min-height: 48px;
  border: 1px solid rgba(105, 113, 127, 0.35);
  border-radius: 6px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.78);
  font-size: 0.7rem;
  font-weight: 800;
}

.replay-base strong,
.replay-shields strong {
  text-align: right;
}

.replay-base.destroyed {
  color: var(--red);
  background: #f8e7e8;
}

.replay-shields {
  grid-template-columns: auto minmax(84px, 1fr) auto;
}

.replay-shields > div {
  display: grid;
  grid-template-columns: repeat(6, 10px);
  gap: 3px;
}

.replay-shields > div span {
  width: 10px;
  height: 16px;
  border: 1px solid #87919e;
  border-radius: 2px;
  background: #ffffff;
}

.replay-shields > div span.live {
  border-color: var(--green);
  background: var(--soft-green);
}

.replay-shields > div span.broken {
  opacity: 0.28;
}

.replay-base.is-hit,
.replay-shields.is-hit {
  animation: replay-hit 360ms ease-out 1;
}

.replay-event-band {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 56px;
  border-top: 1px solid #bcc5cf;
  border-bottom: 1px solid #bcc5cf;
  padding: 8px 14px;
  background: #1b1d23;
  color: #ffffff;
  animation: replay-event 260ms ease-out 1;
}

.replay-event-band span {
  color: #c5ccd5;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.replay-event-band strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.replay-event-band.pilot {
  border-left: 5px solid var(--blue);
}

.replay-event-band.opponent {
  border-left: 5px solid var(--amber);
}

.replay-controls {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) 92px;
  align-items: end;
  gap: 12px;
  padding: 10px 0;
}

.replay-transport {
  display: flex;
  gap: 6px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e5e9ef;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 900;
}

.icon-button.primary {
  border-color: var(--red);
  background: var(--red);
  color: #ffffff;
}

.replay-timeline-label,
.replay-speed-label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
}

.replay-timeline-label input {
  max-width: 100%;
  min-height: 38px;
  border: 0;
  padding: 0;
  background: transparent;
}

.replay-speed-label select {
  min-height: 38px;
}

.replay-swap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  min-height: 34px;
  border-top: 1px solid var(--line);
  padding: 9px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.replay-swap > span:first-child {
  color: var(--ink);
  font-weight: 900;
}

@keyframes replay-attack-up {
  50% { transform: translateY(-18px) scale(1.04); border-color: var(--blue); }
}

@keyframes replay-attack-down {
  50% { transform: translateY(18px) scale(1.04); border-color: var(--amber); }
}

@keyframes replay-target {
  35% { border-color: var(--red); box-shadow: 0 0 0 4px rgba(184, 41, 50, 0.18); }
}

@keyframes replay-hit {
  30% { transform: translateX(-4px); border-color: var(--red); }
  65% { transform: translateX(4px); }
}

@keyframes replay-event {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

.duel-results-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.duel-section h3 {
  margin-top: 0;
}

.finish-chart {
  display: grid;
  gap: 8px;
}

.finish-row {
  display: grid;
  grid-template-columns: 34px minmax(80px, 1fr) 56px;
  align-items: center;
  gap: 9px;
  min-height: 25px;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.finish-row strong {
  color: var(--ink);
  text-align: right;
}

.finish-track {
  height: 10px;
  overflow: hidden;
  border-radius: 4px;
  background: #e3e8ef;
}

.finish-track span {
  display: block;
  height: 100%;
  background: var(--red);
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
}

.seat-grid .metric-tile {
  min-height: 70px;
  padding: 9px;
}

.seat-grid .metric-value {
  font-size: 1.05rem;
}

.game-log {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.game-log summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 900;
}

.game-log ol {
  display: grid;
  gap: 0;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.game-log li {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 9px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.game-log li:nth-child(odd) {
  background: #f7f9fb;
}

.game-log li > span:first-child {
  color: var(--ink);
  font-weight: 900;
}

.game-log .pilot-event {
  border-left-color: var(--blue);
}

.game-log .opponent-event {
  border-left-color: var(--amber);
}

.metric-tile {
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 11px;
  min-height: 76px;
  background: #fbfcfe;
}

.metric-tile:nth-child(2n) {
  border-left-color: var(--green);
}

.metric-tile:nth-child(3n) {
  border-left-color: var(--amber);
}

.metric-value {
  display: block;
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1.15;
  font-weight: 900;
}

.metric-label {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.results-table {
  display: grid;
  gap: 14px;
}

.metric-group {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.metric-group-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, 0.8fr) 64px;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 4px 0;
}

.metric-name {
  font-size: 0.87rem;
  font-weight: 700;
}

.bar-track {
  height: 8px;
  background: #e3e8ef;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--blue);
}

.metric-row:nth-child(3n) .bar-fill {
  background: var(--green);
}

.metric-row:nth-child(4n) .bar-fill {
  background: var(--amber);
}

.metric-percent {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  font-weight: 900;
}

.meta-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 12px;
}

.rank-list,
.event-list,
.rules-list {
  display: grid;
  gap: 8px;
}

.rank-row,
.event-row,
.rule-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 36px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
}

.rank-count,
.event-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.event-row {
  grid-template-columns: minmax(160px, 0.9fr) minmax(180px, 1fr) auto;
}

.event-title,
.rank-name,
.rule-name {
  display: block;
  min-width: 0;
  font-size: 0.86rem;
  font-weight: 800;
}

.load-deck-button {
  min-height: 30px;
  border-radius: 6px;
  padding: 0 9px;
  background: var(--soft-green);
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
}

.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
}

@media (max-width: 1020px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-areas:
      "deck"
      "results"
      "matchup"
      "tournaments"
      "rules";
  }

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

  .matchup-summary,
  .matchup-comparison,
  .duel-results-grid {
    grid-template-columns: 1fr;
  }

  .matchup-score {
    min-width: 0;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    grid-template-columns: auto 1fr;
  }

  .topbar-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .topbar-actions button,
  .button-row button {
    flex: 1 1 130px;
  }

  .panel-head,
  .meta-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .metric-strip,
  .metric-strip.compact,
  .control-grid,
  .matchup-controls,
  .seat-grid {
    grid-template-columns: 1fr;
  }

  .matchup-mode-row,
  .replay-head,
  .replay-player-head {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .segmented-control {
    width: 100%;
  }

  .segmented-control button {
    flex: 1 1 0;
    min-width: 0;
  }

  .bo3-rules-link {
    justify-self: start;
  }

  .replay-player {
    padding: 9px;
  }

  .replay-counts {
    justify-content: flex-start;
  }

  .replay-units {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    min-height: 132px;
  }

  .replay-event-band {
    grid-template-columns: 1fr;
    gap: 3px;
    min-height: 64px;
    padding: 8px 10px;
  }

  .replay-zones {
    display: grid;
    grid-template-columns: 1fr;
  }

  .replay-base,
  .replay-shields {
    width: 100%;
  }

  .replay-controls {
    grid-template-columns: auto 92px;
  }

  .replay-timeline-label {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .replay-speed-label {
    grid-column: 2;
    grid-row: 1;
  }

  .metric-row {
    grid-template-columns: 1fr 74px;
  }

  .bar-track {
    grid-column: 1 / -1;
    order: 3;
  }

  .event-row {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .replay-player,
  .replay-unit,
  .replay-base,
  .replay-shields,
  .replay-event-band {
    animation: none !important;
    transition: none !important;
  }
}
