/* Harbour Regatta: a sailor's instrument HUD in warm evening light. Dark smoked glass, a gold
   accent from the sun, the marks' own red and green, numerals in a mono face. */
:root {
  --ink: #fbf6ee;
  --dim: #d6c7b3;
  --line: rgba(255, 236, 210, 0.18);
  --glass: rgba(22, 15, 11, 0.5);
  --gold: #ffcf7a;
  --red: #e8543f;
  --green: #36c27e;
  --ui: var(--kit-grotesk);
  --num: var(--kit-mono);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #1a1410;
  color: var(--ink);
  font: 500 15px/1.35 var(--ui);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#app { position: relative; width: 100vw; height: 100vh; height: 100dvh; }
#game { position: absolute; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#game canvas:active { cursor: grabbing; }

.num { font-family: var(--num); font-variant-ligatures: none; font-variant-numeric: tabular-nums; font-weight: 500; }

.hud { position: absolute; inset: 0; pointer-events: none; font-size: clamp(11px, 0.95vw, 16px); }
.panel {
  position: absolute;
  padding: 0.75em 1.05em 0.8em;
  border-radius: 0.85em;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.25);
  box-shadow: inset 0 0 0 1px var(--line), 0 0.6em 1.8em rgba(30, 14, 4, 0.28);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.panel header {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1.2em;
  font-size: 0.76em; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim);
}
.big { font-size: 2.1em; line-height: 1.05; }
.sub { display: block; margin-top: 0.2em; font-size: 0.8em; color: var(--dim); letter-spacing: 0.02em; }

.race { top: 2.2vh; left: 2vw; min-width: 11em; }
.race .big { display: block; margin-top: 0.15em; color: #fff; }

.nav { top: 2.2vh; left: 50%; transform: translateX(-50%); min-width: 15em; text-align: center; }
.nav header { justify-content: center; }
.bearing { display: flex; align-items: center; justify-content: center; gap: 0.55em; margin-top: 0.35em; font-size: 1.25em; font-weight: 600; white-space: nowrap; }
.dot { width: 0.7em; height: 0.7em; border-radius: 50%; background: var(--red); box-shadow: 0 0 0.6em rgba(232, 84, 63, 0.7); }
.dot[data-side="green"] { background: var(--green); box-shadow: 0 0 0.6em rgba(54, 194, 126, 0.7); }
.dot[data-side="gate"] { background: var(--gold); box-shadow: 0 0 0.6em rgba(255, 207, 122, 0.7); }
.arrow { width: 0.95em; height: 0.95em; fill: var(--gold); margin-left: 0.3em; }

.speed { top: 2.2vh; right: 2vw; min-width: 8.5em; }
.speed .row { display: flex; align-items: baseline; gap: 0.35em; margin-top: 0.15em; }
.speed .big { color: #fff; }
.unit { color: var(--dim); font-size: 0.9em; letter-spacing: 0.06em; }

.windrose { left: 2vw; bottom: 2.4vh; display: flex; align-items: center; gap: 0.9em; padding: 0.6em 1.1em 0.6em 0.7em; }
.rose { width: 4.6em; height: 4.6em; }
.rose .ring { fill: rgba(255, 255, 255, 0.04); stroke: rgba(255, 236, 210, 0.35); stroke-width: 1.5; }
.rose .bow { fill: rgba(255, 255, 255, 0.85); }
.rose .hull { fill: rgba(255, 255, 255, 0.85); }
.rose .wind { transform-origin: 50px 50px; stroke: var(--gold); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.windrose .num { display: block; margin-top: 0.2em; font-size: 1.35em; color: #fff; }

.trim { right: 2vw; bottom: 2.4vh; width: 17em; }
.trim header #hud-trim-text { letter-spacing: 0.04em; text-transform: none; font-size: 1.15em; color: var(--ink); }
.gauge { position: relative; height: 0.55em; margin: 0.85em 0.2em 0.3em; border-radius: 1em; background: linear-gradient(90deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.28)); }
.gauge .ideal { position: absolute; top: -0.35em; width: 2.6em; height: 1.25em; margin-left: -1.3em; border-radius: 0.6em; background: rgba(54, 194, 126, 0.32); box-shadow: inset 0 0 0 1px rgba(54, 194, 126, 0.75); }
.gauge .pos { position: absolute; top: -0.3em; width: 1.15em; height: 1.15em; margin-left: -0.575em; border-radius: 50%; background: #fff; box-shadow: 0 0 0.6em rgba(255, 255, 255, 0.6); }
.trim[data-state="good"] #hud-trim-text { color: #8ff0bd; }
.trim[data-state="luffing"] #hud-trim-text, .trim[data-state="ease"] #hud-trim-text, .trim[data-state="sheetIn"] #hud-trim-text { color: var(--gold); }

.marker { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 0.3em; pointer-events: none; font-size: clamp(11px, 0.85vw, 14px); will-change: transform; }
.diamond { width: 0.9em; height: 0.9em; transform: rotate(45deg); border: 2px solid var(--red); box-shadow: 0 0 0.8em rgba(232, 84, 63, 0.6); }
.marker[data-side="green"] .diamond { border-color: var(--green); box-shadow: 0 0 0.8em rgba(54, 194, 126, 0.6); }
.marker[data-side="gate"] .diamond { border-color: var(--gold); box-shadow: 0 0 0.8em rgba(255, 207, 122, 0.6); }
.dist { padding: 0.15em 0.55em; border-radius: 0.4em; background: rgba(24, 18, 16, 0.5); color: var(--ink); font-family: var(--num); font-variant-ligatures: none; }

.toast {
  position: absolute; top: 22%; left: 50%; transform: translate(-50%, 0);
  font-size: clamp(18px, 2vw, 34px); font-weight: 600; color: #fff; white-space: nowrap;
  text-shadow: 0 0 1em rgba(255, 207, 122, 0.85), 0 2px 10px rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
}
.toast.warn { text-shadow: 0 0 1em rgba(232, 84, 63, 0.85), 0 2px 10px rgba(0, 0, 0, 0.5); }
.toast.on { animation: toast 1.5s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.92); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.04); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -18px) scale(1); } }

.screen { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 1.3vh; padding: 24px; text-align: center; text-shadow: 0 2px 18px rgba(40, 16, 4, 0.55); }
.screen p { margin: 0; }
.screen-title { background: radial-gradient(ellipse 70% 60% at 50% 46%, rgba(30, 14, 6, 0.5), rgba(30, 14, 6, 0.12) 70%, rgba(30, 14, 6, 0) 100%); }
.kicker { font-size: clamp(12px, 1vw, 17px); letter-spacing: 0.34em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.screen-title h1 { margin: 0 0 0.3vh; font-family: var(--kit-serif); font-size: clamp(54px, 7.6vw, 132px); line-height: 1.04; font-weight: 400; letter-spacing: -0.02em; color: #fff; }
.tagline { font-size: clamp(15px, 1.35vw, 22px); color: rgba(255, 255, 255, 0.88); max-width: 32em; }
.keys { color: rgba(255, 255, 255, 0.75); font-size: clamp(12px, 0.9vw, 15px); }
.meta { color: var(--gold); font-size: clamp(12px, 0.85vw, 14px); letter-spacing: 0.12em; text-transform: uppercase; }
.meta span + span::before { content: "· "; color: rgba(255, 255, 255, 0.5); }
.meta span:empty, .meta span:empty + span::before { display: none; }
.loading { font-size: 16px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

#app > .card {
  inset: auto; top: 50%; left: 50%; transform: translate(-50%, -50%);
  min-width: min(460px, 88vw); padding: 34px 44px 30px; border-radius: 22px;
  background: rgba(28, 20, 16, 0.78); backdrop-filter: blur(18px);
  box-shadow: inset 0 0 0 1px var(--line), 0 30px 80px rgba(20, 8, 2, 0.55);
}
.card h2 { margin: 0 0 4px; font-family: var(--kit-serif); font-size: clamp(30px, 3.2vw, 52px); font-weight: 400; }
.card .big { font-size: clamp(20px, 1.9vw, 30px); font-family: var(--num); font-variant-ligatures: none; color: var(--gold); }

.cta {
  margin-top: 1.6vh; font: inherit; font-size: clamp(14px, 1.1vw, 19px); font-weight: 600; letter-spacing: 0.04em;
  color: #2a1606; background: linear-gradient(#ffe2a8, #ffc061); border: 0; border-radius: 999px; padding: 0.85em 2.1em;
  cursor: pointer; text-shadow: none; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35) inset, 0 0.6em 2em rgba(255, 170, 70, 0.4);
}
.cta:focus-visible { outline: 3px solid #fff; outline-offset: 5px; }

.status {
  position: absolute; left: 50%; bottom: 2.6vh; transform: translateX(-50%); margin: 0; padding: 0.5em 1.2em;
  max-width: calc(100% - 24px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 999px;
  font-size: clamp(12px, 0.9vw, 15px); background: var(--glass); backdrop-filter: blur(10px); box-shadow: inset 0 0 0 1px var(--line); pointer-events: none;
}
.is-capturing .status, .status:empty { display: none; }

.flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, rgba(232, 84, 63, 0) 45%, rgba(232, 84, 63, 0.4)); }
.flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.touch { position: absolute; inset: 0; pointer-events: none; }
.stick { pointer-events: auto; position: absolute; left: 28px; bottom: 120px; width: 128px; height: 128px; border-radius: 50%; background: rgba(24, 18, 16, 0.35); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4); touch-action: none; }
.knob { position: absolute; left: 34px; top: 34px; width: 60px; height: 60px; border-radius: 50%; background: rgba(255, 255, 255, 0.65); }
.touch button { pointer-events: auto; position: absolute; border: 0; border-radius: 50%; color: #111; font: inherit; touch-action: none; }
.touch-pause { right: 20px; top: 110px; width: 46px; height: 46px; font-size: 14px; background: rgba(255, 255, 255, 0.6); }

@media (prefers-reduced-motion: reduce) { .loading { animation: none; } }
