:root {
  color-scheme: light;
  --ink: #141414;
  --muted: #656b73;
  --line: #d9dde3;
  --paper: #f7f6f1;
  --panel: #ffffff;
  --track: #151515;
  --red: #d8172f;
  --gold: #f7c531;
  --green: #0b7b61;
  --blue: #2257a8;
  --shadow: 0 18px 42px rgba(20, 20, 20, 0.11);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(216, 23, 47, 0.08), transparent 30%),
    radial-gradient(circle at 95% 8%, rgba(247, 197, 49, 0.18), transparent 20%),
    var(--paper);
}

body::before {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: -1;
  height: 18px;
  content: "";
  background:
    linear-gradient(45deg, #111 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(45deg, transparent 75%, #111 75%) 0 0 / 18px 18px,
    linear-gradient(45deg, transparent 75%, #111 75%) 9px -9px / 18px 18px,
    linear-gradient(45deg, #111 25%, #fff 25%) 9px -9px / 18px 18px;
}

.boot-loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(247, 246, 241, 0.92);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

body.is-app-loading .boot-loader {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.boot-loader__panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(330px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-align: center;
  background: #fff;
  box-shadow: var(--shadow);
}

.boot-loader__panel span:last-child {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.boot-loader__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(216, 23, 47, 0.22);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  position: relative;
  min-height: 42px;
  border: 1px solid var(--track);
  border-radius: var(--radius);
  color: var(--track);
  background: #fff;
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(20, 20, 20, 0.12);
}

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

button.is-loading {
  cursor: progress;
  opacity: 0.72;
  padding-right: 38px;
}

button.is-loading::after {
  position: absolute;
  top: 50%;
  right: 13px;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.primary {
  border-color: var(--red);
  color: #fff;
  background: var(--red);
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 56px 24px 22px;
}

.photo-ribbon {
  position: relative;
  max-width: 1180px;
  height: clamp(190px, 24vw, 300px);
  margin: 0 auto 18px;
  overflow: hidden;
  border: 1px solid rgba(20, 20, 20, 0.16);
  border-radius: var(--radius);
  background: #111;
  box-shadow: var(--shadow);
}

.photo-ribbon::before,
.photo-ribbon::after {
  position: absolute;
  inset: 0;
  z-index: 2;
  content: "";
  pointer-events: none;
}

.photo-ribbon::before {
  background:
    linear-gradient(90deg, rgba(20, 20, 20, 0.36), transparent 22%, transparent 78%, rgba(20, 20, 20, 0.24)),
    linear-gradient(0deg, rgba(20, 20, 20, 0.24), transparent 42%);
}

.photo-ribbon::after {
  opacity: 0.12;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%) 0 0 / 24px 24px,
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.22) 75%) 0 0 / 24px 24px,
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.22) 75%) 12px -12px / 24px 24px,
    linear-gradient(45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%) 12px -12px / 24px 24px;
}

.photo-ribbon__track,
.photo-ribbon__slide {
  height: 100%;
}

.photo-ribbon__track {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  width: max-content;
  overflow-x: hidden;
  scroll-behavior: auto;
  will-change: transform;
}

.photo-ribbon:hover .photo-ribbon__track {
  cursor: grab;
}

.photo-ribbon__slide {
  flex: 0 0 auto;
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.26);
}

.photo-ribbon img {
  display: block;
  width: auto;
  height: 100%;
  max-width: min(72vw, 520px);
  object-fit: contain;
}

@media (prefers-reduced-motion: reduce) {
  .photo-ribbon__track {
    width: auto;
    overflow-x: auto;
    transform: none !important;
  }
}

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

h1 {
  max-width: none;
  font-size: clamp(2.4rem, 6.2vw, 5rem);
  line-height: 0.9;
  letter-spacing: 0;
  white-space: nowrap;
  text-transform: uppercase;
}

h2 {
  font-size: 1.12rem;
  line-height: 1.1;
}

h3 {
  font-size: 1rem;
  line-height: 1.15;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
  background: #fff;
}

.status-pill--warm {
  border-color: rgba(247, 197, 49, 0.9);
  background: #fff6c7;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

.stage-card {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(280px, 1.2fr) auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.stage-card p {
  color: var(--muted);
  line-height: 1.45;
}

.stage-steps {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.stage-steps span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 900;
  background: #fff;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr) minmax(260px, 1fr);
  gap: 14px;
}

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

.join-panel,
.picks-panel,
.leaderboard-panel {
  min-height: 262px;
  padding: 18px;
}

.panel-heading,
.leader-toolbar,
.pick-header,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stack,
.inline-form,
.race-control {
  display: grid;
  gap: 12px;
}

.inline-form {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-top: 20px;
}

.player-login-form {
  grid-template-columns: 1fr minmax(98px, 0.34fr) auto;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}

textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.45;
}

.join-panel .stack {
  margin-top: 18px;
}

.result-box,
.active-player,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.result-box {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbfb;
}

.active-player {
  margin-top: 16px;
  padding: 12px;
  border-left: 4px solid var(--gold);
  background: #fff9dc;
}

.mini-board {
  display: grid;
  gap: 8px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.mini-board li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  font-weight: 800;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 22px 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.tab {
  border-color: transparent;
  background: transparent;
}

.tab.is-active {
  color: #fff;
  background: var(--track);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.toolbar {
  margin-bottom: 16px;
}

.search-box {
  flex: 1;
}

.select-box {
  width: min(240px, 40vw);
}

.driver-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(242px, 1fr));
  gap: 14px;
}

.driver-card {
  position: relative;
  display: grid;
  grid-template-rows: 170px auto;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.driver-card.is-picked {
  border-color: var(--red);
  box-shadow: inset 0 0 0 2px var(--red);
}

.driver-card.is-reserved:not(.is-picked) {
  opacity: 0.55;
}

.driver-media {
  position: relative;
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 170px;
  padding: 12px;
  background:
    linear-gradient(90deg, rgba(20, 20, 20, 0.92), rgba(20, 20, 20, 0.72)),
    #1c1c1c;
}

.driver-media .portrait {
  position: absolute;
  right: 10px;
  bottom: 0;
  width: 118px;
  height: 158px;
  object-fit: contain;
  object-position: bottom right;
}

.driver-media .car {
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 0;
  width: calc(100% - 18px);
  max-height: 82px;
  object-fit: contain;
  object-position: bottom left;
}

.driver-number {
  position: relative;
  z-index: 2;
  min-width: 52px;
  width: max-content;
  padding: 5px 8px;
  border: 2px solid #fff;
  border-radius: 6px;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 900;
  text-align: center;
}

.driver-start {
  position: relative;
  z-index: 2;
  width: max-content;
  padding: 5px 9px;
  border: 2px solid #fff;
  border-radius: 6px;
  color: #111;
  font-size: 0.82rem;
  font-weight: 900;
  background: var(--gold);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.24);
}

.driver-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.driver-team {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.point-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.point-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 900;
  background: var(--green);
}

.point-chip.alt {
  background: var(--blue);
}

.pick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.pick-actions--single {
  grid-template-columns: 1fr;
}

.pick-actions .winner-button.is-winner,
.pick-actions .pick-button.is-picked {
  color: #fff;
  background: var(--track);
}

.pick-header {
  margin-bottom: 16px;
}

.draft-status {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.draft-card {
  display: grid;
  gap: 4px;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  background: #fff;
}

.draft-card--live {
  border-left-color: var(--red);
  background: #fff8f8;
}

.draft-card span,
.draft-card small {
  color: var(--muted);
  line-height: 1.4;
}

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

.draft-board-player {
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.draft-board-player span {
  color: var(--muted);
  font-size: 0.82rem;
}

.draft-board-player.is-on-clock {
  border-color: var(--red);
  box-shadow: inset 0 0 0 2px rgba(216, 23, 47, 0.2);
}

.draft-board-player.is-active-player {
  background: #fff9dc;
}

.counter {
  min-width: 76px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 900;
  text-align: center;
  background: #fff;
}

.sticky-actions {
  position: sticky;
  bottom: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.leader-toolbar {
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

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

td.points {
  font-size: 1.25rem;
  font-weight: 900;
}

.driver-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.driver-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  background: #fff;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 14px;
}

.admin-grid .panel {
  padding: 18px;
}

.admin-list {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.draft-admin {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.draft-admin[hidden] {
  display: none;
}

.admin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.admin-row small {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.admin-row-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.danger-zone {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.danger-zone[hidden] {
  display: none;
}

.danger-zone button,
.admin-row-actions .danger,
#revertFinal {
  border-color: var(--red);
  color: var(--red);
}

.race-control {
  margin-top: 16px;
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 800;
  background: var(--track);
  box-shadow: var(--shadow);
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 36px;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .workbench,
  .stage-card,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .stage-steps {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .topbar,
  .photo-ribbon,
  main,
  footer {
    padding-right: 14px;
    padding-left: 14px;
  }

  .photo-ribbon {
    width: calc(100% - 28px);
    padding: 0;
  }

  .topbar {
    padding-top: 44px;
  }

  h1 {
    white-space: normal;
  }

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

  .toolbar,
  .leader-toolbar,
  .pick-header,
  .sticky-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .select-box {
    width: 100%;
  }

  .inline-form,
  .player-login-form,
  .control-row {
    grid-template-columns: 1fr;
  }

  .driver-grid {
    grid-template-columns: 1fr;
  }
}
