*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: -webkit-fill-available;
}

html,
body {
  margin: 0;
  height: var(--viewport-height);
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: #0c4a6e;
}

html.is-standalone,
body.is-standalone {
  height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

:root {
  --viewport-height: 100vh;
  --viewport-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bottom-ui-inset: calc(var(--hud-inset) + var(--safe-bottom));
  --wind-panel-width: 248px;
  --wind-head-height: 40px;
  --wind-chart-height: 68px;
  --wind-panel-padding: 8px;
  --wind-panel-gap: 6px;
  --touch-controls-height: 0px;
  --wind-panel-height: 0px;
  --coord-bar-height: 26px;
  --hud-inset: 12px;
  --arrow-gutter: 22px;
  --status-bar-clearance: calc(var(--hud-inset) + var(--coord-bar-height) + var(--hud-inset));
}

#game {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.mark-overlay {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.wind-particles-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

body.is-wind-route.is-wind-particles .wind-particles-overlay,
body.show-wind-particles .wind-particles-overlay {
  display: block;
}

body.is-test-route .mark-overlay {
  display: none;
}

body.is-spectator-route .race-room,
body.is-spectator-route .race-hud,
body.is-spectator-route .race-status,
body.is-spectator-route .game-help,
body.is-spectator-route .touch-controls,
body.is-spectator-route .game-tutorial,
body.is-spectator-route .mark-overlay,
body.is-spectator-route #debug-panel {
  display: none !important;
}

body.is-spectator-route #game {
  display: block;
}

.spectator-placeholder {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: linear-gradient(165deg, #0c4a6e 0%, #082f49 45%, #0f172a 100%);
  color: #e2e8f0;
  text-align: center;
}

.spectator-placeholder[hidden] {
  display: none;
}

.spectator-placeholder__panel {
  max-width: 420px;
  padding: 28px 24px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.88);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.spectator-placeholder__title {
  margin: 0 0 10px;
  font: 600 1.25rem/1.3 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
}

.spectator-placeholder__text {
  margin: 0 0 18px;
  color: #94a3b8;
  font: 15px/1.5 system-ui, -apple-system, sans-serif;
}

.spectator-placeholder__link {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font: 600 14px/1.2 system-ui, -apple-system, sans-serif;
  text-decoration: none;
}

.spectator-placeholder__link:hover {
  border-color: rgba(203, 213, 225, 0.45);
  background: rgba(51, 65, 85, 0.95);
}

.spectator-hud {
  position: fixed;
  top: calc(var(--hud-inset) + var(--safe-top));
  left: 50%;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - var(--hud-inset) * 2 - var(--safe-left) - var(--safe-right));
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.88);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
  pointer-events: auto;
}

.spectator-hud[hidden] {
  display: none;
}

.spectator-hud__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 600 0.875rem/1.2 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
}

.spectator-hud__link {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font: 600 12px/1.2 system-ui, -apple-system, sans-serif;
  text-decoration: none;
}

.spectator-hud__link:hover {
  border-color: rgba(203, 213, 225, 0.45);
  background: rgba(51, 65, 85, 0.95);
}

.spectator-hud__join {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(74, 222, 128, 0.45);
  background: rgba(22, 101, 52, 0.75);
  color: #ecfdf5;
  font: 600 12px/1.2 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.spectator-hud__join:hover {
  background: rgba(22, 101, 52, 0.95);
}

.spectator-hud__join[hidden] {
  display: none;
}

.race-hud__spectate {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font: 600 12px/1.2 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.start-countdown-cue {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.start-countdown-cue[hidden] {
  display: none;
}

.start-countdown-cue__text {
  max-width: min(92vw, 900px);
  font: 800 clamp(3rem, 16vw, 7rem) / 1.05 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
  text-align: center;
  letter-spacing: -0.02em;
  opacity: 1;
  transition: opacity 0.65s ease-out;
  text-shadow:
    0 4px 24px rgba(0, 0, 0, 0.55),
    0 0 48px rgba(15, 23, 42, 0.85);
}

.start-countdown-cue__text--pop {
  animation: start-countdown-cue-pop 0.25s ease-out;
}

.start-countdown-cue__text--fade-out {
  opacity: 0;
}

.start-countdown-cue__text--go {
  font-size: clamp(4rem, 20vw, 9rem);
  color: #4ade80;
}

.start-countdown-cue__text--final {
  font-size: clamp(0.75rem, 4vw, 1.75rem);
  text-shadow:
    0 1px 6px rgba(0, 0, 0, 0.55),
    0 0 12px rgba(15, 23, 42, 0.85);
}

.start-countdown-cue__text--final.start-countdown-cue__text--go {
  font-size: clamp(1rem, 5vw, 2.25rem);
}

@keyframes start-countdown-cue-pop {
  from {
    opacity: 0.35;
    transform: scale(0.92);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.start-jump-prompt {
  position: fixed;
  left: 50%;
  bottom: max(5.5rem, calc(env(safe-area-inset-bottom, 0px) + 4.5rem));
  z-index: 19;
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 0.75rem 1.1rem;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.start-jump-prompt[hidden] {
  display: none;
}

.start-jump-prompt__text {
  margin: 0;
  font: 600 0.95rem/1.35 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
  text-align: center;
}

.race-finish-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  pointer-events: auto;
}

.race-finish-modal[hidden] {
  display: none;
}

.race-finish-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
}

.race-finish-modal__dialog {
  position: relative;
  width: min(420px, 100%);
  max-height: min(85vh, 640px);
  overflow: auto;
  padding: 22px 20px 18px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.96);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}

.race-finish-modal__title {
  margin: 0 0 8px;
  font: 700 1.25rem/1.25 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
  text-align: center;
}

.race-finish-modal__result {
  margin: 0 0 16px;
  font: 600 1rem/1.4 system-ui, -apple-system, sans-serif;
  color: #cbd5e1;
  text-align: center;
}

.race-finish-modal__standings {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.race-finish-modal__row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.7);
}

.race-finish-modal__row--local {
  outline: 1px solid rgba(250, 204, 21, 0.55);
  background: rgba(30, 41, 59, 0.95);
}

.race-finish-modal__swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.8);
}

.race-finish-modal__sail-number {
  min-width: 2.5rem;
  font: 600 0.75rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #94a3b8;
}

.race-finish-modal__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 600 0.875rem/1.2 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
}

.race-finish-modal__status {
  font: 600 0.8125rem/1.2 system-ui, -apple-system, sans-serif;
  color: #94a3b8;
}

.race-finish-modal__status--finished {
  color: #4ade80;
}

.race-finish-modal__error {
  margin: 0 0 12px;
  font: 14px/1.4 system-ui, -apple-system, sans-serif;
  color: #fca5a5;
  text-align: center;
}

.race-finish-modal__error[hidden] {
  display: none;
}

.race-finish-modal__actions {
  display: flex;
  gap: 10px;
}

.race-finish-modal__btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  font: 600 0.9375rem/1.2 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.race-finish-modal__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.race-finish-modal__btn--ghost {
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
}

.race-finish-modal__btn--ghost:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.95);
}

.race-finish-modal__btn--primary {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(22, 163, 74, 0.9);
  color: #f8fafc;
}

.race-finish-modal__btn--primary:hover:not(:disabled) {
  background: rgba(21, 128, 61, 0.95);
}

.race-status {
  position: fixed;
  left: calc(var(--hud-inset) + var(--safe-left));
  right: calc(var(--hud-inset) + var(--safe-right));
  bottom: var(--bottom-ui-inset);
  z-index: 6;
  height: var(--coord-bar-height);
  margin: 0;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px 10px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  user-select: none;
}

.race-status__course {
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #94a3b8;
  font-weight: 600;
}

.race-status__legs {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 4px;
}

.race-status__sep {
  color: #475569;
  opacity: 0.55;
  font-size: 11px;
}

.race-status__leg {
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid transparent;
}

.race-status__leg--pending {
  color: #64748b;
  opacity: 0.55;
}

.race-status__leg--done {
  color: #94a3b8;
  opacity: 0.7;
}

.race-status__leg--current {
  color: #fef08a;
  font-weight: 700;
  opacity: 1;
  background: rgba(250, 204, 21, 0.18);
  border-color: rgba(250, 204, 21, 0.45);
}

.race-status__finished {
  flex-shrink: 0;
  color: #4ade80;
  font-weight: 700;
  white-space: nowrap;
}

#game.is-dragging {
  cursor: grabbing;
}

#wind-chart,
.wind-panel__chart {
  display: block;
  width: 100%;
  height: var(--wind-chart-height);
  pointer-events: none;
}

.wind-panel {
  position: fixed;
  right: var(--hud-inset);
  left: auto;
  bottom: calc(
    var(--status-bar-clearance) + var(--bottom-ui-inset) + var(--touch-controls-height) +
      var(--hud-inset)
  );
  z-index: 19;
  display: none;
  flex-direction: column;
  gap: var(--wind-panel-gap);
  width: var(--wind-panel-width);
  max-width: calc(100vw - var(--hud-inset) * 2);
  padding: var(--wind-panel-padding);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(6px);
  color: #e2e8f0;
  font: 11px/1.3 system-ui, -apple-system, sans-serif;
  pointer-events: none;
  user-select: none;
}

body.wind-panel-visible {
  --wind-panel-height: calc(
    var(--wind-panel-padding) * 2 + var(--wind-head-height) + var(--wind-panel-gap) +
      var(--wind-chart-height)
  );
}

body.wind-panel-visible.wind-panel-is-minimized {
  --wind-panel-height: calc(var(--wind-panel-padding) * 2 + var(--wind-head-height));
}

body.wind-panel-visible .wind-panel {
  display: flex;
}

body.wind-panel-is-minimized {
  --wind-panel-height: calc(var(--wind-panel-padding) * 2 + var(--wind-head-height));
}

.wind-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--wind-head-height);
}

.wind-panel__actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
}

.wind-panel__toggle {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.55);
  color: #e2e8f0;
  cursor: pointer;
  pointer-events: auto;
}

.wind-panel__toggle-icon {
  display: block;
  font-size: 11px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.wind-panel--minimized .wind-panel__toggle-icon {
  transform: rotate(180deg);
}

.wind-panel--minimized .wind-panel__body {
  display: none;
}

.wind-panel__readout {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.wind-panel__label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.9);
}

.wind-panel__stats,
.wind-panel__detail {
  white-space: nowrap;
}

.wind-panel__stat-sep {
  color: rgba(148, 163, 184, 0.75);
}

.wind-panel__stat--direction {
  color: #38bdf8;
}

.wind-panel__stat--strength {
  color: #fbbf24;
}

.wind-panel__stat--boat {
  color: #ef4444;
}

.wind-panel__detail .wind-panel__stat:not(.wind-panel__stat--boat) {
  color: rgba(203, 213, 225, 0.85);
}

.wind-panel__arrow {
  flex-shrink: 0;
  color: rgba(226, 232, 240, 0.9);
}

.wind-indicator__arrow-head {
  transform-origin: 12px 12px;
}

#test-json-stack {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: none;
  flex-direction: column;
  gap: 10px;
  width: min(340px, 42vw);
  max-height: calc(var(--viewport-height) - var(--coord-bar-height) - 24px);
  overflow-y: auto;
}

#course-editor-stack {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: none;
  flex-direction: column;
  gap: 10px;
  width: min(360px, 44vw);
  max-height: calc(var(--viewport-height) - 24px);
  overflow-y: auto;
}

#course-editor-palette-stack {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: none;
  width: min(196px, 34vw);
}

body.is-test-route #course-editor-palette-stack,
body.is-testrules-route #course-editor-palette-stack,
body.is-course-editor-route #course-editor-palette-stack {
  display: block;
  width: min(220px, 38vw);
}

.course-editor-palette {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font: 13px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
}

.course-editor-palette__title {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-editor-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.course-editor-mode__btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.7);
  color: #cbd5e1;
  border-radius: 6px;
  padding: 7px 8px;
  font: 12px/1.2 system-ui, sans-serif;
  cursor: pointer;
}

.course-editor-mode__btn:hover {
  border-color: rgba(56, 189, 248, 0.45);
  color: #f8fafc;
}

.course-editor-mode__btn.is-active {
  background: rgba(14, 116, 144, 0.45);
  border-color: rgba(56, 189, 248, 0.65);
  color: #f0f9ff;
}

.course-terrain-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.course-terrain-tools__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.course-terrain-tools__label {
  font-size: 11px;
  color: #94a3b8;
}

.course-terrain-tools__input {
  width: 100%;
  box-sizing: border-box;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.75);
  color: #e2e8f0;
  padding: 6px 8px;
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.course-editor-snap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.course-editor-snap__toggle {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #38bdf8;
}

.course-editor-snap__label {
  font-size: 12px;
  color: #cbd5e1;
  cursor: pointer;
  user-select: none;
}

body.is-team-race {
  --wind-chart-height: 0px;
  --wind-head-height: 0px;
  --wind-panel-gap: 0px;
  --wind-panel-padding: 0px;
  --wind-panel-height: 0px;
}

body.is-team-race .wind-panel {
  display: none !important;
}

body.is-test-route {
  --wind-chart-height: 0px;
  --wind-head-height: 0px;
  --wind-panel-gap: 0px;
  --wind-panel-padding: 0px;
  --wind-panel-height: 0px;
  --touch-controls-height: 0px;
  --coord-bar-height: 0px;
  --arrow-gutter: 0px;
}

body.is-test-route .wind-panel,
body.is-test-route #wind-chart,
body.is-test-route .race-status {
  display: none;
}

body.is-test-route #test-json-stack {
  display: flex;
  max-height: calc(var(--viewport-height) - 24px);
}

#testrules-json-stack {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: none;
  flex-direction: column;
  gap: 10px;
  width: min(340px, 42vw);
  max-height: calc(var(--viewport-height) - var(--coord-bar-height) - 24px);
  overflow-y: auto;
}

body.is-testrules-route {
  --wind-chart-height: 0px;
  --wind-head-height: 0px;
  --wind-panel-gap: 0px;
  --wind-panel-padding: 0px;
  --wind-panel-height: 0px;
  --touch-controls-height: 0px;
  --coord-bar-height: 0px;
  --arrow-gutter: 0px;
}

body.is-testrules-route .wind-panel,
body.is-testrules-route #wind-chart,
body.is-testrules-route .race-status,
body.is-testrules-route .touch-controls,
body.is-testrules-route .game-help,
body.is-testrules-route .game-tutorial {
  display: none;
}

body.is-testrules-route #testrules-json-stack {
  display: flex;
  max-height: calc(var(--viewport-height) - 24px);
}

body.is-testrules-route .race-standings {
  display: none;
}

body.is-course-editor-route {
  --wind-chart-height: 0px;
  --wind-head-height: 0px;
  --wind-panel-gap: 0px;
  --wind-panel-padding: 0px;
  --wind-panel-height: 0px;
  --touch-controls-height: 0px;
  --coord-bar-height: 0px;
  --arrow-gutter: 0px;
}

body.is-course-editor-route .wind-panel,
body.is-course-editor-route #wind-chart,
body.is-course-editor-route .race-status,
body.is-course-editor-route .touch-controls,
body.is-course-editor-route .game-help,
body.is-course-editor-route .game-tutorial {
  display: none;
}

body.is-course-editor-route #course-editor-stack {
  display: flex;
  overflow: hidden;
}

body.is-course-editor-route #course-json-panel.course-json-panel--standalone {
  flex: 1;
  min-height: 0;
  max-height: none;
  height: calc(var(--viewport-height) - 24px);
}

body.is-course-editor-route .course-editor-panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}

body.is-course-editor-route .course-legs-list {
  max-height: none;
  overflow: visible;
}

body.is-course-editor-route #course-json-output {
  flex: 0 0 auto;
  height: 11rem;
  min-height: 6rem;
  max-height: 28vh;
  resize: vertical;
}

body.is-wind-route {
  --wind-chart-height: 0px;
  --wind-head-height: 0px;
  --wind-panel-gap: 0px;
  --wind-panel-padding: 0px;
  --wind-panel-height: 0px;
  --touch-controls-height: 0px;
  --coord-bar-height: 0px;
  --arrow-gutter: 0px;
}

body.is-wind-route.wind-panel-visible {
  --wind-chart-height: unset;
  --wind-head-height: unset;
  --wind-panel-gap: unset;
  --wind-panel-padding: unset;
}

body.is-wind-route.wind-panel-visible .wind-panel {
  display: flex;
}

body.is-wind-route.wind-panel-visible #wind-chart {
  display: block;
}

body.is-wind-route .wind-panel,
body.is-wind-route #wind-chart,
body.is-wind-route .race-status,
body.is-wind-route .touch-controls,
body.is-wind-route .game-help,
body.is-wind-route .game-tutorial,
body.is-wind-route .race-standings,
body.is-debug-route .race-standings,
body.is-debug-route .touch-controls,
body.is-debug-route .game-help,
body.is-debug-route .game-tutorial,
body.is-wind-route .mark-overlay {
  display: none;
}

.json-panel__head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.course-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.course-editor-toolbar__link {
  color: #7dd3fc;
  font-size: 12px;
  text-decoration: none;
}

.course-editor-toolbar__link:hover {
  text-decoration: underline;
}

.course-editor-toolbar__name {
  flex: 1 1 120px;
  min-width: 0;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(2, 6, 23, 0.55);
  color: #e2e8f0;
  font: 12px system-ui, sans-serif;
}

.course-editor-toolbar__btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font: 12px system-ui, sans-serif;
  cursor: pointer;
}

.course-editor-toolbar__btn:hover {
  background: rgba(51, 65, 85, 0.95);
}

.course-editor-toolbar__file input {
  display: none;
}

.course-race-settings {
  margin-bottom: 10px;
  padding: 8px;
  border-radius: 6px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.course-race-settings__title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-race-settings__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.course-race-settings__label {
  flex: 0 0 auto;
  font-size: 12px;
  color: #cbd5e1;
}

.course-race-settings__input {
  width: 5.5rem;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(2, 6, 23, 0.55);
  color: #e2e8f0;
  font: 12px system-ui, sans-serif;
}

.course-race-settings__unit {
  font-size: 11px;
  color: #64748b;
}

.course-race-settings__hint {
  margin: 6px 0 0;
  font-size: 10px;
  line-height: 1.35;
  color: #64748b;
}

.course-bounds-settings {
  margin-bottom: 0;
  padding: 8px;
  border-radius: 6px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.course-bounds-settings__title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-bounds-settings__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.course-bounds-settings__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: #94a3b8;
}

.course-bounds-settings__label {
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.course-bounds-settings__input {
  width: 100%;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(2, 6, 23, 0.55);
  color: #e2e8f0;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.course-bounds-settings__fit {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.15);
  color: #e0f2fe;
  font: 12px system-ui, sans-serif;
  cursor: pointer;
}

.course-bounds-settings__fit:hover {
  background: rgba(56, 189, 248, 0.28);
}

.course-bounds-settings__hint {
  margin: 8px 0 0;
  font-size: 10px;
  line-height: 1.35;
  color: #64748b;
}

#track-json-panel,
#course-json-panel,
.rules-editor-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font: 13px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
}

#track-json-panel {
  max-height: min(52vh, 420px);
}

.json-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.json-panel__head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.json-panel__copy {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.15);
  color: #e0f2fe;
  font: 12px system-ui, sans-serif;
  cursor: pointer;
}

.json-panel__copy:hover {
  background: rgba(56, 189, 248, 0.28);
}

#course-json-panel {
  max-height: min(56vh, 460px);
}

.course-legs-section {
  margin-bottom: 10px;
  padding: 8px;
  border-radius: 6px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.course-legs-section__title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-legs-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 110px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.course-leg-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.course-leg-row__index {
  flex-shrink: 0;
  width: 14px;
  color: #64748b;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.course-leg-row__swatch {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.5);
}

.course-leg-row__mark {
  flex: 1;
  min-width: 0;
  color: #e2e8f0;
  font-weight: 600;
}

.course-leg-row__actions {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.course-leg-btn {
  min-width: 22px;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(30, 41, 59, 0.9);
  color: #cbd5e1;
  font: 11px/1.2 system-ui, sans-serif;
  cursor: pointer;
}

.course-leg-btn:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.95);
}

.course-leg-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.course-leg-btn--danger {
  color: #fca5a5;
}

.course-leg-add {
  display: flex;
  gap: 6px;
}

.course-leg-add__select {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  font: 11px system-ui, sans-serif;
}

.course-leg-add__btn {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.15);
  color: #e0f2fe;
  font: 11px system-ui, sans-serif;
  cursor: pointer;
}

.course-leg-add__btn:hover {
  background: rgba(56, 189, 248, 0.28);
}

.course-marks-section {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.course-mark-palette {
  padding: 8px;
  border-radius: 6px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.course-mark-palette--boat {
  margin-top: 0;
}

.course-mark-palette__remove {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(127, 29, 29, 0.35);
  color: #fecaca;
  font: 11px system-ui, sans-serif;
  cursor: pointer;
}

.course-mark-palette__remove:hover {
  background: rgba(153, 27, 27, 0.55);
}

.course-mark-palette__remove[hidden] {
  display: none;
}

.course-mark-palette__title {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-mark-palette__hint {
  margin: 0 0 8px;
  font-size: 10px;
  line-height: 1.35;
  color: #64748b;
}

.course-mark-palette__items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.course-mark-palette__item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 42px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.9);
  cursor: grab;
  touch-action: none;
}

.course-mark-palette__item:hover {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(30, 41, 59, 0.95);
}

.course-mark-palette__item:active {
  cursor: grabbing;
}

.course-mark-palette__item--boat {
  width: 52px;
  height: 64px;
}

.course-mark-palette__ghost--boat {
  width: 52px;
  height: 64px;
}

.course-mark-palette__item svg {
  display: block;
  width: 100%;
  height: 100%;
}

.course-mark-palette__ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  width: 76px;
  height: 42px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px dashed rgba(56, 189, 248, 0.75);
  background: rgba(15, 23, 42, 0.72);
  transform: translate(-50%, -50%);
  opacity: 0.92;
}

.course-mark-palette__ghost svg {
  display: block;
  width: 72px;
  height: auto;
}

body.is-palette-dragging {
  cursor: grabbing;
  user-select: none;
}

.course-mark-palette__items--sprites {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.course-mark-palette__item--sprite {
  width: auto;
  height: 52px;
  min-width: 0;
  padding: 3px;
}

.course-mark-palette__sprite-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.course-mark-palette__item--special {
  width: 52px;
  height: 52px;
  font-size: 24px;
}

.course-special-palette__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 24px;
  line-height: 1;
}

.course-special-palette__icon-img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 36px;
  max-height: 36px;
  object-fit: contain;
  pointer-events: none;
}

.course-mark-palette__ghost--sprite,
.course-mark-palette__ghost--special {
  width: 56px;
  height: 56px;
  padding: 4px;
}

.course-mark-palette__ghost-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.course-objects-section {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.course-objects-section__title {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-objects-section__hint {
  margin: 0 0 8px;
  font-size: 10px;
  line-height: 1.35;
  color: #64748b;
}

.course-objects-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.course-object-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.55);
}

.course-object-row__label {
  min-width: 0;
  flex: 1;
  font-size: 11px;
  color: #cbd5e1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.course-object-row__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.course-object-row--expanded {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.course-object-row__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.course-object-row--expanded .course-object-row__label {
  font-weight: 500;
  color: #e2e8f0;
}

.course-object-row__form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
}

.course-object-row__field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.course-object-row__field--full {
  grid-column: 1 / -1;
}

.course-object-row__field-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-object-row__input,
.course-object-row__select,
.course-object-row__message {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.95);
  color: #f1f5f9;
  font: 11px/1.35 system-ui, sans-serif;
}

.course-object-row__message {
  resize: vertical;
  min-height: 52px;
}

.course-object-row__input:focus,
.course-object-row__select:focus,
.course-object-row__message:focus {
  outline: 2px solid rgba(56, 189, 248, 0.45);
  outline-offset: 1px;
  border-color: rgba(56, 189, 248, 0.35);
}

.course-object-row__sprite-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.course-object-row__sprite-picker .course-object-row__select {
  flex: 1;
}

.course-object-row__sprite-preview {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(30, 41, 59, 0.8);
  padding: 2px;
}

body.is-course-editor-route input::selection,
body.is-course-editor-route textarea::selection,
body.is-course-editor-route select::selection {
  background: rgba(56, 189, 248, 0.45);
  color: #f8fafc;
}

body.is-course-editor-route input::-moz-selection,
body.is-course-editor-route textarea::-moz-selection,
body.is-course-editor-route select::-moz-selection {
  background: rgba(56, 189, 248, 0.45);
  color: #f8fafc;
}

.course-marks-section__title {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.course-marks-section__hint {
  margin: 0 0 8px;
  font-size: 10px;
  line-height: 1.35;
  color: #64748b;
}

.course-marks-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 120px;
  overflow-y: auto;
}

.course-mark-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.course-mark-row__swatch {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.5);
}

.course-mark-row__id {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #cbd5e1;
}

.course-mark-row__toggles {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.course-mark-toggle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #94a3b8;
  font-size: 10px;
  cursor: pointer;
  user-select: none;
}

.course-mark-toggle input {
  margin: 0;
  cursor: pointer;
}

#track-test-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font: 13px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
}

.track-test-summary {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
}

.track-test-summary.is-pass {
  color: #4ade80;
}

.track-test-summary.is-fail {
  color: #f87171;
}

.track-test-summary.is-pending {
  color: #94a3b8;
}

.track-test-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track-test-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  line-height: 1.35;
}

.track-test-item.is-pass .track-test-item__name {
  color: #86efac;
}

.track-test-item.is-fail .track-test-item__name {
  color: #fca5a5;
}

.track-test-item__error {
  color: #fecaca;
  font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-word;
}

#rules-test-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font: 13px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
}

.rules-test-settings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.rules-test-settings__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.rules-test-settings__row--check {
  cursor: pointer;
  user-select: none;
}

.rules-test-settings__label {
  flex: 0 0 72px;
  color: #94a3b8;
}

.rules-test-settings__input {
  width: 72px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(15, 23, 42, 0.6);
  color: #e2e8f0;
  font: inherit;
}

.rules-test-settings__unit {
  color: #64748b;
  font-size: 11px;
}

.rules-test-settings__hint {
  margin: 0;
  font-size: 10px;
  line-height: 1.4;
  color: #64748b;
}

.rules-test-summary {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
}

.rules-test-summary.is-active {
  color: #fbbf24;
}

.rules-test-summary.is-none {
  color: #4ade80;
}

.rules-test-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-test-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  border-radius: 6px;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.2);
  font-size: 11px;
  line-height: 1.35;
}

.rules-test-item__name {
  font-weight: 700;
  color: #fde68a;
}

.rules-test-item__desc {
  color: #cbd5e1;
}

.rules-test-item__boats {
  margin: 4px 0 0;
  padding: 0 0 0 14px;
  color: #fca5a5;
}

.rules-boat-detail__select {
  cursor: pointer;
}

.rules-boats-list__rule-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: rgba(251, 191, 36, 0.2);
  color: #fde68a;
  font: 700 9px/1 system-ui, sans-serif;
}

.course-mark-palette__item--rule-card svg {
  width: 36px;
  height: 36px;
}

.course-mark-palette__ghost--rule-card svg {
  width: 36px;
  height: 36px;
}

.rules-editor-panel {
  flex-shrink: 0;
}

.rules-boats-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.rules-boats-list__item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.5);
  color: #e2e8f0;
  font: 11px/1 system-ui, sans-serif;
  cursor: pointer;
}

.rules-boats-list__item.is-selected {
  border-color: rgba(253, 224, 71, 0.55);
  background: rgba(253, 224, 71, 0.12);
}

.rules-boats-list__swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rules-boat-detail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.rules-boat-detail__row[hidden] {
  display: none !important;
}

.rules-boat-detail__row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: #94a3b8;
}

.rules-boat-detail__input,
.rules-boat-detail__select {
  padding: 5px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(15, 23, 42, 0.6);
  color: #e2e8f0;
  font: 12px system-ui, sans-serif;
}

.rules-boat-detail__range {
  width: 100%;
}

.rules-boat-detail__remove {
  margin-top: 4px;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
  font: 12px system-ui, sans-serif;
  cursor: pointer;
}

.rules-boat-detail__remove:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.rules-boat-detail__track {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.rules-boat-detail__track[hidden] {
  display: none !important;
}

.rules-boat-detail__track-caption {
  flex: 1 1 100%;
  font: 11px/1.3 system-ui, sans-serif;
  color: #94a3b8;
}

.rules-boat-detail__track-btn {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
  font: 11px/1 system-ui, sans-serif;
  cursor: pointer;
}

.rules-boat-detail__track-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.rules-boats-list__item--text {
  border-style: dotted;
}

.rules-boats-list__text-icon {
  display: inline-flex;
  width: 14px;
  justify-content: center;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.course-mark-palette__item--label svg {
  width: 36px;
  height: 36px;
}

.course-mark-palette__ghost--label svg {
  width: 36px;
  height: 36px;
}

.rules-boats-list__item--wind {
  border-style: dashed;
}

.rules-boats-list__wind-icon {
  display: inline-flex;
  width: 14px;
  justify-content: center;
  color: #7dd3fc;
  font-size: 14px;
  line-height: 1;
}

.course-mark-palette__item--wind svg {
  width: 36px;
  height: 36px;
}

.course-mark-palette__ghost--wind svg {
  width: 36px;
  height: 36px;
}

.rules-boat-detail__remove--wind {
  border-color: rgba(125, 211, 252, 0.35);
  background: rgba(125, 211, 252, 0.12);
  color: #bae6fd;
}

#course-json-output {
  flex: 1;
  min-height: 100px;
  width: 100%;
  resize: vertical;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(2, 6, 23, 0.65);
  color: #cbd5e1;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  tab-size: 2;
}

.track-leg-legend {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.track-leg-legend__title {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
}

.track-leg-legend__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.track-leg-legend__item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #cbd5e1;
}

.track-leg-legend__swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.track-leg-legend__label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

#track-json-output {
  flex: 1;
  min-height: 160px;
  width: 100%;
  resize: vertical;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(2, 6, 23, 0.65);
  color: #cbd5e1;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  tab-size: 2;
}

#debug-panel {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  min-width: 200px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font: 13px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
  user-select: none;
}

body.is-debug-route #debug-panel {
  display: block;
}

body.is-debug-route.debug-panel-hidden #debug-panel {
  display: none;
}

.debug-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.debug-panel__hide-btn {
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(2, 6, 23, 0.55);
  color: #cbd5e1;
  font: 11px/1.4 system-ui, sans-serif;
  cursor: pointer;
}

.debug-panel__hide-btn:hover {
  background: rgba(30, 41, 59, 0.85);
}

.debug-panel-show {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.82);
  color: #e2e8f0;
  font: 12px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
  cursor: pointer;
}

body.is-debug-route.debug-panel-hidden .debug-panel-show {
  display: block;
}

body.is-wind-route #wind-debug-panel {
  display: block;
  top: 56px;
  max-height: calc(100vh - 68px);
  overflow-y: auto;
}

body.is-wind-route .wind-layer-tabs {
  display: flex;
}

.wind-layer-tabs {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 11;
  justify-content: center;
  gap: 4px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.88);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}

.wind-layer-tab {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #94a3b8;
  font: 600 13px/1 system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.wind-layer-tab:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
}

.wind-layer-tab.is-active {
  color: #f8fafc;
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.45);
}

#wind-debug-panel {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  min-width: 200px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font: 13px/1.4 system-ui, sans-serif;
  backdrop-filter: blur(6px);
  user-select: none;
}

#wind-debug-panel h2 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

#wind-debug-panel input[type="range"] {
  width: 100%;
  grid-column: 1;
  accent-color: #38bdf8;
}

#wind-debug-step-value,
#wind-debug-scale-value,
#wind-debug-sine-wavelength-value,
#wind-debug-sine-direction-value,
#wind-debug-sine-speed-value,
#wind-debug-perlin-scale-value,
#wind-debug-perlin-direction-value,
#wind-debug-perlin-speed-value,
#wind-debug-perlin-octaves-value,
#wind-debug-perlin-seed-value,
#wind-debug-perlin-regen-interval-value,
#wind-debug-perlin-regen-ease-value,
#wind-debug-perlin-advect-value,
#wind-debug-direction-weight-value,
#wind-debug-speed-weight-value,
#wind-debug-distance-impact-value,
#wind-debug-reach-scale-value,
#wind-debug-tick-scale-value {
  min-width: 2.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #cbd5e1;
}

.wind-debug-actions {
  margin-top: 4px;
}

.wind-debug-actions--row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.wind-debug-actions--row .wind-debug-btn {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.wind-debug-course-name {
  margin: 0 0 8px;
  font-size: 12px;
  color: #cbd5e1;
  word-break: break-word;
}

.wind-debug-section {
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.wind-debug-section > summary {
  cursor: pointer;
  list-style: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
  padding: 8px 0 4px;
  user-select: none;
}

.wind-debug-section > summary::-webkit-details-marker {
  display: none;
}

.wind-debug-section > summary::before {
  content: "▸ ";
  color: #64748b;
}

.wind-debug-section[open] > summary::before {
  content: "▾ ";
}

.wind-debug-section .debug-row:first-of-type {
  margin-top: 2px;
}

.wind-debug-btn {
  width: 100%;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(56, 189, 248, 0.2);
  color: #e2e8f0;
  font: 12px system-ui, sans-serif;
  cursor: pointer;
}

.wind-debug-btn:hover {
  background: rgba(56, 189, 248, 0.35);
}

.wind-debug-check {
  margin-top: 8px;
  margin-bottom: 0;
}

#debug-panel h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.debug-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  margin-bottom: 8px;
}

.debug-row:last-child {
  margin-bottom: 0;
}

.debug-label {
  grid-column: 1 / -1;
}

#debug-speed,
#debug-direction,
#debug-wind-direction,
#debug-wind-speed,
#debug-zoom {
  width: 100%;
  grid-column: 1;
  accent-color: #38bdf8;
}

#debug-speed-value,
#debug-direction-value,
#debug-wind-direction-value,
#debug-wind-speed-value,
#debug-zoom-value {
  min-width: 2.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #cbd5e1;
}

.debug-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.debug-check input {
  accent-color: #38bdf8;
}

.debug-row--disabled {
  opacity: 0.45;
  pointer-events: none;
}

.debug-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-section .debug-label {
  display: block;
  margin-bottom: 6px;
}

.debug-file {
  display: block;
  margin-bottom: 6px;
  cursor: pointer;
}

.debug-file-btn,
.debug-btn {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(56, 189, 248, 0.2);
  color: #e2e8f0;
  font: 12px system-ui, sans-serif;
  cursor: pointer;
}

.debug-btn {
  margin-bottom: 6px;
}

.debug-file-btn:hover,
.debug-btn:hover {
  background: rgba(56, 189, 248, 0.35);
}

.course-status {
  margin: 0;
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.35;
  word-break: break-word;
}

.course-status.is-error {
  color: #fca5a5;
}

.course-status.is-loaded {
  color: #86efac;
}

.race-room {
  position: fixed;
  top: var(--hud-inset);
  right: var(--hud-inset);
  z-index: 20;
  width: min(320px, calc(100vw - var(--hud-inset) * 2));
  color: #e2e8f0;
  font: 14px/1.45 system-ui, -apple-system, sans-serif;
  pointer-events: none;
}

.race-room:not([hidden]) {
  display: block;
}

.race-room--started {
  /* Waiting-room panel hidden via [hidden]; in-game controls use .race-hud */
}

.race-standings {
  position: fixed;
  top: var(--hud-inset);
  left: var(--hud-inset);
  z-index: 15;
  pointer-events: auto;
}

.race-standings[hidden] {
  display: none !important;
}

.race-standings__panel {
  min-width: 200px;
  max-width: min(280px, 42vw);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.88);
  color: #e2e8f0;
  font: 13px/1.35 system-ui, -apple-system, sans-serif;
  backdrop-filter: blur(6px);
  user-select: none;
}

.race-standings__bar {
  display: block;
}

.race-standings__toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  cursor: pointer;
}

.race-standings__toggle-icon {
  display: block;
  font-size: 11px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.race-standings__panel.race-standings--expanded .race-standings__toggle-icon {
  transform: rotate(180deg);
}

.race-standings__body {
  display: block;
}

.race-standings__timer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.race-standings__timer[hidden] {
  display: none !important;
}

.race-standings__timer-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a3b8;
}

.race-standings__timer-value {
  font: 700 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}

.race-standings__timer-value--countdown {
  color: #fef08a;
}

.race-standings__title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a3b8;
}

.race-standings__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.race-standings__row {
  display: grid;
  grid-template-columns: 10px minmax(3.5em, auto) 1fr auto;
  gap: 8px;
  align-items: center;
}

.race-standings__sail-number {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #94a3b8;
  text-align: right;
}

.race-standings__row--local .race-standings__name {
  font-weight: 700;
}

.race-standings__swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.85);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.race-standings__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #f1f5f9;
}

.race-standings__status {
  color: #cbd5e1;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  line-height: 1.25;
}

.race-standings__status--finished {
  color: #4ade80;
  font-weight: 700;
}

.race-standings__team-header,
.race-finish-modal__team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.7);
  font: 600 0.8125rem/1.2 system-ui, -apple-system, sans-serif;
}

.race-standings__team-header--winner,
.race-finish-modal__team-header--winner {
  outline: 1px solid rgba(250, 204, 21, 0.45);
}

.race-standings__team-label,
.race-finish-modal__team-label {
  color: #f1f5f9;
}

.race-standings__team-score,
.race-finish-modal__team-score {
  color: #94a3b8;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.race-standings__row--team-a,
.race-finish-modal__row--team-a {
  border-left: 3px solid rgba(56, 189, 248, 0.65);
}

.race-standings__row--team-b,
.race-finish-modal__row--team-b {
  border-left: 3px solid rgba(248, 113, 113, 0.65);
}

body.is-test-route .race-standings {
  display: none !important;
}

.race-hud {
  position: fixed;
  top: var(--hud-inset);
  right: var(--hud-inset);
  z-index: 20;
  pointer-events: auto;
}

.race-hud[hidden] {
  display: none !important;
}

.race-hud__panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color: #e2e8f0;
  font: 14px/1.45 system-ui, -apple-system, sans-serif;
}

.race-hud__bar {
  display: contents;
}

.race-hud__body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.race-hud__toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  cursor: pointer;
}

.race-hud__toggle-icon {
  display: block;
  font-size: 11px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.race-hud__panel.race-hud--expanded .race-hud__toggle-icon {
  transform: rotate(180deg);
}

.race-hud__logo {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.race-hud__title {
  max-width: min(220px, 40vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #f1f5f9;
  font-weight: 600;
}

.race-hud__actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

.race-hud__leave,
.race-hud__restart {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.race-hud__restart:hover,
.race-hud__leave:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: rgba(203, 213, 225, 0.45);
}

.race-hud__restart:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.game-help {
  position: fixed;
  left: calc(var(--hud-inset) + var(--safe-left));
  bottom: calc(var(--status-bar-clearance) + var(--bottom-ui-inset));
  z-index: 20;
  pointer-events: auto;
}

.is-test-route .game-help {
  display: none;
}

.game-help__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  color: #e2e8f0;
  font: 700 18px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.game-help__btn:hover,
.game-help__btn[aria-expanded="true"] {
  background: rgba(30, 41, 59, 0.98);
  border-color: rgba(203, 213, 225, 0.45);
}

.game-help__panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  min-width: 200px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color: #e2e8f0;
  font: 14px/1.45 system-ui, -apple-system, sans-serif;
}

.game-help__panel[hidden] {
  display: none;
}

.game-help__title {
  margin: 0 0 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #f1f5f9;
}

.game-help__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.game-help__key {
  display: inline-block;
  min-width: 1.5em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #f8fafc;
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}

.game-help__item--touch {
  display: none;
  color: #94a3b8;
}

.game-help__item--desktop {
  color: #94a3b8;
}

.game-help__item--touch-zoom {
  display: none;
  color: #94a3b8;
}

.game-help__item--team-race {
  display: none;
}

body.is-team-race .game-help__item--team-race {
  display: list-item;
}

body.is-team-race .game-help__item--team-race.game-help__item--touch {
  display: none;
}

.game-help__tutorial-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(250, 204, 21, 0.45);
  border-radius: 8px;
  background: rgba(250, 204, 21, 0.12);
  color: #fef08a;
  font: 600 13px/1.2 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.game-help__tutorial-btn:hover {
  background: rgba(250, 204, 21, 0.2);
}

.game-tutorial {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.game-tutorial[hidden] {
  display: none;
}

.game-tutorial__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
}

.game-tutorial__dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(720px, 100%);
  max-height: min(92dvh, 720px);
  padding: 14px 16px 16px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.98);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
  color: #e2e8f0;
}

.game-tutorial__header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-tutorial__title {
  flex: 1;
  margin: 0;
  font: 600 1rem/1.2 system-ui, -apple-system, sans-serif;
  color: #f8fafc;
}

.game-tutorial__counter {
  color: #94a3b8;
  font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.game-tutorial__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font: 22px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.game-tutorial__viewport {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  touch-action: pan-y;
}

.game-tutorial__slide {
  margin: 0;
  min-width: 0;
}

.game-tutorial__image {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(52dvh, 420px);
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: #082f49;
}

.game-tutorial__caption {
  margin: 10px 0 0;
  color: #cbd5e1;
  font: 14px/1.45 system-ui, -apple-system, sans-serif;
  text-align: center;
}

.game-tutorial__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 72px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.85);
  color: #f8fafc;
  font: 28px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

.game-tutorial__nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.game-tutorial__dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.game-tutorial__dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.45);
  cursor: pointer;
}

.game-tutorial__dot.is-active {
  background: #facc15;
}

.is-test-route .game-tutorial {
  display: none !important;
}

.touch-controls {
  position: fixed;
  left: 50%;
  bottom: calc(var(--status-bar-clearance) + var(--bottom-ui-inset));
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transform: translateX(-50%);
  touch-action: none;
  pointer-events: auto;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-controls__cluster {
  display: contents;
}

.is-test-route .touch-controls {
  display: none !important;
}

@media (hover: none) and (pointer: coarse) {
  #game {
    touch-action: none;
  }

  .touch-controls {
    display: flex;
  }

  .touch-controls__btn[data-steer="left"] {
    order: 1;
  }

  .touch-controls__btn[data-action="luff"] {
    order: 2;
  }

  .touch-controls__btn[data-action="auto-tack"] {
    order: 3;
  }

  .touch-controls__btn[data-steer="right"] {
    order: 4;
  }

  .game-help__item--touch {
    display: list-item;
  }

  .game-help__item--desktop {
    display: none;
  }

  .game-help__item--touch-zoom {
    display: list-item;
  }

  body.is-team-race .game-help__item--team-race.game-help__item--touch {
    display: list-item;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  :root {
    --touch-controls-height: 0px;
  }

  .touch-controls {
    left: 0;
    right: 0;
    top: auto;
    bottom: calc(var(--status-bar-clearance) + var(--bottom-ui-inset));
    width: auto;
    height: auto;
    transform: none;
    justify-content: space-between;
    align-items: flex-end;
    padding-left: max(var(--hud-inset), env(safe-area-inset-left, 0px));
    padding-right: max(var(--hud-inset), env(safe-area-inset-right, 0px));
    pointer-events: none;
  }

  .touch-controls__cluster {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 10px;
    pointer-events: auto;
  }

  .touch-controls__cluster--left {
    align-items: flex-start;
  }

  .touch-controls__cluster--right {
    align-items: flex-end;
  }

  .touch-controls__btn[data-steer="left"],
  .touch-controls__btn[data-action="luff"],
  .touch-controls__btn[data-action="auto-tack"],
  .touch-controls__btn[data-steer="right"] {
    order: unset;
  }
}

.touch-controls__btn {
  --touch-btn-dim: clamp(56px, 14vw, 72px);
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-btn-dim);
  height: var(--touch-btn-dim);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.42);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  color: rgba(248, 250, 252, 0.92);
  font: 700 clamp(22px, 6vw, 28px) / 1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-controls__btn--secondary {
  width: calc(var(--touch-btn-dim) * 0.8);
  height: calc(var(--touch-btn-dim) * 0.8);
  border-radius: 11px;
  border-color: rgba(148, 163, 184, 0.38);
  background: rgba(51, 65, 85, 0.34);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  color: rgba(203, 213, 225, 0.88);
  font-size: 80%;
}

.touch-controls__btn:active,
.touch-controls__btn.is-active {
  background: rgba(30, 41, 59, 0.62);
  border-color: rgba(255, 255, 255, 0.35);
}

.touch-controls__btn--secondary:active,
.touch-controls__btn--secondary.is-active {
  background: rgba(71, 85, 105, 0.52);
  border-color: rgba(203, 213, 225, 0.45);
}

.race-room__panel {
  pointer-events: auto;
  padding: 18px 20px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.race-room__header {
  margin-bottom: 14px;
}

.race-room__identity {
  min-width: 0;
}

.race-room__toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  cursor: pointer;
}

.race-room__toggle-icon {
  display: block;
  font-size: 12px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.race-room__panel.race-room--expanded .race-room__toggle-icon {
  transform: rotate(180deg);
}

.race-room__body {
  display: block;
}

.race-room__logo {
  display: block;
  width: 40px;
  height: 40px;
  margin-bottom: 10px;
  object-fit: contain;
}

.race-room__identity .race-room__logo {
  margin-bottom: 10px;
}

@media (hover: none) and (pointer: coarse) {
  :root {
    --arrow-gutter: 24px;
    --wind-panel-width: min(200px, calc(100vw - var(--hud-inset) * 2));
    --wind-head-height: 28px;
    --wind-chart-height: 48px;
    --wind-panel-padding: 6px;
    --wind-panel-gap: 4px;
    --touch-controls-height: 76px;
  }

  .race-room {
    top: max(var(--hud-inset), env(safe-area-inset-top));
    right: var(--hud-inset);
    width: fit-content;
    max-width: min(320px, calc(100vw - var(--hud-inset) * 2));
  }

  .race-hud {
    top: max(var(--hud-inset), env(safe-area-inset-top));
    right: var(--hud-inset);
  }

  .race-hud__panel {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: fit-content;
    padding: 8px 10px;
    border-radius: 12px;
  }

  .race-hud__bar {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .race-hud__logo {
    width: 32px;
    height: 32px;
  }

  .race-hud__toggle {
    display: inline-flex;
  }

  .race-hud__body {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 0;
    padding-top: 0;
  }

  .race-hud__panel.race-hud--expanded {
    gap: 8px;
  }

  .race-hud__panel.race-hud--expanded .race-hud__body {
    display: flex;
    padding-top: 8px;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
  }

  .race-hud__title {
    max-width: min(220px, calc(100vw - 80px));
  }

  .race-hud__actions {
    flex-direction: column;
    align-self: stretch;
    width: 100%;
  }

  .race-hud__export,
  .race-hud__leave,
  .race-hud__restart {
    align-self: stretch;
    text-align: center;
  }

  .race-standings {
    top: max(var(--hud-inset), env(safe-area-inset-top));
    left: var(--hud-inset);
  }

  .race-standings__panel {
    width: fit-content;
    min-width: 0;
    max-width: min(220px, calc(100vw - 80px));
    padding: 8px 10px;
  }

  .race-standings__bar {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .race-standings__timer {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
  }

  .race-standings__toggle {
    display: inline-flex;
  }

  .race-standings__body {
    display: none;
  }

  .race-standings__panel.race-standings--expanded {
    min-width: 200px;
  }

  .race-standings__panel.race-standings--expanded .race-standings__body {
    display: block;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .race-room__panel {
    padding: 10px 12px;
  }

  .race-room__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
  }

  .race-room__identity {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  .race-room__identity .race-room__logo {
    width: 32px;
    height: 32px;
    margin-bottom: 0;
    flex-shrink: 0;
  }

  .race-room__label {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .race-room__toggle {
    display: inline-flex;
  }

  .race-room__body {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
  }

  .race-room__panel.race-room--expanded {
    display: flex;
    flex-direction: column;
    max-height: calc(
      var(--viewport-height) - var(--status-bar-clearance) - var(--wind-panel-height) -
        var(--touch-controls-height) - var(--bottom-ui-inset) - var(--hud-inset) -
        max(var(--hud-inset), var(--safe-top)) - var(--install-banner-height, 0px)
    );
    overflow: hidden;
  }

  .race-room__panel.race-room--expanded .race-room__body {
    display: block;
    overflow-y: auto;
    min-height: 0;
  }
}

.race-room__label {
  margin: 0 0 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.race-room__title {
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #f8fafc;
}

.race-room__course {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.875rem;
}

.race-room__section-title {
  margin: 0 0 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #e2e8f0;
}

.race-room__players {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.race-room__player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.race-room__player-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.race-room__player-color {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(248, 250, 252, 0.35);
}

.race-room__player-name {
  color: #f1f5f9;
  font-weight: 500;
}

.race-room__player--self {
  border-color: rgba(56, 189, 248, 0.5);
}

.race-room__player--host {
  background: rgba(2, 132, 199, 0.22);
}

.race-room__badge {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #7dd3fc;
}

.race-room__team {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.race-room__team--a {
  background: rgba(56, 189, 248, 0.18);
  color: #7dd3fc;
}

.race-room__team--b {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

button.race-room__team {
  border: none;
  cursor: pointer;
  font: inherit;
}

button.race-room__team:hover {
  filter: brightness(1.08);
}

button.race-room__team:focus-visible {
  outline: 2px solid rgba(248, 250, 252, 0.85);
  outline-offset: 2px;
}

.race-room__status {
  margin: 0 0 6px;
  color: #cbd5e1;
  font-size: 0.875rem;
}

.race-room__team-balance {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(250, 204, 21, 0.35);
  background: rgba(120, 53, 15, 0.35);
}

.race-room__team-balance[hidden] {
  display: none;
}

.race-room__team-balance-text {
  margin: 0;
  color: #fde68a;
  font-size: 0.8125rem;
  line-height: 1.45;
}

.race-room__btn--balance {
  align-self: flex-start;
  background: rgba(250, 204, 21, 0.16);
  border-color: rgba(250, 204, 21, 0.45);
  color: #fef08a;
}

.race-room__btn--balance:hover:not(:disabled) {
  background: rgba(250, 204, 21, 0.24);
}

.race-room__hint {
  margin: 0 0 14px;
  color: #94a3b8;
  font-size: 0.8125rem;
}

.race-room__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.race-room__btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.race-room__btn--primary {
  background: #0284c7;
  color: #f8fafc;
}

.race-room__btn--primary:hover:not(:disabled) {
  background: #0369a1;
}

.race-room__btn--primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.race-room__btn--ghost {
  background: rgba(30, 41, 59, 0.6);
  border-color: rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
}

.race-room__btn--ghost:hover {
  background: rgba(51, 65, 85, 0.85);
}
