:root {
  --bg: #f5ead7;
  --bg-strong: #ebd9bd;
  --ink: #1f2430;
  --muted: #5d6473;
  --panel: rgba(255, 249, 239, 0.88);
  --panel-border: rgba(31, 36, 48, 0.1);
  --accent: #c44536;
  --accent-strong: #8f2d23;
  --accent-soft: rgba(196, 69, 54, 0.12);
  --track: #12355b;
  --track-soft: rgba(18, 53, 91, 0.14);
  --gold: #d4a017;
  --good: #137547;
  --warn: #b36200;
  --lane-1: #d84c3f;
  --lane-2: #e4a92b;
  --lane-3: #2f8f83;
  --lane-4: #3760bf;
  --shadow: 0 18px 45px rgba(49, 40, 25, 0.14);
  font-family: "Avenir Next Condensed", "Trebuchet MS", "Arial Narrow", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(212, 160, 23, 0.3), transparent 28%),
    linear-gradient(135deg, #f8efe2 0%, #eed5ad 60%, #d5b98e 100%);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(31, 36, 48, 0.36);
}

.modal-card {
  width: min(100%, 460px);
  display: grid;
  gap: 0.85rem;
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-card h3,
.modal-card p {
  margin: 0;
}

.modal-card p {
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(31, 36, 48, 0.16);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  color: var(--ink);
}

label {
  display: grid;
  gap: 0.4rem;
}

label span {
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.app-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 2rem 1.2rem 3rem;
}

.hero {
  margin-bottom: 1.6rem;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: var(--accent-strong);
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 4.5rem);
  line-height: 0.92;
}

.hero-copy {
  max-width: 62ch;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
}

.view-tabs {
  display: inline-flex;
  gap: 0.45rem;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 249, 239, 0.45);
  border: 0;
  box-shadow: inset 0 0 0 1px var(--panel-border);
  backdrop-filter: none;
}

.view-tab {
  border-radius: 999px;
  padding: 0.62rem 1rem;
  font-weight: 800;
  color: var(--muted);
  background: transparent;
}

.hero-actions > .secondary-button,
.hero-actions > .ghost-button {
  padding: 0.62rem 1rem;
  font-size: 0.92rem;
}

.view-tab.is-active {
  color: white;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 12px 22px rgba(143, 45, 35, 0.24);
}

.hero-stats {
  display: flex;
  flex: 1 1 520px;
  min-width: min(100%, 520px);
}

.hero-stats-grid {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.stat-card,
.panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.stat-card {
  border-radius: 18px;
  flex: 1 1 150px;
  min-width: 150px;
  padding: 0.68rem 0.88rem;
}

.stat-card strong {
  display: block;
  font-size: 1.52rem;
  line-height: 1;
}

.stat-card-line {
  display: flex;
  align-items: center;
}

.stat-card-line strong {
  width: 100%;
  font-size: 1.08rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-card span {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(360px, 1fr);
  gap: 1rem;
  align-items: start;
}

.registration-layout {
  display: grid;
  grid-template-columns: minmax(320px, 520px);
  gap: 1rem;
  align-items: start;
}

.panel {
  border-radius: 24px;
  padding: 1.2rem;
}

.panel-rounds {
  grid-column: 1 / -1;
}

.panel-camera {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.panel-heading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  justify-content: end;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.65rem;
}

.stack-form {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.participant-toolbar,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
}

.primary-button,
.secondary-button,
.ghost-button,
.lane-action {
  border-radius: 999px;
  padding: 0.8rem 1.15rem;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  box-shadow: 0 12px 22px rgba(143, 45, 35, 0.28);
}

.secondary-button {
  background: var(--track);
  color: white;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  border: 1px solid rgba(31, 36, 48, 0.12);
}

.toggle {
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  gap: 0.7rem;
}

.toggle input {
  width: auto;
  transform: scale(1.15);
}

.toggle span {
  margin: 0;
}

.collapse-button {
  padding: 0.55rem 0.95rem;
}

.camera-toolbar,
.camera-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
}

.camera-toolbar {
  justify-content: space-between;
}

.camera-toolbar > .pill {
  margin-inline: auto;
  min-height: 2.75rem;
  padding: 0.55rem 0.95rem;
  justify-content: center;
}

.camera-toolbar-actions {
  justify-content: end;
}

.participant-list {
  display: grid;
  gap: 0.65rem;
  max-height: 420px;
  overflow: auto;
  padding-right: 0.2rem;
}

.participant-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.8rem;
  align-items: center;
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(31, 36, 48, 0.08);
}

.participant-badge {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--track-soft);
  color: var(--track);
  font-weight: 800;
}

.participant-meta strong,
.lane-entry strong,
.heat-card h3,
.current-heat-header h3 {
  display: block;
  margin-block-start: 0;
  margin-block-end: 0;
}

.participant-meta span,
.lane-entry span,
.subtle {
  color: var(--muted);
}

.remove-button {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: rgba(196, 69, 54, 0.12);
  color: var(--accent-strong);
  font-weight: 800;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.42);
  border-radius: 18px;
  border: 1px dashed rgba(31, 36, 48, 0.16);
}

.current-heat-card {
  display: grid;
  gap: 1rem;
}

.current-heat-result,
.current-heat-subcard {
  display: grid;
  gap: 0.85rem;
}

.current-heat-subcard {
  padding: 0.9rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(31, 36, 48, 0.08);
}

.current-heat-replay {
  gap: 0.6rem;
}

.manager-replay-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  background: linear-gradient(135deg, #0b132b, #1c2541);
  border: 1px solid rgba(31, 36, 48, 0.15);
  object-fit: cover;
}

.current-heat-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(31, 36, 48, 0.08);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-weight: 700;
  font-size: 0.82rem;
}

.pill.neutral {
  color: var(--track);
  background: var(--track-soft);
}

.pill.good {
  color: var(--good);
  background: rgba(19, 117, 71, 0.12);
}

.pill.ready {
  color: white;
  background: linear-gradient(135deg, var(--good) 0%, #0c5c38 100%);
  box-shadow: 0 10px 20px rgba(19, 117, 71, 0.22);
}

.pill.warn {
  color: var(--warn);
  background: rgba(179, 98, 0, 0.12);
}

.lane-list,
.lane-scores {
  display: grid;
  gap: 0.7rem;
}

.placement-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.placement-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(31, 36, 48, 0.1);
  font-weight: 700;
}

.placement-chip.dnf {
  color: var(--warn);
  border-color: rgba(179, 98, 0, 0.25);
  background: rgba(179, 98, 0, 0.12);
}

.lane-entry,
.score-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.8rem 0.95rem;
  border-radius: 16px;
  border: 1px solid rgba(31, 36, 48, 0.08);
  background: rgba(255, 255, 255, 0.62);
}

.lane-entry-copy {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.lane-entry.compact {
  padding: 0.25rem 0.8rem;
  background: rgba(255, 255, 255, 0.5);
}

.compact-lane-list {
  gap: 0.25rem;
}

.compact-heat-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: start;
}

.compact-heat-header h4 {
  margin: 0;
  font-size: 1rem;
}

.compact-empty-copy {
  padding: 0.75rem 0.9rem;
}

.lane-marker {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
}

.lane-1 {
  background: var(--lane-1);
}

.lane-2 {
  background: var(--lane-2);
}

.lane-3 {
  background: var(--lane-3);
}

.lane-4 {
  background: var(--lane-4);
}

.lane-action {
  color: white;
  min-width: 6rem;
}

.lane-entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: end;
}

.lane-action.lane-1 {
  background: var(--lane-1);
}

.lane-action.lane-2 {
  background: var(--lane-2);
}

.lane-action.lane-3 {
  background: var(--lane-3);
}

.lane-action.lane-4 {
  background: var(--lane-4);
}

.lane-action-dnf {
  min-width: 6rem;
  color: var(--warn);
  border-color: rgba(179, 98, 0, 0.26);
  background: rgba(179, 98, 0, 0.08);
}

.lane-action-dnf.is-active {
  background: rgba(179, 98, 0, 0.2);
  border-color: rgba(179, 98, 0, 0.36);
}

.camera-stage {
  display: grid;
  gap: 1rem;
}

.video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 20px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 12px,
      rgba(255, 255, 255, 0.08) 12px,
      rgba(255, 255, 255, 0.08) 13px
    ),
    linear-gradient(135deg, #0b132b, #1c2541);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.video-frame video,
.video-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-controls {
  display: grid;
  gap: 0.9rem;
}

.camera-settings {
  display: grid;
  gap: 0.9rem;
}

.readiness-banner {
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(31, 36, 48, 0.08);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.readiness-banner.neutral {
  color: var(--track);
  background: rgba(18, 53, 91, 0.08);
}

.readiness-banner.warn {
  color: var(--warn);
  background: rgba(179, 98, 0, 0.12);
}

.readiness-banner.ready {
  color: white;
  background: linear-gradient(135deg, var(--good) 0%, #0c5c38 100%);
  box-shadow: 0 14px 28px rgba(19, 117, 71, 0.2);
}

.primary-button.is-armed {
  background: linear-gradient(135deg, var(--good) 0%, #0c5c38 100%);
  box-shadow: 0 12px 22px rgba(19, 117, 71, 0.28);
}

.detector-readout {
  padding: 0.85rem 1rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(31, 36, 48, 0.08);
  color: var(--muted);
}

.score-chip {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
}

.score-value {
  font-variant-numeric: tabular-nums;
  color: var(--track);
  font-weight: 700;
}

.score-state {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.rounds-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(340px, 1fr));
  gap: 1rem;
}

.round-column {
  display: grid;
  gap: 0.9rem;
  align-content: start;
}

.stage-column {
  min-width: 0;
}

.round-column h3 {
  margin: 0;
  font-size: 1.2rem;
}

.stage-header,
.stage-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
}

.stage-header {
  padding: 0.2rem 0 0.3rem;
}

.standings-card {
  display: grid;
  gap: 0.8rem;
  padding: 0.95rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(31, 36, 48, 0.08);
}

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

.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.standings-table th,
.standings-table td {
  padding: 0.55rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid rgba(31, 36, 48, 0.08);
}

.standings-table th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
}

.cutoff-row {
  background: rgba(212, 160, 23, 0.12);
}

.round-group {
  display: grid;
  gap: 0.8rem;
}

.round-group h4 {
  margin: 0.2rem 0 0;
  color: var(--track);
}

.heat-card {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(31, 36, 48, 0.08);
}

.heat-card.current {
  border-color: rgba(196, 69, 54, 0.38);
  box-shadow: 0 12px 24px rgba(196, 69, 54, 0.12);
}

.heat-card.completed {
  background: rgba(19, 117, 71, 0.08);
}

.heat-card.waiting {
  background: rgba(18, 53, 91, 0.05);
}

.heat-card-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.heat-mini-lane {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  color: var(--muted);
}

.heat-mini-lane strong {
  color: var(--ink);
}

.heat-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.winner-line {
  color: var(--good);
  font-weight: 700;
}

@media (max-width: 1600px), (max-height: 900px) {
  input,
  textarea {
    padding: 0.65rem 0.8rem;
    border-radius: 10px;
  }

  label {
    gap: 0.3rem;
  }

  label span {
    font-size: 0.74rem;
  }

  .app-shell {
    max-width: 1420px;
    padding: 1.15rem 0.9rem 1.6rem;
  }

  .hero {
    margin-bottom: 0.95rem;
  }

  .hero-actions,
  .hero-stats-grid {
    gap: 0.6rem;
  }

  .view-tabs {
    gap: 0.3rem;
    padding: 0;
  }

  .view-tab {
    padding: 0.62rem 0.95rem;
    font-size: 0.92rem;
  }

  .hero-stats {
    flex-basis: 440px;
    min-width: min(100%, 440px);
  }

  .stat-card {
    min-width: 136px;
    padding: 0.6rem 0.78rem;
    border-radius: 16px;
  }

  .stat-card strong {
    font-size: 1.42rem;
  }

  .stat-card-line strong {
    font-size: 1rem;
  }

  .layout {
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    gap: 0.85rem;
  }

  .registration-layout {
    grid-template-columns: minmax(300px, 460px);
    gap: 0.85rem;
  }

  .panel {
    padding: 1rem;
    border-radius: 20px;
  }

  .panel-heading {
    gap: 0.8rem;
    margin-bottom: 0.85rem;
  }

  .panel-heading-actions,
  .stack-form,
  .participant-toolbar,
  .button-row,
  .camera-toolbar,
  .camera-toolbar-group,
  .camera-stage,
  .camera-controls,
  .camera-settings,
  .rounds-board,
  .round-column,
  .round-group,
  .current-heat-card {
    gap: 0.7rem;
  }

  .panel-heading h2 {
    font-size: 1.4rem;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .lane-action {
    padding: 0.8rem 1rem;
    font-size: 0.92rem;
  }

  .toggle {
    gap: 0.55rem;
  }

  .toggle input {
    transform: scale(1.05);
  }

  .collapse-button {
    padding: 0.5rem 0.82rem;
  }

  .camera-toolbar > .pill {
    min-height: 2.35rem;
    padding: 0.45rem 0.8rem;
  }

  .participant-list {
    gap: 0.55rem;
    max-height: 340px;
  }

  .participant-row,
  .lane-entry,
  .score-chip {
    gap: 0.65rem;
    padding: 0.2rem 0.8rem;
  }

  .participant-row {
    border-radius: 14px;
  }

  .participant-badge,
  .remove-button {
    width: 1.95rem;
    height: 1.95rem;
    font-size: 0.88rem;
  }

  .empty-state {
    min-height: 92px;
    border-radius: 16px;
  }

  .current-heat-header {
    gap: 0.8rem;
    padding-bottom: 0.55rem;
  }

  .current-heat-subcard {
    padding: 0.8rem;
    border-radius: 16px;
  }

  .pill {
    padding: 0.3rem 0.68rem;
    font-size: 0.76rem;
  }

  .lane-list,
  .lane-scores,
  .placement-strip {
    gap: 0.25rem;
  }

  .placement-chip {
    padding: 0.35rem 0.65rem;
    font-size: 0.86rem;
  }

  .lane-marker {
    width: 1.8rem;
    height: 1.8rem;
    font-size: 0.82rem;
  }

  .lane-entry.compact {
    padding: 0.1rem 0.4rem;
  }

  .lane-action {
    min-width: 5.2rem;
  }

  .lane-entry-actions {
    gap: 0.3rem;
  }

  .lane-action-dnf {
    min-width: 5.4rem;
  }

  .readiness-banner,
  .detector-readout,
  .standings-card,
  .heat-card {
    padding: 0.8rem 0.9rem;
  }

  .readiness-banner,
  .detector-readout {
    border-radius: 14px;
  }

  .rounds-board {
    grid-template-columns: repeat(2, minmax(300px, 1fr));
  }

  .round-column h3 {
    font-size: 1.08rem;
  }

  .stage-header,
  .stage-meta,
  .heat-card-header,
  .heat-footer {
    gap: 0.65rem;
  }

  .standings-table {
    font-size: 0.88rem;
  }

  .standings-table th,
  .standings-table td {
    padding: 0.45rem 0.35rem;
  }

  .standings-table th {
    font-size: 0.7rem;
  }

  .heat-card {
    border-radius: 16px;
    gap: 0.6rem;
  }

  .heat-footer {
    font-size: 0.82rem;
  }
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .panel-camera {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .rounds-board {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 1rem 0.8rem 2rem;
  }

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

  .hero-actions,
  .hero-stats,
  .hero-stats-grid {
    width: 100%;
  }

  .panel-rounds,
  .panel-camera {
    grid-column: auto;
  }

  .hero h1 {
    max-width: none;
  }

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

  .view-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
}
