/* Titanic Sinking Simulator, site v2.
   One-screen instrument: 3D stage with HUD and a damage-diagram strip; controls docked right on desktop,
   stacked below on narrow windows, and a bottom sheet on phones (html[data-device="phone"], set by the app).
   Deliberately dark: a night sea and a forensic reconstruction. */

/* ---- vendored fonts (SIL Open Font License; files under fonts/) */
@font-face { font-family: "IBM Plex Sans Condensed"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-condensed-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Condensed"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Condensed"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Cormorant Garamond"; font-style: italic; font-weight: 600; font-display: swap; src: url("../fonts/cormorant-garamond-latin-600-italic.woff2") format("woff2"); }

:root {
  color-scheme: dark;
  --abyss: #05090f;
  --deep: #08111b;
  --panel: #0b1520;
  --panel-2: #0f1c2a;
  --line: #1a2a3b;
  --line-2: #27405a;
  --ink: #dbe6ef;
  --ink-2: #a8bbcb;
  --muted: #7187a0;
  --water: #3cc3ff;
  --brass: #e0b15a;
  --teal: #8fd3c9;
  --signal: #ff5d3d;
  --ok: #5fd39a;
  --warn: #ffb547;
  --crit: #ff6b6b;
  --chart-model: #2196d2;
  --chart-obs: #bd8a30;
  --chart-surface: #0c1622;
  --f-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --f-ui: "IBM Plex Sans Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --bar: 54px;   /* collapsed sheet height on phones */
  /* the visible viewport height: svh where supported, and the app overwrites it with the measured
     innerHeight in pixels, because on Android the address bar makes 100vh taller than what is visible */
  --app-h: 100vh;
}
@supports (height: 100svh) { :root { --app-h: 100svh; } }
html, body { height: 100%; }
html { overscroll-behavior: none; }
body { margin: 0; background: var(--abyss); color: var(--ink); font: 14px/1.45 var(--f-ui); -webkit-font-smoothing: antialiased; touch-action: manipulation; }
button, input, select { font: inherit; color: inherit; }
.brass { color: var(--brass); } .teal { color: var(--teal); }
.mb6 { margin-bottom: 6px; } .mb8 { margin-bottom: 8px; } .mt6 { margin-top: 6px; } .mt8 { margin-top: 8px; }
#app { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 384px; }
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #0c1826 0%, var(--abyss) 70%); }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl.tool-hole, #gl.tool-scrape { cursor: crosshair; }
#panel { min-width: 0; height: 100%; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.nogl { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); max-width: min(520px, calc(100% - 32px)); background: rgba(6, 12, 20, 0.92); border: 1px solid var(--line-2); border-radius: 6px; padding: 14px 16px; color: var(--ink-2); font-size: 14px; line-height: 1.5; z-index: 3; }
.nogl b { color: var(--ink); }
noscript .nogl { position: fixed; top: 40%; }

/* HUD */
.hud { position: absolute; left: calc(12px + var(--sal)); top: calc(12px + var(--sat)); right: calc(12px + var(--sar)); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.readout { background: rgba(6, 12, 20, 0.78); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px 10px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); min-width: 0; max-width: 520px; }
.ship-name { font: italic 600 20px/1 var(--f-display); letter-spacing: 0.02em; color: var(--ink); display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ship-name small { font: 500 11px/1 var(--f-ui); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.clock { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.clock .ship-time { font: 500 26px/1 var(--f-num); letter-spacing: -0.01em; }
.clock .elapsed { font: 400 13px/1 var(--f-num); color: var(--ink-2); }
.pill { display: inline-flex; align-items: center; gap: 6px; font: 600 11px/1 var(--f-ui); letter-spacing: 0.08em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; border: 1px solid currentColor; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.crit { color: var(--crit); } .pill.idle { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(5, auto); gap: 4px 16px; margin-top: 10px; }
.stat { min-width: 0; }
.stat .k { font: 500 10.5px/1.2 var(--f-ui); letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.stat .v { font: 500 14px/1.3 var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.forecast-line { margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.forecast-line b { color: var(--ink); font-weight: 600; }
.views { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.seg { display: inline-flex; background: rgba(6, 12, 20, 0.78); border: 1px solid var(--line); border-radius: 6px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 9px; border-radius: 4px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--line-2); color: var(--ink); }
.seg button:hover { color: var(--ink); }
.seg button:focus-visible, .btn:focus-visible, .tab:focus-visible, .tab-close:focus-visible, .card:focus-visible, input:focus-visible, .chip:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }

.strip { position: absolute; left: calc(12px + var(--sal)); right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); background: rgba(6, 12, 20, 0.82); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px 4px; }
.strip canvas { display: block; width: 100%; height: 96px; }
.strip .cap { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.toast { position: absolute; left: 50%; bottom: calc(140px + var(--sab)); transform: translateX(-50%); background: rgba(6, 12, 20, 0.92); border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 12px; font-size: 13px; max-width: min(520px, calc(100% - 32px)); text-align: center; opacity: 0; transition: opacity .25s; pointer-events: none; }
.toast.on { opacity: 1; }

/* Panel */
.tabs { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-bottom: 1px solid var(--line); }
.tab { border: 0; background: transparent; padding: 13px 4px 11px; cursor: pointer; color: var(--muted); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; font-size: 12px; border-bottom: 2px solid transparent; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--water); }
.tab-close { display: none; border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 14px; cursor: pointer; }
.pane { padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.pane[hidden] { display: none !important; }
.sec h3 { margin: 0 0 8px; font: 600 11.5px/1.2 var(--f-ui); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.sec p { margin: 0; color: var(--ink-2); max-width: 62ch; }
.cards { display: grid; gap: 6px; }
.card { text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 9px 11px; cursor: pointer; display: grid; gap: 3px; }
.card:hover { border-color: var(--line-2); }
.card[aria-checked="true"] { border-color: var(--water); box-shadow: inset 3px 0 0 var(--water); }
.card b { font-weight: 600; font-size: 14px; }
.card span { color: var(--ink-2); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 6px; padding: 8px 12px; cursor: pointer; font-weight: 500; min-height: 36px; }
.btn:hover { border-color: var(--water); }
.btn.primary { background: #123a55; border-color: #1f6a96; }
.btn.danger:hover { border-color: var(--signal); }
.seg.wide { width: 100%; }
.seg.wide button { flex: 1; }
.hint { font-size: 12.5px; color: var(--muted); }
.kbd-hint { display: inline; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; color: var(--ink-2); }
.check input { margin-top: 3px; accent-color: var(--water); flex: none; }
.check span { min-width: 0; }
.slider { width: 100%; accent-color: var(--water); }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.kv .v { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font: 600 10.5px/1.2 var(--f-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
th.num { text-align: right; }
.tablewrap { overflow-x: auto; }
.chip { border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: 3px 9px; cursor: pointer; font-size: 12px; min-height: 28px; }
.chip[aria-pressed="true"] { background: #123a55; border-color: #1f6a96; }
.x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; min-width: 28px; min-height: 28px; }
.x:hover { color: var(--signal); }
.tag { font: 500 11px/1 var(--f-num); padding: 2px 5px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--ink-2); }
.tag.e { color: var(--brass); border-color: #6a5326; } .tag.d { color: var(--teal); border-color: #2c5a55; } .tag.b { color: var(--ink); border-color: var(--line-2); }
.chart { position: relative; }
.chart canvas { width: 100%; height: 170px; display: block; touch-action: pan-y; }
.chart .tip { position: absolute; pointer-events: none; background: rgba(6, 12, 20, 0.95); border: 1px solid var(--line-2); border-radius: 5px; padding: 6px 8px; font-size: 12px; min-width: 120px; display: none; }
.chart .tip .val { font: 500 13px/1.3 var(--f-num); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin: 2px 0 6px; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 6px; }
.legend i.line { width: 16px; height: 2px; border-radius: 2px; }
.legend i.dash { width: 16px; height: 0; border-top: 2px dashed; }
.legend i.dot { width: 8px; height: 8px; border-radius: 50%; }
.legend i.model { background: var(--chart-model); border-color: var(--chart-model); }
.legend i.dash.model { background: transparent; }
.legend i.obs { background: var(--chart-obs); }
.foot { padding: 14px 16px 22px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); margin-top: auto; }
.foot a { color: var(--ink-2); }
.foot-meta { margin-top: 8px; }

/* ---- narrow windows (any pointer): stage above, panel below */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: calc(var(--app-h) * 0.6) auto; height: auto; min-height: 100%; }
  #panel { height: auto; overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  .stats { grid-template-columns: repeat(3, auto); gap: 2px 12px; }
  .stat.opt { display: none; }
  .clock .ship-time { font-size: 21px; }
  .readout { padding: 8px 10px; }
  .strip canvas { height: 64px; }
  #stripNote, .strip .cap .long { display: none; }
  .toast { bottom: calc(100px + var(--sab)); }
  .views .seg button { padding: 5px 7px; font-size: 12px; }
  .kbd-hint { display: none; }
}
@media (max-width: 520px) {
  #app { grid-template-rows: calc(var(--app-h) * 0.66) auto; }
  .hud { flex-direction: column; align-items: stretch; gap: 8px; }
  .views { flex-direction: row; flex-wrap: nowrap; justify-content: flex-start; align-items: center; gap: 6px; overflow-x: auto; }
  .views .seg button { padding: 5px 6px; font-size: 11.5px; }
  .forecast-line { display: none; }
  .ship-name { font-size: 17px; }
}

/* ---- phones (coarse pointer, short side under 600 px): full-height stage, the panel as a bottom sheet */
html[data-device="phone"] #app { display: block; height: var(--app-h); min-height: 0; }
html[data-device="phone"] #stage { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--bar) + var(--sab)); }
html[data-device="phone"] #panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; height: calc(var(--bar) + var(--sab)); overflow: hidden; border-top: 1px solid var(--line-2); border-left: 0; transition: height .22s ease; padding-bottom: var(--sab); box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45); }
html[data-device="phone"] #panel.open { height: calc(var(--app-h) * 0.74); overflow-y: auto; }
html[data-device="phone"] .tabs { grid-template-columns: repeat(4, 1fr) auto; min-height: var(--bar); align-items: stretch; }
html[data-device="phone"] .tab { padding: 0 2px; font-size: 11.5px; }
html[data-device="phone"] .tab-close { display: block; }
html[data-device="phone"] #panel:not(.open) .pane, html[data-device="phone"] #panel:not(.open) .foot { display: none; }
html[data-device="phone"] .strip { bottom: 8px; left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); }
html[data-device="phone"] .strip canvas { height: 56px; }
html[data-device="phone"] .hud { left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); top: calc(8px + var(--sat)); }
html[data-device="phone"] .toast { bottom: calc(96px + var(--sab)); }
html[data-device="phone"] .seg button, html[data-device="phone"] .tab { min-height: 40px; }
html[data-device="phone"] .forecast-line { display: block; font-size: 12px; margin-top: 6px; }
html[data-device="phone"] .readout { padding: 7px 10px; }
html[data-device="phone"] .ship-name { font-size: 16px; }
html[data-device="phone"] .clock { margin-top: 5px; }
html[data-device="phone"] .clock .ship-time { font-size: 19px; }
html[data-device="phone"] .stats { margin-top: 6px; gap: 2px 10px; }
html[data-device="phone"] .stat .v { font-size: 13px; }
html[data-device="phone"] .stat .k { font-size: 10px; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } html[data-device="phone"] #panel { transition: none; } }
