:root {
  --accent: #f5b94a;
  --accent-rgb: 245, 185, 74;
  --ink: #e9eef8;
  --ink-dim: rgba(220, 230, 248, 0.58);
  --ink-faint: rgba(220, 230, 248, 0.32);
  --glass: rgba(8, 12, 22, 0.46);
  --glass-edge: rgba(170, 200, 255, 0.13);
  --hud-opacity: 0.9;
  --font: "Segoe UI Variable Display", "Segoe UI Variable Text", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --s: 1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#gl {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  display: block;
  cursor: grab;
}
#gl.dragging { cursor: grabbing; }

/* ───────── labels projected from 3D ───────── */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; left: 0; top: 0;
  white-space: nowrap;
  will-change: transform, opacity;
  opacity: 0;
  transition: opacity .5s ease;
  font-size: calc(12.5px * var(--s));
  line-height: 1.15;
  text-shadow: 0 0 6px #000, 0 0 14px rgba(0,0,0,.9);
}
.lbl .n { font-weight: 650; letter-spacing: .02em; color: #fff; }
.lbl .d { font-size: .8em; color: var(--ink-dim); margin-top: 1px; }
.lbl .tick {
  position: absolute; width: calc(18px * var(--s)); height: 1px;
  background: linear-gradient(90deg, transparent, currentColor);
  top: .65em; opacity: .8;
}
.lbl.planet { color: var(--c, #fff); padding-inline-start: calc(22px * var(--s)); }
.lbl.planet .tick { inset-inline-start: 0; }
.lbl.planet .n { color: var(--c, #fff); }
.lbl.sun .n { color: #ffd38a; font-size: 1.12em; }
.lbl.event { font-size: calc(11.5px * var(--s)); color: #ff8f8f; text-align: center; transform-origin: 50% 100%; }
.lbl.event .n { color: #ffb0a0; }
.lbl.event .d { color: rgba(255, 190, 170, .65); font-family: var(--mono); }
.lbl.event::after {
  content: ""; display: block; margin: 4px auto 0;
  width: 7px; height: 7px; transform: rotate(45deg);
  border: 1.5px solid #ff7a6a; background: rgba(255, 90, 70, .25);
}
.lbl.today .n { color: #8fe3ff; }
.lbl.today::after { border-color: #6fdcff; background: rgba(80, 200, 255, .3); }
.lbl.bh .n { color: #ffcf8a; letter-spacing: .08em; }
.lbl.arrow { font-size: calc(12px * var(--s)); color: rgba(255, 225, 170, .85); letter-spacing: .04em; }
.lbl.arrow .ar { display: inline-block; margin-inline-start: 6px; font-size: 1.3em; transform-origin: 50% 50%; }

/* ───────── HUD ───────── */
#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: var(--hud-opacity);
  transition: opacity .6s ease;
}
#hud.hidden > * { opacity: 0 !important; pointer-events: none !important; }
#hud.minimal .legend, #hud.minimal .telemetry, #hud.minimal .modes { opacity: 0; pointer-events: none; }

.panel {
  background: linear-gradient(160deg, rgba(14, 20, 34, .62), rgba(6, 9, 16, .42));
  border: 1px solid var(--glass-edge);
  border-radius: calc(14px * var(--s));
  backdrop-filter: blur(10px) saturate(1.15);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
  transition: opacity .6s ease;
}

.brand {
  position: absolute;
  top: calc(26px * var(--s));
  left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: calc(12px * var(--s));
  direction: ltr;
}
.logo { width: calc(38px * var(--s)); height: calc(38px * var(--s)); filter: drop-shadow(0 0 8px rgba(var(--accent-rgb), .55)); }
.title { font-size: calc(17px * var(--s)); letter-spacing: .32em; font-weight: 300; color: #f4f6fb; }
.title b { color: var(--accent); font-weight: 700; }
.subtitle { font-size: calc(12px * var(--s)); color: var(--ink-dim); letter-spacing: .04em; margin-top: 2px; text-align: left; }
[dir="rtl"] .subtitle { text-align: right; direction: rtl; }

.clock {
  position: absolute;
  top: calc(30px * var(--s)); right: calc(40px * var(--s));
  text-align: right; direction: ltr;
  transition: opacity .6s ease;
}
.clock .time {
  font-size: calc(64px * var(--s));
  font-weight: 200; letter-spacing: .02em; line-height: 1;
  color: #f7f9ff;
  text-shadow: 0 0 30px rgba(var(--accent-rgb), .25);
  font-variant-numeric: tabular-nums;
}
.clock .time small { font-size: .38em; color: var(--accent); margin-left: 6px; font-weight: 400; letter-spacing: .1em; }
.clock .date { font-size: calc(15px * var(--s)); color: var(--ink-dim); margin-top: calc(6px * var(--s)); letter-spacing: .05em; }
.clock.off { opacity: 0; }

.modes {
  position: absolute;
  right: calc(40px * var(--s));
  top: calc(170px * var(--s));
  display: flex; flex-direction: column;
  padding: calc(6px * var(--s));
  gap: calc(2px * var(--s));
  pointer-events: auto;
  min-width: calc(220px * var(--s));
}
.mode-btn {
  all: unset;
  display: flex; align-items: center; gap: calc(10px * var(--s));
  padding: calc(8px * var(--s)) calc(12px * var(--s));
  border-radius: calc(9px * var(--s));
  font-size: calc(13px * var(--s));
  color: var(--ink-dim);
  cursor: pointer;
  transition: background .25s, color .25s;
  position: relative;
}
.mode-btn .k {
  font-family: var(--mono); font-size: .78em; color: var(--ink-faint);
  border: 1px solid rgba(255,255,255,.12); border-radius: 4px; padding: 0 5px;
}
.mode-btn .ic { width: 1.3em; text-align: center; opacity: .9; }
.mode-btn .lb { flex: 1; }
.mode-btn:hover { background: rgba(255, 255, 255, .06); color: var(--ink); }
.mode-btn.active { background: rgba(var(--accent-rgb), .14); color: #fff; }
.mode-btn.active::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 22%; bottom: 22%;
  width: 3px; border-radius: 3px; background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.mode-btn.playing .lb::after { content: " ●"; color: var(--accent); font-size: .7em; animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.legend {
  position: absolute;
  right: calc(40px * var(--s));
  top: calc(520px * var(--s));
  min-width: calc(220px * var(--s));
  padding: calc(10px * var(--s)) calc(14px * var(--s));
  pointer-events: auto;
}
.leg-row {
  display: flex; align-items: center; gap: calc(10px * var(--s));
  padding: calc(4px * var(--s)) 0;
  font-size: calc(12.5px * var(--s));
  cursor: pointer; color: var(--ink-dim);
  transition: color .2s;
}
.leg-row:hover, .leg-row.on { color: #fff; }
.leg-row .sw { width: calc(22px * var(--s)); height: 3px; border-radius: 3px; background: var(--c); box-shadow: 0 0 8px var(--c); }
.leg-row .nm { flex: 1; }
.leg-row .hx { font-size: .82em; color: var(--ink-faint); }

.telemetry {
  position: absolute;
  right: calc(40px * var(--s));
  bottom: calc(76px * var(--s));
  width: calc(330px * var(--s));
  padding: calc(12px * var(--s)) calc(16px * var(--s)) calc(10px * var(--s));
}
.tele-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: calc(11px * var(--s)); letter-spacing: .14em; color: var(--ink-dim);
  text-transform: uppercase; margin-bottom: calc(8px * var(--s));
}
.live { display: flex; align-items: center; gap: 6px; color: #7dffb5; font-family: var(--mono); letter-spacing: .1em; }
.live i { width: 6px; height: 6px; border-radius: 50%; background: #7dffb5; box-shadow: 0 0 8px #7dffb5; animation: blink 1.4s infinite; }
.tele-grid { display: grid; grid-template-columns: 1fr 1fr; gap: calc(8px * var(--s)) calc(14px * var(--s)); }
.tv .l { font-size: calc(10.5px * var(--s)); color: var(--ink-faint); letter-spacing: .02em; }
.tv .v { font-family: var(--mono); font-size: calc(15px * var(--s)); color: #fff; margin-top: 1px; direction: ltr; text-align: start; font-variant-numeric: tabular-nums; }
[dir="rtl"] .tv .v { text-align: right; }
.tv .v.a { color: var(--accent); }
.tv .v.c { color: #7fdcff; }
.tv .v small { font-size: .68em; color: var(--ink-dim); margin-inline-start: 4px; }
#wave { width: 100%; height: calc(46px * var(--s)); margin-top: calc(10px * var(--s)); display: block; }
.tele-foot { font-family: var(--mono); font-size: calc(10px * var(--s)); color: var(--ink-faint); margin-top: calc(6px * var(--s)); direction: ltr; text-align: right; }

.caption {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: calc(78px * var(--s));
  width: min(calc(860px * var(--s)), 56vw);
  text-align: center;
  text-shadow: 0 0 18px #000, 0 0 4px #000;
}
.shot-index { font-family: var(--mono); font-size: calc(11px * var(--s)); letter-spacing: .4em; color: var(--accent); opacity: .9; direction: ltr; }
.shot-name { font-size: calc(30px * var(--s)); font-weight: 300; letter-spacing: .04em; margin-top: calc(4px * var(--s)); color: #fff; }
.shot-desc { font-size: calc(15px * var(--s)); line-height: 1.6; color: rgba(230, 236, 250, .78); margin-top: calc(6px * var(--s)); }
.shot-desc .en { display: block; font-size: .86em; color: var(--ink-dim); direction: ltr; margin-top: 2px; }
.shot-bar { width: calc(120px * var(--s)); height: 2px; margin: calc(12px * var(--s)) auto 0; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
.shot-bar i { display: block; height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.credit {
  margin-top: calc(10px * var(--s));
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap;
  gap: calc(8px * var(--s));
  font-size: calc(11.5px * var(--s));
  letter-spacing: .04em;
  color: rgba(220, 230, 248, .5);
}
.credit b { color: rgba(var(--accent-rgb), .9); font-weight: 600; }
.credit .en { direction: ltr; letter-spacing: .08em; }
.credit .mail { direction: ltr; font-family: var(--mono); font-size: .92em; color: rgba(220, 230, 248, .42); }
.credit .sep { color: rgba(var(--accent-rgb), .55); }
.caption.swap .shot-name, .caption.swap .shot-desc, .caption.swap .shot-index { animation: capIn 1.4s ease both; }
@keyframes capIn { from { opacity: 0; transform: translateY(10px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

.toast {
  position: absolute; left: 50%; top: calc(110px * var(--s));
  transform: translate(-50%, -8px);
  padding: 8px 18px; border-radius: 999px;
  background: rgba(10, 14, 24, .75); border: 1px solid var(--glass-edge);
  font-size: calc(13px * var(--s)); opacity: 0;
  transition: opacity .35s, transform .35s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#fallback { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; gap: 12px; color: #ddd; }
#fallback[hidden] { display: none; }
.boot, .boot * { transition: none !important; animation: none !important; }
#hud.hidden { visibility: hidden; }
/* bilingual second line (English under Arabic) */
.en2 { display: block; font-style: normal; direction: ltr; text-align: right; font-size: .78em; letter-spacing: .03em; color: var(--ink-faint); margin-top: 1px; }
.mode-btn.active .en2 { color: rgba(255, 255, 255, .55); }
.leg-row .hx .en2 { font-size: .9em; }
#hud.bi .mode-btn { padding-top: calc(4px * var(--s)); padding-bottom: calc(4px * var(--s)); }
#hud.bi .legend { top: calc(545px * var(--s)); }
.leg-row .en2 { display: inline; margin-inline-start: .5em; margin-top: 0; }
.leg-row .hx .en2 { display: none; }

/* ───────── settings gear + drawer ───────── */
#gear {
  all: unset; box-sizing: border-box;
  position: fixed; z-index: 30;
  top: calc(124px * var(--s)); right: calc(40px * var(--s));
  width: calc(36px * var(--s)); height: calc(36px * var(--s));
  display: grid; place-items: center;
  border-radius: 50%;
  color: rgba(230, 236, 250, .62);
  background: rgba(10, 14, 24, .38);
  border: 1px solid var(--glass-edge);
  backdrop-filter: blur(8px);
  cursor: pointer;
  opacity: .55;
  transition: opacity .25s, color .25s, transform .5s cubic-bezier(.2,.8,.2,1), background .25s;
}
#gear svg { width: 58%; height: 58%; }
#gear:hover, #gear:focus-visible { opacity: 1; color: var(--accent); background: rgba(10, 14, 24, .7); transform: rotate(60deg); }
#gear.off { display: none; }
.set-open #gear { opacity: 1; color: var(--accent); transform: rotate(90deg); }

#setScrim { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: opacity .3s; }
.set-open #setScrim { opacity: 1; pointer-events: auto; }

#settings {
  position: fixed; z-index: 50; top: 0; bottom: 0; right: 0;
  width: min(400px, 100vw);
  display: flex; flex-direction: column;
  background: linear-gradient(165deg, rgba(16, 22, 38, .92), rgba(7, 10, 18, .94));
  border-inline-start: 1px solid var(--glass-edge);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .5);
  backdrop-filter: blur(16px) saturate(1.2);
  transform: translateX(105%);
  transition: transform .42s cubic-bezier(.2,.8,.2,1);
  font-size: 13px; color: var(--ink);
}
.set-open #settings { transform: none; }
.set-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 14px; border-bottom: 1px solid rgba(255,255,255,.07); }
.set-title { font-size: 19px; font-weight: 600; letter-spacing: .02em; }
.set-title span { font-weight: 300; color: var(--ink-dim); font-size: .8em; }
.set-sub { font-size: 11.5px; color: var(--ink-faint); margin-top: 3px; }
.set-x { all: unset; cursor: pointer; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--ink-dim); flex: none; }
.set-x:hover { background: rgba(255,255,255,.08); color: #fff; }
.set-body { flex: 1; overflow-y: auto; padding: 4px 20px 16px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.set-sec { padding: 14px 0 6px; border-bottom: 1px solid rgba(255,255,255,.05); }
.set-sec:last-child { border-bottom: 0; }
.set-sec h3 { font-size: 11.5px; font-weight: 600; letter-spacing: .1em; color: var(--accent); margin-bottom: 10px; }
.set-sec h3 span { color: var(--ink-faint); font-weight: 400; }
.set-row { margin-bottom: 12px; }
.set-lab { display: block; margin-bottom: 6px; line-height: 1.35; }
.lab-ar { color: var(--ink); }
.lab-en { display: block; direction: ltr; font-size: .86em; color: var(--ink-faint); }
[dir="rtl"] .lab-en { text-align: right; }
#settings select {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  background: rgba(255,255,255,.05); color: var(--ink);
  border: 1px solid rgba(255,255,255,.1); font: inherit; outline: none; cursor: pointer;
}
#settings select:focus { border-color: rgba(var(--accent-rgb), .6); }
#settings option { background: #121827; color: #e9eef8; }
.set-line { display: flex; align-items: center; gap: 12px; }
.set-line input[type=range] { flex: 1; accent-color: var(--accent); cursor: pointer; }
.set-line output { min-width: 3ch; font-family: var(--mono); font-size: 12px; color: var(--accent); text-align: center; }
.set-switch { display: flex; align-items: center; gap: 12px; cursor: pointer; position: relative; }
.set-switch .set-lab { margin: 0; flex: 1; order: 1; }
.set-switch input { position: absolute; opacity: 0; pointer-events: none; }
.set-switch .knob { order: 2; flex: none; width: 38px; height: 22px; border-radius: 22px; background: rgba(255,255,255,.12); position: relative; transition: background .2s; }
.set-switch .knob::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #dfe6f5; transition: transform .2s; }
.set-switch input:checked ~ .knob { background: var(--accent); }
.set-switch input:checked ~ .knob::after { transform: translateX(16px); background: #1a1306; }
[dir="rtl"] .set-switch input:checked ~ .knob::after { transform: translateX(-16px); }
.set-switch input:focus-visible ~ .knob { outline: 2px solid rgba(var(--accent-rgb), .7); outline-offset: 2px; }
.set-colors { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.set-colors .chip { all: unset; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.15); }
.set-colors .chip:hover { transform: scale(1.12); }
.set-colors input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid rgba(255,255,255,.15); border-radius: 6px; background: none; cursor: pointer; }
.set-foot { padding: 12px 20px 16px; border-top: 1px solid rgba(255,255,255,.07); display: flex; flex-direction: column; gap: 10px; }
.set-reset { all: unset; cursor: pointer; text-align: center; padding: 9px; border-radius: 9px; border: 1px solid rgba(255,255,255,.12); color: var(--ink-dim); }
.set-reset:hover { color: #fff; border-color: rgba(var(--accent-rgb), .6); }
.set-credit { font-size: 11px; color: var(--ink-faint); text-align: center; }
.set-credit b { color: rgba(var(--accent-rgb), .85); font-weight: 600; }

/* ───────── v2: mode tabs, story mode ───────── */
.panel { backdrop-filter: none; background: linear-gradient(160deg, rgba(14, 20, 34, .74), rgba(6, 9, 16, .6)); }   /* blur over a moving canvas is costly at 4K */
.mode-tabs { display: flex; gap: 4px; margin-bottom: 4px; }
.mode-tab { all: unset; flex: 1; text-align: center; cursor: pointer; padding: calc(6px * var(--s)) 4px; border-radius: calc(8px * var(--s)); font-size: calc(12px * var(--s)); color: var(--ink-faint); letter-spacing: .03em; }
.mode-tab:hover { color: var(--ink); }
.mode-tab.on { color: var(--accent); background: rgba(var(--accent-rgb), .12); }
.mode-btn .k:empty { display: none; }
body.story .legend, body.story #wave { display: none; }
#gl { touch-action: none; }

/* ───────── v2: toolbar (web build) ───────── */
#tools { position: fixed; z-index: 30; top: calc(124px * var(--s)); right: calc(40px * var(--s)); display: flex; flex-direction: row-reverse; gap: calc(8px * var(--s)); transition: opacity .4s; }
#tools #gear { position: static; }
.tbtn {
  all: unset; box-sizing: border-box; width: calc(36px * var(--s)); height: calc(36px * var(--s)); display: grid; place-items: center; border-radius: 50%;
  color: rgba(230, 236, 250, .62); background: rgba(10, 14, 24, .38); border: 1px solid var(--glass-edge); cursor: pointer; opacity: .55;
  transition: opacity .25s, color .25s, background .25s;
}
.tbtn svg { width: 56%; height: 56%; }
.tbtn:hover, .tbtn:focus-visible, .tbtn.on { opacity: 1; color: var(--accent); background: rgba(10, 14, 24, .7); }
body.clean1 .brand, body.clean1 .clock, body.clean1 .modes, body.clean1 .legend, body.clean1 .telemetry { opacity: 0 !important; pointer-events: none !important; }
body.clean2 #hud, body.clean2 #labels { opacity: 0 !important; pointer-events: none !important; }
body.clean1 #tools, body.clean2 #tools { opacity: 0; }
body.clean1.awake #tools, body.clean2.awake #tools, body.clean1 #tools:hover, body.clean2 #tools:hover { opacity: 1; }
body.exporting #hud, body.exporting #labels, body.exporting #tools { opacity: 0 !important; pointer-events: none !important; }
body.exporting #gl { object-fit: contain; background: #000; }

/* ───────── v2: export dialog ───────── */
#xdlg { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
#xdlg.open { opacity: 1; pointer-events: auto; }
.xbox { width: min(460px, 94vw); max-height: 92vh; overflow-y: auto; padding: 18px 20px; border-radius: 16px; font-size: 13px; color: var(--ink);
  background: linear-gradient(165deg, rgba(16, 22, 38, .97), rgba(7, 10, 18, .98)); border: 1px solid var(--glass-edge); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.xbox header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.xrow { margin-bottom: 11px; }
.xrow > label { display: block; margin-bottom: 5px; color: var(--ink-dim); }
.xbox select { width: 100%; padding: 8px 10px; border-radius: 9px; background: rgba(255,255,255,.05); color: var(--ink); border: 1px solid rgba(255,255,255,.1); font: inherit; }
.xbox option { background: #121827; }
.xscenes { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
.xsc, .xchk label { display: flex !important; align-items: center; gap: 8px; cursor: pointer; color: var(--ink) !important; }
.xbox input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.xnote { font-size: 11.5px; color: var(--ink-faint); line-height: 1.6; margin: 4px 0 12px; }
.xgo { all: unset; display: block; width: 100%; box-sizing: border-box; text-align: center; padding: 11px; border-radius: 10px; cursor: pointer; background: var(--accent); color: #1a1306; font-weight: 650; }
.xgo:hover { filter: brightness(1.1); }
.xprog { position: fixed; z-index: 70; left: 50%; bottom: 28px; transform: translateX(-50%); width: min(420px, 90vw); padding: 14px 16px; border-radius: 14px; text-align: center; font-size: 13px;
  background: rgba(10, 14, 24, .92); border: 1px solid var(--glass-edge); display: flex; flex-direction: column; gap: 10px; pointer-events: auto; }
.xprog[hidden] { display: none; }
.xbar { height: 4px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; }
.xbar i { display: block; height: 100%; width: 0; background: var(--accent); }

/* ───────── v2: phone / portrait layout ───────── */
body.portrait .clock, body.portrait .legend, body.portrait .telemetry, body.portrait .subtitle { display: none; }
body.portrait .brand { top: calc(14px + env(safe-area-inset-top, 0px)); left: 14px; transform: none; gap: 8px; }
body.portrait .title { font-size: 11px; letter-spacing: .13em; white-space: nowrap; }
body.portrait .logo { width: 26px; height: 26px; }
body.portrait #tools { top: calc(12px + env(safe-area-inset-top, 0px)); right: 10px; gap: 6px; }
body.portrait .tbtn, body.portrait #gear { width: 34px; height: 34px; opacity: .8; }
body.portrait .modes {
  top: auto; left: 8px; right: 8px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); min-width: 0;
  flex-direction: row; align-items: stretch; overflow-x: auto; gap: 4px; padding: 5px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
body.portrait .modes::-webkit-scrollbar { display: none; }
body.portrait .mode-tabs { flex: none; flex-direction: column; margin: 0; gap: 2px; }
body.portrait .mode-tab { padding: 3px 9px; font-size: 11px; white-space: nowrap; }
body.portrait .mode-btn { flex: none; padding: 7px 11px; font-size: 12.5px; white-space: nowrap; gap: 6px; }
body.portrait .mode-btn .k, body.portrait .mode-btn .en2 { display: none; }
body.portrait .mode-btn.active::before { top: auto; bottom: 2px; left: 22%; right: 22%; width: auto; height: 2px; }
body.portrait .caption { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); width: 92vw; }
body.portrait .shot-name { font-size: 22px; }
body.portrait .shot-desc { font-size: 13px; line-height: 1.55; }
body.portrait .shot-desc .en { font-size: .88em; }
body.portrait .shot-index { font-size: 10px; }
body.portrait .credit { font-size: 10px; gap: 5px; margin-top: 7px; }
body.portrait .lbl { font-size: 11px; }
body.portrait .lbl .d { display: none; }
body.portrait .toast { top: calc(60px + env(safe-area-inset-top, 0px)); font-size: 12px; white-space: nowrap; }
body.portrait #settings { width: 100vw; }
@media (max-height: 520px) and (orientation: landscape) {
  .legend, .telemetry, .clock .date { display: none; }
  .modes { max-height: calc(100vh - 150px * var(--s)); overflow-y: auto; }
}
/* v2: keep the right-hand column from overlapping now that the scene list has tabs */
#hud.bi .mode-btn { padding-top: calc(2px * var(--s)); padding-bottom: calc(2px * var(--s)); }
#hud.bi .legend { top: calc(562px * var(--s)); padding-top: calc(7px * var(--s)); padding-bottom: calc(7px * var(--s)); }
#hud.bi .leg-row { padding: calc(2.5px * var(--s)) 0; }
#wave { height: calc(34px * var(--s)); }
