:root {
  --paper: #f4ead2;
  --paper-2: #e9dbb8;
  --ink: #3a2716;
  --ink-2: #5c4630;
  --muted: #665238; /* 4.5:1 or better on the vellum (WCAG 2.2 AA); was #9a8466 at 2.99:1 */
  --red: #a2372b;
  --sea-ink: #1e3246;
  --good: #3f6b3a;
  --gold: #7a4f0c; /* was #9a6a12 at 3.95:1 */
  --shadow: 0 8px 30px rgba(40, 25, 10, 0.28);
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --display: "IM Fell English", Georgia, serif;
  /* materials: photographs of vellum, tooled leather and oak (tools/art/publish.py calms them so
     text over them keeps AA contrast) */
  --vellum: #f6eedb url(img/ui/vellum.webp) center / cover;
  --leather: linear-gradient(rgba(20, 10, 4, 0.15), rgba(20, 10, 4, 0.15)), url(img/ui/leather.webp) center / 420px #3b2416;
  --oak: #2a1a0e url(img/ui/oak.webp) center / cover;
  --on-dark: #efdcae;   /* text on leather and oak */
  --on-dark-2: #ecd9a8; /* smaller labels on leather */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #ecdfc0; color: var(--ink); font-family: var(--serif); font-size: 16px; }
#chart { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }

button {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid var(--ink-2);
  border-radius: 4px; padding: 5px 10px; cursor: pointer; line-height: 1.2;
}
button:hover:not(:disabled) { background: #fff7e3; }
button:disabled { opacity: 0.4; cursor: default; }
button.on { background: var(--ink); color: var(--paper); }
button.icon { display: inline-flex; align-items: center; justify-content: center; padding: 4px 8px; min-width: 38px; }
button.icon svg { display: block; }
button.primary { background: var(--red); border-color: #6e2219; color: #fff6e6; font-weight: 600; }
button.primary:hover { background: #b8473a; }
button.danger { color: var(--red); border-color: var(--red); }

/* HUD */
#hud {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 8px 14px;
  align-items: center; pointer-events: none; z-index: 6; /* the top bar stays reachable above panels */
}
#hud > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); background: rgba(244, 234, 210, 0.92); border: 1px solid var(--ink-2); border-radius: 6px; box-shadow: var(--shadow); padding: 5px 12px 5px 7px; }
.brand img { display: block; }
.brand .word { font-family: "IM Fell English SC", var(--display); font-size: 27px; letter-spacing: 0.05em; line-height: 1; }
.brand .tag { font-size: 13px; font-family: var(--serif); color: var(--ink-2); font-style: italic; align-self: flex-end; margin-bottom: 3px; }
.stats { display: flex; gap: 2px; background: rgba(244, 234, 210, 0.92); border: 1px solid var(--ink-2); border-radius: 6px; box-shadow: var(--shadow); }
.stats > div { padding: 4px 12px; display: flex; flex-direction: column; border-left: 1px solid rgba(107, 82, 54, 0.25); }
.stats > div:first-child { border-left: 0; }
.stats small { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stats span { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats > div.big { padding: 4px 16px; }
.stats > div.big span { font-size: 23px; font-weight: 600; line-height: 1.1; }
#hud-purse.debt { color: var(--red); font-weight: 600; }
.controls { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; min-width: 38px; }
.seg button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.seg button:last-child { border-radius: 0 4px 4px 0; }

#status {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(244, 234, 210, 0.94); border: 1px solid var(--ink-2); border-radius: 6px; padding: 6px 14px;
  font-size: 15px; box-shadow: var(--shadow); max-width: calc(100vw - 24px); text-align: center; pointer-events: none;
}

/* Panel */
#panel {
  position: fixed; top: calc(var(--hud-h, 66px) + 10px); right: 10px; width: min(520px, calc(100vw - 20px)); max-height: calc(100vh - var(--hud-h, 66px) - 74px); overflow: auto; /* --hud-h: the top bar, however many rows it wraps to (main.js) */
  background: var(--paper); border: 1px solid var(--ink-2); border-radius: 8px; box-shadow: var(--shadow); padding: 14px 16px 16px;
  z-index: 4; /* above the zoom buttons and tips */
  background-image: linear-gradient(rgba(255,255,255,0.25), rgba(0,0,0,0.02));
}
#panel.wide { width: min(720px, calc(100vw - 20px)); }
.pricebook th, .pricebook td { padding: 5px 5px; font-size: 15px; }
#panel header { display: flex; justify-content: space-between; align-items: baseline; }
#panel h2 { font-family: var(--display); font-weight: 400; font-size: 28px; margin: 0; }
#panel h3 { font-family: var(--display); font-weight: 400; font-size: 19px; margin: 16px 0 6px; }
#panel .close { border: 0; background: none; font-size: 24px; padding: 0 4px; }
.blurb { margin: 4px 0 10px; color: var(--ink-2); font-style: italic; }
.foot { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 6px; border-bottom: 1px solid rgba(107, 82, 54, 0.2); text-align: left; vertical-align: middle; }
thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 400; }
th[scope=row] { font-weight: 600; white-space: nowrap; }
th small, td small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.num { text-align: right; }
.market td.acts { text-align: right; white-space: nowrap; }
.market td.acts button { padding: 3px 7px; font-size: 13px; margin-left: 2px; }
.scroll { overflow-x: auto; }
.pricebook td.hi { color: var(--gold); font-weight: 600; }
.pricebook td.lo { color: var(--good); }
.pricebook .stale { opacity: 0.45; }
.pricebook thead th { white-space: normal; max-width: 92px; line-height: 1.15; vertical-align: bottom; }
.pricebook thead th small { white-space: normal; }
.sugg { padding-left: 20px; margin: 0; }
.sugg li { margin-bottom: 6px; line-height: 1.35; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.log li { padding: 2px 0; }
.log span { color: var(--muted); font-size: 12px; margin-right: 6px; }

/* Toasts */
#toast { position: fixed; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 46px); transform: translateX(-50%); display: flex; flex-direction: column-reverse; gap: 6px; align-items: center; pointer-events: none; z-index: 5; }
#toast .t {
  background: rgba(58, 39, 22, 0.94); color: #f6ecd4; padding: 8px 16px; border-radius: 6px; box-shadow: var(--shadow);
  font-size: 16px; max-width: min(var(--toast-max, 560px), 92vw); text-align: center; transition: opacity 0.5s, transform 0.5s;
}
#toast .t.discover { background: rgba(162, 55, 43, 0.95); }
#toast .t.out { opacity: 0; transform: translateY(-6px); }

/* Intro */
#intro { position: fixed; inset: 0; background: rgba(46, 36, 27, 0.55); display: grid; place-items: center; z-index: 10; padding: 16px; }
#intro[hidden], #panel[hidden], #modal[hidden], button[hidden] { display: none; }

/* Contracts */
.contracts { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.contract { border: 1px solid rgba(107, 82, 54, 0.35); border-radius: 6px; padding: 9px 12px; background: rgba(255, 255, 255, 0.35); }
.contract p { margin: 4px 0 0; font-size: 14px; line-height: 1.35; }
.contract .row { margin-top: 8px; }
.c-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.c-title { font-family: var(--display); font-size: 18px; }
.c-pay { font-weight: 600; color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums; }
.c-patron { font-size: 13px; font-style: italic; color: var(--ink-2); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 3px; border-radius: 9px; background: var(--red); color: #fff6e6; font-size: 12px; line-height: 18px; text-align: center; font-weight: 600; }
.badge[hidden] { display: none; }

/* Standing, news, fleet routes, help */
.standing { border: 1px solid rgba(107, 82, 54, 0.3); border-radius: 6px; padding: 8px 12px; margin: 4px 0 6px; background: rgba(255, 255, 255, 0.3); }
.standing p { margin: 2px 0; font-size: 14px; line-height: 1.35; }
.banner { border: 1px solid currentColor; border-radius: 6px; padding: 7px 10px; margin: 0 0 10px; font-size: 14px; }
.news, .help { padding-left: 18px; margin: 0; }
.news li, .help li { margin-bottom: 6px; font-size: 14px; line-height: 1.4; }
.route { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; margin-top: 8px; }
.route label { display: flex; flex-direction: column; font-size: 12px; color: var(--ink-2); gap: 2px; }
.route select { font: inherit; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid var(--ink-2); border-radius: 4px; padding: 4px 6px; min-height: 34px; }

/* Zoom buttons and tips */
#zoom { position: fixed; right: 10px; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; box-shadow: var(--shadow); border-radius: 6px; z-index: 3; }
#zoom button { width: 40px; height: 40px; font-size: 22px; line-height: 1; padding: 0; border-radius: 0; }
#zoom button:first-child { border-radius: 6px 6px 0 0; }
#zoom button:last-child { border-radius: 0 0 6px 6px; margin-top: -1px; }
/* the note sits under the top bar, clear of the toasts at the bottom and beside an open panel */
#tip { position: fixed; left: 10px; top: calc(var(--hud-h, 66px) + 10px + var(--amb-h, 0px)); max-width: min(360px, calc(100vw - 80px)); background: rgba(244, 234, 210, 0.96); border: 1px solid var(--gold); border-radius: 6px; box-shadow: var(--shadow); padding: 7px 30px 8px 12px; font-size: 14px; line-height: 1.35; z-index: 2; }
#tip[hidden] { display: none; }
body.panel-open #tip { max-width: min(360px, calc(100vw - min(520px, 100vw - 20px) - 40px)); }
#tip .tip-label { display: block; font-family: var(--display); color: var(--gold); font-size: 14px; }
#tip .tip-off { display: block; margin-top: 4px; border: 0; background: none; padding: 0; font-size: 12px; text-decoration: underline; color: inherit; opacity: 0.75; cursor: pointer; }
#tip-close { position: absolute; top: 2px; right: 2px; border: 0; background: none; font-size: 18px; padding: 2px 6px; color: var(--ink-2); }

/* Cloud save */
#btn-cloud { position: relative; }
#btn-cloud .dot { position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: transparent; }
#btn-cloud.linked .dot { background: var(--good); }
#btn-cloud.problem .dot { background: var(--red); }
.save-code { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; }
.save-code span { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 22px; letter-spacing: 0.08em; background: rgba(255,255,255,0.5); border: 1px dashed var(--ink-2); border-radius: 6px; padding: 6px 12px; }
.code-form label { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; font: inherit; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 17px; letter-spacing: 0.06em; text-transform: uppercase; padding: 8px 10px; border: 1px solid var(--ink-2); border-radius: 4px; background: #fffaf0; color: var(--ink); min-height: 44px; }
button.link { border: 0; background: none; padding: 0; color: var(--red); text-decoration: underline; font-size: inherit; }

/* Route editor */
.contract details { margin-top: 8px; }
.contract summary { cursor: pointer; font-size: 14px; color: var(--ink-2); }
.route-editor { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.stop { border: 1px solid rgba(107, 82, 54, 0.3); border-radius: 6px; padding: 7px 8px; background: rgba(255, 255, 255, 0.35); display: flex; flex-direction: column; gap: 5px; }
.stop-head { display: flex; align-items: center; gap: 8px; }
.stop-n { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 13px; display: grid; place-items: center; font-weight: 600; }
.stop-head select { flex: 1; }
.order { display: grid; grid-template-columns: 76px minmax(0, 1fr) 118px 30px; gap: 5px; align-items: center; }
.route-editor select { font: inherit; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid var(--ink-2); border-radius: 4px; padding: 4px 6px; min-height: 34px; min-width: 0; }
button.mini { font-size: 13px; padding: 3px 8px; justify-self: start; }
.stop > button.mini { align-self: flex-start; }
.stop-arrow { text-align: center; color: var(--muted); font-size: 13px; line-height: 1; }
.row.choice { justify-content: stretch; }
.row.choice button { flex: 1; min-height: 44px; }
.banner button { margin-left: 8px; }

/* Destination list */
.dests { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 6px; }
.dests .dest { width: 100%; min-height: 48px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 8px 12px; }
.dests .dest .name { font-family: var(--display); font-size: 19px; }
.dests .dest .meta { font-size: 13px; color: var(--ink-2); }

/* Panel tabs */
.tabs { display: flex; gap: 0; margin: -4px 0 10px; border-bottom: 1px solid rgba(107, 82, 54, 0.3); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 0 0 auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 14px 7px; font-size: 15px; color: var(--ink-2); }
.tabs button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.4); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--red); font-weight: 600; background: none; }

/* Confirmation dialog */
/* The dialog floats over the chart: the chart underneath can still be zoomed and panned. */
#modal { position: fixed; inset: 0; background: rgba(46, 36, 27, 0.18); display: grid; place-items: center; z-index: 20; padding: 16px; pointer-events: none; }
#modal.aside { background: transparent; place-items: start; padding: calc(var(--hud-h, 66px) + 10px) 10px 10px; }
#modal .card { pointer-events: auto; width: min(420px, 100%); background: var(--paper); border: 1px solid var(--ink-2); border-radius: 10px; padding: 20px 22px 16px; box-shadow: var(--shadow);
  /* never taller than the screen: the body scrolls and the buttons stay in view */
  display: flex; flex-direction: column; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
#modal-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#modal .card > .row { flex: none; padding-top: 6px; }
#modal.aside .card { max-height: calc(100vh - 86px); max-height: calc(100dvh - 86px); }
#modal h2 { font-family: var(--display); font-weight: 400; font-size: 26px; margin: 0 0 10px; line-height: 1.15; }
#modal p { margin: 8px 0; }
#modal .fine { font-size: 13px; color: var(--muted); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-variant-numeric: tabular-nums; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; text-align: right; font-weight: 600; }
.warn { color: var(--red); }
#intro .card {
  max-width: 560px; background: var(--paper); border: 1px solid var(--ink-2); border-radius: 10px; padding: 26px 30px 20px;
  box-shadow: var(--shadow); max-height: calc(100vh - 32px); overflow: auto;
}
#intro .lockup { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 14px; }
#intro .lockup img { display: block; }
#intro h1 { font-family: "IM Fell English SC", var(--display); font-weight: 400; font-size: 56px; margin: 4px 0 0; line-height: 1; letter-spacing: 0.06em; }
#intro .tagline { display: flex; align-items: center; gap: 12px; margin: 0; font-style: italic; color: var(--ink-2); font-size: 18px; letter-spacing: 0.04em; }
#intro .tagline span { display: block; width: 44px; height: 1px; background: var(--ink-2); }
#intro .sub { font-style: italic; color: var(--ink-2); margin: 0 0 10px; text-align: center; }
#intro ul { padding-left: 18px; line-height: 1.4; }
#intro li { margin-bottom: 5px; }
#intro .fine { font-size: 13px; color: var(--muted); text-align: right; margin: 10px 0 0; }

@media (max-width: 700px) {
  .brand { display: none; }
  .stats > div { padding: 3px 8px; }
  .stats span { font-size: 14px; }
  .stats > div.big { padding: 3px 10px; }
  .stats > div.big span { font-size: 19px; }
  .controls { margin-left: 0; }
  #panel { top: auto; bottom: 60px; right: 8px; left: 8px; width: auto; max-height: 58vh; }
  #status { font-size: 13px; }
  #toast { top: auto; left: 8px; right: 58px; transform: none; flex-direction: column; justify-content: flex-end; align-items: stretch; overflow: hidden; }
  #toast .t { max-width: none; font-size: 14px; padding: 7px 12px; text-align: left; }
  #modal.aside { align-items: end; justify-items: stretch; padding: 10px 8px 60px; }
  #modal.aside .card { max-height: calc(100vh - 70px); max-height: calc(100dvh - 70px); }
  #zoom { bottom: 64px; }
  #zoom button { width: 44px; height: 44px; }
  #tip, body.panel-open #tip { left: 8px; right: 8px; top: calc(var(--hud-h, 60px) + 8px + var(--amb-h, 0px)); max-width: none; font-size: 13px; z-index: 6; }
  .route { grid-template-columns: minmax(0, 1fr); }
  .order { grid-template-columns: 66px minmax(0, 1fr) 30px; }
  .order select[data-f="pct"] { grid-column: 2 / 3; }
  .order > span { display: none; }
  .market th small { white-space: normal; }
  .market th, .market td { padding: 4px 3px; font-size: 14px; }
  .market td.acts button { padding: 3px 5px; font-size: 12px; margin-left: 1px; }
  .market td.acts button[data-n="1"][data-buy] { display: none; }
  #panel h2 { font-size: 24px; }
}

/* Ledger */
.accounts { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.accounts th, .accounts td { padding: 5px 6px; font-size: 15px; border-bottom: 1px solid rgba(107, 82, 54, 0.18); vertical-align: top; text-align: left; }
.accounts th.num, .accounts td.num { text-align: right; white-space: nowrap; }
.accounts tfoot th, .accounts tfoot td { font-weight: 600; border-top: 1px solid var(--ink-2); border-bottom: 0; }
.accounts .in { color: var(--good); }
.accounts .out, .facts dd.out { color: var(--red); }
.accounts small { display: block; color: var(--muted); font-size: 13px; }
.accounts .when { white-space: nowrap; width: 1%; }
.accounts .who { font-weight: 600; }
.who-filter { display: flex; align-items: center; gap: 8px; margin: 2px 0 8px; font-size: 14px; color: var(--ink-2); }
.who-filter select { font: inherit; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid var(--ink-2); border-radius: 4px; padding: 4px 6px; min-height: 34px; }
.accounts thead th { white-space: normal; font-size: 12px; line-height: 1.15; vertical-align: bottom; }
@media (max-width: 520px) {
  .accounts th, .accounts td { padding: 4px 3px; font-size: 14px; }
  .accounts .when { white-space: normal; width: 74px; }
}

/* Notices */
#toast .t { pointer-events: auto; cursor: pointer; }
#btn-notices { position: relative; }
#btn-notices .dot-badge { position: absolute; top: -6px; right: -6px; margin: 0; min-width: 18px; padding: 0 4px; font-size: 11px; line-height: 17px; }
.notices { list-style: none; margin: 0; padding: 0; }
.notices li.day { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 12px 0 4px; }
.notices li.day:first-child { margin-top: 0; }
.notices li.n { padding: 7px 10px; margin-bottom: 5px; border-left: 3px solid var(--ink-2); background: rgba(255, 255, 255, 0.35); border-radius: 0 4px 4px 0; font-size: 15px; line-height: 1.35; }
.notices li.n.discover { border-left-color: var(--red); }
.notices li.n.port { border-left-color: var(--good); }

/* Feedback */
.feedback-entry { justify-content: flex-start; margin: 0 0 6px; }
.feedback { display: flex; flex-direction: column; gap: 10px; }
.feedback .seg.kind { display: flex; gap: 0; }
.feedback .seg.kind label { flex: 1; text-align: center; padding: 8px 6px; border: 1px solid var(--ink-2); cursor: pointer; font-size: 15px; background: var(--paper); min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.feedback .seg.kind label:first-child { border-radius: 6px 0 0 6px; }
.feedback .seg.kind label:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.feedback .seg.kind label.on { background: var(--ink); color: var(--paper); }
.feedback .seg.kind input { position: absolute; opacity: 0; pointer-events: none; }
.feedback .field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink-2); }
.feedback textarea, .feedback input[name="contact"] { font: inherit; font-size: 16px; color: var(--ink); background: #fffaf0; border: 1px solid var(--ink-2); border-radius: 4px; padding: 8px 10px; width: 100%; box-sizing: border-box; }
.feedback textarea { resize: vertical; min-height: 120px; }
.feedback .check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.feedback details summary { cursor: pointer; }
.facts.small dt, .facts.small dd { font-size: 12px; font-weight: 400; }
.facts.small dd { text-align: left; overflow-wrap: anywhere; }

/* Bottom bar for phones: time, Sail, Books, More. Hidden on wide screens. */
#dock { display: none; }
@media (max-width: 700px) {
  :root { --dock: calc(58px + env(safe-area-inset-bottom)); }
  /* top: one row, the figures and the bell */
  #hud { flex-wrap: nowrap; gap: 6px; left: 8px; right: 8px; top: max(8px, env(safe-area-inset-top)); }
  .stats { flex: 1 1 auto; min-width: 0; }
  .stats > div, .stats > div.big { padding: 3px 7px; min-width: 0; }
  .stats small { font-size: 10px; }
  .stats span { font-size: 13px; }
  .stats > div.big span { font-size: 18px; }
  .controls { flex: 0 0 auto; flex-wrap: nowrap; margin-left: 0; }
  .controls > *:not(#btn-notices) { display: none !important; }
  #btn-notices { width: 46px; height: 46px; }
  /* bottom bar */
  #dock {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
    height: var(--dock); padding: 0 4px env(safe-area-inset-bottom); box-sizing: border-box;
    background: rgba(244, 234, 210, 0.97); border-top: 1px solid var(--ink-2); box-shadow: 0 -2px 10px rgba(46, 36, 27, 0.18);
  }
  #dock button {
    position: relative; border: 0; background: none; border-radius: 8px; margin: 4px 2px; padding: 2px 0 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 12px; color: var(--ink-2); min-height: 48px;
  }
  #dock button .ico { font-size: 18px; line-height: 22px; height: 22px; color: var(--ink); font-weight: 600; }
  #dock button.on { background: var(--ink); color: var(--paper); }
  #dock button.on .ico { color: var(--paper); }
  #dock button.alert::after { content: ''; position: absolute; top: 6px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
  #dock .dot-badge { position: absolute; top: 2px; right: calc(50% - 22px); margin: 0; min-width: 16px; font-size: 10px; line-height: 16px; padding: 0 4px; }
  /* everything that sat at the bottom moves up above the bar */
  #status { bottom: calc(var(--dock) + 8px); }
  #zoom { bottom: calc(var(--dock) + 10px); }
  #panel { bottom: calc(var(--dock) + 6px); max-height: calc(100vh - var(--dock) - 84px - var(--tip-h, 0px)); max-height: calc(100dvh - var(--dock) - 84px - var(--tip-h, 0px)); }
  /* with a panel open the panel gives the note room (--tip-h, panels.js) */
  #modal.aside { padding: 10px 8px calc(var(--dock) + 8px); }
  #modal.aside .card { max-height: calc(100vh - var(--dock) - 24px); max-height: calc(100dvh - var(--dock) - 24px); }
}

/* The More menu */
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-grid button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 10px 12px; min-height: 56px; }
.menu-grid button b { font-weight: 600; font-size: 15px; }
.menu-grid button small { font-size: 12px; color: #dcc89c; } /* light on the leather buttons (var(--muted) is for the vellum) */

/* ---- Ship register and shipyard (full screen) ---- */
#yard { position: fixed; inset: 0; z-index: 9; background: rgba(46, 36, 27, 0.55); display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
#yard[hidden], #scene[hidden] { display: none; }
body.screen-open #toast { z-index: 11; }
.yard-card {
  width: min(1120px, 100%); height: min(860px, 100%); display: flex; flex-direction: column; overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #f8f0dc 0%, var(--paper) 55%, #e6d5ad 100%); border: 1px solid var(--ink-2); border-radius: 12px; box-shadow: 0 18px 60px rgba(30, 18, 6, 0.5);
}
.yard-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 22px 10px; border-bottom: 1px solid rgba(107, 82, 54, 0.35); }
.yard-head h2 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0; line-height: 1.1; }
.yard-head .sub { margin: 2px 0 0; color: var(--ink-2); font-style: italic; }
.yard-head .close { font-size: 22px; line-height: 1; padding: 4px 11px; }
.yard-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 22px 24px; overscroll-behavior: contain; }
.yard-body.split { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 22px; overflow: hidden; padding-bottom: 0; }
.yard-body.split > section { overflow-y: auto; padding-bottom: 18px; overscroll-behavior: contain; }
.ship-art { display: block; width: 100%; height: auto; }
.art.big { background: linear-gradient(#e9ddc0, #f3e8cf 60%); border: 1px solid rgba(107, 82, 54, 0.4); border-radius: 8px; box-shadow: inset 0 0 40px rgba(120, 90, 40, 0.18); overflow: hidden; }
.yard-card .sec { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 22px 0 4px; border-bottom: 1px solid rgba(107, 82, 54, 0.3); padding-bottom: 3px; }
.yard-card .fine { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.yard-card .row.start { justify-content: flex-start; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.hero { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 22px; align-items: center; }
.hero .kicker { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; font-size: 12px; color: var(--gold); }
.hero h3 { font-family: var(--display); font-weight: 400; font-size: 34px; margin: 2px 0 4px; line-height: 1.05; }
.ship-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; margin: 12px 0 4px; }
.ship-stats > div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted rgba(107, 82, 54, 0.35); padding: 3px 0; }
.ship-stats dt { color: var(--ink-2); font-size: 14px; }
.ship-stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta { margin-left: 4px; font-size: 11px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--red); }
.hulls { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; position: relative; }
.hulls:not(.compact)::before { content: ''; position: absolute; left: 0; right: 0; top: 13px; border-top: 2px solid rgba(107, 82, 54, 0.4); }
.hull-card { position: relative; background: rgba(255, 250, 238, 0.55); border: 1px solid rgba(107, 82, 54, 0.35); border-radius: 8px; padding: 30px 12px 12px; font-size: 14px; line-height: 1.35; }
.hulls.compact .hull-card { padding-top: 10px; }
.hull-card .year { position: absolute; top: 2px; left: 10px; background: var(--paper); border: 1px solid var(--ink-2); border-radius: 12px; padding: 1px 9px; font-size: 13px; font-weight: 600; }
.hull-card h4 { font-family: var(--display); font-weight: 400; font-size: 20px; margin: 6px 0 2px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hull-card p { margin: 4px 0; }
.hull-card .nums { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.hull-card.pencil { background: rgba(255, 250, 238, 0.25); border-style: dashed; color: var(--ink-2); }
.hull-card .need { color: var(--gold); font-style: italic; }
.hull-card .ship-stats { grid-template-columns: 1fr; font-size: 13px; }
.tag { font-family: var(--serif); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; border: 1px solid var(--ink-2); border-radius: 10px; padding: 1px 7px; color: var(--ink-2); background: var(--paper); }
.tag.own { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tag.order { border-color: var(--gold); color: var(--gold); }
.tag.locked { border-style: dashed; }
.orders, .fleet-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.order-card { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: center; background: rgba(255, 250, 238, 0.55); border: 1px solid rgba(107, 82, 54, 0.35); border-radius: 8px; padding: 8px 14px 8px 8px; }
.order-card h4 { font-family: var(--display); font-weight: 400; font-size: 20px; margin: 0 0 2px; }
.order-card p { margin: 3px 0; }
.bar { height: 6px; background: rgba(107, 82, 54, 0.18); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; background: var(--gold); }
.fleet-list { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.hired { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; font-size: 14px; }
.stage .name { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-style: italic; color: var(--ink-2); }
.stage .name input { flex: 1; font: inherit; font-family: var(--display); font-style: normal; font-size: 20px; color: var(--ink); background: rgba(255, 250, 238, 0.7); border: 1px solid var(--ink-2); border-radius: 4px; padding: 3px 8px; min-width: 0; }
.choices .tabs { position: sticky; top: 0; background: var(--paper); z-index: 1; padding-top: 2px; }
.opt-group { border: none; padding: 0; margin: 14px 0 6px; }
.opt-group legend { font-family: var(--display); font-size: 19px; padding: 0; margin-bottom: 4px; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
button.opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 8px 10px; background: rgba(255, 250, 238, 0.6); border-color: rgba(107, 82, 54, 0.5); border-radius: 6px; font-size: 14px; }
button.opt .note { font-size: 12.5px; color: var(--ink-2); line-height: 1.3; }
button.opt .price { font-size: 12.5px; color: var(--gold); font-weight: 600; margin-top: 2px; }
button.opt.on { background: #fff7e3; border-color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); color: var(--ink); }
button.opt.current:not(.on) .price { color: var(--muted); }
.yard-foot { border-top: 1px solid rgba(107, 82, 54, 0.35); padding: 10px 22px 14px; display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; align-items: end; background: rgba(233, 219, 184, 0.6); }
.yard-foot .row { margin: 0; }
.yard-foot .warn.fine { grid-column: 1 / -1; margin: 0; color: var(--red); }
.bill { list-style: none; margin: 0; padding: 0; font-size: 14px; max-height: 96px; overflow-y: auto; }
.bill li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dotted rgba(107, 82, 54, 0.3); }
.total { display: flex; justify-content: space-between; gap: 12px; margin: 4px 0 0; font-size: 16px; }
.bill-wrap .muted, .bill-wrap .warn { margin: 0; }
.banner.ready { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 10px 22px 0; padding: 8px 12px; background: #f6ecc9; border: 1px solid var(--gold); border-radius: 6px; }
.banner.ready > span { flex: 1 1 260px; }
.hire-hulls { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin: 6px 0; }
.hire-hulls button { display: flex; flex-direction: column; align-items: center; padding: 4px; font-size: 13px; }
.hire-hulls button.on { background: #fff7e3; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.hire-hulls button small { color: #dcc89c; }
.c-title small { font-family: var(--serif); font-size: 12px; font-weight: 400; }
#modal-body .art { margin: 0 0 8px; border-radius: 6px; overflow: hidden; }
@media (max-width: 860px) {
  .hulls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hulls:not(.compact)::before { display: none; }
  .yard-body.split { display: block; overflow-y: auto; padding-bottom: 18px; }
  .yard-body.split > section { overflow: visible; }
  .hero { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  #yard { padding: 0; }
  .yard-card { border-radius: 0; height: 100%; border: none; }
  .yard-head { padding: 12px 14px 8px; }
  .yard-head h2 { font-size: 24px; }
  .yard-body { padding: 12px 14px 20px; }
  .hulls { grid-template-columns: 1fr; }
  .order-card { grid-template-columns: 1fr; }
  .ship-stats { grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 14px; }
  .yard-foot { grid-template-columns: 1fr; padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); }
  .opts { grid-template-columns: 1fr 1fr; }
}
.hulls.compact { grid-template-columns: 1fr; gap: 10px; }
.hull-card.wide { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 14px; align-items: start; padding: 10px 12px; }
.hull-card.wide .info h4 { margin-top: 0; }
.hull-card.wide .ship-stats { grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hull-card.wide .row.start .fine, .hull-card.wide .row.start .warn { margin: 0; }
@media (max-width: 520px) { .hull-card.wide { grid-template-columns: 1fr; } }

/* ---- Arrival scene ---- */
#scene { position: fixed; inset: 0; z-index: 9; background: #2e241b; opacity: 0; cursor: pointer; overflow: hidden; }
#scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
body.scene-open #panel, body.scene-open #toast, body.scene-open #tip { visibility: hidden; }
.scene-cap { position: absolute; left: 50%; top: max(8vh, 40px); transform: translate(-50%, 8px); text-align: center; color: var(--ink); opacity: 0; transition: opacity 0.6s ease, transform 0.6s ease; pointer-events: none; width: min(560px, 90vw);
  background: rgba(244, 234, 210, 0.82); border: 1px solid rgba(107, 82, 54, 0.5); border-radius: 8px; padding: 10px 22px 12px; box-shadow: 0 8px 30px rgba(40, 25, 10, 0.25); }
#scene.cap-on .scene-cap { opacity: 1; transform: translate(-50%, 0); }
.scene-cap .kicker { margin: 0; text-transform: uppercase; letter-spacing: 0.16em; font-size: 12px; color: var(--gold); }
.scene-cap h2 { font-family: var(--display); font-weight: 400; font-size: clamp(34px, 6vw, 56px); margin: 0; line-height: 1.05; }
.scene-cap .line { margin: 4px 0 0; font-style: italic; }
.scene-skip { position: absolute; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); background: rgba(244, 234, 210, 0.75); font-size: 13px; }
.register .setting { margin: 22px 0 0; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.register .setting select { font: inherit; margin-left: 6px; }

/* ---- Materials: vellum sheets, leather fittings, the oak of the shipyard ---- */
#chart-skin { position: fixed; inset: 0; pointer-events: none; background: url(img/ui/vellum.webp) center / cover; mix-blend-mode: multiply; opacity: 0.55; }
#panel, #modal .card, #intro .card, .choices .tabs { background: var(--vellum); }
#panel, #modal .card, #intro .card { box-shadow: 0 14px 40px rgba(20, 12, 4, 0.5), inset 0 0 60px rgba(110, 70, 20, 0.22); border-color: #4a3420; }
.brand, .stats, #status, #dock, #tip, .scene-cap { background: var(--leather); color: var(--on-dark); border-color: #120b06; box-shadow: inset 0 1px 0 rgba(255, 230, 180, 0.16), 0 3px 10px rgba(0, 0, 0, 0.45); text-shadow: 0 1px 1px #000; }
.brand .tag, .stats small, .scene-cap .kicker { color: var(--on-dark-2); }
.brand .tag { background: none; border: none; padding: 0; }
#tip .tip-label { color: var(--on-dark); }
.stats > div { border-color: rgba(201, 162, 76, 0.35); }
#hud-purse.debt { color: #ffb3a3; }
#tip-close { color: var(--on-dark); }
#hud button, #zoom button, #dock button { background: var(--leather); color: var(--on-dark); border-color: #120b06; text-shadow: 0 1px 1px #000; }
#hud button:hover:not(:disabled):not(.on), #zoom button:hover:not(:disabled) { background: #4a2e1c url(img/ui/leather.webp) center / 420px; filter: brightness(1.15); }
#hud button.on, #dock button.on { background: linear-gradient(#d8b25a, #a8823a); color: #1d1209; border-color: #120b06; text-shadow: none; }
#dock button .ico { color: var(--on-dark); }
#dock button.on .ico { color: #1d1209; }
#dock { border-top-color: #120b06; }
#panel button:not(.close):not(.opt), #modal .card button { background: var(--leather); color: var(--on-dark); border-color: #120b06; text-shadow: 0 1px 1px #000; }

#panel .tabs button, #panel .tabs button:not(.close) { background: none; color: var(--ink); border: none; text-shadow: none; }
#panel .tabs button.on { border-bottom: 2px solid var(--red); }
.scene-cap { color: var(--on-dark); }
.scene-cap .line { color: var(--on-dark); }
.scene-skip { background: var(--leather); color: var(--on-dark); border-color: #120b06; }
/* the shipyard and register: an oak frame with vellum sheets on it */
#yard { background: rgba(10, 6, 3, 0.7); }
.yard-card { background: linear-gradient(rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.18)), var(--oak); border-color: #0d0804; }
.yard-head { border-color: rgba(201, 162, 76, 0.3); }
.yard-head h2, .yard-card .sec, .yard-head .sub, .yard-card .yard-body > .fine, .register .setting, .register .setting .fine { color: var(--on-dark); text-shadow: 0 1px 2px #000; }
.yard-card .sec { border-color: rgba(201, 162, 76, 0.35); }
.yard-card button:not(.opt):not([role=tab]) { background: var(--leather); color: var(--on-dark); border-color: #120b06; text-shadow: 0 1px 1px #000; }
.hero, .hull-card, .order-card, .choices, .stage .name, .stage .ship-stats, .yard-foot, .art.big.plan, .hired, .banner.ready { background: var(--vellum); border: none; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); color: var(--ink); text-shadow: none; }
.hero { padding: 14px; }
.hired { padding: 6px 10px 6px 6px; }
.choices { padding: 8px 14px 18px; }
.stage .name, .stage .ship-stats { padding: 6px 12px; margin-top: 10px; }
.yard-foot { margin: 0 22px 14px; }
.hull-card.pencil { background: rgba(246, 238, 219, 0.82); border: 1px dashed #5c4630; }
.hull-card .year { background: var(--vellum); }
.choices .tabs button[role=tab] { background: none; color: var(--ink); border: none; }
.choices .tabs button.on { border-bottom: 2px solid var(--red); }
.yard-card button.opt { background: rgba(255, 250, 235, 0.55); color: var(--ink); border-color: rgba(80, 55, 25, 0.45); }
.yard-card button.opt.on { background: rgba(255, 248, 226, 0.92); box-shadow: inset 0 0 0 2px #6d2617; }
@media (max-width: 520px) { .yard-foot { margin: 0; border-radius: 0; } }

/* Photographs */
.afloat { position: relative; margin: 0; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 6px; display: flex; align-items: flex-end; justify-content: center; background-size: cover; background-position: center; }
.afloat.sea { background: linear-gradient(#d7e1df 0%, #c3d3d2 55%, #8fadb1 56%, #5f8590 100%); }
.afloat.hero { aspect-ratio: 16 / 10; }
.afloat .ship-at { position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%); max-height: 74%; }
.afloat.sea .ship-at { bottom: 18%; }
.afloat .ship { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: bottom; }
.afloat .reflect { position: absolute; left: 0; top: 100%; width: 100%; height: 50%; object-fit: fill; transform: scaleY(-1); opacity: 0.22; filter: blur(1.2px); pointer-events: none; }
.hull-card .afloat, .order-card .afloat, .hired .afloat { border-radius: 4px; }
.hull-card.wide .afloat { aspect-ratio: 4 / 3; }
.art.big .afloat { border-radius: 8px; }
.art.big:has(.afloat) { border: none; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5); }
.hire-hulls .afloat { width: 100%; aspect-ratio: 3 / 2; }
.stocks { margin: 0; }
.stocks img, .yard-photo img { display: block; width: 100%; height: auto; border-radius: 6px; }
.yard-photo img { aspect-ratio: 16 / 7; object-fit: cover; object-position: 50% 60%; }
.yard-photo { margin: 0 0 10px; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5); border-radius: 6px; }
.art.big.plan { padding: 4px 10px 6px; }
.art.big.plan svg { display: block; width: 100%; height: min(230px, 34vh); }
.plan-title { margin: 4px 0 0; font-family: var(--display); font-style: italic; color: var(--ink-2); font-size: 15px; }
@media (prefers-reduced-motion: no-preference) { .afloat .ship { animation: bob 6s ease-in-out infinite; } }
@keyframes bob { 50% { transform: translateY(1.5%) rotate(-0.4deg); } }
.tag { white-space: nowrap; }
#panel button:not(.close):not(.opt):hover:not(:disabled), #modal .card button:hover:not(:disabled), .yard-card button:not(.opt):not([role=tab]):hover:not(:disabled) { filter: brightness(1.18); }
#panel button.primary:not(.close):not(.opt), #modal .card button.primary, .yard-card button.primary:not(.opt):not([role=tab]) { background: linear-gradient(#a8442e, #6d2617); color: #fff6e6; border-color: #3d120a; }
.contract .on-course { font-size: 14px; font-style: italic; align-self: center; }
/* Notice levels: alerts are red like news; routine port reports are quieter */
#toast .t.alert { background: rgba(162, 55, 43, 0.95); }
.notices li.n.alert { border-left-color: var(--red); background: rgba(162, 55, 43, 0.08); }
.notices li.n.routine { font-size: 14px; background: none; border-left-style: dotted; }
.notice-filter { margin: 0 0 10px; font-size: 14px; }
.notice-filter label { display: inline-flex; gap: 6px; align-items: center; }
.afloat.drawn .ship-art { position: absolute; inset: 4% 4% 0; width: 92%; height: 96%; }
.harbour { font-size: 14px; color: var(--ink); margin: 4px 0 10px; line-height: 1.4; }
.stop-note { font-size: 13px; color: var(--ink-2); margin: 2px 0 4px; } .stop-note.warn { color: var(--red); }

/* Your house (houseview.js) */
.house-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.house-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid rgba(74, 54, 34, 0.18); }
.house-item b { display: block; }
.house-item small { display: block; color: var(--muted); font-size: 13px; }
.house-item.owned b { color: var(--muted); }
.house-act { text-align: right; flex: 0 0 auto; max-width: 45%; }
.house-act small { max-width: 14em; margin-left: auto; }
.house-act .owned { font-style: italic; color: var(--muted); }

.help-more { margin: 6px 0; }
.help-more summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.help-more[open] summary { margin-bottom: 2px; }
/* a captain asking for a raise */
.contract .warn-note { border: 1px solid var(--gold); border-radius: 6px; padding: 6px 10px; margin: 6px 0; background: rgba(184, 134, 11, 0.08); }
.contract .warn-note p { margin: 0 0 4px; }
.contract details.train { margin: 4px 0; }
.contract details.train summary { cursor: pointer; }
/* the story: letters, chapter cards, the rutter */
.story .story-from { display: flex; justify-content: space-between; font-family: var(--display); color: var(--gold); margin: 0 0 6px; font-size: 14px; }
.story-letter p { font-style: normal; }
.story .sig { text-align: right; font-style: italic; margin-top: 4px; }
.story-card p:first-of-type { font-size: 16px; }
.story-name { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-weight: 600; }
.story-name input { font: inherit; padding: 4px 8px; border: 1px solid var(--ink-2); border-radius: 4px; width: 12em; background: var(--paper); color: var(--ink); }
.story-choices { flex-wrap: wrap; justify-content: flex-end; margin-top: 10px; }
ol.rutter { list-style: none; padding: 0; margin: 0 0 8px; }
.rutter-page { border-left: 3px solid var(--ink-2); padding: 4px 10px; margin: 6px 0; opacity: 0.75; }
.rutter-page.found { border-color: var(--gold); opacity: 1; }
.rutter-page h4 { margin: 0 0 2px; font-family: var(--display); }
.rutter-page .riddle { font-style: italic; margin: 0; }
.rutter-page .found-line { margin: 4px 0 0; font-weight: 600; }
.story-log { padding-left: 0; list-style: none; }
.story-log .when { color: var(--ink-2); font-size: 12px; margin-right: 6px; }
.story-debt { border: 1px solid var(--gold); border-radius: 6px; padding: 6px 10px; margin: 8px 0; }
.story-debt p { margin: 0 0 4px; }
/* the Saves panel: account and its saves */
.account-form { display: grid; gap: 8px; max-width: 360px; }
.account-form label { display: grid; gap: 2px; font-weight: 600; }
.account-form input { font: inherit; padding: 6px 8px; border: 1px solid var(--ink-2); border-radius: 4px; background: var(--paper); color: var(--ink); }
ul.slots { list-style: none; padding: 0; margin: 6px 0; }
ul.slots li.slot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(0, 0, 0, 0.12); flex-wrap: wrap; }
ul.slots li.slot.current b { color: var(--red); }
ul.slots .badge { font-size: 11px; border: 1px solid currentColor; border-radius: 8px; padding: 0 6px; margin-left: 4px; }
.route-mode { margin: 2px 0 6px; }

/* the voyage planner */
.sail-view, .plan-sort { margin: 2px 0 8px; }

.plan-sort .fine { margin-right: 6px; }
ul.plans { list-style: none; padding: 0; margin: 0; }
li.plan { border: 1px solid rgba(0, 0, 0, 0.18); border-radius: 6px; padding: 8px 10px; margin: 8px 0; }
li.plan p { margin: 3px 0; }
li.plan .plan-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 17px; }
li.plan .net.up { color: #2f6b2f; font-weight: 600; }
li.plan .net.down { color: var(--red); font-weight: 600; }
li.plan .meta { color: var(--ink-2); font-size: 13px; }
li.plan .row { justify-content: flex-end; margin-top: 6px; }

/* the selected choice in a two-way switch: the gold of the top bar's buttons */
#panel .route-mode button.on, #panel .sail-view button.on, #panel .plan-sort button.on { background: linear-gradient(#d8b25a, #a8823a); color: #1d1209; text-shadow: none; font-weight: 600; }
/* a port you know: its description folded away */
.port-about { margin: 2px 0 8px; }
.port-about summary { cursor: pointer; color: var(--ink-2); font-style: italic; }
/* the hull figure in the top bar */
#hud-hull.warn { color: #f0c46a; }
#hud-hull.danger { color: #ff8a73; }
/* the Ship button in the bottom bar, lit in a port that can see to her */
#dock button.lit:not(.on) { color: #f0c46a; box-shadow: inset 0 -3px 0 #d8b25a; }
#dock button.lit:not(.on) .ico { color: #f0c46a; }
/* tabs that run off the panel: a fade where there are more */
.tabs.more-right { -webkit-mask-image: linear-gradient(to right, #000 82%, transparent); mask-image: linear-gradient(to right, #000 82%, transparent); }
.tabs.more-left { -webkit-mask-image: linear-gradient(to left, #000 82%, transparent); mask-image: linear-gradient(to left, #000 82%, transparent); }
.tabs.more-left.more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 14%, #000 86%, transparent); mask-image: linear-gradient(to right, transparent, #000 14%, #000 86%, transparent); }
.row.invest { flex-wrap: wrap; align-items: center; gap: 6px 10px; }
/* contracts in the planner */
.plan-held { border: 1px solid var(--gold); border-radius: 6px; padding: 6px 10px; margin: 4px 0 10px; }
.plan-held h3 { margin: 0 0 4px; font-size: 15px; }
.plan-held ul { margin: 0; padding-left: 18px; }
.plan-held li { margin: 2px 0; }
li.plan .plan-offer { border-top: 1px dashed rgba(0, 0, 0, 0.2); margin-top: 6px; padding-top: 4px; }
li.plan .plan-offer .row { justify-content: flex-end; margin-top: 2px; }
/* the arrival scene's buttons */
.scene-buttons { position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.scene-buttons button { position: static; }
.scene-less { background: var(--leather); color: var(--on-dark); border: 1px solid #120b06; font-size: 13px; }

/* Money and patrons (lendingview.js) */
.money-box { margin: 8px 0 10px; border: 1px solid var(--rule, #c9b48a); border-radius: 6px; padding: 6px 10px; }
.money-box summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.money-box p { margin: 6px 0; font-size: 14px; }
.money-box .row { flex-wrap: wrap; justify-content: flex-start; gap: 6px; }
#modal .field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; margin: 8px 0; color: var(--ink-2); }
.loan-waters { border: 0; padding: 0; margin: 8px 0; }
.loan-waters legend { font-size: 14px; color: var(--ink-2); padding: 0; margin-bottom: 4px; }
.loan-waters label { display: block; padding: 6px 4px; font-size: 14px; line-height: 1.35; cursor: pointer; }
.route-est { margin: 10px 0 4px; padding: 8px 10px; border-left: 3px solid var(--rule, #c9b48a); background: rgba(255,255,255,0.25); }
.route-est h4 { margin: 0 0 4px; font-size: 14px; }
.route-est ul { margin: 4px 0; padding-left: 18px; }
.route-est p { margin: 4px 0; }
.refit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 12px; }
.refit-grid select { max-width: 100%; }
.nation-pick { display: grid; gap: 10px; margin-top: 12px; }
.nation-pick .sub { margin: 0; }
.nation-pick button.nation { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 10px 14px; white-space: normal; line-height: 1.35; }
.nation-pick button.nation b { font-size: 17px; }
.nation-pick button.nation span { font-size: 14px; opacity: 0.9; }
li.plan.focus { outline: 2px solid var(--gold, #b8892b); outline-offset: 2px; }
#intro.choosing .card > p:not(.fine), #intro.choosing .card > ul, #intro.choosing .card > .row { display: none; }
#intro.choosing .nation-pick p.sub { display: block; }
#hud-purse .owed { display: block; font-style: normal; font-size: 11px; line-height: 1.1; letter-spacing: 0.02em; white-space: nowrap; }

/* Taking a sight (sightview.js): a pill above the bottom controls, and the sight itself */
.pilot-games { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); z-index: 30; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.sight-btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px; font: 600 15px/1 Georgia, serif; background: linear-gradient(#d8b25a, #a8823a); color: #1d1209; border: 1px solid #120b06; box-shadow: 0 6px 18px rgba(0,0,0,0.35); cursor: pointer; }
@media (min-width: 701px) { .pilot-games { bottom: calc(66px + env(safe-area-inset-bottom, 0px)); } }
@media (prefers-reduced-motion: no-preference) { .sight-btn { animation: sight-in .4s ease-out; } @keyframes sight-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } } }
#sight-canvas { width: 100%; height: auto; display: block; border-radius: 6px; margin: 8px 0; background: #0b1626; }
.sight-slider { display: grid !important; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px; }
.sight-slider input { grid-column: 1 / -1; width: 100%; height: 34px; }
.sight-slider output { grid-row: 1; grid-column: 2; font-variant-numeric: tabular-nums; font-weight: 600; }

.astro-meter, .glass { height: 10px; border-radius: 5px; background: rgba(0,0,0,0.15); overflow: hidden; margin: 4px 0 8px; }
.astro-meter i, .glass i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #d8b25a, #f0d48a); }
.glass i { width: 100%; background: linear-gradient(90deg, #c8a05a, #e8c98a); }
table.almanac { border-collapse: collapse; margin: 6px 0; font-variant-numeric: tabular-nums; }
table.almanac th, table.almanac td { padding: 3px 12px; border-bottom: 1px solid rgba(0,0,0,0.12); text-align: left; }
table.almanac .num { text-align: right; }
.board-call { font-size: 17px; margin: 6px 0 2px; min-height: 2.6em; }
.board { position: relative; width: min(300px, 78vw); aspect-ratio: 1; margin: 10px auto; border-radius: 50%; background: radial-gradient(circle, #b98d55 0 60%, #8a5f33 61% 100%); border: 3px solid #4a3018; }
.board .peg { position: absolute; transform: translate(-50%, -50%); min-width: 40px; min-height: 30px; padding: 2px 4px; font-size: 12px; border-radius: 6px; }
.board .peg.pegged { background: #3f6b3a; color: #fff; }
.board .peg.wrong { background: #8a2c1c; color: #fff; }
.board-hub { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; transform: translate(-50%, -50%); border-radius: 50%; background: #3b2412; }
.pilot-games[hidden] { display: none; }
.yard-repair { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: #f3e8cf; color: #2e2216; border-color: #8a6a3a; margin: 8px 0 12px; }
.yard-repair span { flex: 1 1 220px; }

/* The first voyage (firstvoyage.js): three steps at the top of the market for a new player. */
.first { border: 1.5px solid var(--gold); border-radius: 8px; background: #f6ecc9; padding: 10px 12px; margin: 0 0 12px; }
.first h3 { font: 400 19px/1.2 var(--display); margin: 0 0 6px; }
.first-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.first-head .link { font-size: 13px; color: var(--muted); }
.first ol { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.first li { font-size: 15px; }
.first li > span { display: block; }
.first li.did { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.first li.next { color: var(--muted); }
.first li.now { font-weight: 600; }
.first li button { margin-top: 5px; font-size: 15px; padding: 6px 12px; }
.first p { margin: 8px 0 0; font-size: 14px; }
.first .row { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }

/* Callings and ambitions (ambitionsview.js): a ledger slip under the HUD, three goals with bars. */
#ambitions { position: fixed; left: 10px; top: calc(var(--hud-h, 66px) + 10px); width: min(320px, calc(100vw - 80px)); background: rgba(244, 234, 210, 0.96); border: 1px solid var(--gold); border-radius: 6px; box-shadow: var(--shadow); padding: 6px 10px 8px; font-size: 13.5px; line-height: 1.3; z-index: 2; }
#ambitions[hidden] { display: none; }
body.panel-open #ambitions { width: min(320px, calc(100vw - min(520px, 100vw - 20px) - 40px)); }
.amb-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.amb-fold { all: unset; cursor: pointer; display: flex; flex-direction: column; min-width: 0; }
.amb-fold:focus-visible, .amb-link:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.amb-title { font-family: var(--display); font-size: 17px; color: var(--ink); }
.amb-sub { font-size: 12px; color: var(--ink-2); }
.amb-link { border: 0; background: none; padding: 0; font-size: 12px; text-decoration: underline; color: var(--ink-2); cursor: pointer; }
.amb-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.amb-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; }
.amb-text { grid-column: 1 / -1; }
.amb-list li.big .amb-text::before { content: "★ "; color: var(--gold); }
.amb-bar { height: 6px; background: rgba(90, 70, 40, 0.15); border-radius: 3px; overflow: hidden; }
.amb-bar i { display: block; height: 100%; background: var(--gold); border-radius: 3px; }
.amb-of { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.amb-choose { margin-top: 7px; width: 100%; font-size: 13px; padding: 5px 8px; }
#ambitions.folded .amb-list { display: none; }
/* the choices */
.calling-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 10px; }
.calling-card { border: 1px solid var(--gold); border-radius: 6px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; background: rgba(255, 250, 238, 0.6); }
.calling-card.current { border-width: 2px; }
.calling-card > button, .calling-card > p:last-child { margin-top: auto; }
.calling-card h3 { font-family: var(--display); font-weight: 400; font-size: 21px; margin: 0; }
.calling-card p { margin: 0; font-size: 14px; }
.calling-card .ranks { font-size: 12.5px; color: var(--ink-2); font-style: italic; }
.ambition-offers { display: grid; gap: 8px; margin-top: 10px; }
.ambition-offer { display: grid; gap: 2px; text-align: left; padding: 9px 12px; border: 1px solid var(--gold); border-radius: 6px; background: rgba(255, 250, 238, 0.6); font: inherit; color: inherit; cursor: pointer; }
.ambition-offer:hover { background: rgba(255, 250, 238, 0.95); }
.ambition-offer.big { border-width: 2px; }
.ambition-offer .who { font-size: 12px; color: var(--ink-2); }
#modal[data-kind="calling"] .card { width: min(780px, 100%); }
#modal[data-kind="ambition"] .card { width: min(520px, 100%); }
#modal .card button.ambition-offer { background: rgba(255, 250, 238, 0.7); color: var(--ink); text-shadow: none; border-color: var(--gold); }
#modal .card button.ambition-offer:hover { background: #fffaf0; filter: none; }
@media (max-width: 640px) {
  #ambitions, body.panel-open #ambitions { left: 8px; right: 8px; width: auto; top: calc(var(--hud-h, 60px) + 8px); font-size: 13px; z-index: 6; }
}

/* The Houses of the Sea (housesview.js) */
table.houses { width: 100%; border-collapse: collapse; font-size: 15px; }
table.houses th, table.houses td { padding: 6px 6px; border-bottom: 1px solid rgba(90, 70, 40, 0.25); vertical-align: top; text-align: left; }
table.houses .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.houses small { display: block; color: var(--ink-2); font-size: 12.5px; white-space: normal; }
table.houses tr.you td { font-weight: 600; }
table.houses tr.gone td { opacity: 0.55; }
table.houses tr.act td { border-bottom-style: dashed; padding-top: 0; }
table.houses td { overflow-wrap: anywhere; }
/* on a phone the ships and ports-led columns give way, so the names and buy-out lines can wrap */
@media (max-width: 560px) {
  table.houses th:nth-child(4), table.houses td:nth-child(4), table.houses th:nth-child(5), table.houses td:nth-child(5) { display: none; }
  table.houses tr.act td[colspan] { white-space: normal; }
}
.house-sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
p.shares { font-size: 14px; margin: 6px 0 0; color: var(--ink); }
p.shares .sw-you { color: #8a5a0a; }

/* Port works (worksview.js) */
ol.works { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 10px; }
ol.works li.work { border: 1px solid rgba(90, 70, 40, 0.3); border-radius: 6px; padding: 9px 11px; display: grid; gap: 4px; }
ol.works li.work.have { border-color: var(--gold); background: rgba(255, 250, 238, 0.5); }
ol.works li.work > div:first-child { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
ol.works li.work p { margin: 0; font-size: 14.5px; }
.tag { font-size: 13px; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; }
.tag.ok { color: #3f6b3a; } .tag.bad { color: #a2372b; }
table.store { width: 100%; border-collapse: collapse; font-size: 15px; }
table.store th, table.store td { padding: 5px 6px; border-bottom: 1px solid rgba(90, 70, 40, 0.25); text-align: left; }
table.store .num { text-align: right; font-variant-numeric: tabular-nums; }
table.store .acts { display: flex; gap: 6px; justify-content: flex-end; }
ul.empire { margin: 6px 0; padding-left: 18px; font-size: 14.5px; }

/* ---- Fights at sea (fightview.js), spoils and prizes (huntview.js, lawview.js) ---- */
#modal[data-kind="fight"] .card { width: min(640px, 100%); }
.fight { display: grid; gap: 10px; }
.fintro p { margin: 0; }
.fsides { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fside { border: 1px solid rgba(90, 70, 40, 0.3); border-radius: 6px; padding: 8px 10px; display: grid; gap: 4px; min-width: 0; }
.fside.you { border-color: var(--gold); background: rgba(255, 250, 238, 0.5); }
.fside h3 { font-family: var(--display); font-weight: 400; font-size: 17px; margin: 0; overflow-wrap: anywhere; }
.fside p { margin: 0; }
.fbar { display: grid; grid-template-columns: 3.6em 1fr 2em; align-items: center; gap: 6px; font-size: 13px; }
.fbar i { height: 7px; border-radius: 4px; background: linear-gradient(90deg, var(--ink-2) var(--v), rgba(90, 70, 40, 0.15) var(--v)); }
.fbar.low i { background: linear-gradient(90deg, var(--red) var(--v), rgba(90, 70, 40, 0.15) var(--v)); }
.fbar b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.frange { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; padding: 0; gap: 3px; font-size: 13px; text-align: center; }
.frange li { padding: 4px 2px; border-bottom: 3px solid rgba(90, 70, 40, 0.2); color: var(--muted); }
.frange li.on { border-color: var(--red); color: var(--ink); font-weight: 600; }
.flog { margin: 0; padding-left: 18px; font-size: 14.5px; }
.fround { margin: 0; }
.fintent { font-style: italic; color: var(--red); }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 6px; }
.facts-grid .fact { text-align: left; display: grid; gap: 2px; min-height: 44px; padding: 7px 9px; }
.facts-grid .fact small { font-size: 12.5px; line-height: 1.25; opacity: 0.85; }
.facts-grid .fact .odds { font-variant-numeric: tabular-nums; font-weight: 400; }
.fauto { margin: 0; text-align: center; }
ul.spoils { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
ul.spoils button { width: 100%; text-align: left; display: grid; gap: 2px; min-height: 44px; padding: 7px 10px; }
ul.spoils small { font-size: 12.5px; opacity: 0.85; }
.banner.prize button, .banner button { margin-left: 6px; }
@media (max-width: 480px) {
  .fsides { grid-template-columns: 1fr; gap: 6px; }
  .fside { padding: 6px 9px; gap: 2px; }
  .fside p.fine { display: none; }
  .facts-grid .fact small { font-size: 12px; }
  .fbar { grid-template-columns: 3.2em 1fr 1.8em; }
  .facts-grid { grid-template-columns: 1fr 1fr; }
}
#modal .fauto button.link { background: none; border: 0; box-shadow: none; color: var(--red); padding: 0; min-height: 0; text-shadow: none; }
