:root {
  color-scheme: dark;
  --bg: #160c0b;
  --panel: rgba(44, 20, 22, 0.9);
  --panel-2: rgba(70, 31, 34, 0.78);
  --line: rgba(255, 235, 210, 0.18);
  --text: #fff7ec;
  --muted: rgba(255, 247, 236, 0.68);
  --gold: #ffd166;
  --sand: #e7b778;
  --cyan: #7ee7ff;
  --red: #ff5b6d;
  --green: #8dffbc;
  --wine: #5a1628;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 18% 8%, rgba(121, 58, 38, 0.42), transparent 30%),
    radial-gradient(circle at 90% 18%, rgba(113, 25, 48, 0.42), transparent 28%),
    linear-gradient(140deg, #120909 0%, #251113 44%, #3a171d 100%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: inherit;
}

.version {
  position: fixed;
  top: 8px;
  right: 12px;
  z-index: 20;
  color: rgba(255, 247, 236, 0.56);
  font-size: 11px;
  font-weight: 900;
}

.orientation-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 14px;
  z-index: 40;
  display: grid;
  gap: 3px;
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 10px;
  background: rgba(24, 10, 9, 0.9);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.38);
  color: var(--text);
  padding: 12px 48px 12px 14px;
}

.orientation-hint[hidden] {
  display: none;
}

.orientation-hint strong {
  color: var(--gold);
  font-size: 13px;
  text-transform: uppercase;
}

.orientation-hint span {
  color: rgba(255, 247, 236, 0.82);
  font-size: 13px;
  font-weight: 800;
}

.orientation-hint button {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 30px;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  padding: 0;
}

.shell {
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar,
.panel,
.stage-card,
.toolbar {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(58, 24, 26, 0.92), rgba(26, 12, 12, 0.88));
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.24);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 14px 16px;
}

.brand-logo {
  display: block;
  width: 240px;
  max-width: 30vw;
  height: auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 4px;
  font-size: clamp(28px, 4vw, 58px);
  line-height: 0.95;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.topbar h1 {
  max-width: 100%;
  font-size: clamp(28px, 3.4vw, 54px);
}

h2 {
  margin-bottom: 12px;
  font-size: clamp(24px, 2.4vw, 36px);
}

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

.button,
button {
  appearance: none;
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: var(--gold);
  color: #1a0d0d;
  cursor: pointer;
  font: inherit;
  font-weight: 950;
  padding: 9px 16px;
  text-decoration: none;
}

.button.ghost,
button.ghost {
  background: rgba(255, 247, 236, 0.08);
  color: var(--text);
}

.button.danger,
button.danger {
  background: var(--red);
  color: white;
}

.button.small,
button.small {
  min-height: 30px;
  padding: 6px 11px;
  font-size: 12px;
}

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

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

.stage-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  text-decoration: none;
}

.stage-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
}

.stage-open-button,
.stage-live-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stage-open-button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: var(--gold);
  color: #1a0d0d;
  font-size: 14px;
  font-weight: 950;
  padding: 8px 14px;
  text-align: center;
}

.stage-live-pill {
  min-width: 102px;
  min-height: 44px;
  border: 1px solid rgba(255, 209, 102, 0.32);
  background: rgba(255, 209, 102, 0.08);
  color: #f3d6a6;
  font-size: 18px;
  font-weight: 950;
  padding: 8px 12px;
}

.stage-card h2 {
  margin-bottom: 2px;
  font-size: 28px;
}

.stage-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stage-stat {
  min-height: 76px;
  border: 1px solid rgba(255, 235, 210, 0.13);
  background: rgba(16, 8, 7, 0.32);
  padding: 12px;
}

.stage-stat span,
.stage-section-title {
  color: #d8b996;
  font-size: 14px;
  font-weight: 950;
  text-transform: uppercase;
}

.stage-stat strong {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-size: 30px;
  line-height: 1;
}

.stage-section-title {
  margin: 8px 0 9px;
}

.stage-meta,
.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: rgba(255, 247, 236, 0.1);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  padding: 6px 9px;
}

.pill.gold {
  background: rgba(255, 209, 102, 0.18);
  color: var(--gold);
}

.podium-list,
.ontrack-list {
  display: grid;
  gap: 7px;
}

.result-row,
.ontrack-row {
  display: grid;
  grid-template-columns: 46px 72px minmax(0, 1fr) 120px;
  gap: 9px;
  align-items: center;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(10, 5, 5, 0.36);
  padding: 7px 9px;
}

.stage-card .result-row {
  grid-template-columns: 38px 68px minmax(0, 1fr) 170px;
}

.stage-card .ontrack-row {
  grid-template-columns: 38px 68px minmax(0, 1fr) 112px;
}

.result-row.podium.gold {
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.34), rgba(10, 5, 5, 0.32));
  border-color: rgba(255, 209, 102, 0.7);
}

.result-row.podium.silver {
  background: linear-gradient(90deg, rgba(210, 219, 229, 0.26), rgba(10, 5, 5, 0.32));
  border-color: rgba(230, 235, 240, 0.48);
}

.result-row.podium.bronze {
  background: linear-gradient(90deg, rgba(198, 126, 73, 0.28), rgba(10, 5, 5, 0.32));
  border-color: rgba(218, 143, 89, 0.58);
}

tr.stage-podium.gold {
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.25), rgba(255, 209, 102, 0.06));
}

tr.stage-podium.silver {
  background: linear-gradient(90deg, rgba(210, 219, 229, 0.2), rgba(210, 219, 229, 0.05));
}

tr.stage-podium.bronze {
  background: linear-gradient(90deg, rgba(198, 126, 73, 0.22), rgba(198, 126, 73, 0.05));
}

tr.stage-podium.gold td:first-child,
tr.stage-podium.silver td:first-child,
tr.stage-podium.bronze td:first-child {
  color: var(--gold);
  font-weight: 950;
}

.ontrack-row.last-start.is-running {
  border-color: rgba(141, 255, 188, 0.42);
  background: rgba(19, 52, 35, 0.28);
}

.ontrack-row.just-started {
  animation: start-flash 0.35s alternate 9;
}

.ontrack-row.just-finished {
  animation: finish-flash 0.35s alternate 9;
}

.empty.compact {
  min-height: 78px;
  display: flex;
  align-items: center;
  border: 1px dashed rgba(255, 235, 210, 0.12);
}

@keyframes start-flash {
  from {
    border-color: rgba(255, 209, 102, 0.35);
    box-shadow: none;
  }
  to {
    border-color: rgba(141, 255, 188, 0.95);
    box-shadow: 0 0 22px rgba(141, 255, 188, 0.34);
  }
}

@keyframes finish-flash {
  from {
    border-color: rgba(255, 209, 102, 0.35);
    box-shadow: none;
  }
  to {
    border-color: rgba(255, 209, 102, 0.98);
    box-shadow: 0 0 26px rgba(255, 209, 102, 0.42);
  }
}

.result-row .pos,
.ontrack-row .pos {
  color: var(--gold);
  font-weight: 950;
}

.num {
  color: var(--gold);
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.time,
.clock {
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.gap-pill {
  display: inline-flex;
  justify-content: center;
  min-width: 54px;
  margin-left: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 247, 236, 0.12);
  color: var(--text);
  font-size: 11px;
  font-style: normal;
  font-weight: 950;
  padding: 2px 7px;
  vertical-align: middle;
}

.result-time {
  display: grid;
  grid-template-columns: 82px 62px;
  align-items: center;
  justify-content: end;
}

.result-time > span {
  text-align: right;
}

.clock.running {
  color: var(--green);
}

.clock.finished {
  color: var(--sand);
  font-size: 12px;
}

.panel {
  margin-top: 16px;
  min-width: 0;
  padding: 18px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 9px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--sand);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.admin-grid > * {
  min-width: 0;
}

.form-card {
  display: grid;
  gap: 12px;
  min-width: 0;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 247, 236, 0.08);
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

select option {
  background: #fff7ec;
  color: #1a0d0d;
}

select option:checked,
select option:hover {
  background: #93c5fd;
  color: #071321;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.checkline {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

textarea {
  min-height: 94px;
  resize: vertical;
}

.stage-editor,
.mapping-grid {
  display: grid;
  gap: 10px;
}

.stage-editor-row,
.mapping-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
  padding: 10px;
}

.mapping-row {
  grid-template-columns: minmax(140px, 1fr) minmax(160px, 1.4fr);
  align-items: center;
}

.demo-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(110px, 0.6fr) minmax(220px, 1.4fr) auto;
  gap: 10px;
  align-items: end;
}

.penalty-editor {
  display: grid;
  grid-template-columns: minmax(90px, 0.7fr) minmax(180px, 1fr) minmax(130px, 0.7fr) minmax(220px, 1.4fr) auto;
  gap: 10px;
  align-items: end;
}

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

.penalty-row {
  display: grid;
  grid-template-columns: 72px minmax(160px, 1fr) 120px minmax(180px, 1.4fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.16);
  padding: 9px;
}

.penalty-time,
.penalty-mini {
  color: var(--red);
}

.penalty-mini {
  display: inline-block;
  font-size: 10px;
  font-weight: 950;
}

.stage-live-pill.neutralized,
.neutralized-box {
  border-color: rgba(255, 91, 109, 0.48);
  background: rgba(255, 91, 109, 0.12);
  color: #ffd6dc;
}

.stage-editor-row .inline-actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.form-card > .inline-actions:first-child {
  justify-content: space-between;
  align-items: flex-start;
}

.form-card > .inline-actions:first-child h2 {
  font-size: clamp(30px, 3vw, 46px);
}

.notice {
  margin: 10px 0 0;
  color: var(--gold);
  font-weight: 850;
}

.preview-table {
  max-height: 280px;
  overflow: auto;
}

.empty {
  padding: 18px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .stage-grid,
  .topbar,
  .admin-grid,
  .stage-editor-row,
  .demo-grid,
  .penalty-editor,
  .penalty-row,
  .stage-card-head,
  .stage-stats {
    grid-template-columns: 1fr;
  }

  .brand-logo {
    width: 180px;
    max-width: 62vw;
  }

  .shell {
    width: min(100% - 18px, 1500px);
    padding: 10px 0 22px;
  }

  .topbar {
    gap: 9px;
    padding: 10px;
  }

  .topbar h1 {
    font-size: clamp(23px, 7vw, 34px);
  }

  .lead {
    margin-bottom: 0;
    font-size: 13px;
  }

  .toolbar {
    margin-top: 9px;
    padding: 8px 10px;
  }

  .stage-grid {
    gap: 9px;
    margin-top: 9px;
  }

  .stage-card {
    gap: 8px;
    padding: 10px;
  }

  .stage-card h2 {
    font-size: 22px;
    line-height: 1.05;
  }

  .stage-open-button,
  .stage-live-pill {
    min-height: 34px;
    font-size: 13px;
    padding: 6px 10px;
  }

  .stage-stats {
    gap: 6px;
  }

  .stage-stat {
    min-height: 52px;
    padding: 8px;
  }

  .stage-stat span,
  .stage-section-title {
    font-size: 11px;
  }

  .stage-stat strong {
    margin-top: 4px;
    font-size: 22px;
  }

  .stage-section-title {
    margin: 4px 0 5px;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .result-row,
  .ontrack-row {
    grid-template-columns: 34px 54px minmax(0, 1fr);
    min-height: 32px;
    gap: 6px;
    padding: 5px 7px;
  }

  .result-row .time,
  .ontrack-row .clock {
    grid-column: 1 / -1;
    text-align: left;
  }

  .stage-card .result-row,
  .stage-card .ontrack-row {
    grid-template-columns: 28px 50px minmax(0, 1fr) 96px;
  }

  .stage-card .result-row .time,
  .stage-card .ontrack-row .clock {
    grid-column: auto;
    text-align: right;
  }

  .stage-card .result-time {
    grid-template-columns: 56px 36px;
  }

  .empty.compact {
    min-height: 48px;
    padding: 10px;
    font-size: 13px;
  }
}

@media (max-width: 920px) and (orientation: landscape) {
  .shell {
    width: min(100% - 14px, 1500px);
    padding-top: 7px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    padding: 8px 10px;
  }

  .brand-logo {
    width: 130px;
    max-width: 20vw;
  }

  .topbar h1 {
    font-size: clamp(22px, 4vw, 34px);
  }

  .eyebrow,
  .lead {
    font-size: 11px;
  }

  .button,
  button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .toolbar {
    margin-top: 7px;
    padding: 6px 8px;
  }

  .stage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
  }

  .stage-card {
    gap: 6px;
    padding: 8px;
  }

  .stage-card-head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
  }

  .stage-card-head .stage-open-button {
    display: none;
  }

  .stage-card h2 {
    font-size: 19px;
  }

  .stage-live-pill {
    min-width: 84px;
    min-height: 30px;
    font-size: 12px;
    padding: 5px 8px;
  }

  .stage-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .stage-stat {
    min-height: 42px;
    padding: 6px 7px;
  }

  .stage-stat span,
  .stage-section-title {
    font-size: 10px;
  }

  .stage-stat strong {
    font-size: 18px;
  }

  .stage-card .result-row,
  .stage-card .ontrack-row {
    grid-template-columns: 28px 44px minmax(0, 1fr) 84px;
    min-height: 27px;
    gap: 5px;
    padding: 4px 6px;
    font-size: 12px;
  }

  .stage-card .result-row .time,
  .stage-card .ontrack-row .clock {
    grid-column: auto;
    text-align: right;
  }

  .result-time {
    grid-template-columns: 58px 44px;
  }

  .stage-card .result-time {
    grid-template-columns: 50px 32px;
  }

  .gap-pill {
    min-width: 40px;
    margin-left: 4px;
    font-size: 9px;
    padding: 1px 4px;
  }

  .empty.compact {
    min-height: 34px;
    padding: 7px;
    font-size: 12px;
  }
}
