:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #e9f1ef;
  background: #101c24;
  --panel: #172730;
  --stroke: #304550;
  --muted: #a6babc;
  --mint: #8ce8ce;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 300px; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }
[hidden] { display: none !important; }
.mast, main { width: min(1550px, 100%); margin: auto; }
.mast { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 22px; padding: 18px 26px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 41px; height: 41px; background: var(--mint); color: #122832; border-radius: 11px; font: 25px system-ui; }
h1 { font-size: 23px; letter-spacing: -.035em; }
.metrics { display: flex; gap: clamp(16px, 4vw, 58px); }
.metrics div, .status { display: grid; gap: 4px; }
.metrics span, .status strong { color: var(--muted); font-size: 12px; font-weight: 500; }
.metrics strong { font-size: 19px; font-variant-numeric: tabular-nums; }
#cash, #connection[data-online="true"] { color: var(--mint); }
#cash[data-low="true"], #connection { color: #ffab9f; }
.status { text-align: right; font-size: 13px; }
main { display: grid; grid-template-columns: minmax(0, 1fr) 325px; gap: 16px; padding: 0 26px 24px; align-items: start; }
.operations, .dispatch { border: 1px solid var(--stroke); border-radius: 15px; background: var(--panel); overflow: hidden; }
.chart-head, .panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; }
.chart-head h2, .panel-head h2 { font-size: 17px; letter-spacing: -.015em; }
#assignment, .panel-head span { color: var(--muted); font-size: 13px; }
.speed { border: 1px solid var(--stroke); border-radius: 6px; padding: 5px 7px; color: var(--mint); font: 600 11px ui-monospace, monospace; white-space: nowrap; }
.chart-tools { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
#zoom { color: inherit; background: #20333d; border: 1px solid var(--stroke); border-radius: 6px; padding: 5px 7px; font: 600 11px ui-monospace, monospace; white-space: nowrap; }
.chart { position: relative; background: #204655; }
canvas { display: block; width: 100%; aspect-ratio: 1100 / 650; }
.legend { display: flex; position: absolute; bottom: 7px; right: 8px; gap: 10px; padding: 5px 8px; border-radius: 5px; background: #132a34; color: #ebf2ed; font-size: 10px; pointer-events: none; }
.legend span { display: flex; align-items: center; gap: 4px; }
.legend i { width: 6px; height: 6px; border-radius: 50%; background: var(--mint); }
.legend span:nth-child(2) i { background: #f4b868; }
.legend span:nth-child(3) i { background: #a6babc; }
.helm { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px 8px; }
.helm-readout { display: grid; gap: 3px; min-width: 116px; font-size: 13px; }
.helm-readout span, .guidance { color: var(--muted); font-size: 12px; }
.helm-buttons { display: flex; flex-wrap: wrap; gap: 5px; }
.helm-buttons button, .release { touch-action: none; color: #e9f1ef; background: #20333d; border: 1px solid var(--stroke); border-radius: 6px; padding: 6px 8px; font-size: 12px; }
kbd { color: var(--mint); font-size: 11px; }
.helm-buttons button[data-active="true"], .helm-buttons button:hover, .release:hover { background: #30505a; }
.guidance { padding: 0 16px 14px; line-height: 1.5; }
.dispatch { padding-bottom: 10px; }
.panel-head { border-bottom: 1px solid var(--stroke); }
.order-group, .log { padding: 12px 13px 4px; }
.order-group h3, .log h3 { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 13px; }
.order-group h3 span { color: var(--mint); }
.order-group small { margin-left: auto; color: var(--muted); }
.orders { display: grid; gap: 6px; }
.order { position: relative; display: grid; width: 100%; gap: 4px; text-align: left; color: inherit; background: #1c303a; border: 1px solid var(--stroke); border-radius: 8px; padding: 9px 10px 9px 13px; }
.order::before { position: absolute; content: ""; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: var(--ship-color); }
.order:hover:not(:disabled), .order[data-mine="true"] { border-color: var(--mint); }
.order[data-mine="true"] { opacity: 1; }
.order-top, .order-bottom { display: flex; justify-content: space-between; align-items: center; gap: 7px; }
.order-top { font-size: 13px; }
.order-bottom, .order-status, .empty { color: var(--muted); font-size: 11px; }
.order-time { color: var(--mint); font: 600 12px ui-monospace, monospace; white-space: nowrap; }
.order-time[data-urgent="true"], .log li[data-kind="loss"] { color: #ffab9f; }
.log ul { display: grid; gap: 6px; list-style: none; padding: 0; margin: 0; }
.log li { color: var(--muted); font-size: 11px; line-height: 1.4; }
.log li[data-kind="gain"] { color: var(--mint); }
.overlay { position: fixed; z-index: 2; inset: 0; display: grid; place-items: center; padding: 16px; background: #0a161ee0; }
.dialog { width: min(100%, 390px); display: grid; gap: 13px; padding: 25px; border-radius: 15px; background: var(--panel); border: 1px solid var(--stroke); }
.dialog p { color: var(--muted); font-size: 14px; line-height: 1.55; }
.dialog label { font-size: 13px; }
.dialog input { width: 100%; padding: 10px; color: inherit; background: #101c24; border: 1px solid var(--stroke); border-radius: 6px; }
.primary { padding: 10px; border: 0; border-radius: 7px; color: #122832; background: var(--mint); font-weight: 700; }
#join-error:empty { display: none; }
.toast { position: fixed; z-index: 3; bottom: 18px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); padding: 10px 14px; background: #243d49; border: 1px solid var(--stroke); border-radius: 8px; font-size: 13px; }
@media (max-width: 950px) {
  main { grid-template-columns: minmax(0, 1fr) 265px; padding-inline: 12px; gap: 10px; }
  .mast { padding-inline: 12px; }
}
@media (max-width: 700px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .metrics { order: 3; flex-basis: 100%; justify-content: space-between; }
  .mast { gap: 12px; }
}

/* The chart is the viewport. Only the instruments intercept chart input. */
body { overflow: hidden; }
main, .operations { display: contents; }
.chart { position: fixed; inset: 0; }
#map { width: 100%; height: 100%; aspect-ratio: auto; }
.mast, .chart-head, .dispatch, .helm, .guidance {
  position: fixed; z-index: 1; margin: 0; background: #13232df2;
  border: 1px solid #536873; border-radius: 10px; box-shadow: 0 3px 14px #07101855;
}
.mast { top: 10px; left: 10px; width: auto; padding: 8px 12px; gap: 18px; }
.mast .metrics { flex-basis: auto; order: 0; gap: 15px; }
.mast .brand-mark { width: 29px; height: 29px; font-size: 19px; }
.mast h1 { font-size: 16px; }
.metrics strong { font-size: 15px; }
.chart-head { top: 74px; left: 10px; padding: 8px 12px; gap: 12px; }
.chart-head h2 { font-size: 14px; }
.dispatch { top: 10px; right: 10px; width: min(275px, 46vw); max-height: calc(100dvh - 220px); overflow-y: auto; }
.dispatch.folded { width: auto; padding: 0; }
.dispatch.folded > section { display: none; }
.panel-head { gap: 12px; padding: 8px 12px; }
#dispatch-toggle { background: none; border: 0; color: inherit; padding: 4px; font-weight: 700; }
.helm { bottom: 12px; left: 10px; width: min(640px, calc(100vw - 20px)); padding: 9px 13px; justify-content: center; gap: 8px; }
.instruments { width: 100%; display: flex; align-items: center; justify-content: space-around; gap: 14px; }
.helm-readout { flex: 1; gap: 5px; font-variant-numeric: tabular-nums; }
.helm-readout strong { font-size: 17px; }
.engine, .steering { display: grid; gap: 4px; font: 11px ui-monospace, monospace; }
.engine { justify-items: center; }
.steering { width: 20%; text-align: center; }
.ends { display: flex; justify-content: space-between; }
.bar { position: relative; border: 1px solid #b2c7c9; background: #101c24; }
.bar i, .bar b, .bar::before { content: ''; position: absolute; display: block; }
.bar i { background: var(--fill); }
.bar b { background: white; }
.vertical { width: 22px; height: 46px; }
.vertical::before { width: 100%; bottom: 50%; border-top: 1px solid #abb9bc; }
.vertical i { left: 0; right: 0; bottom: var(--start); height: var(--extent); }
.vertical b { left: -3px; right: -3px; bottom: var(--order,50%); height: 2px; }
.horizontal { height: 15px; }
.horizontal::before { top: 0; bottom: 0; left: 50%; border-left: 1px solid #abb9bc; }
.horizontal i { top: 0; bottom: 0; left: var(--start); width: var(--extent); }
.horizontal b { top: -3px; bottom: -3px; left: var(--order,50%); width: 2px; }
.guidance { top: 136px; left: 10px; max-width: min(360px, 47vw); padding: 6px 10px; }
@media (max-width: 850px) {
  .mast .brand, .mast .status strong { display: none; }
  .dispatch { top: 70px; }
  .chart-head { max-width: 49vw; flex-wrap: wrap; top: 70px; }
  .guidance { display: none; }
  .legend { display: none; }
  .helm-buttons { justify-content: center; }
}
@media (max-height: 560px) {
  .guidance { display: none; }
  .dispatch { max-height: 48dvh; }
  .helm { left: 10px; transform: none; bottom: 5px; }
}

#ship-editor { border: 1px solid var(--stroke); padding: 0; border-radius: 14px; background: var(--panel); color: inherit; max-height: 90dvh; }
#ship-editor::backdrop { background: #081923cc; }
#ship-editor form { width: min(440px, 90vw); border: none; }
.fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.fields label { display: grid; gap: 3px; }
.fields select, #cancel-spawn, #custom { color: inherit; background: #233842; border: 1px solid var(--stroke); border-radius: 6px; padding: 7px; }
#custom { margin: 8px 12px; }
.dispatch.folded #custom { display: none; }
#spawn-error:empty { display: none; }
#moor { background: #ffdd52; font-size: 16px; }
.order:focus { outline: 3px solid #ffdd52; outline-offset: -2px; }

.port-hud { position: fixed; z-index: 1; top: 74px; left: 10px; width: min(360px,47vw); display: grid; gap: 5px; pointer-events: none; }
.port-hud .chart-head, .port-hud .guidance { position: static; max-width: none; pointer-events: auto; }
.port-hud .log { padding: 3px 6px; background: transparent; text-shadow: 0 1px 3px #0b131a; }
.port-hud .log h3 { display: none; }
.port-hud .log li { color: #ff9690; font-weight: 600; }
@media (max-width:850px) { .port-hud { top:70px; } }
.port-hud .log { max-height: 48dvh; overflow-y: auto; pointer-events: auto; }

.room-actions { display: flex; gap: 10px; }
.room-actions button { flex: 1; }
#room-code { text-transform: uppercase; letter-spacing: .12em; }
#room-invite, #copy-link { color: var(--mint); background: #20333d; border: 1px solid var(--stroke); border-radius: 6px; padding: 6px 9px; }
#lobby-crew { overflow-wrap: anywhere; }
:root { --receipt-height: min(145px, 23dvh); }
#receipts { position: fixed; z-index: 1; bottom: 5px; left: 10px; display: flex; justify-content: flex-start; gap: 6px; width: min(940px, calc(100vw - 20px)); pointer-events: none; }
.receipt { flex: 1; min-width: 0; max-width: 320px; height: var(--receipt-height); overflow: auto; pointer-events: auto; padding: 8px 10px; border: 1px solid var(--stroke); border-radius: 8px; background: #13232df5; font-size: 12px; font-variant-numeric: tabular-nums; }
.receipt h3 { font-size: 13px; overflow-wrap: anywhere; }
.receipt .positive { color: var(--mint); }
.receipt .negative { color: #ff9690; }
.receipt p { color: var(--muted); margin: 4px 0; font-size: 11px; }
.receipt dl { margin: 0; display: grid; grid-template-columns: 1fr auto; column-gap: 6px; }
.receipt dd { margin: 0; text-align: right; }
.has-reports .helm { bottom: calc(var(--receipt-height) + 12px); }
.has-reports .legend { bottom: calc(var(--receipt-height) + 10px); }
.has-reports:has(#game-over:not([hidden]), #pause-screen:not([hidden])) #receipts { z-index: 3; }
@media (max-width: 600px) {
  .mast { gap: 6px; }
  .mast .metrics { gap: 7px; }
  #receipts { gap: 3px; }
  .receipt { padding: 4px; font-size: 10px; }
  .receipt h3 { font-size: 11px; }
}

#vsp-helm { display:flex; align-items:center; gap:14px; }
#vsp-helm label { display:grid; justify-items:center; gap:3px; font-size:11px; color:var(--muted); }
.drive-pad { width:48px; height:48px; border:1px solid #6b9c99; border-radius:50%; display:grid; place-items:center; touch-action:none; background:radial-gradient(circle,#376064,#183039); }
.drive-pad i { width:8px; height:8px; border-radius:50%; background:var(--mint); pointer-events:none; }
.vsp .engine,.vsp .steering,.vsp .helm-buttons,.vsp #center { display:none; }
#live-card { position:fixed; z-index:2; bottom:8px; left:10px; width:min(285px,calc(100vw - 20px)); height:auto; max-height:31dvh; border-left:3px solid var(--mint); }
.has-reports #live-card { bottom:calc(var(--receipt-height) + 12px); }
#live-card button { margin:5px 4px 0 0; }
#help { color:#edf3ed; background:#13232d; width:min(600px,92vw); max-height:84dvh; overflow:auto; padding:20px; border:1px solid var(--stroke); border-radius:12px; }
#help::backdrop { background:#07151cbb; }
#help form { float:right; }
#help h3 { margin:16px 0 6px; }
#help p,#help td,#help th { font-size:13px; line-height:1.5; }
#help p { margin:7px 0; }
#help table { border-collapse:collapse; width:100%; }
#help td,#help th { text-align:left; padding:4px; border-bottom:1px solid var(--stroke); }

/* Brass fittings, varnished teal panels and cream voyage slips. */
:root { --panel:#142c31; --stroke:#496765; --mint:#9ce8cf; --muted:#b3cbc3; font-family:"Barlow","Segoe UI",sans-serif; }
.mast,.chart-head,.dispatch,#help,.dialog {
  background:linear-gradient(148deg,#213f42f7,#10282ff7 76%);
  border:1px solid #72908a; border-top-color:#a7b5a2;
  box-shadow:inset 0 1px #e6e2c61a,0 4px 14px #07232a66;
}
.brand-mark,.mast .brand-mark { background:#efbe73; color:#19363a; border:1px solid #ffe2a6; border-radius:50%; }
.mast h1,.dialog h2,.panel-head h2,#help h2 { font-family:Georgia,serif; letter-spacing:-.035em; }
.mast h1 { font-size:20px; color:#f4e9cf; }
.metrics span,.order-group h3,.receipt dt { letter-spacing:.045em; }
.metrics strong,.order-time,.receipt strong { font-variant-numeric:tabular-nums; }
.order-group h3 { color:#ddc695; text-transform:uppercase; font-size:10px; }
.order { background:linear-gradient(110deg,#304b4c,#1a3439); border-radius:4px; }
.order:hover:enabled,.order:focus-visible { background:#365554; }
.receipt,#live-card { background:#eae3cf; color:#213c3b; border-color:#c3b492; border-radius:3px; box-shadow:0 3px 12px #09272855; }
.receipt h3 { font-family:Georgia,serif; }
.receipt p { color:#495d54; }
.receipt dl { border-top:1px dashed #a2aa97; margin-top:4px; padding-top:4px; }
.receipt .positive { color:#00654c; }.receipt .negative { color:#a03527; }
#live-card { border-left-color:#db9547; }
#gate .dialog { position:relative; overflow:hidden; border-top:5px solid #d7ae71; }
#gate h2 { color:#f6e8c8; font-size:36px; }
#gate .brand-mark { width:50px;height:50px;font-size:30px; }
#gate .dialog::before { content:""; pointer-events:none; position:absolute; top:-78px;right:-60px;width:220px;height:220px;border-radius:50%;
  background:repeating-radial-gradient(circle,transparent 0 25px,#abdac518 26px 27px),repeating-conic-gradient(from 4deg,#abdac514 0 1deg,transparent 1deg 30deg); }
#radio-call { position:fixed;z-index:2;bottom:clamp(80px,24dvh,220px);left:50%;translate:-50% 0;
  display:grid;gap:4px;text-align:center;pointer-events:none;padding:10px 20px;max-width:min(440px,80vw);
  color:#fff2c9;background:#173e3cf2;border:1px solid #bfc8a1;border-top:3px solid #edc880;
  border-radius:4px;box-shadow:0 4px 18px #082a3055; }
#radio-call strong { font:700 18px Georgia,serif; }
#radio-call span { font-size:12px; }
#radio-call[data-kind="loss"] { background:#492e2af5;border-color:#da967d; }
@media(max-width:700px){#radio-call{bottom:auto;top:29%;}}
#certificate { position:fixed; z-index:3; pointer-events:none; width:min(440px,83vw); left:50%; top:18%; translate:-50% 0; text-align:center;
 padding:18px 24px 17px; background:radial-gradient(ellipse at 40% 18%,#fffae3,#ead8aa 84%); color:#243d39;
 border:5px double #8e733e; outline:2px solid #f9ebbf; box-shadow:0 12px 28px #10252b65,inset 0 0 0 5px #f8ebc7,inset 0 0 0 6px #ac925b; }
#certificate small { display:block; margin:8px 0 6px; text-transform:uppercase; font:700 10px/1.3 Georgia,serif; letter-spacing:.16em; }
#certificate h2 { font: bold clamp(29px,4vw,48px)/1 Georgia,serif; letter-spacing:-.05em; }
#certificate .citation { margin:8px 0;color:#526253; font:600 13px system-ui; }
#certificate .signature { font:italic 24px Georgia,serif; }
#certificate .seal { display:grid; place-items:center; margin:auto; width:40px;height:40px; border-radius:50%; background:#d6a047;
 border:4px double #775326; color:#584325; font-size:23px;box-shadow:0 2px 1px #82653255; }
#certificate .ribbon { display:inline-block; margin:12px auto -28px; padding:6px 24px; background:#20584e;color:#fff0c7; text-transform:uppercase;
 font:700 11px system-ui;letter-spacing:.09em;clip-path:polygon(0 0,100% 0,97% 50%,100% 100%,0 100%,3% 50%); }
@media(max-height:560px){#certificate{top:8%;padding:10px 20px}#certificate .seal{display:none}}
