:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --line: #e2e8f0;
  --paper: #fff;
  --ground: #f1f5f9;
  --surface: #f8fafc;
  --teal: #0f766e;
  --teal-soft: #f0fdfa;
  --primary: #1e293b;
  --radius: 4px;
  font: 18.4px/1.45 Inter, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shell { width: calc(100% - 48px); margin-inline: auto; }

.masthead-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 18px 14px;
}

.brand {
  margin: 0;
  font-size: 2rem;
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -.035em;
}

[id$="-heading"] { scroll-margin-top: 16px; }
main.shell { padding-top: 8px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) clamp(320px, 18vw, 420px); gap: 16px; align-items: start; }
.side { display: grid; gap: 12px; }
.panel { background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 14px; }
.panel-head h2 { margin: 0; font-size: 1.08rem; font-weight: 650; letter-spacing: -.015em; }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.map-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.layer-tools { display: flex; gap: 6px; }
.layer-tools:not(:has(button:not([hidden]))) { display: none; }
.map-feedback { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding: 8px 14px; background: #fffbeb; color: #854d0e; font-size: .875rem; }
.map-feedback p { margin: 0; }

button, .button, select, .race-form input, .rider-name-form input {
  font: inherit;
  color: inherit;
  font-size: .875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 6px 11px;
  min-height: 2rem;
}

button, .button { cursor: pointer; font-weight: 600; white-space: nowrap; }
button:hover:not(:disabled), select:hover:not(:disabled) { background: var(--surface); border-color: #94a3b8; }
button:disabled, select:disabled { opacity: .5; cursor: default; }
button[aria-pressed="true"] { background: var(--teal-soft); color: var(--teal); border-color: #99cbbb; }
:is(button, select, input, a):focus-visible, .upload:focus-within { outline: 2px solid #0d9488; outline-offset: 2px; }
.primary { background: var(--primary); color: white; border-color: var(--primary); padding-inline: 12px; }
.primary:hover, .primary:focus-within { background: #334155; }
.upload { position: relative; display: inline-flex; align-items: center; flex-shrink: 0; }
.upload input { position: absolute; inset: 0; margin: 0; opacity: 0; width: 100%; cursor: pointer; }
.subtle { color: var(--teal); border-color: transparent; padding-inline: 5px; }
.subtle:hover:not(:disabled) { color: #115e59; border-color: transparent; background: var(--teal-soft); }

.map-frame { position: relative; background: var(--surface); border-block: 1px solid var(--line); }
.map-frame canvas { display: block; width: 100%; height: clamp(420px, 53vh, 920px); touch-action: none; }
.map-frame canvas.editing { cursor: crosshair; }
.map-frame canvas.pannable { cursor: grab; }
.map-frame canvas.over-marker { cursor: grab; }
.map-frame canvas.panning { cursor: grabbing; }
.zoom { position: absolute; top: 10px; right: 10px; display: grid; gap: 4px; }
.zoom button { color: var(--primary); padding: 4px; min-width: 34px; }
.scale {
  position: absolute;
  bottom: 11px;
  left: 14px;
  color: var(--muted);
  font-size: .8rem;
  border-bottom: 2px solid;
  min-width: 28px;
  text-align: center;
  pointer-events: none;
}

.basemap-info { color: var(--muted); font-size: .8rem; }
#basemap-status:not(:empty) { display: block; margin-top: 2px; }
.map-corner { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: calc(100% - 140px); pointer-events: none; }
.map-credits { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 10px; padding: 3px 6px; background: #ffffffeb; font-size: .75rem; line-height: 1.25; text-align: right; }
.map-credits:not(:has(a:not([hidden]))) { display: none; }
.map-credits a { color: var(--muted); pointer-events: auto; }
.map-credits a:hover { color: var(--teal); }

#map-empty { position: absolute; inset: 45% 44px auto; color: var(--muted); text-align: center; pointer-events: none; }
.map-controls { display: flex; align-items: center; gap: 12px; padding: 9px 14px; background: var(--surface); }
.map-controls label, .side-footer label { font-size: .9rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.scrub { flex: 1; min-width: 150px; color: var(--muted); }
.scrub span { flex: none; min-width: 49px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.scrub input { flex: 1; min-width: 0; width: 0; accent-color: var(--teal); }

.count { font-size: .8rem; font-weight: 600; color: var(--muted); margin-left: 5px; }
.riders, .lines { border-top: 1px solid var(--line); }
.rider, .line-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; min-height: 38px; }
.rider + .rider, .line-item + .line-item { border-top: 1px solid var(--line); }
.rider-body, .line-name { flex: 1; min-width: 0; }
.rider { align-items: flex-start; }
.rider > .swatch { margin-top: 10px; }
.rider-name { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-height: 28px; padding: 2px 5px 2px 0; border-color: transparent; font-size: .95rem; text-align: left; }
.rider-name-label { overflow: hidden; text-overflow: ellipsis; }
.name-edit-mark { color: var(--teal); }
.rider-name-form { display: flex; flex-wrap: wrap; gap: 5px; }
.rider-name-form input { width: 100%; }
.rider-name-form button { min-height: 28px; padding: 3px 7px; }
.rider-file { overflow-wrap: anywhere; }
.swatch { width: 9px; height: 9px; border-radius: 50%; background: var(--swatch); flex: none; }
.icon-button { font-size: 1.15rem; line-height: 1; padding: 4px 6px; min-height: 28px; border-color: transparent; color: var(--muted); }
.rider select { display: block; margin-top: 4px; font-size: .83rem; padding: 2px 4px; min-height: 1.65rem; max-width: 100%; color: var(--muted); }
.side-footer { border-top: 1px solid var(--line); padding: 8px 14px; }
.side-footer label { justify-content: space-between; }
.side-footer select { min-width: 80px; max-width: 58%; text-overflow: ellipsis; }
.line-item { padding-block: 4px; }
.line-mark { flex: none; width: 12px; height: 3px; background: var(--trace-color); border-radius: 2px; }
.line-name { min-height: 28px; padding: 3px 6px; border-color: transparent; font-size: .92rem; font-weight: 500; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.small-message, .empty { padding: 10px 14px; color: var(--muted); font-size: .875rem; }

.results { margin: 14px 0 28px; }
.results .panel-head { flex-wrap: wrap; }
.results-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.results th, .results td { padding-block: 5px; }
.results table { table-layout: fixed; }
.results thead th { width: 8rem; white-space: normal; overflow-wrap: anywhere; }
.switch { display: flex; gap: 4px; align-self: stretch; }
.switch button { padding: 4px 9px; min-height: 32px; background: transparent; border-color: transparent; }
.switch button[aria-pressed="true"] { border-color: transparent; border-bottom-color: var(--teal); border-bottom-width: 2px; border-radius: 0; }
.switch button:hover:not(:disabled) { color: var(--teal); border-inline-color: transparent; border-top-color: transparent; }
.table-scroll { overflow: auto; border-radius: 0 0 var(--radius) var(--radius); }
table { width: 100%; border-collapse: collapse; text-align: left; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 14px; border-top: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
thead th { background: var(--surface); color: var(--muted); font-weight: 650; font-size: .8rem; text-transform: uppercase; letter-spacing: .045em; }
tbody th, td { font-size: .91rem; }
tbody tr:nth-child(even) { background: var(--surface); }
.delta { margin-left: 7px; font-size: .82rem; color: #9a3412; font-weight: 650; }
.delta.faster { color: var(--teal); }
.delta.even, .missing { color: var(--muted); }
.warning, #notice { padding: 8px 14px; color: #854d0e; background: #fffbeb; border-top: 1px solid #fde68a; font-size: .875rem; }
#notice { border: 1px solid #fde68a; border-radius: var(--radius); margin: 0 0 14px; white-space: pre-line; }

.activity-profile { border-top: 1px solid var(--line); padding: 8px 14px; }
.profile-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px 12px; }
.profile-head h2 { margin: 0; font-size: 1rem; font-weight: 650; overflow-wrap: anywhere; }
#profile-rider, #profile-value { color: var(--muted); font-size: .875rem; }
#profile-rider { font-weight: 500; }
#profile-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
#profile { display: block; width: 100%; height: clamp(145px, 13vh, 215px); cursor: crosshair; touch-action: pan-y; }
#profile.lap-comparison { cursor: default; }
#profile-empty { margin: 0; padding: 8px 0 4px; }

.race-details { margin-top: 5px; font-size: .85rem; color: var(--muted); }
.race-details summary { cursor: pointer; font-weight: 600; }
.race-form { display: grid; gap: 6px; margin-top: 6px; }
.race-form label { display: grid; gap: 3px; min-width: 0; font-weight: 600; }
.race-form select, .race-form input { width: 100%; min-height: 29px; margin: 0; padding: 3px 5px; font: inherit; color: var(--ink); }
.race-message { margin: 1px 0; color: var(--muted); font-size: .81rem; }
.race-form .race-apply { justify-self: start; min-height: 28px; padding: 3px 7px; font-size: .83rem; }

.map-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 5px 8px;
  pointer-events: none;
}
.wind-badge { position: absolute; top: 10px; left: 10px; max-width: calc(100% - 68px); }
.north-badge { gap: 4px; }
.map-badge strong { display: block; font-size: .82rem; line-height: 1.25; }
.wind-badge button { pointer-events: auto; }
.wind-badge button { min-height: 1.7rem; margin-top: 5px; font-size: .82rem; padding: 3px 8px; }
.map-badge-arrow { display: inline-flex; flex: none; justify-content: center; align-items: center; font-size: 1.25rem; line-height: 1; inline-size: 1.2em; block-size: 1.2em; color: var(--teal); }

.profile-actions, .profile-line-actions, .profile-key { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.profile-actions button, .profile-line-actions button, .profile-line-actions select { min-height: 1.8rem; padding: 3px 7px; font-size: .84rem; }
.profile-key { gap: 4px 14px; color: var(--muted); font-size: .84rem; margin-top: 5px; }
.profile-key-entry { display: inline-flex; align-items: center; gap: 5px; min-width: 0; overflow-wrap: anywhere; }
.profile-key-entry::before { content: ""; width: 12px; height: 3px; background: var(--trace-color); border-radius: 2px; flex: none; }
.profile-key-entry strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.profile-key button { min-height: 26px; padding: 2px 7px; font-size: inherit; }
.profile-key button[aria-pressed="false"]::before { opacity: .3; }
.profile-line-actions { margin-top: 6px; }

@media (max-width: 920px) {
  .shell { width: calc(100% - 32px); }
  .workspace { grid-template-columns: minmax(0, 1fr) 252px; }
  .course .panel-head { align-items: flex-start; flex-direction: column; gap: 8px; }
  .map-tools { justify-content: flex-start; }
  .map-controls { flex-wrap: wrap; }
  .scrub { flex-basis: 100%; }
}

@media (max-width: 680px) {
  .shell { width: calc(100% - 24px); }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .map-frame canvas { height: clamp(320px, 48vh, 480px); }
  .masthead-inner { gap: 12px; padding-block: 14px 10px; }
  .panel-head, th, td { padding-inline: 12px; }
}

@media (max-width: 475px) {
  :root { font-size: 18px; }
  .brand { font-size: 1.65rem; }
  .results .panel-head { align-items: flex-start; flex-direction: column; gap: 3px; }
}
