:root {
  color-scheme: dark;
  --bg: #08131b;
  --panel: #12202c;
  --panel-2: #182b3a;
  --text: #e9f3fb;
  --muted: #9ab1c3;
  --accent: #62d2a2;
  --accent-2: #61a8ff;
  --danger: #ff7c7c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #102232, var(--bg));
  color: var(--text);
}

.app-shell {
  position: relative;
  min-height: 100vh;
}

.sidebar-toggle {
  position: fixed;
  top: 14px;
  left: 314px;
  z-index: 30;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  font-size: 1.35rem;
  line-height: 1;
  background: rgba(18, 32, 44, 0.95);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  transition: left 180ms ease, background 180ms ease;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  left: 12px;
}

.panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 360px;
  z-index: 20;
  padding: 20px;
  overflow-y: auto;
  background: rgba(10, 19, 27, 0.96);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 12px 0 34px rgba(0, 0, 0, 0.28);
  transform: translateX(0);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.app-shell.sidebar-collapsed .panel {
  transform: translateX(calc(-100% - 16px));
  box-shadow: none;
}

h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

h2 {
  font-size: 1rem;
  margin: 18px 0 10px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 18px;
}

.control-grid {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
  color: var(--muted);
}

input,
select {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 12px;
  font-size: 1rem;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

button {
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  cursor: pointer;
  background: #284155;
  color: var(--text);
}

button:hover {
  filter: brightness(1.08);
}

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

button.primary {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--accent), #2ca1b5);
  color: #041018;
}

button.secondary-action {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #355772, #243c50);
}

button.ultra-btn {
  background: linear-gradient(135deg, #6c5ce7, #4338ca);
}

button.max-btn {
  background: linear-gradient(135deg, #ff9f43, #d97706);
  color: #1b1204;
}

.save-status {
  margin: 10px 4px 0;
  min-height: 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.save-status.ready {
  color: #a9ebc6;
}

.save-status.error {
  color: #ffc0c0;
}

.stats,
.legend {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 12px;
  margin-top: 16px;
}

.stats-inline {
  margin-top: 0;
}

.fitness-settings {
  overflow: hidden;
}

.fitness-settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.fitness-settings-grid label {
  font-size: 0.88rem;
  min-width: 0;
}

.fitness-settings-grid input {
  font-size: 0.95rem;
  padding: 8px 10px;
}

.fitness-settings-hint {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.84rem;
}

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

.stats-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stats-list span,
.legend li {
  color: var(--muted);
}

.legend ul {
  margin: 0;
  padding-left: 18px;
}

#log {
  min-height: 220px;
  max-height: 420px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 12px;
  color: #bfd4e3;
  white-space: pre-wrap;
}

.pitch-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
  padding: 14px 16px;
  overflow-x: hidden;
  overflow-y: auto;
}

.broadcast-bar {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.broadcast-row {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 12px;
  align-items: end;
}

.broadcast-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

.broadcast-field select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(9, 20, 30, 0.92);
  color: #eaf4ff;
  font-size: 0.85rem;
  font-weight: 600;
}

.highlight-inline {
  display: flex;
  gap: 6px;
  align-items: center;
}

.highlight-inline select {
  flex: 1 1 auto;
  min-width: 0;
}

.highlight-btn {
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 8px;
  background: linear-gradient(135deg, #ff7a45, #e11d48);
  color: #ffffff;
  white-space: nowrap;
  border: none;
  cursor: pointer;
}

.replay-btn {
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 8px;
  background: rgba(97, 168, 255, 0.22);
  color: #cfe6ff;
  border: 1px solid rgba(97, 168, 255, 0.4);
  white-space: nowrap;
  cursor: pointer;
}

.replay-btn.pulse {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border-color: transparent;
}

.broadcast-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.smart-broadcast-toggle {
  font-size: 0.82rem;
  margin: 0;
}

.broadcast-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 141, 107, 0.2);
  color: #ffb899;
  border: 1px solid rgba(255, 141, 107, 0.35);
  white-space: nowrap;
}

.broadcast-badge.midfield {
  background: rgba(97, 168, 255, 0.16);
  color: #a9d1ff;
  border-color: rgba(97, 168, 255, 0.3);
}

.broadcast-badge.replay {
  background: rgba(225, 29, 72, 0.28);
  color: #ffd1dc;
  border-color: rgba(244, 63, 94, 0.5);
}

.main-stage-row {
  display: grid;
  grid-template-columns: minmax(0, 740px) 280px;
  grid-template-areas: "pitch fitness";
  align-items: start;
  justify-content: center;
  gap: 18px;
  width: min(1060px, calc(100vw - 32px));
  max-width: 100%;
}

.pitch-column {
  grid-area: pitch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 740px;
  min-width: 0;
}

.match-controls {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 12px;
}

.visualization-panels-row {
  display: none !important;
}

.generation-flow-card,
.network-viz-card {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  padding: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.generation-flow-card {
  min-width: 0;
}

.network-viz-card {
  min-width: 0;
}

.generation-flow-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.generation-flow-header h2 {
  margin: 0;
}

.generation-flow-status {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.generation-flow-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}

.generation-flow-canvas {
  display: block;
  min-width: 100%;
  height: 280px;
  background: linear-gradient(180deg, rgba(10, 23, 34, 0.96), rgba(14, 29, 42, 0.98));
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.generation-flow-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.network-viz-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.network-viz-header h2 {
  margin: 0;
}

.network-viz-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: end;
  margin-top: 10px;
}

.network-viz-toolbar {
  display: grid;
  gap: 6px;
  min-width: min(220px, 100%);
  font-size: 0.84rem;
  color: var(--muted);
}

.network-viz-toolbar select,
.network-viz-toolbar input {
  min-width: 0;
}

.network-viz-status {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.network-viz-canvas {
  width: 100%;
  height: 400px;
  background: linear-gradient(180deg, rgba(10, 23, 34, 0.96), rgba(14, 29, 42, 0.98));
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.network-viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.network-viz-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}

.legend-swatch-base {
  background: rgba(137, 203, 255, 0.9);
}

.legend-swatch-recent {
  background: rgba(255, 108, 108, 0.95);
}

.legend-swatch-older {
  background: rgba(255, 172, 172, 0.9);
}

label[hidden],
.overlay-toggle[hidden],
[hidden] {
  display: none !important;
}

.overlay-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  cursor: pointer;
}

.overlay-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-2);
}

.pitch-stage {
  position: relative;
  width: min(740px, 100%);
  max-width: 100%;
  flex: 0 0 auto;
}

.pitch-stage::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 16px;
  height: 16px;
  background:
    linear-gradient(135deg, transparent 0 45%, rgba(255, 255, 255, 0.72) 45% 55%, transparent 55%),
    linear-gradient(135deg, transparent 0 65%, rgba(255, 255, 255, 0.52) 65% 75%, transparent 75%),
    linear-gradient(135deg, transparent 0 85%, rgba(255, 255, 255, 0.36) 85% 95%, transparent 95%);
  pointer-events: none;
  opacity: 0.9;
}

.pitch-stage.is-resizing {
  user-select: none;
}

.skip-btn,
.pause-btn {
  min-width: 115px;
  padding: 6px 14px;
}

.skip-btn {
  background: linear-gradient(135deg, #324c62, #1e3142);
}

.pause-btn {
  background: linear-gradient(135deg, #5a6980, #36495d);
}

.fitness-panels {
  grid-area: fitness;
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  display: grid;
  gap: 14px;
  align-self: start;
  justify-self: start;
  flex: 0 0 280px;
}

.fitness-card {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 10px;
}

.fitness-card-combined {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.fitness-card h2 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.fitness-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.8rem;
}

.fitness-table th,
.fitness-table td {
  padding: 5px 3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.fitness-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
}

.fitness-table td {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fitness-table-combined th:first-child,
.fitness-table-combined td:first-child {
  width: 56%;
}

.fitness-table-combined th:nth-child(2),
.fitness-table-combined td:nth-child(2),
.fitness-table-combined th:nth-child(3),
.fitness-table-combined td:nth-child(3) {
  width: 22%;
}

.fitness-table-combined th:nth-child(2),
.fitness-table-combined td:nth-child(2) {
  color: #8dc2ff;
}

.fitness-table-combined th:nth-child(3),
.fitness-table-combined td:nth-child(3) {
  color: #ffae96;
}

.fitness-table tr.total-row th,
.fitness-table tr.total-row td {
  padding-top: 10px;
  border-bottom: none;
  color: var(--text);
  font-weight: 700;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #1b7f38;
  border-radius: 0;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

@media (max-width: 1100px) {
  .panel {
    width: min(360px, calc(100vw - 24px));
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: none;
  }

  .app-shell.sidebar-collapsed .sidebar-toggle {
    left: 12px;
  }

  .pitch-wrap {
    align-items: center;
    width: 100%;
    max-width: 100%;
    padding: 68px 16px 16px 16px;
  }

  .main-stage-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
  }

  .fitness-panels {
    width: min(100%, 320px) !important;
    min-width: 0;
    max-width: 320px;
    flex-basis: auto;
  }

  .visualization-panels-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(100%, calc(100vw - 32px));
  }

  .generation-flow-card,
  .network-viz-card {
    width: min(100%, calc(100vw - 32px));
  }

  .network-viz-canvas {
    height: 320px;
  }
}
