:root {
  --bg: #07131f; --panel: rgba(8, 20, 34, 0.82); --line: rgba(140, 190, 230, 0.25); --fg: #dbe9f4; --muted: #8fb0c8;
  --accent: #f2b134; --green: #58d68d; --red: #ff6b6b; --cyan: #5ad6ff; --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px/1.4 var(--font); overflow: hidden; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: var(--fg); background: rgba(40, 80, 120, 0.6); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
button:hover { background: rgba(60, 110, 160, 0.8); }
button.danger { border-color: rgba(255, 100, 100, 0.5); }
button.primary { background: var(--accent); color: #1a1200; border-color: transparent; font-weight: 600; }
button:disabled { opacity: 0.45; cursor: default; }
input { font: inherit; color: var(--fg); background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
a { color: var(--cyan); }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(2, 8, 14, 0.55); z-index: 20; padding: 16px; }
/* Stacking: the harbour panel stays open while docked, so the transient overlays (chart, ships, help) must paint above it; the login card above everything. */
#harborWrap { z-index: 20; }
#chartWrap, #shipsWrap, #helpWrap { z-index: 25; }
#welcome { z-index: 40; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px 32px; width: min(560px, 100%); backdrop-filter: blur(8px); text-align: center; }
.card h1 { margin: 0; letter-spacing: 0.35em; font-weight: 800; color: var(--accent); font-size: 34px; }
.card .tag { margin: 6px 0 18px; color: var(--muted); }
.card label { display: block; text-align: left; margin: 12px 0; }
.card input { width: 100%; margin-top: 6px; font-size: 16px; }
.card #startBtn { width: 100%; padding: 12px; font-size: 16px; background: var(--accent); color: #1a1200; border: 0; font-weight: 700; }
.card .help { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: left; }
.card .help b { color: var(--fg); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(720px, 100%); max-height: 92vh; display: flex; flex-direction: column; backdrop-filter: blur(8px); overflow: hidden; }
.panel.wide { width: min(1140px, 100%); }
.panelHead { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 16px; }
.panelHead .close { margin-left: auto; }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: 0; background: transparent; }
.tabs button.on { background: rgba(60, 110, 160, 0.5); }
.tab { padding: 12px 14px; overflow: auto; }
.prose { padding: 14px 18px; overflow: auto; }
.prose p { margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 6px 8px; border-bottom: 1px solid rgba(140, 190, 230, 0.12); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-family: var(--mono); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: rgba(90, 214, 255, 0.15); color: var(--cyan); margin-right: 4px; }
.pill.bad { background: rgba(255, 107, 107, 0.2); color: var(--red); }
.pill.good { background: rgba(88, 214, 141, 0.18); color: var(--green); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.box h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.inline input { width: 90px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 18px; align-items: center; padding: 6px 14px; background: linear-gradient(rgba(4, 12, 20, 0.85), rgba(4, 12, 20, 0)); font-size: 13px; flex-wrap: wrap; }
#topbar #hbName { font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }
#hbOnline { margin-left: auto; }
#connPill { font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat label { color: var(--muted); margin-right: 5px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat b { font-family: var(--mono); font-weight: 600; }
#log { position: absolute; top: 46px; left: 14px; width: min(440px, 60vw); max-height: 32vh; overflow: hidden; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
#log .ev { background: rgba(4, 12, 20, 0.7); border-left: 3px solid var(--cyan); padding: 4px 8px; border-radius: 0 6px 6px 0; font-size: 13px; animation: fadein 0.3s; }
#log .ev.warn { border-color: var(--accent); } #log .ev.law { border-color: var(--red); } #log .ev.shady { border-color: #b07cff; } #log .ev.pirate { border-color: #ff8c42; }
@keyframes fadein { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; } }
#alerts { position: absolute; top: 46px; right: 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#alerts .alert { background: rgba(140, 30, 30, 0.8); border: 1px solid rgba(255, 107, 107, 0.5); padding: 6px 10px; border-radius: 6px; font-weight: 600; }
#alerts .alert.warn { background: rgba(120, 80, 10, 0.8); border-color: rgba(242, 177, 52, 0.5); }

#telemetry { position: absolute; left: 14px; bottom: 14px; width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-family: var(--mono); font-size: 12px; backdrop-filter: blur(6px); }
/* minmax(0, 1fr) lets a value column shrink below its content so a long value truncates instead of overlapping the next label */
#telemetry .row { display: grid; grid-template-columns: 62px minmax(0, 1fr) 62px minmax(0, 1fr); gap: 2px 6px; align-items: baseline; padding: 1px 0; white-space: nowrap; }
#telemetry .row > b { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#telemetry .row span { margin-left: -4px; }
#telemetry label { color: var(--muted); font-family: var(--font); font-size: 11px; text-transform: uppercase; }
#telemetry b { font-weight: 600; }
#telemetry span { color: var(--muted); font-size: 11px; }
#bars { display: flex; gap: 8px; margin-top: 6px; }
.bar { flex: 1; height: 8px; background: rgba(0, 0, 0, 0.4); border-radius: 4px; position: relative; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--green); }
.bar.rud i { left: 50%; background: var(--cyan); }

#radarWrap { position: absolute; right: 14px; bottom: 14px; width: 260px; }
#radar { display: block; width: 260px; height: 260px; border-radius: 50%; background: rgba(4, 16, 26, 0.85); border: 1px solid var(--line); }
#radarCtl { display: flex; justify-content: center; gap: 8px; align-items: center; margin-top: 4px; font-family: var(--mono); font-size: 12px; }
#radarCtl button { padding: 1px 9px; }

#actions { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 720px); }
#actions button { font-size: 12.5px; padding: 6px 9px; background: rgba(8, 20, 34, 0.82); }
#actions button.on { background: rgba(88, 214, 141, 0.3); border-color: var(--green); }

/* Touch helm: throttle −, port (hold), starboard (hold), throttle +. Shown only when a touch device is detected (body.touch). */
#touch { position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%); display: none; gap: 8px; }
body.touch #touch { display: flex; }
#touch button { width: 58px; height: 50px; font-size: 20px; line-height: 1; padding: 0; background: rgba(8, 20, 34, 0.82); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
#touch button.on { background: rgba(88, 214, 141, 0.3); border-color: var(--green); }

#chatWrap { position: absolute; left: 14px; bottom: 206px; width: 380px; }
#chat { max-height: 120px; overflow-y: auto; font-size: 12.5px; display: flex; flex-direction: column-reverse; gap: 2px; }
#chat div { background: rgba(4, 12, 20, 0.6); padding: 2px 6px; border-radius: 4px; }
#chat b { color: var(--cyan); }
#chatInput { width: 100%; margin-top: 4px; font-size: 12.5px; opacity: 0.7; }
#chatInput:focus { opacity: 1; }

/* width/height auto + both max constraints keep the canvas's intrinsic aspect ratio (so it shrinks on short viewports instead of
   being clipped); align-self cancels the flex stretch; the click mapping divides by the rendered rect so it stays exact. */
#chart { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(92vh - 90px); min-height: 0; align-self: center; object-fit: contain; background: #0a2238; cursor: crosshair; }
#chartInfo { padding: 6px 12px; font-family: var(--mono); font-size: 12px; }

#hail { position: fixed; top: 20%; left: 50%; transform: translateX(-50%); z-index: 30; background: rgba(140, 30, 30, 0.9); border: 2px solid var(--red); border-radius: 10px; padding: 12px 20px; font-size: 18px; font-weight: 700; text-align: center; box-shadow: 0 0 30px rgba(255, 60, 60, 0.4); }
#hail small { display: block; font-size: 13px; font-weight: 400; color: #ffd0d0; }
#prompts { position: fixed; top: 14%; right: 14px; z-index: 30; display: flex; flex-direction: column; gap: 8px; }
#prompts .prompt { background: var(--panel); border: 1px solid var(--cyan); border-radius: 10px; padding: 10px 14px; width: 300px; }
#prompts .prompt .inline { margin-top: 8px; }

@media (max-width: 900px) {
  /* bottom-left: telemetry (two columns so values stay readable); bottom-right: radar with the touch helm and the action buttons stacked above it */
  #telemetry { left: 8px; bottom: 8px; width: 200px; font-size: 10.5px; padding: 6px 8px; }
  #telemetry .row { grid-template-columns: 50px minmax(0, 1fr); }
  #radarWrap { right: 8px; bottom: 8px; width: 140px; } #radar { width: 140px; height: 140px; }
  #touch { left: auto; right: 8px; bottom: 172px; transform: none; display: none; grid-template-columns: 1fr 1fr; gap: 6px; }
  body.touch #touch { display: grid; }
  #touch button { width: 54px; height: 46px; }
  #actions { left: auto; right: 8px; bottom: 14px; transform: none; max-width: 52vw; justify-content: flex-end; }
  body.touch #actions { bottom: 278px; }
  body:not(.touch) #actions { bottom: 176px; }
  #chatWrap { display: none; }
  #log { width: 50vw; }
}
