/* Here Be Blunders - an inked sea chart: sandy islands on a dotted route over a lined sea, hatched hazard zones,
 * a compass rose, and a ship's logbook page for the island you open. */
:root {
  --bg: #eef3f1; --panel: #fbfcf8; --ink: #14283d; --muted: #4f5f6e; --line: #c9d5d2; --soft: #dfe8e5;
  --accent: #1f4f7a; --accent-ink: #ffffff; --focus: #c2410c;
  --sea: #d4e7e8; --sea-line: #a9cdd1; --frame: #6d8a99; --sand: #efe0b4; --sand-edge: #9c7d3c; --route: #b0392e; --xmark: #b0392e;
  --hz-fill: #f3d3c9; --hz-line: #a8452f; --hz-ink: #6e2416; --isle-no: #14283d; --isle-no-ink: #ffffff;
  --landed: #23704a; --landed-bg: #dcefe3; --stuck: #a8452f; --stuck-bg: #f8e0d8;
  --warn-bg: #f8e3de; --warn-ink: #7a1f12; --info-bg: #e2edf5; --info-ink: #173f60; --note-bg: #fbf0cc; --note-ink: #5a4200;
  --reach: #23704a; --leg: #8a5a06; --rethink: #8e2c5c; --starter: #4f5f6e;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0c1a24; --panel: #122431; --ink: #e5eef2; --muted: #a3b5c0; --line: #2a4152; --soft: #183040;
  --accent: #8cc3ea; --accent-ink: #0b1a25; --focus: #ffb37a;
  --sea: #10283a; --sea-line: #23465d; --frame: #5d8098; --sand: #c9b27a; --sand-edge: #e4cf98; --route: #ff8a7a; --xmark: #ff8a7a;
  --hz-fill: #3a2320; --hz-line: #ff9f86; --hz-ink: #ffd6cb; --isle-no: #e5eef2; --isle-no-ink: #0c1a24;
  --landed: #7fd8a6; --landed-bg: #173a29; --stuck: #ffab94; --stuck-bg: #43231c;
  --warn-bg: #46201a; --warn-ink: #ffd5cc; --info-bg: #15334a; --info-ink: #cfe5f5; --note-bg: #3d3112; --note-ink: #ffe6a6;
  --reach: #7fd8a6; --leg: #f2c06a; --rethink: #f3a2c8; --starter: #a3b5c0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-image: repeating-linear-gradient(0deg, transparent 0 27px, var(--soft) 27px 28px); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hidden { display: none !important; }
.small { font-size: .9rem; } .muted { color: var(--muted); } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.note { background: var(--note-bg); color: var(--note-ink); padding: .4rem .6rem; border-radius: 6px; }
.serif, h1, .ph, .res-head h2, .logbook h3 { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }

.bar { display: flex; align-items: center; gap: .75rem; padding: .55rem 16px; background: var(--panel); border-bottom: 3px double var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.back { text-decoration: none; font-size: .9rem; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: .45rem; font-size: 1.05rem; flex: 1 0 auto; min-width: max-content; white-space: nowrap; font-family: "Iowan Old Style", Palatino, Georgia, serif; }
.logo { width: 30px; height: 30px; flex: none; }
.logo .lg-ring { fill: none; stroke: var(--accent); stroke-width: 2.5; } .logo .lg-n { fill: var(--route); } .logo .lg-s { fill: var(--ink); }
.session { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: .35rem .9rem; cursor: pointer; text-decoration: none; color: var(--ink); min-height: 36px; }
.pill:hover { border-color: var(--accent); }
.pill.solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.ghost { cursor: default; background: transparent; }
.pill.tiny { padding: .15rem .65rem; min-height: 30px; font-size: .85rem; }
.pill.big { padding: .6rem 1.4rem; font-weight: 600; font-size: 1.02rem; }
.pill:disabled { opacity: .55; cursor: not-allowed; }

main { max-width: 1120px; margin: 0 auto; padding: 1rem 16px 2rem; }
.hero { padding: 1rem 0 .5rem; }
.kicker { font-size: .88rem; color: var(--muted); margin: 0 0 .3rem; max-width: 80ch; }
h1 { font-size: clamp(1.7rem, 4.6vw, 2.7rem); line-height: 1.12; margin: 0 0 .5rem; text-wrap: balance; overflow-wrap: anywhere; font-style: italic; }
h2, h3 { overflow-wrap: anywhere; }
.lede { max-width: 66ch; margin: 0 0 .8rem; }
.samples { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: .3rem .9rem; cursor: pointer; min-height: 36px; text-align: left; }
.chip.on { border-color: var(--route); box-shadow: inset 0 0 0 1px var(--route); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 1rem 1.1rem; margin: 1rem 0; box-shadow: 3px 3px 0 var(--soft); }
.ph { font-size: 1.25rem; margin: 0 0 .5rem; display: flex; align-items: center; gap: .5rem; }
.step-no { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; border: 2px solid var(--route); color: var(--route); font-size: .85rem; font-weight: 700; flex: none; font-family: system-ui, sans-serif; }
.lbl { display: block; font-weight: 600; font-size: .9rem; margin: .6rem 0 .25rem; }
input[type=text], input[type=number], select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: .45rem .6rem; background: var(--bg); min-height: 40px; }
textarea { resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.quits { border: 0; margin: .4rem 0 0; padding: 0; min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .1rem 1rem; }
.quits legend { padding: 0; }
.quits label { display: flex; align-items: center; gap: .45rem; min-height: 34px; font-size: .95rem; }
.quits input { width: 18px; height: 18px; flex: none; }
.quits label:has(input:disabled) { color: var(--muted); }
.sub { font-size: 1rem; margin: 1rem 0 .35rem; }

/* the verdict and the tally */
.verdict-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .2rem 0 .5rem; }
.badge { display: inline-block; font-weight: 700; padding: .15rem .7rem; border-radius: 4px; border: 2px solid currentColor; letter-spacing: .02em; white-space: nowrap; }
.badge.v-reachable { color: var(--reach); } .badge.v-first-leg { color: var(--leg); } .badge.v-rethink { color: var(--rethink); } .badge.v-starter, .badge.v-none { color: var(--starter); }
.tally { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .35rem; margin: 0 0 .6rem; }
.tile { border: 1px solid var(--line); border-radius: 6px; padding: .3rem .55rem; display: grid; background: var(--bg); }
.tile b { font-size: 1.05rem; }

/* the chart */
.chart-host { border: 1px solid var(--frame); border-radius: 4px; overflow: hidden; background: var(--sea); }
.chart { display: block; width: 100%; height: auto; max-width: 1000px; margin: 0 auto; }
.chart.portrait { max-width: 440px; }
.chart .sea { fill: var(--sea); }
.chart .wave { fill: none; stroke: var(--sea-line); stroke-width: 1.2; }
.chart .frame { fill: none; stroke: var(--frame); stroke-width: 1.5; stroke-dasharray: 10 4 2 4; }
.chart .route { fill: none; stroke: var(--route); stroke-width: 3; stroke-dasharray: 2 9; stroke-linecap: round; }
.chart .land { fill: var(--sand); stroke: var(--sand-edge); stroke-width: 2; stroke-linejoin: round; }
.chart .isle { cursor: pointer; }
.chart .isle:hover .land, .chart .isle:focus-visible .land { stroke-width: 3.5; }
.chart .isle:focus-visible { outline: none; }
.chart .isle.sel .land { stroke: var(--route); stroke-width: 4; }
.chart .isle.starter .land { stroke-dasharray: 6 3; }
.chart .isle.landed .land { fill: var(--landed-bg); stroke: var(--landed); }
.chart .isle.stuck .land { fill: var(--stuck-bg); stroke: var(--stuck); }
.chart .isle-no { fill: var(--isle-no); }
.chart .isle-num { fill: var(--isle-no-ink); font: 700 15px system-ui, sans-serif; dominant-baseline: middle; }
.chart .isle-name { fill: var(--ink); font: italic 600 15px "Iowan Old Style", Palatino, Georgia, serif; paint-order: stroke; stroke: var(--sea); stroke-width: 4px; stroke-linejoin: round; }
.chart .flag { fill: var(--route); stroke: var(--ink); stroke-width: 1.5; }
.chart .landed-flag { fill: var(--landed); }
.chart .buoy { fill: var(--stuck); stroke: var(--ink); stroke-width: 1.5; } .chart .buoy-pole { stroke: var(--ink); stroke-width: 2; }
.chart .harbour-label, .chart .x-label { fill: var(--ink); font: italic 14px "Iowan Old Style", Palatino, Georgia, serif; paint-order: stroke; stroke: var(--sea); stroke-width: 4px; stroke-linejoin: round; }
.chart .x-label { font-weight: 700; fill: var(--xmark); }
.chart .x { fill: none; stroke: var(--xmark); stroke-width: 6; stroke-linecap: round; }
.chart .hazard { cursor: pointer; }
.chart .hazard:focus-visible { outline: none; }
.chart .hz-zone { fill: url(#hb-hatch); stroke: var(--hz-line); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .hazard:hover .hz-zone, .chart .hazard:focus-visible .hz-zone { stroke-width: 3; }
.chart .hz-hatch { stroke: var(--hz-line); stroke-width: 2; opacity: .35; }
.chart .hz-name { fill: var(--hz-ink); font: 700 14px system-ui, sans-serif; paint-order: stroke; stroke: var(--sea); stroke-width: 4px; stroke-linejoin: round; }
.chart .hz-sub { fill: var(--hz-ink); font: italic 12px "Iowan Old Style", Palatino, Georgia, serif; paint-order: stroke; stroke: var(--sea); stroke-width: 3px; }
.chart .cp-ring { fill: none; stroke: var(--frame); stroke-width: 1.5; } .chart .cp-ring.thin { stroke-dasharray: 2 3; }
.chart .cp-n { fill: var(--route); } .chart .cp-pt { fill: var(--ink); } .chart .cp-pt.thin { fill: var(--frame); }
.chart .cp-label { fill: var(--ink); font: 700 13px system-ui, sans-serif; }
.chart .scale { stroke: var(--ink); stroke-width: 3; stroke-dasharray: 15 15; }
.chart .scale-label { fill: var(--muted); font: italic 13px "Iowan Old Style", Palatino, Georgia, serif; }

/* the logbook page for the open island */
.logbook { border: 1px solid var(--line); border-left: 8px double var(--accent); border-radius: 4px; padding: .7rem .9rem; margin: .7rem 0; background: var(--panel); }
.logbook.m-landed { border-left-color: var(--landed); } .logbook.m-stuck { border-left-color: var(--stuck); }
.lb-top { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.lb-no { display: inline-grid; place-items: center; min-width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--isle-no); color: var(--isle-no-ink); font-weight: 800; }
.logbook h3 { margin: .3rem 0 .3rem; font-size: 1.25rem; font-style: italic; }
.lb-grid { display: grid; grid-template-columns: 9.5rem 1fr; gap: .25rem .8rem; margin: .2rem 0; }
.lb-grid dt { font-weight: 700; font-size: .85rem; color: var(--muted); padding-top: .1rem; }
.lb-grid dd { margin: 0; }
.markpill { display: inline-block; font-size: .78rem; font-weight: 700; padding: .05rem .5rem; border-radius: 4px; white-space: nowrap; }
.markpill.landed { background: var(--landed-bg); color: var(--landed); } .markpill.stuck { background: var(--stuck-bg); color: var(--stuck); }
.cardrow { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.stuckrow { margin-top: .3rem; }
.route-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .45rem; }
.rl { border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.rl.sel { box-shadow: 0 0 0 2px var(--route); }
.rl.landed { border-color: var(--landed); } .rl.stuck { border-color: var(--stuck); }
.rl-btn { display: grid; gap: .15rem; width: 100%; text-align: left; background: none; border: 0; padding: .5rem .65rem; cursor: pointer; }
.rl-head { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; }
.rl-no { display: inline-grid; place-items: center; min-width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--isle-no); color: var(--isle-no-ink); font-size: .82rem; }
.rl-name { font-family: "Iowan Old Style", Palatino, Georgia, serif; font-style: italic; }
.rl-hours { font-size: .82rem; color: var(--muted); }
.rl-build { font-size: .92rem; } .rl-done { font-size: .84rem; color: var(--muted); }
.rl-print { display: none; }
.hazards, .rules, .weeks, .plain, .recon, .saved { list-style: none; padding: 0; margin: 0; }
.hazards li { border-left: 4px solid var(--hz-line); padding: .35rem .6rem; margin: .3rem 0; background: var(--bg); border-radius: 0 4px 4px 0; }
.hazards li.open { background: var(--hz-fill); color: var(--hz-ink); }
.hazards li.open .muted { color: var(--hz-ink); }
.hazards .rule { margin: .2rem 0 0; }
.weeks li { padding: .2rem 0; border-bottom: 1px dotted var(--line); }
.exports { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }

/* run, progress, result */
.runrow { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: .6rem; }
.gate { background: var(--info-bg); color: var(--info-ink); padding: .5rem .7rem; border-radius: 6px; }
.steps { list-style: none; padding: 0; margin: .3rem 0; }
.step { padding: .15rem 0; color: var(--muted); } .step.active { color: var(--ink); font-weight: 600; } .step.done { color: var(--reach); }
.step-ic { display: inline-block; width: 1.2rem; font-family: ui-monospace, Menlo, monospace; }
.raw { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 360px; overflow: auto; background: var(--bg); padding: .6rem; border-radius: 6px; }
.res-head { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.res-head h2 { margin: 0; font-size: 1.4rem; font-style: italic; }
.summary { font-size: 1.02rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.4rem; }
.cols h3, .result h3 { font-size: 1rem; margin: .9rem 0 .3rem; }
.rules li { padding: .3rem 0; border-bottom: 1px dotted var(--line); }
.plain li { padding: .25rem 0; border-bottom: 1px dotted var(--line); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.recon li { padding: .35rem .6rem; border-radius: 6px; margin: .25rem 0; font-size: .9rem; }
.recon li.warn { background: var(--warn-bg); color: var(--warn-ink); } .recon li.info { background: var(--info-bg); color: var(--info-ink); }
.recon li.none, .plain li.none, .rules li.none, .saved li.none { background: none; color: var(--muted); border: 0; }
.saved .hrow { display: flex; gap: .6rem; align-items: center; padding: .45rem 0; border-bottom: 1px dotted var(--line); }
.hinfo { flex: 1; min-width: 0; display: grid; } .hinfo b { overflow-wrap: anywhere; }
.hbtns { display: flex; gap: .3rem; flex: none; }
.mini { width: 40px; height: 28px; flex: none; }
.mini .sea { fill: var(--sea); stroke: var(--frame); } .mini .route { fill: none; stroke: var(--route); stroke-width: 2; stroke-dasharray: 1 3; stroke-linecap: round; } .mini .x { stroke: var(--xmark); stroke-width: 2.5; }
.mini.v-reachable .sea { stroke: var(--reach); } .mini.v-first-leg .sea { stroke: var(--leg); } .mini.v-rethink .sea { stroke: var(--rethink); }
.foot { max-width: 1120px; margin: 0 auto; padding: 0 16px 2rem; font-size: .9rem; color: var(--muted); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: .4rem; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--panel); padding: .55rem .8rem; border-radius: 6px; font-size: .92rem; transition: opacity .5s; }
.toast.err { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-ink); }
.toast a { color: inherit; font-weight: 700; }
.toast.gone { opacity: 0; }

@media (max-width: 720px) {
  .two, .cols { grid-template-columns: 1fr; }
  .panel { padding: .9rem .8rem; }
  .route-list { grid-template-columns: 1fr; }
  .lb-grid { grid-template-columns: 1fr; gap: 0; }
  .lb-grid dd { margin-bottom: .35rem; }
  .bar { gap: .5rem; }
  .back { font-size: .82rem; }
  .session .pill { padding: .3rem .7rem; }
}

/* Print: the chart and the island list as a logbook to tick off. */
@media print {
  body { background: #fff; color: #000; }
  .bar, .hero, .panel:not(.chartbox), .foot, .toasts, .chartbox .exports, .chartbox .cardrow, .chartbox .verdict-row, .chartbox .tally, #sourceNote, .logbook { display: none !important; }
  .chartbox { border: 0; box-shadow: none; padding: 0; margin: 0; }
  .chart-host { break-inside: avoid; }
  .route-list { display: block; }
  .rl { break-inside: avoid; border: 1px solid #000; margin: 0 0 3mm; box-shadow: none !important; }
  .rl-print { display: block; font-size: .85rem; }
  .rl-done, .rl-hours { color: #333; }
}
@media (max-width: 480px) {
  .back-t { display: none; }
  .bar { gap: .4rem; padding: .5rem 12px; }
  .brand { font-size: 1rem; gap: .35rem; }
  .logo { width: 26px; height: 26px; }
  .session { gap: .3rem; }
  .session .pill { padding: .25rem .6rem; min-height: 34px; font-size: .92rem; }
}
