:root {
  --panel-w: min(420px, 100vw);
  --line: #d9e0e7;
  --text: #102030;
  --muted: #5e6a76;
  --accent: #005ea8;
  --accent-soft: #e8f3ff;
  --water: #b8d5e6;
  --danger: #a40000;
  --warn: #8a5a00;
  --ok: #0b6b2d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #f4f7fa;
}
button, input, select { font: inherit; }
button {
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: white;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
}
button.secondary { background: white; color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
label { display: block; margin: 0.9rem 0 0.35rem; font-weight: 700; }
select, input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 0.55rem 0.65rem;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 100vh;
}
.panel {
  overflow: auto;
  max-height: 100vh;
  padding: 1rem;
  background: white;
  border-right: 1px solid var(--line);
}
.panel-header { margin-bottom: 1rem; }
.eyebrow { margin: 0; color: var(--accent); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
h1 { margin: 0.1rem 0 0.35rem; font-size: 1.45rem; }
h2 { margin: 0; font-size: 1.05rem; }
.muted, .hint { color: var(--muted); }
.hint { margin: 0.35rem 0 0; font-size: 0.84rem; }
.card {
  margin: 0.8rem 0;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
}
.card summary { cursor: pointer; font-weight: 800; }
.status-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.status-pill, .pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}
.status-pill.offline { background: #fff0d6; color: var(--warn); }
.status-pill.ready { background: #e6f6ec; color: var(--ok); }
.button-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.mode-button { background: white; color: var(--accent); }
.mode-button[aria-pressed="true"] { background: var(--accent); color: white; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.7rem;
}
.summary-item { padding: 0.55rem; border-radius: 10px; background: white; border: 1px solid #edf0f3; }
.summary-label { display: block; color: var(--muted); font-size: 0.74rem; }
.summary-value { display: block; margin-top: 0.15rem; font-weight: 800; }
.race-day-panel { display: grid; gap: 0.65rem; }
.race-hero {
  padding: 0.8rem;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid #c9e4ff;
}
.race-hero-label { display:block; color: var(--muted); font-size: 0.74rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.race-hero-value { display:block; margin-top: 0.15rem; font-size: 1.45rem; line-height: 1.1; font-weight: 900; }
.race-hero-sub { display:block; margin-top: 0.2rem; color: var(--muted); }
.race-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.race-item { padding: 0.65rem; border-radius: 12px; background: white; border: 1px solid #edf0f3; }
.race-label { display:block; color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .035em; }
.race-value { display:block; margin-top: 0.2rem; font-size: 1.05rem; font-weight: 900; }
.route-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th, td { padding: 0.45rem 0.3rem; border-bottom: 1px solid #e9eef3; text-align: left; vertical-align: top; }
th { color: #46515e; font-size: 0.74rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small-block { color: var(--muted); font-size: 0.86rem; line-height: 1.45; }
.race-day-info {
  max-height: 48vh;
  overflow: auto;
  margin-top: 0.7rem;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.42;
}
.race-day-info h3 { margin: 0.95rem 0 0.35rem; font-size: 0.95rem; color: var(--text); }
.race-day-info h3:first-child { margin-top: 0; }
.race-day-info ul { margin: 0.35rem 0 0.7rem 1.15rem; padding: 0; }
.race-day-info li { margin: 0.3rem 0; }
.race-day-info table { margin: 0.45rem 0 0.75rem; }
.race-day-info th,
.race-day-info td { font-size: 0.78rem; }
.checklist { list-style: none; margin: 0.35rem 0 0.7rem; padding: 0; }
.checklist li { display: flex; gap: 0.45rem; align-items: baseline; margin: 0.35rem 0; }
.check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 1.25rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 900;
  background: #eef2f7;
  color: var(--muted);
}
.check.ok { background: #e6f6ec; color: var(--ok); }
.check.no { background: #fff0f0; color: var(--danger); }
.check.unknown { background: #fff7e8; color: var(--warn); }
.warn { color: var(--warn); font-weight: 700; }
.error { color: var(--danger); font-weight: 700; }
.map-wrap { min-width: 0; }
#map { width: 100%; height: 100vh; background: var(--water); }
.rounding-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: rgba(255,255,255,0.96);
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
  box-shadow: 0 1px 2px rgba(0,0,0,0.22);
}
.rounding-icon.bb { color: #d40000; }
.rounding-icon.sb { color: #008f45; }
.rounding-icon.inline { width: 22px; height: 22px; font-size: 18px; border-width: 1.5px; box-shadow: none; }
.rounding-icon.map { width: 34px; height: 34px; font-size: 30px; }
.leaflet-div-icon.rounding-div-icon,
.leaflet-div-icon.wind-angle-div-icon,
.leaflet-div-icon.race-area-flag-div-icon { background: transparent; border: 0; }
.leaflet-div-icon.muted-map-icon {
  opacity: 0.24;
  filter: grayscale(1);
}
.new-rounding-icon,
.wind-rounding-icon,
.wind-rounding-icon svg,
.race-area-flag-icon {
  display: block;
  overflow: visible;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.30));
  pointer-events: auto;
}
.wind-rounding-icon.bb { color: #e00000; }
.wind-rounding-icon.sb { color: #008f45; }
.wind-rounding-twa {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 900;
  fill: #102030;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5px;
  stroke-linejoin: round;
}
body.mode-race-day .planning-only { display: none !important; }
body.mode-planning .race-only { display: none !important; }
body.mode-planning #raceDayPanel { display: none !important; }
body.mode-race-day .panel { padding: 0.75rem; }
body.mode-race-day .card { margin: 0.55rem 0; padding: 0.75rem; }
body.mode-race-day .panel-header .muted { display: none; }
body.mode-race-day h1 { font-size: 1.2rem; }
body.mode-race-day #currentLegLabel,
body.mode-race-day #currentLegSelect { display: block; }
body.mode-planning #currentLegLabel,
body.mode-planning #currentLegSelect { display: none; }

@media (max-width: 900px) {
  .app-shell { display: flex; flex-direction: column; min-height: 100vh; }
  .panel { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .map-wrap { order: 2; }
  #map { height: 64vh; }
  .summary-grid, .race-grid { grid-template-columns: 1fr; }
  body.mode-race-day .panel { order: 2; }
  body.mode-race-day .map-wrap { order: 1; }
  body.mode-race-day #map { height: 72vh; }
}
