:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7a;
  --border: #d9e0e6;
  --accent: #1f7a9c;
  --accent-text: #ffffff;
  --danger: #c62828;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --surface: #1a222b;
    --text: #e6edf3;
    --muted: #9aa8b6;
    --border: #2c3946;
    --accent: #3aa3c8;
    --accent-text: #0b1218;
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}

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

body {
  margin: 0;
  padding: 16px clamp(16px, 4vw, 40px) 40px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header, main, footer { max-width: 1600px; margin: 0 auto; }
footer { padding-block: 24px 8px; color: var(--muted); font-size: 0.88rem; }
footer a { color: var(--accent); }

h1 { margin: 0; font-size: 1.8rem; letter-spacing: -0.01em; }
header p { margin: 4px 0 16px; color: var(--muted); }
h2 { margin: 0 0 8px; font-size: 1.1rem; }

/* Wide screens: race setup on the left, the river view and results in the
   middle, river conditions on the right. */
main {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "setup stage river"
    "setup results river"
    "settings settings settings";
  gap: 16px;
  align-items: start;
}

.stage { grid-area: stage; }
.setup-panel { grid-area: setup; }
.river-panel { grid-area: river; }
.results { grid-area: results; }
.settings { grid-area: settings; }

/* Medium screens: the river view gets the full width, with the two panels
   side by side underneath. */
@media (max-width: 1200px) {
  main {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas:
      "stage stage"
      "results results"
      "setup river"
      "settings settings";
  }
}

.stage, .panel, .results, .settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

canvas {
  display: block;
  width: 100%;
  border-radius: 6px;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

/* Colour key for the water, under the river. */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}
.legend-item { display: grid; grid-template-columns: auto 160px; gap: 2px 8px; align-items: center; }
.legend-bar { height: 10px; border-radius: 3px; border: 1px solid var(--border); }
.legend-ticks { grid-column: 2; display: flex; justify-content: space-between; font-size: 0.72rem; white-space: nowrap; }

button {
  font: inherit;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button + button { background: transparent; color: var(--accent); }

select, input { font: inherit; color: inherit; }
select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 100%;
}

.you { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Touch controls; keyboards use the arrow keys instead. */
.pad { display: none; gap: 8px; margin-top: 10px; }
.pad button { flex: 1; padding: 14px 0; font-size: 1.2rem; touch-action: none; user-select: none; }
@media (pointer: coarse) {
  .pad { display: flex; }
}

.clock { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }

.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: 0.9rem; }
.field select, .field input { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.field output { float: right; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent); }
input[type="range"]:disabled { opacity: 0.4; }

/* Where your boat is now, marked on the line slider under the starting line.
   The 8px insets match half the thumb, so 0% and 100% line up with its ends. */
.slider-wrap { position: relative; display: block; }
.now-marker {
  position: absolute;
  top: 50%;
  left: calc(8px + (100% - 16px) * var(--at, 0.5));
  width: 0;
  height: 0;
  margin-top: 6px;
  transform: translateX(-6px);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 9px solid var(--marker, #e4572e);
  pointer-events: none;
}
.now-text { margin-top: 0; }
.now-text .key { display: inline-block; width: 0; height: 0; margin-right: 4px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid var(--marker, #e4572e); }

/* A position rather than an amount: no filled track, and a mark at the middle. */
input[type="range"].position {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 18px;
  /* No side margins, so the thumb's travel matches the marker below it. */
  margin-left: 0;
  margin-right: 0;
}
input[type="range"].position::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background:
    linear-gradient(to right, transparent calc(50% - 1px), var(--muted) calc(50% - 1px), var(--muted) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--border);
}
input[type="range"].position::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background:
    linear-gradient(to right, transparent calc(50% - 1px), var(--muted) calc(50% - 1px), var(--muted) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--border);
}
input[type="range"].position::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"].position::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

.check { display: flex; align-items: center; gap: 8px; margin: -4px 0 12px; font-size: 0.9rem; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.check.sub { margin-left: 24px; }

.river-editor {
  display: block;
  width: 100%;
  height: 140px;                      /* replaced by the editor to fit its scale */
  margin: 0 0 10px;
  color: var(--muted);
  touch-action: none;
  cursor: ns-resize;
}

.hint { margin: -4px 0 12px; color: var(--muted); font-size: 0.88rem; }

.group { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 12px; padding: 6px 10px 0; min-width: 0; }
.group legend { font-weight: 600; font-size: 0.9rem; padding: 0 4px; }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0 10px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child, th:last-child, td:last-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
.risk { color: var(--danger); font-weight: 600; }
.verdict { margin: 10px 0 0; font-weight: 600; }

.settings-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.settings-head h2 { margin: 0; }
.boat-table th[scope="row"] { text-align: left; white-space: normal; min-width: 260px; max-width: 520px; color: var(--text); }
.boat-table th[scope="row"] small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.boat-table .unit { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.boat-table td { text-align: center; }
.boat-table thead th:not(:first-child) { text-align: center; }
.boat-table input {
  width: 5.5em;
  font: inherit;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  text-align: right;
}
.note { color: var(--muted); font-size: 0.82rem; margin: 8px 0 0; }

@media (max-width: 860px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "stage" "results" "setup" "river" "settings"; }
}
