/* Fog City HUD. Dark is the default; light is hand-tuned, not inverted. Components use the tokens only. */
:root {
  color-scheme: dark;
  --bg: #0D121D;
  --panel: rgba(16, 21, 32, 0.74);
  --panel-solid: #141A27;
  --line: rgba(233, 237, 244, 0.13);
  --line-strong: rgba(233, 237, 244, 0.24);
  --ink: #E9EDF4;
  --muted: #9BA5B7;
  --accent: #F2B650;
  --accent-ink: #1A1204;
  --accent-soft: rgba(242, 182, 80, 0.16);
  --good: #5ED3A2; --warn: #F2B650; --bad: #FF7B72; --info: #86B7FF;
  --s-sleep: #6E7FB8; --s-home: #8FA3C9; --s-work: #86B7FF; --s-eat: #F2B650; --s-fun: #5ED3A2; --s-shop: #C9A0E8; --s-walk: #FF9D6E; --s-wait: #E7D38A; --s-ride: #FF7B72; --s-away: #5A6478;
  --radius: 14px; --pill: 999px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, monospace;
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #EDF0F4;
  --panel: rgba(247, 248, 250, 0.84);
  --panel-solid: #F7F8FA;
  --line: rgba(20, 26, 40, 0.14);
  --line-strong: rgba(20, 26, 40, 0.28);
  --ink: #141A28;
  --muted: #556073;
  --accent: #875700;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(135, 87, 0, 0.12);
  --good: #0F7F58; --warn: #875700; --bad: #B8322B; --info: #1F5FBF;
  --s-sleep: #54669E; --s-home: #6C82AE; --s-work: #1F5FBF; --s-eat: #A26A00; --s-fun: #0F7F58; --s-shop: #7A4FA8; --s-walk: #C2551F; --s-wait: #8C7A1E; --s-ride: #B8322B; --s-away: #8A93A3;
  --shadow: 0 18px 60px rgba(30, 40, 60, 0.20);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 14px; line-height: 1.4; -webkit-font-smoothing: antialiased; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; cursor: grab; }
#view.dragging { cursor: grabbing; }
#view.picking { cursor: pointer; }
#hud { position: fixed; inset: 0; pointer-events: none; user-select: none; -webkit-user-select: none; }
#hud > * { pointer-events: auto; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2); }

/* brand + clock */
#brand { position: absolute; left: max(14px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top)); padding: 10px 14px 10px; min-width: 190px; }
#brand h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 21px; letter-spacing: 0.01em; }
#brand .sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
#brand .clock { display: flex; align-items: baseline; gap: 8px; margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--line); }
#brand .time { font-family: var(--mono); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
#brand .day { color: var(--muted); font-size: 12px; }
#brand .wx { margin-top: 3px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#brand .wx i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; }

/* top-right tools */
#tools { position: absolute; right: max(14px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; max-width: 62vw; }
.iconbtn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); transition: background .15s, border-color .15s, transform .1s; }
.iconbtn:hover { border-color: var(--line-strong); }
.iconbtn:active { transform: scale(0.96); }
.iconbtn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#ledgerPill { height: 38px; padding: 0 12px; border-radius: 12px; display: flex; align-items: center; gap: 10px; font-size: 12.5px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
#ledgerPill b { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; }
#ledgerPill { white-space: nowrap; }
#ledgerPill .ok { color: var(--good); font-weight: 600; }
#ledgerPill .sep { width: 1px; height: 16px; background: var(--line); }

/* mode dock */
#dock { position: absolute; left: max(14px, env(safe-area-inset-left)); top: max(50%, calc(var(--tl-b, 139px) + var(--dock-h, 352px) / 2 + 8px)); transform: translateY(-50%); display: flex; flex-direction: column; gap: 6px; padding: 6px; }
.mode { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 9px; border-radius: 10px; border: 1px solid transparent; background: transparent; text-align: left; min-width: 148px; transition: background .15s, border-color .15s; }
.mode:hover { background: var(--accent-soft); }
.mode[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.mode svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mode span { font-size: 13px; font-weight: 550; }
.mode small { display: block; font-size: 11px; font-weight: 400; opacity: 0.72; }
.mode b { font-weight: inherit; }
.mode .short { display: none; }

/* time bar */
#timebar { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(760px, calc(100vw - 28px)); padding: 10px 14px 12px; }
#timebar .row { display: flex; align-items: center; gap: 10px; }
#timebar .label { font-size: 12px; color: var(--muted); white-space: nowrap; }
#track { position: relative; flex: 1; height: 30px; border-radius: 9px; cursor: ew-resize; touch-action: none; overflow: visible; }
#track .sky { position: absolute; inset: 9px 0; border-radius: 6px; border: 1px solid var(--line); background: linear-gradient(90deg, #101a33 0%, #101a33 22%, #c7794a 25.8%, #7fb2e6 31%, #8fc0ee 55%, #7fb2e6 78%, #e39a52 83.5%, #b6524a 85.6%, #1b2447 89%, #101a33 100%); opacity: 0.95; }
#track .ticks { position: absolute; inset: 0; pointer-events: none; }
#track .ticks i { position: absolute; top: 3px; width: 1px; height: 4px; background: var(--muted); opacity: 0.6; }
#track .ticks em { position: absolute; top: -9px; transform: translateX(-50%); font-style: normal; font-size: 9.5px; color: var(--muted); font-family: var(--mono); }
#sun { position: absolute; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff6d8, #ffcf66 55%, #f2a53a); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 0 18px rgba(255, 200, 90, 0.75); pointer-events: none; transition: background .3s, box-shadow .3s; }
#sun .at { position: absolute; left: 50%; bottom: 29px; transform: translateX(-50%); padding: 4px 8px; border-radius: 7px; background: var(--panel-solid); border: 1px solid var(--line-strong); color: var(--ink); font: 600 12px/1 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; opacity: 0; transition: opacity .2s; pointer-events: none; }
#track.dragging #sun .at { opacity: 1; }      /* while dragged: the time being asked for, "tomorrow" when it is earlier than now */
#sun.night { background: radial-gradient(circle at 35% 35%, #ffffff, #cfd8ee 60%, #9aa6c6); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 0 14px rgba(190, 205, 255, 0.6); }
#speeds { display: flex; gap: 4px; }
#speeds button { height: 28px; min-width: 38px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: transparent; font-family: var(--mono); font-size: 12px; }
#speeds button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
#hint { margin-top: 8px; text-align: center; font-size: 12.5px; color: var(--muted); min-height: 17px; text-wrap: balance; }
#hint b { color: var(--ink); font-weight: 600; }
#fogrow { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#fogrow input[type=range] { flex: 1; accent-color: var(--accent); height: 18px; }

/* card */
#card { position: absolute; right: max(14px, env(safe-area-inset-right)); top: 62px; width: min(350px, calc(100vw - 28px)); max-height: calc(100dvh - 190px); overflow: hidden; display: none; flex-direction: column; }
#card.open { display: flex; }
#card header { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
#card header .who { flex: 1; min-width: 0; }
#card h2 { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 600; }
#card .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
#card .body { padding: 10px 14px 12px; overflow-y: auto; overscroll-behavior: contain; }
#card .now { font-size: 14px; font-weight: 600; }
#card .now small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
#card h3 { margin: 12px 0 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.needs { display: grid; grid-template-columns: 62px 1fr 34px; gap: 5px 8px; align-items: center; font-size: 12.5px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.needs span:nth-child(3n) { font-family: var(--mono); font-size: 11.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.why { font-size: 13px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); border: 1px solid var(--line); }
#card h3:first-of-type { margin-top: 9px; }
.opts { margin-top: 8px; display: grid; gap: 5px; }
.opt { display: grid; grid-template-columns: 1fr 44px; gap: 2px 8px; align-items: center; font-size: 12.5px; }
.opt .bar { grid-column: 1 / 3; height: 5px; }
.opt .bar i { background: var(--muted); opacity: 0.55; }
.opt.win { font-weight: 600; }
.opt.win .bar i { background: var(--accent); opacity: 1; }
.opt b { font-family: var(--mono); font-weight: 500; font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.opt .parts { grid-column: 1 / 3; color: var(--muted); font-size: 11px; font-weight: 400; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.plan { font-size: 12.5px; display: grid; grid-template-columns: 62px 1fr; gap: 3px 8px; }
.plan span:nth-child(odd) { font-family: var(--mono); color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: var(--pill); border: 1px solid var(--line); background: transparent; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.btn { flex: 1 1 0; min-width: max-content; min-height: 36px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: transparent; font-size: 13px; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:hover { filter: brightness(1.06); }
.x { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: transparent; display: grid; place-items: center; flex: none; }
.x svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
details.older { margin-top: 8px; font-size: 12.5px; }
details.older summary { cursor: pointer; color: var(--muted); }
details.older li { margin: 5px 0; }
details.older ul { margin: 6px 0 0; padding-left: 16px; }
details.older li b { font-variant-numeric: tabular-nums; }
.chipline { display: none; }

/* ledger + about sheets */
.sheet { position: absolute; right: max(14px, env(safe-area-inset-right)); top: 62px; width: min(380px, calc(100vw - 28px)); max-height: calc(100dvh - 190px); overflow-y: auto; padding: 14px 16px 16px; display: none; }
.sheet.open { display: block; }
.sheet h2 { margin: 0 28px 4px 0; font-family: var(--serif); font-size: 19px; }
.sheet p { margin: 8px 0; color: var(--muted); font-size: 13px; }
.sheet p b, .sheet li b { color: var(--ink); }
.sheet ul { margin: 6px 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.sheet .x { position: absolute; right: 12px; top: 12px; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 10px 0 12px; border: 1px solid var(--line); }
.stack i { display: block; height: 100%; }
.lrow { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; font-size: 13px; padding: 3px 0; }
.lrow i { width: 10px; height: 10px; border-radius: 3px; }
.lrow b { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.sum { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sheet p.note { margin: 3px 0 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.sum .ok { color: var(--good); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; margin-top: 8px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { font-variant-numeric: tabular-nums; }
kbd { font-family: var(--mono); font-size: 11.5px; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--accent-soft); }

/* credit */
#credit { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); font-size: 11.5px; color: #fff; opacity: 0.86; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.75), 0 0 2px rgba(0, 0, 0, 0.6); pointer-events: none; max-width: calc((100vw - 760px) / 2 - 30px); line-height: 1.3; }
#credit a { color: inherit; text-decoration: none; pointer-events: auto; border-bottom: 1px solid rgba(255, 255, 255, 0.45); }

/* drive HUD */
#drive { position: absolute; left: 240px; right: 240px; margin: 0 auto; width: fit-content; top: calc(max(var(--bn-b, 0px), var(--top-b, 50px)) + 8px); padding: 8px 16px; display: none; gap: 18px; align-items: center; white-space: nowrap; }      /* centred under the banner, in the same corridor */
#drive.open { display: flex; }
#drive .big { font-family: var(--mono); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
#drive .lab { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
#drive .delta.ahead { color: var(--good); } #drive .delta.behind { color: var(--bad); }
#pad { position: absolute; inset: auto 0 max(22px, env(safe-area-inset-bottom)) 0; display: none; justify-content: space-between; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); pointer-events: none; }
#pad.open { display: flex; }
#pad .grp { display: flex; gap: 10px; pointer-events: auto; }
#pad button { width: 64px; height: 64px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line-strong); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 22px; touch-action: none; }
#pad button.on { background: var(--accent); color: var(--accent-ink); }
/* the steering pad takes the time bar's place while it is on screen */
body.pad-on #timebar { opacity: 0; pointer-events: none; }

/* banner for modes (what am I looking at, how to leave) */
#banner { position: absolute; left: 240px; right: 240px; margin: 0 auto; width: fit-content; top: calc(max(12px, env(safe-area-inset-top)) + 50px); padding: 7px 8px 7px 14px; display: none; align-items: center; gap: 12px; font-size: 13px; }
#banner.open { display: flex; }
#banner b { font-weight: 600; }
#banner span { color: var(--muted); }
#banner button { flex: none; height: 28px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: transparent; font-size: 12.5px; font-weight: 600; white-space: nowrap; }

/* toast */
#toast { position: absolute; left: 14px; right: 14px; margin: 0 auto; width: fit-content; bottom: 150px; transform: translateY(8px); padding: 8px 14px; font-size: 13px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; text-align: center; }      /* centred between the edges: hung from left 50% it could never be wider than half the screen */
#toast.show { opacity: 1; transform: translateY(0); }

/* loading */
#loading { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(1200px 700px at 50% 60%, #2a2233 0%, #0D121D 70%); color: #E9EDF4; transition: opacity .9s ease; z-index: 10; pointer-events: auto; }
#loading.done { opacity: 0; pointer-events: none; }
#loading .box { text-align: center; padding: 24px; }
#loading h1 { font-family: var(--serif); font-size: clamp(34px, 7vw, 60px); margin: 0; font-weight: 600; letter-spacing: 0.01em; }
#loading p { color: #9BA5B7; margin: 8px 0 22px; font-size: 15px; }
#loading .prog { width: min(360px, 70vw); height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); margin: 0 auto; overflow: hidden; }
#loading .prog i { display: block; height: 100%; width: 0%; background: #F2B650; border-radius: 2px; transition: width .2s; }
#loading .step { margin-top: 12px; font-size: 12.5px; color: #9BA5B7; font-family: var(--mono); min-height: 18px; }

/* cinematic: hide chrome while the opening shot plays, or when H is pressed */
body.cine #brand, body.cine #tools, body.cine #dock, body.cine #timebar, body.cine #card, body.cine .sheet, body.cine #banner, body.cine #drive { opacity: 0; pointer-events: none; }
body.cine #pad { display: none; }
#brand, #tools, #dock, #timebar, #card, #banner, #drive { transition: opacity .6s ease; }
#title { position: absolute; left: 0; right: 0; top: 16%; text-align: center; color: #fff; pointer-events: none; opacity: 0; transition: opacity 1.2s ease; text-shadow: 0 2px 30px rgba(0, 0, 0, 0.55), 0 0 6px rgba(0, 0, 0, 0.35); }
#title.show { opacity: 1; }
#title h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(40px, 8vw, 84px); margin: 0; letter-spacing: 0.01em; }
#title p { margin: 6px 0 0; font-size: clamp(14px, 2.2vw, 20px); opacity: 0.92; }
#skip { position: absolute; right: 18px; bottom: 18px; height: 34px; padding: 0 14px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.4); background: rgba(0, 0, 0, 0.3); color: #fff; font-size: 13px; display: none; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
body.intro-on #skip { display: block; }      /* only while the opening shot plays (main.js sets the class), not whenever H hides the panels */
#cursor { position: absolute; width: 26px; height: 26px; margin: -3px 0 0 -3px; pointer-events: none; display: none; z-index: 5; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)); transform-origin: 3px 3px; }
/* the tour: a pale caption, and panels brought back one at a time */
#label { position: absolute; left: 50%; top: max(22px, env(safe-area-inset-top)); transform: translate(-50%, -8px); width: max-content; max-width: min(88vw, 620px); text-align: center; padding: 9px 16px 10px; border-radius: 12px; background: #E8F6FA; color: #141A28; font: 700 clamp(17px, 3.6vw, 26px)/1.18 "Avenir Next Condensed", "Avenir Next", "Helvetica Neue", var(--sans); letter-spacing: 0.005em; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.28); opacity: 0; transition: opacity .32s ease, transform .32s ease; pointer-events: none; z-index: 4; }
#label.show { opacity: 1; transform: translate(-50%, 0); }
body.cine.show-card #card, body.cine.show-time #timebar, body.cine.show-drive #drive, body.cine.show-banner #banner { opacity: 1; pointer-events: auto; }
body.film #card { top: auto; bottom: 11px; left: 10px; right: 10px; width: auto; max-height: 45vh; zoom: 1.25; }   /* the tour shows the card at a size a phone can read */
body.film #timebar { bottom: 16px; }
body.film #drive { top: 86px; }
body.film #title { top: 8.5%; transition: none; }
body.film #title h1 { font-size: 66px; }
body.film #title p { font-size: 19px; font-weight: 600; letter-spacing: 0.01em; }
body.film #skip, body.film #toast, body.film #hint { display: none; }
body.film #credit { display: none; }      /* the tour carries the credit on its closing title */
body.film #title .by { display: block; margin-top: 9px; font-size: 13.5px; font-weight: 500; opacity: 0.92; }
body.film #label { top: 34px; white-space: pre-line; }
body.film *, body.film *::before, body.film *::after { transition: none !important; }
body.film #timebar { padding-bottom: 12px; }
body.film #cursor { transform: scale(1.35); }
body.film #cursor.down { transform: scale(1.15); }
#cursor.down { transform: scale(0.86); }

/* ---------- desktop: who gives way to whom ---------- */
@media (min-width: 761px) and (min-height: 521px) {
  /* the banner keeps clear of the card and the sheets */
  #card.open ~ #banner { right: 378px; }
  .sheet.open ~ #banner { right: 408px; }
}
/* where the credit cannot fit on one line it is two tidy lines: the sentence, then the link */
@media (min-width: 761px) and (max-width: 1489px) and (min-height: 521px) {
  #credit .dot { display: none; }
  #credit a::before { content: '\A'; white-space: pre; }
}
/* where the time bar leaves no room in the corner, the credit goes under the brand */
@media (min-width: 761px) and (max-width: 1279px) and (min-height: 521px) {
  #credit { bottom: auto; top: calc(var(--brand-b, 139px) + 6px); max-width: 216px; font-size: 10.5px; }      /* no wider than the brand panel above it */
}
/* notes keep clear of the mode list on the left */
@media (min-width: 761px) and (min-height: 521px) { #toast { left: 250px; right: 250px; } }
/* a low window: the mode list drops its second lines so it fits between the brand and the time bar */
@media (min-width: 761px) and (max-width: 1279px) and (min-height: 521px) and (max-height: 640px), (min-width: 1280px) and (min-height: 521px) and (max-height: 600px) {
  .mode { padding: 7px 12px 7px 9px; }
  .mode small { display: none; }
}
/* a narrow window: the banner takes the row beside the brand and the card starts under it */
@media (min-width: 761px) and (max-width: 1000px) and (min-height: 521px) {
  #ledgerPill .long { display: none; }
  #banner, #card.open ~ #banner, .sheet.open ~ #banner, #drive { right: max(14px, env(safe-area-inset-right)); }
  :where(body.with-banner) #card, :where(body.with-banner) .sheet { top: calc(var(--bn-b, 104px) + 8px); max-height: calc(100% - var(--bn-b, 104px) - 136px); }
}
/* the opening title: on a wide screen the bridge tower stands right of centre, so the words go in the clear sky on the left */
@media (min-width: 1000px), (min-aspect-ratio: 3/2) {
  body:not(.film) #title { left: max(7%, env(safe-area-inset-left)); right: auto; text-align: left; }
}

/* ---------- phones, upright or sideways ---------- */
@media (max-width: 760px), (max-height: 520px) {
  #dock { flex-direction: row; max-width: calc(100vw - 20px); overflow-x: auto; }
  .mode { min-width: 0; padding: 8px 10px; flex-direction: column; gap: 3px; }
  .mode small { display: none; }
  .mode span { font-size: 11px; }
  .mode .long { display: none; } .mode .short { display: inline; white-space: nowrap; }
  #brand { padding: 8px 11px; min-width: 0; }
  #brand h1 { font-size: 17px; } #brand .sub, #brand .wx { display: none; }
  #brand .day { font-size: 0; } #brand .day::after { content: attr(data-short); font-size: 12px; }      /* Thu, not Thursday: the clock has to fit beside the tools */
  #ledgerPill .long { display: none; }
  #ledgerPill { padding: 0 10px; gap: 8px; }
  #timebar { padding: 14px 12px 10px; }
  #timebar .label { display: none; }
  #track { height: 34px; }
  #speeds button { min-width: 32px; padding: 0 5px; }
  #drive { left: 10px; right: 10px; gap: 12px; padding: 6px 12px; }
  #drive .big { font-size: 17px; }
  /* the banner is pinned to both edges, so it can never shrink to a column of single words; two lines at most */
  #banner { margin: 0; width: auto; padding: 6px 6px 6px 12px; gap: 8px; font-size: 12px; }
  #banner > div { flex: 1; min-width: 0; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  #banner button { padding: 0 9px; font-size: 12px; }
  /* inside a view the card folds to one line (who, and what they are doing) so the view is the picture; tap the line for the whole card */
  #card.folded { max-height: none; }
  #card.folded > :not(.chipline) { display: none; }
  #card.folded > .chipline { display: flex; }
  .chipline { align-items: center; gap: 8px; width: 100%; min-height: 42px; padding: 0 8px 0 14px; border: 0; background: transparent; text-align: left; }
  .chipline b { flex: none; font-family: var(--serif); font-size: 15.5px; font-weight: 600; white-space: nowrap; }
  .chipline span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12.5px; }
  .chipline svg { flex: none; width: 28px; height: 28px; padding: 6px; border-radius: 8px; border: 1px solid var(--line); stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
}

/* ---------- a phone held upright: everything stacks ---------- */
@media (max-width: 760px) {
  #hud { --low: calc(max(14px, env(safe-area-inset-bottom)) + var(--tb-h, 150px) + var(--dock-h, 58px) + 8px); }      /* the height the time bar and the mode bar take at the bottom */
  #tools { display: grid; grid-template-columns: repeat(4, 38px); justify-content: end; max-width: none; }      /* always two rows: the ledger pill, then the four buttons */
  #ledgerPill { grid-column: 1 / -1; justify-self: end; }
  #dock { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + var(--tb-h, 150px) + 8px); left: 50%; transform: translateX(-50%); }
  #card, .sheet { top: auto; bottom: calc(var(--low) + 8px); right: 10px; left: 10px; width: auto; max-height: min(44vh, calc(100% - var(--low) - max(var(--bn-b, 0px), var(--top-b, 126px)) - 16px)); }      /* never up into the banner or the brand, however short the screen */
  #credit { bottom: auto; top: calc(var(--brand-b, 93px) + 5px); max-width: 46vw; font-size: 10.5px; }
  #timebar .row { flex-wrap: wrap; row-gap: 8px; justify-content: center; }
  #track { flex: 1 0 100%; }
  #banner { top: calc(var(--top-b, 126px) + 6px); left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); }
  #pad { bottom: calc(max(14px, env(safe-area-inset-bottom)) + (var(--tb-h, 150px) - 64px) / 2); }      /* in the slot the hidden time bar leaves */
  #toast { bottom: calc(var(--low) + 58px); }      /* above the folded card's line */
  :where(body.pad-on) #toast { bottom: calc(var(--low) + 10px); }      /* Drive has no card: the note sits just above the mode bar, clear of the speed panel */
}

/* a short upright phone: there is no room under the banner, so the opened card covers it (✕ folds the card away again) */
@media (max-width: 760px) and (max-height: 640px) and (min-height: 521px) {
  #card, .sheet { z-index: 3; max-height: min(52vh, calc(100% - var(--low) - 112px)); }
  :where(body.with-card) #credit { visibility: hidden; }      /* no half-covered line peeking out above the card */
}

/* ---------- a phone turned sideways (or any very short window): one row at the top, one at the bottom, the card in a side column ---------- */
@media (max-height: 520px) {
  #toast { top: calc(var(--bn-b, 100px) + 8px); bottom: auto; }      /* a phone on its side: keep messages off the car */
  #brand { display: flex; align-items: baseline; gap: 10px; padding: 6px 12px 7px; }
  #brand .clock { margin: 0; padding: 0 0 0 10px; border-top: 0; border-left: 1px solid var(--line); }
  #tools { display: flex; max-width: none; flex-wrap: nowrap; }
  #timebar .row { flex-wrap: nowrap; justify-content: flex-start; }
  #track { flex: 1 1 auto; }
  #card, .sheet { top: calc(var(--top-b, 50px) + 8px); bottom: auto; left: auto; right: max(14px, env(safe-area-inset-right)); width: min(336px, calc(100vw - 28px)); max-height: calc(100% - var(--top-b, 50px) - var(--low, 72px) - 16px); }
  #banner { top: calc(var(--top-b, 50px) + 8px); left: max(14px, env(safe-area-inset-left)); right: calc(max(14px, env(safe-area-inset-right)) + 346px); width: fit-content; }
  #drive { top: calc(var(--top-b, 50px) + 8px); left: auto; right: max(14px, env(safe-area-inset-right)); margin: 0; }
  .chipline svg { transform: rotate(180deg); }      /* the card opens downwards here */
  #card header { padding: 9px 12px 8px; } #card .body { padding: 8px 12px 10px; } .actions { padding: 8px 12px 10px; }
}
/* sideways and narrow (a small phone): the stacked bars stay, the two loose lines go */
@media (max-height: 520px) and (max-width: 760px) {
  #hint, #credit { display: none; }
  #banner { right: max(14px, env(safe-area-inset-right)); }
  :where(body.with-banner) #card, :where(body.with-banner) .sheet, :where(body.with-banner) #drive { top: calc(var(--bn-b, 100px) + 8px); }
  :where(body.with-banner) #card, :where(body.with-banner) .sheet { max-height: calc(100% - var(--bn-b, 100px) - var(--low, 138px) - 16px); }
  /* Drive: the banner leaves the right of its row to the speed panel */
  :where(body.pad-on) #banner { right: calc(max(14px, env(safe-area-inset-right)) + 256px); }
  :where(body.pad-on) #drive { top: calc(var(--top-b, 50px) + 8px); }
  #toast { bottom: calc(var(--low) + 10px); }
}
/* sideways and wide: the mode bar and the time bar share the bottom row */
@media (max-height: 520px) and (min-width: 761px) {
  #hud { --low: calc(max(14px, env(safe-area-inset-bottom)) + var(--tb-h, 58px)); }
  #dock { top: auto; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); transform: none; transition: left .3s ease, transform .3s ease, opacity .6s ease; }
  :where(body.pad-on) #dock { left: 50%; transform: translateX(-50%); }      /* Drive: steering in one corner, pedals in the other, the mode bar between them */
  #timebar { left: calc(max(14px, env(safe-area-inset-left)) + var(--dock-w, 372px) + 10px); right: max(14px, env(safe-area-inset-right)); width: auto; transform: none; min-height: var(--dock-h, 67px); padding: 12px 12px 8px; display: flex; flex-direction: column; justify-content: center; }
  #pad { bottom: max(14px, env(safe-area-inset-bottom)); }
  /* the hint and the credit share one line above the bottom row: the hint on the left, the credit on the right */
  #hint { position: absolute; left: calc(-1 * (var(--dock-w, 372px) + 11px)); bottom: calc(100% + 8px); margin: 0; min-height: 0; width: max-content; max-width: min(560px, calc(100vw - 372px)); padding: 4px 11px 5px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); text-align: left; font-size: 11.5px; }
  #hint:empty { display: none; }
  #credit { top: auto; left: auto; right: max(14px, env(safe-area-inset-right)); bottom: calc(var(--low) + 12px); max-width: 320px; text-align: right; font-size: 10.5px; }
  :where(body.with-card) #credit { display: none; }      /* the open card or sheet uses that corner */
  #toast { bottom: calc(var(--low) + 46px); }
}
/* a short screen has a short sky: a smaller title keeps the words clear of the hills */
@media (max-height: 520px) {
  #title { top: 8%; }
  #title h1 { font-size: clamp(30px, 11vh, 46px); }
  #title p { margin-top: 3px; font-size: 14px; }
}
/* while the panels are hidden (the opening shot, or H) the credit is alone on screen: it sits in the bottom left corner on every screen */
:where(body.cine) #credit { top: auto; right: auto; left: max(14px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); max-width: min(64vw, 440px); text-align: left; }
@media (max-width: 760px) { :where(body.cine) #credit .dot { display: none; } :where(body.cine) #credit a::before { content: '\A'; white-space: pre; } }
/* narrow phones: the pill drops its divider, then its words; the clock and the buttons shrink a little; the banner may take a third line */
@media (max-width: 380px) { #ledgerPill .sep { display: none; } }
@media (max-width: 350px) {
  #ledgerPill .ok .w { display: none; }
  #brand .time { font-size: 15px; }
  #tools { grid-template-columns: repeat(4, 34px); gap: 6px; }
  .iconbtn { width: 34px; height: 34px; }
  #banner > div { -webkit-line-clamp: 3; }
}
/* ---------- touch screens and phones (brief 2026-11-15, Protein Play's ADR-008) ----------
   Every control is at least 44 px where a finger uses it; the site bar (/next-by-email.js sets --sm-bar) and the home bar
   never sit over a control; on a phone the time bar is the bottom sheet: the sun stays, the speeds and the hint fold
   behind Controls. Desktop with a mouse keeps the sizes above. */
:root { --foot: max(env(safe-area-inset-bottom, 0px), var(--sm-bar, 0px)); --foot-gap: max(14px, calc(var(--foot) + 8px)); }
#tbFold { display: none; }
@media (max-width: 899px), (max-height: 520px), (pointer: coarse) {
  .iconbtn { width: 44px; height: 44px; }
  #ledgerPill { height: 44px; }
  #speeds button { height: 44px; min-width: 44px; }
  .x { width: 44px; height: 44px; }
  .sheet h2 { margin-right: 48px; }
  .sheet .x { right: 8px; top: 8px; }
  .btn { min-height: 44px; }
  .chip { min-height: 44px; padding: 0 12px; font-size: 13px; }
  .chipline { min-height: 44px; }
  details.older summary { min-height: 44px; display: flex; align-items: center; }
  #fogrow input[type=range] { height: 44px; }
  #banner button { height: 44px; }
  #skip { height: 44px; padding: 0 16px; }
  /* the credit's link: the same line on screen, a finger-sized target around it */
  #credit a { display: inline-block; padding: 14px 0; margin: -14px 0; border-bottom: 0; text-decoration: underline; text-decoration-color: rgba(255, 255, 255, 0.45); text-decoration-thickness: 1px; text-underline-offset: 3px; }
  #timebar { bottom: var(--foot-gap); }
  #credit a::before { content: none !important; }
}
/* where the credit is two lines (the sentence, then the link) the break is the dot's, so the link stays one box */
@media (min-width: 761px) and (max-width: 899px) and (min-height: 521px), (min-width: 761px) and (max-width: 1489px) and (min-height: 521px) and (pointer: coarse) {
  #credit .dot { display: block; height: 0; overflow: hidden; }
}
@media (max-width: 760px) {
  :where(body.cine) #credit .dot { display: block; height: 0; overflow: hidden; }
}
/* a phone, upright or sideways: the time bar folds, and everything at the bottom stands on the site bar */
@media (max-width: 760px), (max-height: 520px) {
  .mode { min-width: 44px; }
  #tbFold { display: grid; place-items: center; flex: none; order: 1; width: 44px; height: 44px; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
  #tbFold svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
  #timebar:not(.folded) #tbFold svg { transform: rotate(180deg); }
  #track { order: 0; }
  #speeds { order: 2; }
  body:not(.film) #timebar.folded #speeds, body:not(.film) #timebar.folded #hint { display: none; }
  body.film #tbFold { display: none; }
  #timebar { bottom: var(--foot-gap); }
  #skip { right: max(14px, calc(14px + env(safe-area-inset-right))); bottom: var(--foot-gap); }
  #credit { font-size: 13px; }
  #brand .day::after { font-size: 13px; }
}
@media (max-width: 760px) {
  #hud { --low: calc(var(--foot-gap) + var(--tb-h, 150px) + var(--dock-h, 58px) + 8px); }
  #dock { bottom: calc(var(--foot-gap) + var(--tb-h, 150px) + 8px); }
  #pad { bottom: calc(var(--foot-gap) + (var(--tb-h, 150px) - 64px) / 2); }
  #tools { grid-template-columns: repeat(4, 44px); }
  #card, .sheet { max-height: min(44dvh, calc(100% - var(--low) - max(var(--bn-b, 0px), var(--top-b, 126px)) - 16px)); }
  :where(body:not(.cine)) #credit { max-width: calc(100vw - 240px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); }      /* left of the two rows of tools */
}
@media (max-width: 760px) and (min-height: 521px) {
  #track { flex: 1 1 0; min-width: 0; }
  #speeds { flex: 1 0 100%; justify-content: center; }
}
@media (max-width: 760px) and (max-height: 640px) and (min-height: 521px) {
  #card, .sheet { max-height: min(52dvh, calc(100% - var(--low) - 112px)); }
}
@media (max-width: 350px) { #tools { grid-template-columns: repeat(4, 44px); gap: 4px; } }
@media (max-height: 520px) {
  #tbFold { order: 1; }
  /* opened on its side: the sun keeps its row (with the fold button), the speeds take a second row */
  body:not(.film) #timebar:not(.folded) .row { flex-wrap: wrap; row-gap: 8px; }
  body:not(.film) #timebar:not(.folded) #track { flex: 1 1 calc(100% - 64px); }
  body:not(.film) #timebar:not(.folded) #speeds { order: 2; flex: 1 0 100%; justify-content: center; }
}
@media (max-height: 520px) and (min-width: 761px) {
  #hud { --low: calc(var(--foot-gap) + var(--tb-h, 58px)); }
  #dock { bottom: var(--foot-gap); }
  #pad { bottom: var(--foot-gap); }
  #credit { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { * { transition-duration: 0.01ms !important; } }
