/* Layout: chart-room worksheet. Inputs and results on the left, the course plot on the right,
   helm card below. Colors borrow from nautical charts: sounding blue water, chart magenta, nav-aid red/green. */
:root {
  --paper: #f2f5f7;
  --surface: #ffffff;
  --ink: #12202b;
  --muted: #5b6b77;
  --line: #d3dde4;
  --water: #e3eff6;
  --grid: #b9cfdc;
  --magenta: #a8186f;
  --magenta-soft: #f7e3ef;
  --red: #c6302c;
  --green: #1d7a49;
  --buoy: #e2a300;
  --focus: #a8186f;

  --font-display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0c141a; --surface: #121c24; --ink: #e3ebf0; --muted: #8fa1ae; --line: #22323d;
    --water: #0f2230; --grid: #1f3a4c; --magenta: #f06bbd; --magenta-soft: #3a1830;
    --red: #f2645e; --green: #4cc78a; --buoy: #f3c246; --focus: #f06bbd;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0c141a; --surface: #121c24; --ink: #e3ebf0; --muted: #8fa1ae; --line: #22323d;
  --water: #0f2230; --grid: #1f3a4c; --magenta: #f06bbd; --magenta-soft: #3a1830;
  --red: #f2645e; --green: #4cc78a; --buoy: #f3c246; --focus: #f06bbd;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font-body);
}
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 28px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 20px;
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

h1, h2 { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.01em; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2.4rem, 6vw, 3.6rem); line-height: 0.95; text-transform: uppercase; }
h2 { font-size: 1.35rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* header */
.masthead { display: grid; gap: 8px; max-width: 68ch; }
.lede { margin: 0; color: var(--muted); }

/* layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); gap: 20px; align-items: start; }
.col-main { display: grid; gap: 20px; min-width: 0; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 14px;
  min-width: 0;
}
.note { margin: 0; font-size: 0.82rem; color: var(--muted); }

/* inputs */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 18px; }
.field { display: grid; gap: 5px; align-content: start; }
.field-label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.field-hint { font-size: 0.8rem; color: var(--muted); }
.input-unit {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  padding: 0 10px; min-height: 44px;
}
.input-unit:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px var(--magenta-soft); }
.input-unit input, .input-unit select {
  border: 0; background: transparent; color: var(--ink); font: 600 1.15rem var(--font-mono);
  width: 100%; min-width: 0; padding: 8px 0; outline: none;
}
.input-unit select { width: auto; flex: none; font-size: 1rem; cursor: pointer; padding-right: 4px; }
.input-unit > span { color: var(--muted); font-size: 0.9rem; }
.field-speed .input-unit { border-color: var(--magenta); }
.input-unit input:disabled, .input-unit select:disabled { opacity: 1; color: var(--ink); -webkit-text-fill-color: var(--ink); cursor: default; }
.input-unit:has(input:disabled) { border-style: dashed; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--magenta); margin: 0; }

/* result */
.result {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: end;
  background: var(--magenta); color: var(--surface);
  border-radius: var(--radius); padding: 20px 22px;
}
.result-label { font-size: 1rem; letter-spacing: 0.08em; opacity: 0.9; }
.result-value { margin: 2px 0 0; display: flex; align-items: baseline; gap: 8px; line-height: 1; }
.result-value .mono { font-size: clamp(3.4rem, 10vw, 5rem); font-weight: 600; }
.result-unit { font-family: var(--font-display); font-size: 1.6rem; text-transform: uppercase; }
.result-exact { margin: 6px 0 0; font-size: 0.9rem; opacity: 0.9; }
.result-stats { margin: 0; display: grid; gap: 8px; }
.result-stats div { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid color-mix(in srgb, var(--surface) 30%, transparent); padding-top: 6px; }
.result-stats dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.85; }
.result-stats dd { margin: 0; font-weight: 600; }
@media (max-width: 560px) { .result { grid-template-columns: minmax(0, 1fr); } }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
thead th.num { font-family: var(--font-body); }
td.strong { font-weight: 600; color: var(--magenta); font-size: 1.02rem; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
.leg-to { margin-right: 6px; }
.pill { display: inline-block; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; border: 1px solid currentColor; }
.pill-port { color: var(--red); }
.pill-starboard { color: var(--green); }
.pill-line { color: var(--muted); }

.coords th[scope="row"] { font-weight: 600; white-space: normal; min-width: 140px; }
.coord-detail { display: block; font-weight: 400; font-size: 0.76rem; color: var(--muted); max-width: 30ch; }
.ddm { display: flex; align-items: center; gap: 4px; font-family: var(--font-mono); color: var(--muted); }
.ddm input {
  font: 500 0.95rem var(--font-mono); color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 6px; min-height: 36px;
}
.ddm input[id$="d"] { width: 4.2em; }
.ddm input[id$="m"] { width: 6em; }
.ddm input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.coords a { color: var(--magenta); font-weight: 600; text-decoration: none; }
.coords a:hover { text-decoration: underline; }

/* chart */
.chart-panel { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); }
@media (max-width: 900px) { .chart-panel { position: static; } }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.plot { width: 100%; height: auto; max-height: 76vh; display: block; border-radius: 6px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.plot .water { fill: var(--water); }
.plot .grid { stroke: var(--grid); stroke-width: 1; }
.plot .grid-label { fill: var(--muted); font: 500 9.5px var(--font-mono); }
.plot .leg { stroke: var(--magenta); stroke-width: 2; }
.plot .arrow-head { fill: var(--magenta); }
.plot .leg-tag circle { fill: var(--magenta); }
.plot .leg-tag text { fill: var(--surface); font: 600 10.5px var(--font-mono); }
.plot .leg-label { fill: var(--ink); font: 600 10.5px var(--font-mono); paint-order: stroke; stroke: var(--water); stroke-width: 3px; stroke-linejoin: round; }
.plot .mark { cursor: grab; touch-action: none; }
.plot.is-dragging .mark { cursor: grabbing; }
.plot .mark:focus { outline: none; }
.plot .mark:focus .hit { stroke: var(--focus); stroke-width: 2; }
.plot .hit { fill: transparent; }
.plot .mark-label { fill: var(--ink); font: 600 11.5px var(--font-body); paint-order: stroke; stroke: var(--water); stroke-width: 3.5px; stroke-linejoin: round; }
.sym-red { fill: var(--red); stroke: var(--surface); stroke-width: 1.5; }
.sym-green { fill: var(--green); stroke: var(--surface); stroke-width: 1.5; }
.sym-buoy { fill: var(--buoy); stroke: var(--surface); stroke-width: 1.5; }
.sym-line { fill: var(--surface); stroke: var(--magenta); stroke-width: 2.5; }
.sym-line-dot { fill: var(--magenta); }
.plot .rose circle { fill: var(--surface); fill-opacity: 0.75; stroke: var(--grid); }
.plot .rose-true { stroke: var(--ink); stroke-width: 1.2; }
.plot .rose-t { fill: var(--ink); font: 600 10px var(--font-mono); }
.plot .rose-mag { fill: var(--magenta); }
.plot .rose-v { fill: var(--magenta); font: 600 9.5px var(--font-mono); }
.plot .scale line { stroke: var(--ink); stroke-width: 1.5; }
.plot .scale text { fill: var(--ink); font: 600 9.5px var(--font-mono); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend svg { width: 14px; height: 14px; }

/* buttons */
.btn {
  font: 600 0.9rem var(--font-body); color: var(--surface); background: var(--ink);
  border: 1px solid var(--ink); border-radius: 8px; padding: 9px 14px; min-height: 40px; cursor: pointer;
}
.btn:hover { opacity: 0.88; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }

/* helm card */
.helm-card {
  background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius);
  padding: 20px; display: grid; gap: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap; }
.card-meta { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.copy-status { font-size: 0.85rem; color: var(--green); font-weight: 600; }
.card-legs { list-style: none; margin: 0; padding: 0; display: grid; }
.card-leg {
  display: grid; grid-template-columns: 2.2rem 7.5rem minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.card-n {
  width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--magenta); color: var(--surface); font: 600 0.95rem var(--font-mono);
}
.card-course { font: 600 2.4rem/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.card-course small { font-size: 1rem; margin-left: 2px; color: var(--muted); }
.card-to { min-width: 0; line-height: 1.35; }
.card-to b { font-size: 1.05rem; }
.card-to .muted { font-size: 0.85rem; }
.card-time { font: 600 1.05rem var(--font-mono); color: var(--muted); text-align: right; }
.card-foot { display: flex; justify-content: space-between; align-items: baseline; border-top: 2px solid var(--ink); padding-top: 12px; }
.card-foot span { font-family: var(--font-display); font-size: 1.2rem; text-transform: uppercase; letter-spacing: 0.04em; }
.card-foot strong { font-size: 1.8rem; color: var(--magenta); }
@media (max-width: 480px) {
  .card-leg { grid-template-columns: 2rem minmax(0, 1fr) auto; }
  .card-course { grid-column: 2; grid-row: 1; font-size: 2rem; }
  .card-to { grid-column: 2 / 4; grid-row: 2; }
  .card-time { grid-column: 3; grid-row: 1; }
}

.foot { font-size: 0.8rem; color: var(--muted); max-width: 72ch; }
.foot p { margin: 0; }
.copy-fallback { position: fixed; left: -9999px; top: 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* print: the helm card only, large type */
@media print {
  :root { --paper: #fff; --surface: #fff; --ink: #000; --muted: #333; --line: #999; --magenta: #000; }
  body { background: #fff; font-size: 13pt; }
  .page > *:not(.helm-card) { display: none !important; }
  .card-actions { display: none; }
  .helm-card { border: 2px solid #000; }
  .card-n { background: #000; color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .card-course { font-size: 30pt; }
}
