:root {
  --ink: #092f43;
  --muted: #527182;
  --cream: #fff8e9;
  --paper: #fffcf4;
  --orange: #ff6b3d;
  --orange-dark: #e94e24;
  --aqua: #42c6c7;
  --navy: #073f57;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  background: #0a6174;
  font-family: Inter, ui-rounded, "Avenir Next", "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }

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

.setup-view {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 0.92fr) minmax(420px, 0.78fr);
  align-items: center;
  gap: clamp(48px, 8vw, 130px);
  padding: clamp(36px, 6vw, 90px) max(6vw, 32px);
  overflow: hidden;
  background:
    radial-gradient(circle at 13% 14%, rgba(255,255,255,.55) 0 2px, transparent 3px),
    radial-gradient(circle at 84% 84%, rgba(255,255,255,.4) 0 1px, transparent 2px),
    linear-gradient(125deg, #fff6df 0%, #fffdf7 56%, #d9f1e9 100%);
}

.setup-view::before,
.setup-view::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.setup-view::before {
  width: 48vw;
  height: 48vw;
  min-width: 540px;
  min-height: 540px;
  left: -21vw;
  bottom: -27vw;
  border: 2px solid rgba(49, 172, 178, .18);
  border-radius: 46% 54% 61% 39%;
  box-shadow: 0 0 0 38px rgba(49,172,178,.05), 0 0 0 76px rgba(49,172,178,.04);
}

.setup-view::after {
  width: 240px;
  height: 180px;
  top: 5%;
  right: 4%;
  opacity: .23;
  background: repeating-radial-gradient(ellipse at center, transparent 0 12px, #1c9ca7 13px 14px, transparent 15px 26px);
  transform: rotate(-16deg);
}

.setup-copy, .setup-card { position: relative; z-index: 1; }
.setup-copy { max-width: 600px; padding-left: clamp(0px, 3vw, 50px); }

.brand-mark {
  position: relative;
  width: 84px;
  height: 76px;
  margin-bottom: 28px;
}
.brand-mark::before {
  content: "";
  position: absolute;
  width: 3px;
  height: 59px;
  left: 41px;
  top: 1px;
  border-radius: 4px;
  background: var(--navy);
}
.brand-sail { position: absolute; top: 3px; filter: drop-shadow(0 3px 0 rgba(7,63,87,.08)); }
.brand-sail--left {
  left: 5px;
  width: 34px; height: 50px;
  background: var(--orange);
  clip-path: polygon(100% 0, 100% 100%, 0 82%);
}
.brand-sail--right {
  left: 45px;
  width: 30px; height: 51px;
  background: #46c9c6;
  clip-path: polygon(0 5%, 0 100%, 100% 84%);
}
.brand-hull {
  position: absolute; left: 10px; bottom: 4px; width: 64px; height: 17px;
  background: var(--navy); border-radius: 2px 2px 30px 30px;
  transform: skewX(-8deg);
}

.eyebrow, .step-label, .winner-kicker {
  margin: 0 0 12px;
  color: var(--orange);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .2em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(64px, 7.4vw, 116px);
  font-weight: 700;
  letter-spacing: -.075em;
  line-height: .78;
}
h1 em { color: var(--orange); font-weight: 400; }
.intro {
  max-width: 530px;
  margin: 36px 0 30px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 1.5vw, 23px);
  line-height: 1.55;
}
.feature-row { display: flex; flex-wrap: wrap; gap: 9px; }
.feature-row span {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 13px;
  color: #406575;
  background: rgba(255,255,255,.54);
  border: 1px solid rgba(9,47,67,.08);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.feature-row b { color: var(--navy); font-size: 15px; }

.setup-card {
  width: min(100%, 590px);
  padding: clamp(24px, 3vw, 42px);
  justify-self: start;
  background: rgba(255, 253, 247, .88);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 30px;
  box-shadow: 0 24px 80px rgba(23,83,89,.17), inset 0 1px 0 #fff;
  backdrop-filter: blur(20px);
}
.card-heading, .roster-heading { display: flex; justify-content: space-between; align-items: center; }
.card-heading { margin-bottom: 28px; }
.card-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 31px; letter-spacing: -.03em; }
.step-label { margin-bottom: 5px; font-size: 10px; }
.icon-button, .glass-button {
  border: 0;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.icon-button:hover, .glass-button:hover { transform: translateY(-2px); }
.icon-button {
  width: 42px; height: 42px;
  border-radius: 50%;
  color: var(--navy); background: #e6f3ed;
  font-weight: 900;
}
.icon-button.is-muted, .glass-button.is-muted { opacity: .55; text-decoration: line-through; }

.counter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 84px;
  gap: 12px;
  margin-bottom: 30px;
}
.field-group > label, .field-label {
  display: block; margin-bottom: 8px;
  color: #65808d;
  font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
}
.stepper {
  height: 50px;
  display: grid; grid-template-columns: 38px 1fr 38px; align-items: center;
  background: #eef4ef; border: 1px solid #e2ece7; border-radius: 14px;
}
.stepper button {
  width: 30px; height: 30px; margin: auto;
  border: 0; border-radius: 9px;
  color: #397080; background: rgba(255,255,255,.75);
  font-size: 20px; cursor: pointer;
}
.stepper button:hover { background: #fff; color: var(--orange); }
.stepper output { text-align: center; color: var(--navy); font-size: 18px; font-weight: 900; }
.pc-total {
  height: 78px; padding: 12px 10px; align-self: end;
  text-align: center; background: #e8f5f2; border-radius: 14px;
}
.pc-total .field-label { margin: 0 0 5px; font-size: 9px; }
.pc-total strong { color: #168d91; font-size: 22px; }

.race-format { margin: -10px 0 25px; }
.race-format > .field-label { margin-bottom: 9px; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-toggle > button {
  min-width: 0; padding: 10px 12px;
  text-align: left; color: #66808b; background: #f2f5f1;
  border: 1px solid #e2eae5; border-radius: 12px; cursor: pointer;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.mode-toggle > button:hover { transform: translateY(-1px); }
.mode-toggle > button.is-active { color: #b94a29; background: #fff1e9; border-color: #ff9474; }
.mode-toggle strong, .mode-toggle small { display: block; }
.mode-toggle strong { font-size: 11px; }
.mode-toggle small { margin-top: 2px; opacity: .72; font-size: 9px; }
.tournament-options {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-top: 9px; padding: 9px 10px 9px 13px;
  color: #466775; background: #e8f5f2; border-radius: 12px;
}
.tournament-options[hidden] { display: none; }
.tournament-options strong, .tournament-options small { display: block; }
.tournament-options strong { font-size: 10px; }
.tournament-options small { margin-top: 2px; color: #779099; font-size: 8px; }
.compact-stepper { width: 142px; height: 38px; grid-template-columns: 32px 1fr 32px; flex: 0 0 auto; }
.compact-stepper output { font-size: 11px; }
.compact-stepper button { width: 25px; height: 25px; font-size: 17px; }

.roster-heading { margin-bottom: 10px; color: #466675; font-size: 12px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.roster-heading button {
  border: 0; padding: 5px;
  color: var(--orange); background: transparent;
  font-size: 11px; font-weight: 900; text-transform: uppercase; cursor: pointer;
}
.roster { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; max-height: 246px; overflow: auto; padding: 1px 4px 1px 1px; }
.roster-entry {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center;
  min-width: 0; padding: 8px 9px;
  background: #fff; border: 1px solid #e7ece7; border-radius: 12px;
  transition: border .2s ease, transform .2s ease;
}
.roster-entry:focus-within { border-color: #5ac7c5; transform: translateY(-1px); }
.roster-number {
  width: 26px; height: 26px; display: grid; place-items: center;
  color: #fff; background: var(--entry-color, var(--navy)); border-radius: 8px;
  font-size: 10px; font-weight: 900;
}
.roster-entry input { min-width: 0; width: 100%; border: 0; outline: 0; color: var(--navy); background: transparent; font-size: 13px; font-weight: 800; }
.roster-entry input::placeholder { color: #9eb0b7; }
.entrant-type {
  padding: 4px 6px; border-radius: 5px;
  color: #6c828c; background: #edf3f1;
  font-size: 8px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase;
}
.entrant-type.human { color: #b94926; background: #fff0e8; }

.start-button {
  width: 100%; height: 58px; margin-top: 25px; padding: 0 12px 0 23px;
  display: flex; align-items: center; justify-content: space-between;
  border: 0; border-radius: 16px;
  color: #fff; background: var(--orange);
  box-shadow: 0 12px 24px rgba(255,107,61,.25);
  font-size: 15px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase;
  cursor: pointer;
  transition: transform .17s ease, box-shadow .17s ease, background .17s ease;
}
.start-button:hover { transform: translateY(-2px); background: var(--orange-dark); box-shadow: 0 15px 30px rgba(255,107,61,.32); }
.start-arrow { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--orange); background: #fff; font-size: 20px; }
.fine-print { margin: 12px 0 0; color: #8ca0a8; text-align: center; font-size: 11px; }
.creator-link {
  width: max-content; display: block; margin: 9px auto 0;
  color: #3c7885; font-size: 10px; font-weight: 800; letter-spacing: .04em;
  text-decoration: none; transition: color .15s ease, transform .15s ease;
}
.creator-link:hover { color: var(--orange); transform: translateX(-2px); }
.creator-link:focus-visible { outline: 2px solid var(--orange); outline-offset: 4px; border-radius: 2px; }

.race-view { position: relative; height: 100vh; min-height: 560px; overflow: hidden; background: #168fa4; }
.setup-view[hidden], .race-view[hidden], .finish-overlay[hidden] { display: none; }
#raceCanvas { display: block; width: 100%; height: 100%; }

.race-header {
  position: absolute; inset: 0 0 auto 0; z-index: 4;
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 26px;
  pointer-events: none;
}
.race-brand { display: flex; align-items: center; gap: 11px; color: #fff; text-shadow: 0 2px 10px rgba(4,57,70,.24); }
.race-brand span, .race-brand strong { display: block; font-family: Georgia, serif; line-height: .9; }
.race-brand span { font-size: 17px; }
.race-brand strong { color: #ffe5a1; font-size: 20px; font-style: italic; }
.mini-sail { width: 30px; height: 37px; background: linear-gradient(90deg, #ff7147 0 47%, transparent 48%), linear-gradient(270deg, #ffdfa0 0 47%, transparent 48%); clip-path: polygon(48% 0, 100% 77%, 51% 67%, 51% 100%, 46% 100%, 46% 67%, 0 77%); }
.course-pill {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px 9px 11px;
  color: #fff; background: rgba(5,62,78,.56); border: 1px solid rgba(255,255,255,.22); border-radius: 15px;
  box-shadow: 0 7px 22px rgba(6,48,62,.14); backdrop-filter: blur(10px);
}
.course-pill > span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: #ffe7a9; background: rgba(255,255,255,.12); font-size: 20px; font-weight: 900; }
.course-pill small, .course-pill strong { display: block; }
.course-pill small { margin-bottom: 2px; opacity: .72; font-size: 8px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.course-pill strong { font-size: 12px; }
.race-actions { display: flex; gap: 8px; pointer-events: auto; }
.glass-button { height: 38px; min-width: 38px; padding: 0 14px; color: #fff; background: rgba(5,62,78,.53); border: 1px solid rgba(255,255,255,.2); border-radius: 11px; backdrop-filter: blur(10px); font-size: 11px; font-weight: 800; }

.leaderboard {
  position: absolute; z-index: 4; left: 24px; top: 104px;
  width: 224px; padding: 16px;
  color: #fff; background: rgba(4,57,72,.68); border: 1px solid rgba(255,255,255,.18); border-radius: 18px;
  box-shadow: 0 15px 40px rgba(3,44,59,.16); backdrop-filter: blur(13px);
}
.leaderboard-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding: 0 3px; }
.leaderboard-title small, .leaderboard-title strong { display: block; }
.leaderboard-title small { color: #78dee0; font-size: 8px; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
.leaderboard-title strong { margin-top: 2px; font-family: Georgia, serif; font-size: 18px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff7050; box-shadow: 0 0 0 5px rgba(255,112,80,.14); animation: pulse 1.3s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px rgba(255,112,80,0); } }
.leaderboard ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.standing-row {
  display: grid; grid-template-columns: 17px 9px 1fr auto; align-items: center; gap: 7px;
  min-width: 0; padding: 7px 7px;
  border-radius: 9px; background: rgba(255,255,255,.055);
  transition: transform .35s ease, background .2s ease;
}
.standing-row.is-leading { background: rgba(255,225,154,.17); }
.standing-position { color: rgba(255,255,255,.65); font-size: 9px; font-weight: 900; }
.standing-swatch { width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255,255,255,.45); }
.standing-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 800; }
.standing-gap { color: rgba(255,255,255,.62); font-size: 8px; font-weight: 800; }

.race-clock {
  position: absolute; z-index: 4; right: 25px; bottom: 24px;
  min-width: 112px; padding: 10px 16px;
  color: #fff; text-align: right; background: rgba(4,57,72,.65); border: 1px solid rgba(255,255,255,.2); border-radius: 14px; backdrop-filter: blur(10px);
}
.race-clock small, .race-clock strong { display: block; }
.race-clock small { opacity: .65; font-size: 8px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.race-clock strong { margin-top: 2px; font-size: 19px; font-variant-numeric: tabular-nums; }

.countdown {
  position: absolute; z-index: 8; inset: 0; display: grid; place-items: center;
  color: #fff; font-family: Georgia, serif; font-size: min(30vw, 240px); font-weight: 700;
  text-shadow: 0 7px 0 rgba(3,62,78,.18), 0 20px 70px rgba(3,62,78,.3);
  pointer-events: none;
}
.countdown:empty { display: none; }
.countdown.pop { animation: count-pop .6s ease-out; }
@keyframes count-pop { from { opacity: 0; transform: scale(.65); } 35% { opacity: 1; transform: scale(1.08); } to { opacity: 0; transform: scale(1); } }

.gust-notice {
  position: absolute; z-index: 5; left: 50%; top: 105px; transform: translate(-50%, -15px);
  padding: 9px 16px 9px 12px;
  color: #17485a; background: rgba(255,251,230,.92); border-radius: 999px;
  box-shadow: 0 8px 25px rgba(5,58,72,.16);
  font-size: 10px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase;
  opacity: 0; transition: opacity .3s ease, transform .3s ease; pointer-events: none;
}
.gust-notice::before { content: "〰"; margin-right: 7px; color: #f56d41; font-size: 16px; vertical-align: -1px; }
.gust-notice.show { opacity: 1; transform: translate(-50%, 0); }

.finish-overlay {
  position: absolute; z-index: 12; inset: 0;
  display: grid; place-items: center; padding: 24px;
  background: rgba(3,45,59,.48); backdrop-filter: blur(7px);
}
.winner-card {
  width: min(94vw, 560px); padding: 34px 40px 30px;
  text-align: center; background: var(--paper); border-radius: 28px;
  box-shadow: 0 30px 90px rgba(1,33,45,.32);
  animation: winner-in .55s cubic-bezier(.2,.9,.25,1.2);
}
@keyframes winner-in { from { opacity: 0; transform: translateY(30px) scale(.9); } }
.winner-kicker { margin-bottom: 9px; font-size: 10px; }
.winner-card h2 { margin: 6px 0; font-family: Georgia, serif; font-size: 42px; letter-spacing: -.04em; }
.winner-card > p:not(.winner-kicker) { margin: 0 0 20px; color: #708790; font-family: Georgia, serif; font-style: italic; }
.winner-boat { position: relative; width: 90px; height: 65px; margin: 0 auto; }
.winner-boat::before { content: ""; position: absolute; left: 43px; top: 0; width: 4px; height: 49px; border-radius: 4px; background: #123e50; }
.winner-boat::after { content: ""; position: absolute; left: 13px; bottom: 3px; width: 66px; height: 16px; border-radius: 2px 2px 30px 30px; background: var(--winner-color, #ff6b3d); }
.winner-boat { background: linear-gradient(135deg, transparent 49%, var(--winner-color, #ff6b3d) 50%) 11px 3px / 33px 44px no-repeat, linear-gradient(225deg, transparent 49%, #fff2c5 50%) 47px 7px / 31px 40px no-repeat; }
.final-podium { list-style: none; margin: 0 0 22px; padding: 0; display: flex; justify-content: center; gap: 10px; }
.final-podium li { min-width: 105px; padding: 9px; border-radius: 11px; color: #496673; background: #edf3ef; font-size: 10px; font-weight: 800; }
.final-podium b { display: block; margin-bottom: 2px; color: var(--navy); font-size: 12px; }
.tournament-results { margin: 0 0 22px; text-align: left; }
.tournament-results[hidden], .final-podium[hidden] { display: none; }
.tournament-table-head,
.tournament-results li {
  display: grid; grid-template-columns: 1fr 46px 52px; align-items: center; gap: 8px;
}
.tournament-table-head {
  padding: 0 11px 6px; color: #80949c;
  font-size: 8px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase;
}
.tournament-table-head span:not(:first-child), .tournament-results li > span:not(.tournament-name) { text-align: right; }
.tournament-results ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 234px; overflow: auto; }
.tournament-results li { padding: 7px 11px; color: #54707c; background: #edf3ef; border-radius: 9px; font-size: 10px; font-weight: 800; }
.tournament-results li.is-leader { color: #9c482a; background: #fff0e7; }
.tournament-name { display: flex; align-items: center; min-width: 0; gap: 7px; }
.tournament-name i { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; }
.tournament-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--navy); font-size: 11px; }
.tournament-points { color: var(--orange); font-weight: 900; }
.winner-actions { display: flex; gap: 10px; }
.winner-actions button { flex: 1; height: 45px; border-radius: 12px; font-size: 11px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.primary-small { color: #fff; background: var(--orange); border: 1px solid var(--orange); }
.secondary-small { color: var(--navy); background: transparent; border: 1px solid #cad8d5; }

@media (max-width: 940px) {
  .setup-view { grid-template-columns: 1fr; gap: 35px; padding: 48px max(5vw, 20px); }
  .setup-copy { max-width: 680px; padding-left: 0; }
  .brand-mark { transform: scale(.8); transform-origin: left bottom; margin-bottom: 12px; }
  h1 { font-size: clamp(61px, 14vw, 92px); }
  .intro { margin: 26px 0 22px; }
  .setup-card { justify-self: center; }
  .leaderboard { top: auto; left: 12px; bottom: 12px; width: 195px; padding: 12px; }
  .race-clock { right: 12px; bottom: 12px; }
}

@media (max-width: 620px) {
  .setup-view { padding-top: 30px; }
  .setup-copy { text-align: center; }
  .brand-mark { margin-left: auto; margin-right: auto; transform-origin: center bottom; }
  .feature-row { justify-content: center; }
  .setup-card { padding: 22px 18px; border-radius: 23px; }
  .counter-grid { grid-template-columns: 1fr 1fr 68px; gap: 7px; }
  .pc-total { padding-left: 3px; padding-right: 3px; }
  .roster { grid-template-columns: 1fr; max-height: 276px; }
  .race-header { padding: 12px; }
  .race-brand { display: none; }
  .course-pill { padding: 7px 10px; }
  .course-pill > span { display: none; }
  .exit-button { padding: 0 9px; }
  .leaderboard { width: 174px; max-height: 218px; overflow: hidden; }
  .leaderboard ol { max-height: 158px; overflow-y: auto; padding-right: 2px; scrollbar-width: thin; }
  .standing-row { padding: 5px; }
  .gust-notice { top: 75px; }
  .winner-card { padding: 28px 20px 22px; }
  .winner-card h2 { font-size: 35px; }
  .final-podium li { min-width: 0; flex: 1; }
  .tournament-results ol { max-height: 205px; }
}

@media (max-height: 559px) {
  .race-view { height: 100vh; min-height: 100vh; height: 100dvh; min-height: 100dvh; }
  .leaderboard {
    max-height: calc(100vh - 84px);
    max-height: calc(100dvh - 84px);
    overflow: hidden;
  }
  .leaderboard ol {
    max-height: calc(100vh - 154px);
    max-height: calc(100dvh - 154px);
    overflow-y: auto;
    padding-right: 2px;
    scrollbar-width: thin;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
