:root {
  --bg: #071018;
  --panel: #10202b;
  --panel-2: #173041;
  --ink: #e7eef3;
  --muted: #8aa0ad;
  --line: rgba(255, 255, 255, 0.08);
  --amber: #f0b429;
  --green: #3ecf8e;
  --red: #ff5d5d;
  --course: #f2c14e;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

body {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
}

body > header {
  position: relative;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: calc(8px + var(--safe-t)) 12px 6px;
  background: #0b1720;
  border-bottom: 1px solid var(--line);
}
.header-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.header-sub {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  line-height: 1.2;
}
.header-sub .sub {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-sub .sub.ok { color: var(--green); }
.header-sub .sub.bad { color: var(--amber); }
#prestart, #racing {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  flex-wrap: nowrap;
  min-width: 0;
}
#prestart[hidden], #racing[hidden], .race-time[hidden], .clock-label[hidden] { display: none; }
.header-clock {
  font-size: clamp(24px, 7.2vw, 34px);
  font-weight: 720;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.clock-actions { display: flex; gap: 6px; flex-wrap: nowrap; flex: none; }
.clock-actions button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 13px;
  white-space: nowrap;
}
.race-readout { display: flex; align-items: baseline; gap: 4px; min-width: 0; }
.race-readout:first-child { flex: 1; }
.race-readout:last-child { flex: none; }
#racing .k {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
#racing .v {
  font-size: clamp(18px, 5.4vw, 26px);
  font-weight: 720;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rose-frame { position: relative; }
.rose-nav {
  position: absolute;
  top: 0;
  z-index: 2;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #10202b;
  font-size: 28px;
  line-height: 1;
}
.rose-nav.right { right: 0; }
.rose-heading { text-align: center; line-height: 1; margin-bottom: 2px; }
.rose-heading span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2px;
  font-weight: 650;
}
.rose-heading b { font-size: 40px; font-weight: 720; font-variant-numeric: tabular-nums; }
.speed-wrap { position: relative; margin-left: auto; flex: none; }
.speed-num {
  display: block;
  margin: 0;
  padding: 2px 0;
  border: none;
  background: none;
  font-size: clamp(24px, 7.2vw, 34px);
  font-weight: 720;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.speed-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 148px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}
.speed-menu[hidden] { display: none; }
.speed-menu button {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: none;
  text-align: left;
}
.speed-menu button:hover,
.speed-menu button:focus { background: var(--panel-2); }
.race-time {
  flex: none;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1;
}
.clock-label {
  flex: none;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.speed-unit {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}

main {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(220px, 1fr) auto;
}
.map-wrap { position: relative; z-index: 1; min-height: 0; }
#map { height: 100%; width: 100%; background: #0a1a24; }
.leaflet-control-attribution {
  font-size: 10px;
  max-width: 46vw;
  opacity: 0.18;
  background: transparent;
}
.map-tools {
  position: absolute;
  z-index: 500;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-tools button, .layers button, .primary, .ghost, .danger {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #10202b;
}
.map-tools button { width: 44px; font-size: 18px; }
.layers {
  position: absolute;
  z-index: 500;
  top: 10px;
  right: 62px;
  width: min(280px, calc(100vw - 84px));
  padding: 12px;
  border-radius: 12px;
  background: rgba(16, 32, 43, 0.96);
  border: 1px solid var(--line);
  display: none;
}
.layers.open { display: block; }
.layers h2, .panel h2 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.layers button, .row-actions button, .primary, .ghost { padding: 8px 12px; }
.layers button { display: block; width: 100%; margin-top: 6px; text-align: left; }
.layers button.active { border-color: var(--amber); color: var(--amber); }

.sheet {
  position: relative;
  z-index: 2;
  background: var(--panel);
  border-top: 1px solid var(--line);
  max-height: 58vh;
  overflow: auto;
  padding: 8px 14px calc(14px + var(--safe-b));
}
.sheet.collapsed .sheet-body { display: none; }
.handle {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 6px 0 8px;
}
.handle span {
  display: block;
  width: 42px;
  height: 4px;
  border-radius: 4px;
  background: #3d5564;
  margin: 0 auto;
}

.clock-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.clock {
  font-size: 48px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.clock-actions { justify-content: flex-start; }
.primary { background: var(--amber); color: #1a1203; border-color: transparent; font-weight: 720; }
.ghost { background: transparent; }
.danger { background: transparent; color: var(--red); }

.tabs { display: flex; gap: 6px; margin: 12px 0; }
.tabs button {
  flex: 1;
  min-height: 40px;
  padding: 0 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.tabs button.on { background: var(--ink); color: #10202b; border-color: transparent; font-weight: 720; }

.panel { display: none; }
.panel.on { display: block; }

.login {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login[hidden] { display: none; }
.login-card, .account-form {
  width: min(420px, 100%);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}
.login-logo {
  display: block;
  width: min(180px, 52vw);
  height: auto;
  margin: 0 auto 8px;
  border-radius: 12px;
  background: #fff;
}
.brand-kicker {
  margin: 0;
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.login-card h1 { margin: 4px 0 0; font-size: 32px; }
.brand-sub { margin: 8px 0 4px; color: var(--muted); }
.login-card label, .account-form label {
  display: block;
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 13px;
}
.login-card input, .account-form input {
  width: 100%;
  background: #0b1720;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.login-card .primary, .account-form .primary { width: 100%; margin-top: 14px; }
.login-error { min-height: 1.2em; margin: 10px 0 0; color: var(--red); }
.login-card .fine { margin-top: 14px; }
#accountBoat { margin-top: 4px; text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 22px; }
#signOut { margin-top: 18px; }
.crew-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.crew-row button { min-height: 32px; padding: 0 10px; }
.course-row, .form-row, .part-form, .replace-form { display: flex; gap: 8px; flex-wrap: wrap; }
.replace-form input { flex: 1 1 120px; }
.course-row input, .form-row input, .part-form input, .layers input, textarea {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b1720;
  padding: 8px 10px;
  font-size: 16px;
}
.meta { color: var(--muted); font-size: 13px; margin: 8px 0; }
.marks { list-style: none; margin: 0; padding: 0; }
.marks li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.marks li.active { background: rgba(242, 193, 78, 0.08); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 720;
}
.badge.port { background: rgba(255, 93, 93, 0.18); color: #ff8d8d; }
.badge.stbd { background: rgba(62, 207, 142, 0.18); color: var(--green); }
.badge.plain { background: #0b1720; color: var(--muted); }
.mark-name { font-weight: 650; }
.mark-pos { color: var(--muted); font-size: 12px; }
.tiny { min-height: 36px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0b1720; }

.wind-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.wind-compact { display: flex; gap: 8px; }
.wind-compact label { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.wind-compact input { min-height: 36px; width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #0b1720; padding: 6px 8px; font-size: 16px; }
.sail-tag { justify-self: end; font-size: 11px; font-weight: 720; padding: 3px 8px; border-radius: 999px; color: #10202b; }
.sail-tag.nogo { color: #f3e6ea; }
.place-banner {
  position: absolute;
  z-index: 500;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 999px;
  background: #7c3aed;
  color: white;
  font-weight: 700;
  font-size: 14px;
  max-width: calc(100% - 90px);
  text-align: center;
}
.mark-row { display: grid; grid-template-columns: 16px 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.mark-row.active { background: rgba(124, 58, 237, 0.16); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #1a1203; }
.buoy-pin, .gate-pin, .pin-post {
  border: 1px solid #1a1203;
  color: #10202b;
  font-size: 8px;
  font-weight: 720;
  display: grid;
  place-items: center;
  line-height: 1;
}
.buoy-pin, .gate-pin { border-radius: 50%; }
.buoy-pin { width: 11px; height: 11px; }
.gate-pin { width: 10px; height: 10px; }
.pin-post { width: 7px; height: 12px; border-radius: 2px; }
.pin-flag { width: 12px; height: 14px; }
.pin-flag svg { display: block; }
.round-arrow { width: 46px; height: 46px; transform-origin: center center; }
.round-arrow svg { display: block; filter: drop-shadow(0 1px 1px rgba(16, 32, 43, 0.45)); }
.gear {
  display: block;
  margin: 22px auto 6px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #0b1720;
  font-size: 20px;
}
.gear.on { border-color: var(--amber); color: var(--amber); }
.mark-tools { display: flex; gap: 4px; align-items: center; }
.mark-tools .sym {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}
.mark-tools .sym.on { color: var(--ink); border-color: var(--amber); }
.color-chip {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 8px;
  border: 2px solid #1a1203;
}
.palette[hidden] { display: none; }
.palette {
  position: fixed;
  z-index: 800;
  display: grid;
  grid-template-columns: repeat(8, 20px);
  gap: 4px;
  padding: 8px;
  border-radius: 10px;
  background: #10202b;
  border: 1px solid var(--line);
}
.palette .swatch {
  width: 20px;
  height: 20px;
  min-height: 20px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.45);
}
.palette .swatch.on { outline: 2px solid #fff; outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.field input { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #0b1720; padding: 8px 10px; font-size: 16px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }
.forecast { font-size: 18px; font-weight: 700; }

.part {
  padding: 0;
  border-bottom: 1px solid var(--line);
}
.part-line {
  display: grid;
  grid-template-columns: 1fr 40px 84px;
  gap: 8px;
  align-items: center;
  min-height: 32px;
  padding: 2px 0;
  cursor: pointer;
  background: transparent;
  border: 0;
  width: 100%;
}
.part .name { font-weight: 650; font-size: 14px; }
.part .qty, .part .price { color: var(--muted); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.part .source { color: var(--muted); font-size: 13px; }
.part.needed .name { color: var(--amber); }
.part-detail { padding: 2px 0 8px; font-size: 13px; line-height: 1.35; }
.part-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.part-detail .check { margin: 0; }
.history { color: var(--muted); font-size: 12px; margin-top: 4px; }
.empty { color: var(--muted); padding: 12px 0; }
.fine {
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}
.boat-full { display: none; }
.desk-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.desk-bar input, .desk-bar select {
  min-height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b1720;
  padding: 4px 8px;
  font-size: 14px;
}
.desk-bar input { flex: 1; min-width: 120px; }
.desk-bar select { flex: 0 1 168px; max-width: 46%; }
.desk-bar select.due { border-color: var(--amber); color: var(--amber); font-weight: 720; }
#view-parts[hidden], #view-history[hidden], #view-care[hidden] { display: none; }
.care-intro { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
#view-care h2 { margin-top: 18px; }
.care-line {
  grid-template-columns: 28px 1fr;
  min-height: 44px;
}
.care-line input[type="checkbox"] { width: 22px; height: 22px; margin: 0; }
.care-hist {
  grid-template-columns: 1fr auto auto;
  min-height: 36px;
  cursor: default;
}
.replace-now {
  flex: none;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--amber);
  background: transparent;
  color: var(--amber);
  font-weight: 720;
}
.replace-now.on { background: var(--amber); color: #1a1203; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.desk-bar .filters { margin-left: 8px; padding-left: 12px; border-left: 1px solid var(--line); }
.filters button { min-height: 34px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 4px 10px; }
.filters button.on { background: var(--ink); color: #10202b; border-color: transparent; }
.desk-total { margin-left: auto; color: var(--amber); font-weight: 700; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table.parts { width: 100%; border-collapse: collapse; font-size: 13px; }
table.parts th { text-align: left; color: var(--muted); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; padding: 10px; position: sticky; top: 0; background: #173041; }
table.parts td { vertical-align: middle; padding: 4px 8px; border-top: 1px solid var(--line); }
table.parts tr.summary { cursor: pointer; }
table.parts tr.needed td { background: rgba(240, 180, 41, 0.07); }
table.parts tr.detail td { color: var(--muted); font-size: 13px; }
table.parts .name { font-weight: 700; }
.order-link { display: inline-block; margin: 8px 8px 0 0; color: var(--amber); }
.refs { display: grid; gap: 8px; }
.refs div { color: var(--muted); font-size: 13px; line-height: 1.4; }
.refs strong { color: var(--ink); }
.refs a { color: var(--amber); }

.boat-icon { background: none; border: none; }
.boat-pin {
  display: block;
  width: 22px;
  height: 44px;
  overflow: visible;
  transform-origin: 50% 50%;
}
.mark-pin {
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 720;
  color: #10202b;
  background: var(--course);
  border: 2px solid #1a1203;
}

@media (max-width: 520px) {
  .clock-row { flex-direction: column; align-items: stretch; }
  .clock-actions { justify-content: flex-start; }
  .clock { font-size: 42px; }
}
@media (min-width: 900px) {
  main { grid-template-columns: 1fr 420px; grid-template-rows: 1fr; }
  .sheet { max-height: none; border-top: 0; border-left: 1px solid var(--line); }
  .handle { display: none; }
  .sheet.collapsed .sheet-body { display: block; }
  .boat-simple { display: none; }
  .boat-full { display: block; }
  .boat-expand { display: inline-flex; margin-bottom: 8px; }
  main.boat-open { grid-template-columns: minmax(280px, 1fr) minmax(640px, 68vw); }
}
.boat-expand { display: none; }
.rose-layout { display: block; }
.rose { width: min(100%, 460px); margin: 0 auto; }
.rose svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.rose-legs { list-style: none; margin: 12px 0 0; padding: 0; }
.rose-legs li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.rose-legs li.active { background: rgba(242, 193, 78, 0.08); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.rose-legs .num {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 720; font-size: 12px;
  background: var(--course); color: #10202b;
}
