:root {
  --cream: #fffaf3;
  --paper: #fbf3e8;
  /* "Mars dusk": warm sand surfaces + the blue of a Martian sunset for ink and active states */
  --ink: #2a2744;
  --muted: #8b819f;
  --line: #f0dcc7;
  --stitch: rgba(234, 106, 51, .38);   /* mission-patch stitching on panels */
  --orange: #ea6a33;
  --orange-dk: #c94f1c;
  --orange-soft: #fde8da;
  --dark: #2e2b63;
  --green: #3fb46e;
  --red: #e5484d;
  --purple: #8b6cf0;
  --teal: #2fb3a5;
  --blue: #3a86ff;
  --yellow: #f2b632;
  --glass: rgba(255, 250, 243, .93);
  --shadow: 0 6px 18px rgba(46, 40, 99, .14);
  /* Chinese falls through to the rounded Chiron GoRound TC, matching Baloo/Nunito's soft ends */
  --head: "Baloo 2", "Nunito", "Chiron GoRound TC", "Noto Sans TC", system-ui, sans-serif;
  --num: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;   /* mission-control readout numerals */
  --body: "Nunito", "Chiron GoRound TC", "Noto Sans TC", system-ui, sans-serif;
  --side: 380px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 600 15px/1.45 var(--body); color: var(--ink); background: var(--paper); overflow: hidden; }
h1, h2, h3 { font-family: var(--head); font-weight: 800; margin: 0; line-height: 1.1; }
a { color: var(--orange-dk); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------- layout ---------- */
.app { position: relative; display: grid; grid-template-columns: 1fr var(--side); height: 100vh; height: 100dvh; }  /* dvh: phone browser bars don't hide the bottom of the side panel */
body.menu .app { grid-template-columns: 1fr; }
body.menu .game-only { display: none !important; }
.stage { position: relative; overflow: hidden; min-width: 0; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- floating chrome ---------- */
.topbar { position: absolute; top: 18px; left: 18px; right: 18px; display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; gap: 14px; align-items: center;
  padding: 12px 20px 12px 16px; border-radius: 24px; background: var(--glass); box-shadow: var(--shadow);
}
.logo { font: 800 2.3rem/.82 var(--head); color: var(--orange); padding-top: 6px; }
.brand-name { font: 800 1.05rem var(--head); }
.sol-read { font-family: var(--head); color: var(--orange); font-size: 1.05rem; }
.sol-read span { font-size: .8rem; letter-spacing: .08em; }
body.menu .sol-read { display: none; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 auto; }
.pill { display: flex; align-items: center; gap: 2px; padding: 6px 10px; border-radius: 999px; background: var(--glass); box-shadow: var(--shadow); }
.tbtn {
  display: grid; justify-items: center; gap: 1px; min-width: 50px; padding: 2px 4px; border: 0; background: none;
  cursor: pointer; font-size: .72rem; font-weight: 800; color: var(--muted);
}
.tbtn svg:not(.ri) { width: 34px; height: 34px; padding: 7px; border-radius: 50%; stroke: var(--ink); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tbtn.on { color: var(--ink); }
.tbtn.on svg:not(.ri) { background: var(--dark); stroke: #fff; }
.tbtn:not(.on):hover svg:not(.ri) { background: var(--orange-soft); }
.daybar .tbtn { cursor: default; min-width: 38px; }
.daybar .tbtn svg:not(.ri) { stroke: #aaa3c2; }
.daybar .tbtn.on svg:not(.ri) { background: var(--orange); stroke: #fff; }
.clock { font: 800 1rem var(--head); padding: 0 8px 0 4px; min-width: 52px; }

.corner { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.corner-btns { display: flex; gap: 8px; }
.pill-btn { border: 0; cursor: pointer; padding: 12px 18px; border-radius: 16px; background: var(--glass); box-shadow: var(--shadow); font-weight: 800; }
.pill-btn.round { width: 46px; padding: 12px 0; }
.pill-btn:hover { background: #fff; }
.pill-btn.sound { display: grid; place-items: center; color: var(--ink); }
.pill-btn.sound svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pill-btn.sound .spk { fill: currentColor; }
.pill-btn.sound .x, .pill-btn.sound.off .on { display: none; }
.pill-btn.sound.off .x { display: inline; }
.pill-btn.sound.off { color: var(--muted); }
/* Language button (langpicker.js): one fixed width for EN / DE / 中文, so switching or opening never moves Data and ? */
.pill-btn.lang, .intro-lang { --chev: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23c94f1c' stroke-width='2.2' stroke-linecap='round'/></svg>");
  position: relative; display: inline-flex; align-items: center; flex: none; width: 82px; padding-right: 0; color: var(--ink); font: inherit; font-weight: 800; white-space: nowrap; }
.pill-btn.lang::after, .intro-lang::after { content: ""; position: absolute; right: 13px; top: 50%; width: 10px; height: 7px; margin-top: -3.5px;
  background: var(--chev) no-repeat center / contain; transition: transform .18s; }
.pill-btn.lang[aria-expanded="true"]::after, .intro-lang[aria-expanded="true"]::after { transform: rotate(180deg); }
.pill-btn.lang[aria-expanded="true"] { background: #fff; box-shadow: var(--shadow), 0 0 0 2px var(--orange-soft); }
.pill-btn.lang:focus-visible, .intro-lang:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* The open list: a little mission-patch card like the "Change date" calendar - cream paper, orange stitching.
   Fixed to the window over everything, so it never pushes the layout. */
.lang-menu { position: fixed; z-index: 95; min-width: 186px; padding: 12px; border-radius: 22px; background: var(--cream);
  box-shadow: var(--shadow), 0 0 0 2px var(--line); display: grid; gap: 4px; animation: lang-pop .18s cubic-bezier(.3, .7, .4, 1.4); }
.lang-menu::before { content: ""; position: absolute; inset: 6px; border: 2px dashed var(--stitch); border-radius: 17px; pointer-events: none; }
.lang-menu[hidden] { display: none; }
@keyframes lang-pop { from { opacity: 0; transform: translateY(-6px) scale(.96); } to { opacity: 1; transform: none; } }
.lang-opt { position: relative; display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 6px 12px 6px 8px; border-radius: 999px;
  color: var(--ink); font: 800 .95rem var(--body); cursor: pointer; user-select: none; transition: background .12s, transform .12s; }
.lang-short { display: grid; place-items: center; min-width: 40px; height: 30px; padding: 0 6px; border-radius: 999px; border: 2px solid var(--line);
  background: #fff; color: var(--orange-dk); font: 800 .8rem var(--head); }
.lang-name { flex: 1; white-space: nowrap; }
.lang-tick { font-style: normal; color: #fff; visibility: hidden; }
.lang-opt:hover { background: var(--orange-soft); transform: translateX(2px); }
.lang-opt.on { background: var(--orange); color: #fff; box-shadow: 0 3px 0 var(--orange-dk); }
.lang-opt.on .lang-short { border-color: rgba(255, 255, 255, .55); background: rgba(255, 255, 255, .2); color: #fff; }
.lang-opt.on .lang-tick { visibility: visible; }
.lang-opt.on:hover { transform: none; }
.lang-opt:focus { outline: none; }
.lang-opt:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) { .lang-menu { animation: none; } .lang-opt, .pill-btn.lang::after, .intro-lang::after { transition: none; } }

/* map labels */
.labels { position: absolute; inset: 0; pointer-events: none; }
.label {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; border: 1.5px solid var(--line);
  display: flex; align-items: center; gap: 6px; white-space: nowrap; padding: 4px 12px 4px 10px; border-radius: 999px;
  background: #fffdf8; box-shadow: 0 3px 8px rgba(46, 40, 99, .18); font-weight: 800; font-size: .85rem;
}
.label:hover { background: #fff; border-color: var(--orange); }
.label .n { font: 700 .88rem var(--num); color: var(--orange); letter-spacing: -.02em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c4bed6; flex: none; }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, .25); }
.dot.busy { background: var(--yellow); }

/* resources */
.resbar { position: absolute; left: 18px; bottom: 18px; right: calc(var(--side) + 18px); display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none; }
.res {
  pointer-events: auto; display: flex; align-items: center; gap: 9px; padding: 7px 14px 7px 7px; border-radius: 18px;
  background: var(--glass); box-shadow: var(--shadow); border: 2px solid transparent; min-width: 128px; cursor: help;
}
.res .ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.res .ic svg:not(.ri) { width: 19px; height: 19px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.res .v { font: 800 1.05rem/1 var(--head); white-space: nowrap; }
.res .v small { font-size: .72rem; color: var(--muted); font-family: var(--body); }
.res .bar { height: 4px; border-radius: 9px; background: #f2e6d8; margin-top: 5px; overflow: hidden; }
.res .bar i { display: block; height: 100%; border-radius: 9px; transition: width .3s; }
.res.warn { border-color: var(--yellow); }
/* danger alarms: the louder the problem, the louder the screen (see alarm.js) */
.res.danger { border-color: var(--red); animation: pulse 1s infinite; }
.res.critical { border-color: var(--red); background: #ffe3e3; transform-origin: 20% 100%; animation: shake .5s infinite, blare .6s infinite; z-index: 2; }
.res.critical .v { color: #b3141a; }
@keyframes shake { 0%, 100% { transform: scale(1.12) translateX(0); } 25% { transform: scale(1.12) translateX(-3px); } 75% { transform: scale(1.12) translateX(3px); } }
@keyframes blare { 50% { box-shadow: 0 0 0 9px rgba(229, 72, 77, .38); } }
body[data-alarm]::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 30; box-shadow: inset 0 0 0 0 rgba(229, 72, 77, 0); }
body[data-alarm="danger"]::after { animation: edge 1.6s ease-in-out infinite; }
body[data-alarm="critical"]::after { animation: edge .7s ease-in-out infinite; }
@keyframes edge { 50% { box-shadow: inset 0 0 90px 18px rgba(229, 72, 77, .55); } }
.alarmbar { position: fixed; top: 74px; left: calc((100vw - var(--side)) / 2); transform: translateX(-50%); z-index: 45; display: flex; gap: 6px; align-items: stretch; max-width: min(560px, 92vw); }
.alarmbar[hidden] { display: none; }
.alarm-main, .alarm-mute { border: 3px solid #fff; background: #e5484d; color: #fff; font: inherit; cursor: pointer; box-shadow: 0 6px 22px rgba(179, 20, 26, .5); }
.alarm-main { display: flex; align-items: center; gap: 12px; padding: 10px 20px 10px 14px; border-radius: 22px; text-align: left; animation: pop .25s ease-out, blare .9s infinite; }
.alarm-main b { display: block; font: 800 1.2rem/1.15 var(--head); }
.alarm-main small { display: block; margin-top: 3px; font-size: .86rem; font-weight: 700; opacity: .95; }
.alarm-ic { font-size: 1.9rem; animation: shake .5s infinite; }
.alarmbar[data-level="danger"] .alarm-main, .alarmbar[data-level="danger"] .alarm-mute { background: #f08a24; box-shadow: 0 6px 22px rgba(190, 100, 10, .45); }
.alarmbar[data-level="critical"] .alarm-main { animation: pop .25s ease-out, blare .5s infinite; }
.alarm-mute { width: 44px; border-radius: 22px; font-size: 1.1rem; }
body.menu .alarmbar { left: 50%; }
@media (max-width: 900px) { .alarmbar { left: 50%; top: 64px; } .alarm-main b { font-size: 1.02rem; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(229, 72, 77, .22); } }
.datachip { font-size: .75rem; padding: 6px 12px; border-radius: 999px; background: rgba(46, 43, 99, .8); color: #fff; }
.datachip b { color: #ffcf8a; }

/* ---------- side panel ---------- */
.side { background: var(--cream); border-left: 1px solid var(--line); padding: 30px 26px 20px; overflow-y: auto; }
.side h1 { font-size: 2rem; margin-bottom: 18px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.tab { border: 1.5px solid var(--line); background: #fff; border-radius: 14px; padding: 13px; cursor: pointer; font-weight: 800; }
.tab.on { background: var(--dark); border-color: var(--dark); color: #fff; }
.tab #log-count, .tab #diary-count { display: inline-block; min-width: 1.5em; margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: var(--orange-soft); color: var(--orange-dk); font: 800 .8rem/1.4 var(--head); text-align: center; }
.tab.on #log-count, .tab.on #diary-count { background: rgba(255, 255, 255, .18); color: #fff; }

.syslist, .log { list-style: none; margin: 0; padding: 0; }
.focus { display: grid; gap: 12px; margin: 10px 0 4px; justify-items: start; }
.fstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.fstats div { background: #fff; border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 12px; }
.fstats b { display: block; font: 800 1.15rem/1.1 var(--head); }
.fstats span { font-size: .74rem; color: var(--muted); }
.label.sel { background: var(--orange); border-color: var(--orange); color: #fff; }
.label.sel .n { color: #fff; }
.sys { display: grid; grid-template-columns: 58px 1fr; padding: 16px 6px; border-bottom: 1px solid var(--line); border-radius: 12px; transition: background .5s; }
.sys.flash { background: var(--orange-soft); transition: none; }
.sys .n { font: 500 2.15rem/.9 var(--num); color: var(--orange); letter-spacing: -.06em; }
.sys-top { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.sys-top .name { font: 800 1.08rem var(--head); }
.sys-top .kw { margin-left: auto; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.state { font-size: .76rem; color: var(--muted); margin-top: 6px; min-height: 1.1em; }
.state.bad { color: var(--red); }
.state.ok { color: var(--green); }
.seg { display: flex; background: #f6ebde; border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 999px; padding: 7px 4px; cursor: pointer; font-weight: 800; font-size: .84rem; }
.seg button.on { background: var(--dark); color: #fff; }
.seg button:not(.on):hover { background: #fff; }
.seg-row { display: flex; gap: 8px; align-items: center; }
.seg-row .seg { flex: 1; }
.mini { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-weight: 800; font-size: .82rem; cursor: pointer; white-space: nowrap; }
.mini:hover:not(:disabled) { border-color: var(--orange); }
.mini:disabled { opacity: .45; cursor: not-allowed; }

.log { display: grid; grid-template-columns: max-content 1fr; column-gap: 8px; }
.log li { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: .86rem; }
.log .t { font: 600 .8rem var(--num); color: var(--orange); white-space: nowrap; }
.log li.log-bad { color: #b42d2d; }
.log li.log-good { color: #22794a; }
.log li.log-fact { color: #5a6b8c; }

/* ---------- buttons, tips ---------- */
.btn {
  border: 0; cursor: pointer; border-radius: 999px; padding: 12px 28px; font: 800 1.1rem var(--head);
  background: #fff; box-shadow: 0 4px 0 var(--line); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--orange); color: #fff; box-shadow: 0 4px 0 var(--orange-dk); }
.btn.primary:active { box-shadow: 0 1px 0 var(--orange-dk); }
.btn.ghost { background: none; box-shadow: none; color: var(--muted); }
.tip { border-bottom: 2px dotted #d8b597; cursor: help; }
.info {
  display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; border: 1.5px solid var(--muted);
  color: var(--muted); font: 700 .7rem/1 var(--num); cursor: help; vertical-align: 2px; margin-left: 4px;
}
.tooltip {
  position: fixed; z-index: 90; max-width: 260px; padding: 9px 13px; border-radius: 14px; pointer-events: none;
  background: var(--dark); color: #fff3e6; font-size: .84rem; box-shadow: 0 8px 22px rgba(0, 0, 0, .25);
  white-space: pre-line; /* multi-line tips (mission replay) */
}
.what-pop {
  position: fixed; z-index: 89; max-width: 240px; padding: 9px 13px 10px; border-radius: 16px; pointer-events: none;
  background: rgba(255, 250, 243, .97); color: var(--ink); box-shadow: 0 8px 22px rgba(40, 34, 90, .22); font-size: .84rem;
}
.what-pop b { display: block; font: 800 .95rem var(--head); margin-bottom: 2px; }
.what-pop p { margin: 0; line-height: 1.35; }
.what-pop::after { /* little tail pointing at the clicked spot */
  content: ""; position: absolute; left: var(--tail, 50%); bottom: -7px; width: 14px; height: 14px; margin-left: -7px;
  background: inherit; transform: rotate(45deg); border-radius: 0 0 4px 0;
}
.what-pop.below::after { bottom: auto; top: -7px; border-radius: 4px 0 0 0; }
.chip { display: inline-block; white-space: nowrap; line-height: 1.3; padding: 3px 10px; border-radius: 999px; background: #f6ebde; font-size: .78rem; font-weight: 800; }
.chip.hot { background: var(--red); color: #fff; }
.chip.ph { color: transparent; user-select: none; animation: chip-wait 1s ease-in-out infinite alternate; }   /* holds the place of a chip still loading */
@keyframes chip-wait { to { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .chip.ph { animation: none; opacity: .6; } }

/* ---------- overlays & modals ---------- */
.overlay { position: fixed; inset: 0; display: none; z-index: 30; pointer-events: none; padding: 18px; }
.overlay.active { display: grid; place-items: end center; }
#ov-debrief.active { place-items: center; background: rgba(42, 38, 86, .3); pointer-events: auto; }
.sheet {
  --px: 26px; --pt: 24px; --pb: 24px;   /* padding as vars: sticky footers (below) pull their edges back to the sheet's */
  pointer-events: auto; width: min(560px, 100%); background: rgba(255, 250, 243, .97); border-radius: 28px; padding: var(--pt) var(--px) var(--pb);
  box-shadow: 0 18px 50px rgba(40, 34, 90, .25); margin-bottom: 12px;
  /* never taller than the screen: long sheets scroll inside, so their buttons stay reachable on phones */
  max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain;
}
.sheet.wide { width: min(820px, 100%); }
.sheet.scroll, .card.scroll { max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow-y: auto; }
.sheet h2 { font-size: 1.6rem; margin-bottom: 14px; }
.sheet h3 { font-size: 1.15rem; margin: 22px 0 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.row.end { justify-content: flex-end; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { text-align: left; display: grid; gap: 8px; padding: 14px 16px; border-radius: 20px; cursor: pointer; background: #fff; border: 2px solid var(--line); }
.mode.on { border-color: var(--orange); background: #fff6ef; }
.mode-name { font: 800 1.05rem var(--head); }
.modes.tiers { grid-template-columns: repeat(3, minmax(0, 1fr)); }   /* minmax: long (German) chips can't push the cards out of the sheet */
/* Mission sheet grows (up to the wide-sheet size) so every chip stays on one line; the three equal
   cards then share that width, so nothing pokes out. Only a screen narrower than that lets chips wrap. */
#ov-title .sheet { width: fit-content; min-width: min(560px, 100%); max-width: min(820px, 100%); }
.modes.tiers .chips { flex-direction: column; align-items: flex-start; }   /* stacked, so the card is sized by its widest chip */
.modes.tiers .chip { max-width: 100%; white-space: nowrap; }
@media (max-width: 860px) { .modes.tiers .chip { white-space: normal; } }
.tier-tag { justify-self: start; font-size: .7rem; font-weight: 800; line-height: 1.2; padding: 3px 9px; border-radius: 999px; color: #fff; white-space: nowrap; }
.tier-tag.easy { background: var(--green); }
.tier-tag.normal { background: var(--blue); }
.tier-tag.hard { background: var(--red); }
.postcard {
  position: fixed; left: 18px; bottom: 18px; z-index: 31; margin: 0; width: 220px; padding: 8px 8px 10px; background: #fff;
  border-radius: 10px; box-shadow: var(--shadow); transform: rotate(-3deg); display: none;
}
body.title .postcard:not([hidden]) { display: block; }
.postcard img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 5px; display: block; background: #e9d8c4; }
.postcard figcaption { font-size: .74rem; font-weight: 800; margin-top: 6px; color: var(--muted); }

/* debrief dose charts: small multiples, one series each */
.dose-charts { display: grid; gap: 12px; }
.dchart h4 { margin: 0 0 4px; font: 800 .85rem var(--body); display: flex; justify-content: space-between; }
.dchart h4 span { color: var(--muted); font-weight: 700; }
.dbars { display: flex; align-items: flex-end; gap: 2px; height: 56px; border-bottom: 1px solid var(--line); }
.dbars i { flex: 1; min-height: 1px; border-radius: 4px 4px 0 0; }
.dbars i:hover { filter: brightness(.85); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 800; margin-left: auto; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { width: 40px; height: 24px; border-radius: 99px; background: #e6d6c5; position: relative; transition: background .2s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; }
.toggle input:checked + span { background: var(--orange); }
.toggle input:checked + span::after { left: 19px; }
.toggle input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

.slots { display: flex; gap: 6px; align-items: center; }
.slots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); }
.slots i.full { background: var(--orange); border-color: var(--orange); }
.slots b { font: 600 1.05rem var(--num); color: var(--orange); margin-left: 6px; }
.cargo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.cargo { position: relative; display: grid; justify-items: start; gap: 6px; padding: 14px; border-radius: 20px; cursor: pointer; background: #fff; border: 2px solid var(--line); text-align: left; }
.cargo .ci { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.4rem; background: #f6ebde; }
.cargo strong { font: 800 1rem var(--head); }
.cargo .pips { display: flex; gap: 4px; }
.cargo .pips i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.cargo.on { border-color: var(--orange); background: #fff6ef; }
.cargo.on .pips i { background: var(--orange); }
.cargo.on::after { content: "✓"; position: absolute; top: 10px; right: 12px; width: 24px; height: 24px; border-radius: 50%; background: var(--orange); color: #fff; display: grid; place-items: center; font-weight: 800; }
.cargo:disabled, .cargo.nofit { opacity: .4; cursor: not-allowed; }
.cargo.nudge { animation: cargo-nudge .4s; }
@keyframes cargo-nudge { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
/* Sits left of Back / Launch in the same row, so showing it doesn't push the cards up. */
.pack-hint { flex: 1 1 0; min-width: 0; margin: 0 auto 0 0; padding: 8px 12px; border-radius: 14px; background: #fff1e5; color: #8a3b12; font-weight: 700; font-size: .88rem; line-height: 1.35; }
@media (max-width: 600px) { .pack-hint { flex-basis: 100%; order: -1; } }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(42, 38, 86, .35); backdrop-filter: blur(2px); }
.card { --px: 24px; --pt: 24px; --pb: 24px; width: min(500px, 100%); background: var(--cream); border-radius: 28px; padding: var(--pt) var(--px) var(--pb);
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; box-shadow: 0 24px 60px rgba(30, 24, 72, .35); animation: pop .22s ease-out; }
.card.wide { width: min(680px, 100%); }
/* Long scrolling card (Data): Close stays pinned to the bottom edge. */
.card.scroll > .row.end { position: sticky; bottom: calc(-1 * var(--pb)); z-index: 2; margin: 16px calc(-1 * var(--px)) calc(-1 * var(--pb));
  padding: 12px var(--px) var(--pb); background: var(--cream); box-shadow: 0 -10px 14px -12px rgba(40, 34, 90, .25); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 1.6rem; background: var(--orange-soft); flex: none; }
.card h2 { font-size: 1.5rem; }
.card p { margin: 0 0 14px; font-size: 1rem; }
.real { display: inline-block; margin-bottom: 12px; padding: 5px 12px; border-radius: 999px; background: var(--dark); color: #fff; font-size: .78rem; text-decoration: none; }
.real b { color: #ffcf8a; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.choice { text-align: left; padding: 14px 16px; border-radius: 20px; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.choice:hover { border-color: var(--orange); background: #fff6ef; }
.choice strong { display: block; font: 800 1.08rem var(--head); }
.choice span { font-size: .8rem; color: var(--muted); }
.timer { height: 6px; background: #f2e6d8; border-radius: 9px; overflow: hidden; margin-top: 16px; }
.timer div { height: 100%; width: 100%; background: var(--orange); }
.rules { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.rules li { display: grid; grid-template-columns: 40px 1fr; }
.rules b { font: 500 1.35rem/1 var(--num); color: var(--orange); letter-spacing: -.05em; }
.numbers { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 10px; }
.numbers th, .numbers td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.numbers th { width: 44%; }
.note { font-size: .82rem; color: var(--muted); }

.toasts { position: fixed; bottom: max(84px, var(--lift, 0px)); left: calc((100vw - var(--side)) / 2); transform: translateX(-50%); z-index: 40; display: grid; gap: 6px; justify-items: center; pointer-events: none; transition: bottom .3s ease-out; }  /* --lift: outcome-ui.js, clears the +/− numbers */
body.menu .toasts { left: 50%; }
.toast { padding: 8px 16px; border-radius: 999px; background: rgba(255, 250, 243, .96); box-shadow: var(--shadow); font-size: .86rem; max-width: min(600px, 90vw); text-align: center; animation: drop .25s ease-out; border: 1.5px solid var(--line); }
.toast.good { border-color: #a6dfbd; }
.toast.bad { border-color: #f3a5a7; }
.toast.warn { border-color: #f4d58a; }
@keyframes drop { from { transform: translateY(-8px); opacity: 0; } }

/* debrief */
.stars { display: flex; gap: 8px; flex-wrap: wrap; }
.star { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 999px; background: #fff; border: 2px solid var(--line); font-weight: 800; font-size: .85rem; }
.star svg:not(.ri) { width: 24px; height: 24px; fill: #e6dacb; }
.star.got { border-color: var(--yellow); }
.star.got svg:not(.ri) { fill: var(--yellow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 14px; }
.stat { background: #fff; border-radius: 18px; padding: 10px 12px; border: 1.5px solid var(--line); }
.stat b { display: block; font: 800 1.35rem var(--head); }
.stat span { font-size: .75rem; color: var(--muted); }
.lessons, .decisions, .real-events { padding: 0; margin: 0; list-style: none; display: grid; gap: 6px; font-size: .9rem; }
.lessons li { padding: 8px 12px; background: #fff; border-radius: 14px; border: 1.5px solid var(--line); }
.decisions, .real-events { grid-template-columns: max-content 1fr; column-gap: 10px; }
.decisions li, .real-events li { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; }
.decisions .t, .real-events .t { font: 600 .84rem var(--num); color: var(--orange); white-space: nowrap; }
.real-events { max-height: 220px; overflow-y: auto; }
#debrief-src { font: 700 .75rem var(--body); color: var(--muted); }
.osdr { display: grid; gap: 8px; font-size: .88rem; }
.osdr a { text-decoration: none; display: block; padding: 10px 12px; background: #fff; border-radius: 14px; border: 1.5px solid var(--line); color: var(--ink); }
.osdr a:hover { border-color: var(--orange); }
.osdr b { font: 600 .9rem var(--num); color: var(--orange); margin-right: 4px; }
.nogl { position: fixed; inset: 0; display: grid; place-items: center; font-weight: 800; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app { display: block; height: auto; }
  .stage { height: max(60vh, 400px); }
  body.menu .stage { height: 100vh; height: 100dvh; }
  .side { border-left: 0; border-top: 1px solid var(--line); padding: 22px 16px; }
  .topbar { top: 10px; left: 10px; right: 10px; }
  .brand { padding: 8px 12px; gap: 8px; border-radius: 18px; }
  .logo { font-size: 1.45rem; }
  .brand-name { display: none; }
  .toolbar { position: absolute; left: 0; right: 0; top: calc(max(60vh, 400px) - 84px); justify-content: center; margin: 0; }
  .daybar { display: none; }
  .tbtn { min-width: 40px; font-size: .62rem; }
  .tbtn svg:not(.ri) { width: 30px; height: 30px; padding: 6px; }
  .pill-btn { padding: 9px 13px; }
  .pill-btn.round { width: 38px; }
  .resbar { position: static; padding: 12px 16px 0; display: grid; grid-template-columns: 1fr 1fr; }
  .res { min-width: 0; }
  .datachip { display: none !important; }
  .label { font-size: .72rem; padding: 3px 8px; gap: 4px; }
  .label .nm { display: none; }
  .modes, .modes.tiers { grid-template-columns: 1fr; }
  .postcard { display: none !important; }
  .toasts { position: fixed; left: 50%; bottom: max(16px, var(--lift, 0px)); }
}

/* Commander greenhouse beds: click to change the crop */
.seg.beds { margin-top: 6px; background: #eaf5e4; }
.seg.beds button { font-size: .8rem; }
.seg.beds button.on { background: #fff; color: inherit; }

/* ---------- crew creator ---------- */
.crew-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.crew-card {
  display: grid; justify-items: center; gap: 2px; padding: 8px 6px 10px; border-radius: 20px; cursor: pointer;
  background: #fff; border: 2px solid var(--line); font: 800 .95rem var(--head);
}
.crew-card svg:not(.ri) { width: 56px; height: 62px; }
.crew-card span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crew-card.on { border-color: var(--orange); background: #fff6ef; }
.crew-edit { display: grid; grid-template-columns: 150px 1fr; gap: 20px; align-items: center; margin-top: 16px; }
.crew-big { display: grid; place-items: center; background: #fff; border-radius: 24px; border: 2px solid var(--line); padding: 10px; }
.crew-big svg:not(.ri) { width: 120px; height: 132px; }
.crew-fields { display: grid; gap: 10px; }
.field { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px; font: 800 .95rem var(--head); }
.field input {
  font: 700 1.05rem var(--body); padding: 8px 14px; border-radius: 14px; border: 2px solid var(--line); background: #fff; min-width: 0;
}
.field input:focus { border-color: var(--orange); outline: none; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; background: var(--c);
  border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line);
}
.swatch.on { box-shadow: 0 0 0 3px var(--orange); }
.crew-note { margin-right: auto; color: var(--muted); font-size: .85rem; }
@media (max-width: 600px) {
  .crew-pick { grid-template-columns: repeat(2, 1fr); }
  .crew-edit { grid-template-columns: 1fr; }
  .crew-big { display: none; }
}

/* ---------- crew diary ---------- */
.side .tabs:has(> :nth-child(3)) { grid-template-columns: repeat(3, 1fr); }
.diary-crew { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 6px; }
.dchip {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 6px; padding: 6px 8px; text-align: left;
  border-radius: 16px; border: 1.5px solid var(--line); background: #fff; cursor: pointer;
}
.dchip.on { border-color: var(--orange); background: #fff6ef; }
.dchip .dav svg:not(.ri) { width: 34px; height: 37px; display: block; }
.dname { display: grid; line-height: 1.1; min-width: 0; }
.dname b { font: 800 .9rem var(--head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dname small { color: var(--muted); font-size: .7rem; }
.dmood { font-size: 1.3rem; line-height: 1; }
.dmood .ri { width: 1.5rem; height: 1.5rem; vertical-align: middle; }
.diary-list { list-style: none; margin: 0; padding: 0; }
.dentry { display: grid; grid-template-columns: 36px 1fr; gap: 8px; padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: .88rem; }
.dentry .dav svg:not(.ri) { width: 34px; height: 37px; }
.dentry p { margin: 2px 0 0; }
.dhead { display: flex; gap: 8px; align-items: baseline; }
.dhead .t { font: 600 .78rem var(--num); color: var(--orange); white-space: nowrap; }
.dentry.good p { color: #22794a; }
.dentry.bad p { color: #b42d2d; }
.dentry.murmur p { display: inline-block; font-style: italic; background: #f6ebde; padding: 4px 10px; border-radius: 4px 14px 14px 14px; }
.dempty { color: var(--muted); padding: 12px 2px; }
.crew-card small { color: var(--muted); font: 700 .72rem var(--body); white-space: nowrap; }
.jobs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jobs-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.job {
  padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); background: #fff; cursor: pointer;
  font: 800 .85rem var(--body);
}
.job.on { border-color: var(--orange); background: #fff6ef; }

/* ---------- landing sites ---------- */
.site-when { color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.site-day { color: var(--ink); font-weight: 800; }
/* "📅 Change date": a quiet link; the real date input sits invisibly on top so a tap opens the native picker */
.site-date { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; }
.site-date[hidden] { display: none; }
.site-date-pick, .site-date-today { position: relative; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 10px;
  border-radius: 999px; border: 2px solid var(--line); background: #fff; color: var(--orange-dk); font: 800 .8rem var(--body); cursor: pointer; white-space: nowrap; }
.site-date-pick::before { content: "📅"; }
.site-date-pick:hover, .site-date-today:hover { background: var(--orange-soft); }
.site-date-pick[aria-expanded="true"] { background: var(--orange-soft); border-color: var(--orange); }
.site-date { position: relative; }
/* While a new date's Sun data loads the date gently pulses (no "…" that would make the line wrap and jump back) */
.site-day.loading { animation: day-load 1s ease-in-out infinite alternate; }
@keyframes day-load { from { opacity: 1; } to { opacity: .35; } }

/* "Change date" calendar (calendar.js): a little mission-patch card - cream paper, orange stitching, round days */
.cal { position: fixed; z-index: 60; width: 300px;
  max-width: calc(100vw - 32px); padding: 14px 14px 12px; border-radius: 22px; background: var(--cream);
  box-shadow: var(--shadow), 0 0 0 2px var(--line); animation: cal-pop .18s cubic-bezier(.3, .7, .4, 1.4); }
.cal::before { content: ""; position: absolute; inset: 6px; border: 2px dashed var(--stitch); border-radius: 17px; pointer-events: none; }
.cal[hidden] { display: none; }
@keyframes cal-pop { from { opacity: 0; transform: translateY(-6px) scale(.96); } to { opacity: 1; transform: none; } }
.cal-head { position: relative; display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.cal-title { flex: 1; text-align: center; font: 800 1.05rem var(--head); color: var(--ink); }
.cal-nav { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); background: #fff; color: var(--orange-dk);
  font: 800 1rem/1 var(--head); cursor: pointer; display: grid; place-items: center; padding: 0; transition: transform .12s, background .12s; }
.cal-nav:hover:not(:disabled) { background: var(--orange-soft); transform: scale(1.08); }
.cal-nav:disabled { opacity: .3; cursor: default; }
.cal-grid { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; justify-items: center; }
.cal-wd span { font: 800 .72rem var(--body); color: var(--muted); padding: 2px 0 4px; }
.cal-day { position: relative; display: grid; place-items: center; margin: 0; width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; color: var(--ink);
  font: 800 .85rem var(--body); cursor: pointer; padding: 0; transition: transform .12s, background .12s; }
.cal-day:hover:not(:disabled) { background: var(--orange-soft); transform: scale(1.1); }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--orange); color: var(--orange-dk); }
.cal-day.on { background: var(--orange); color: #fff; box-shadow: 0 3px 0 var(--orange-dk); transform: translateY(-1px); }
.cal-day.on:hover { background: var(--orange); }
.cal-day:disabled { color: #d9cfc3; cursor: default; }
.cal-day:focus-visible, .cal-nav:focus-visible, .cal-today:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }
.cal-foot { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px;
  padding-top: 9px; border-top: 2px dotted var(--line); }
.cal-foot small { color: var(--muted); font-size: .72rem; line-height: 1.3; }
.cal-today { flex: none; min-height: 28px; padding: 0 12px; border-radius: 999px; border: 0; background: var(--dark); color: #fff;
  font: 800 .78rem var(--body); cursor: pointer; }
.cal-today:hover { filter: brightness(1.2); }
@media (prefers-reduced-motion: reduce) { .cal, .site-day.loading { animation: none; } .cal-day, .cal-nav { transition: none; } }
.site-date-today[hidden] { display: none; }
.site-body { display: grid; grid-template-columns: minmax(240px, 1fr) 1.2fr; gap: 16px; align-items: start; }
.site-globe { position: relative; aspect-ratio: 1; max-height: 380px; border-radius: 22px; overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #3a2b45 0%, #1d1626 70%); }
.site-globe canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.site-globe svg:not(.ri) { display: block; width: 100%; height: 100%; }
.globe-hint { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; color: #fff; opacity: .75; font-size: .75rem; pointer-events: none; }
.site-side { display: grid; gap: 10px; }
.site-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.site-pill { padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); background: #fff; cursor: pointer; font: 800 .82rem var(--body); }
.site-pill.on { border-color: var(--orange); background: #fff6ef; }
.site-pill.deadly { color: #b42d2d; background: #fdf1f1; }               /* the crew won't make it here now */
.site-pill.deadly:not(.on) { opacity: .6; }
/* the danger colour stays when the site is picked: the orange border alone says "picked" */
.site-pill.harsh, .site-pill.reactor { color: #9a6400; }
.site-pill.harsh.on, .site-pill.reactor.on { background: #fff6e3; }
/* What the pill colours mean (under the globe) */
.site-left { display: grid; gap: 10px; align-content: start; min-width: 0; }
.site-legend { padding: 10px 12px; border-radius: 16px; background: #fff; border: 2px dashed var(--line); }
.site-legend ul { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 6px; }
.site-legend li { display: flex; align-items: center; gap: 8px; font: 800 .8rem var(--body); color: var(--ink); }
.site-legend .sw { flex: none; padding: 2px 10px; cursor: default; font-size: .75rem; opacity: 1; }
.site-legend small { display: block; color: var(--muted); font-size: .72rem; line-height: 1.35; }
/* landing somewhere deadly: the next button stops inviting */
#btn-site-next.danger { background: #fff; color: var(--red); box-shadow: 0 4px 0 var(--line); }
/* Back / Next stay visible at the bottom of the landing-site sheet while the rest scrolls
   (bottom: -24px = the sheet padding, so at the end of the scroll it never covers the site card) */
#ov-site .sheet > .row.end { position: sticky; bottom: calc(-1 * var(--pb)); z-index: 2; margin: 16px calc(-1 * var(--px)) calc(-1 * var(--pb)); padding: 12px var(--px) 18px;
  background: rgba(255, 250, 243, .97); border-radius: 0 0 28px 28px; box-shadow: 0 -10px 14px -12px rgba(40, 34, 90, .25); }
/* Fit the landing-site sheet to the window height: the sheet is a column capped at the viewport,
   and the satellite map (the one stretchy thing) shrinks to fill what's left, so short laptop
   screens get a smaller map instead of a scrollbar. Phones held sideways (~300px tall) can't fit it
   at all — squeezed, the list spilled out past Back / Next — so they scroll instead (see below). */
@media (min-width: 701px) and (min-height: 521px) {
  #ov-site .sheet { display: flex; flex-direction: column; max-height: calc(100dvh - 48px); }
  #ov-site .sheet-head, #ov-site .sheet > .row.end { flex: none; }
  #ov-site .site-body { flex: 1 1 auto; min-height: 0; grid-template-rows: minmax(0, 1fr); }
  /* left column: the globe takes what the legend leaves, and stays round */
  #ov-site .site-left { display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
  #ov-site .site-legend { flex: none; }
  #ov-site .site-globe { flex: 0 1 auto; min-height: 0; max-height: 380px; width: 100%; aspect-ratio: 1; height: auto; }
  #ov-site .site-side { display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
  #ov-site .site-pills { flex: none; }
  #site-list { display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0; }
  #site-list .site { display: flex; flex-direction: column; min-height: 0; }
  #site-list .site > :not(.orbit) { flex: none; }
  #site-list .orbit { display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0; }
  #site-list .orbit > :not(.orbit-frame) { flex: none; }
  #site-list .orbit-frame { flex: 0 1 auto; min-height: 90px; max-height: none; }
}
@media (max-width: 700px) { .site-body { grid-template-columns: 1fr; } .site-globe { max-height: 300px; margin: 0 auto; width: 100%; } }
.mdot { cursor: pointer; }
.mdot circle { fill: #fff; stroke: var(--dark); stroke-width: 2; }
.mdot.on circle { fill: var(--orange); stroke: #fff; }
.mdot .ring { fill: none !important; stroke: #fff !important; stroke-width: 2; opacity: .8; }
.site-list { display: grid; gap: 8px; }
.site {
  display: grid; gap: 6px; text-align: left; padding: 14px 16px; border-radius: 18px;
  background: #fff; border: 2px solid var(--line);
}
.site.on { border-color: var(--orange); background: #fff6ef; }
.site-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.site-head b { font: 800 1.05rem var(--head); }
.site-head small { color: var(--muted); font-weight: 800; }
.site-desc { font-size: .9rem; }
.site-lander { color: var(--muted); font-size: .78rem; }
.site .chip.good { background: #e3f5ea; color: #22794a; }
.site .chip.warn { background: #fff1d6; color: #9a6400; }
.site .chip.bad { background: #fde3e3; color: #b42d2d; }
.site-head .chip.harsh { background: #fff1d6; color: #9a6400; }
.site-head .chip.reactor { background: #ffe1c7; color: #a2400f; }

/* ---------- rover panel, driving, Mastcam photo mode ---------- */
.rover-panel {
  position: fixed; left: calc((100vw - var(--side)) / 2); top: 120px; transform: translateX(-50%); z-index: 40; width: min(460px, calc(100% - 32px));
  background: rgba(255, 250, 243, .97); border-radius: 22px; padding: 16px 18px; box-shadow: 0 14px 40px rgba(40, 34, 90, .28);
  max-height: calc(100dvh - 130px); overflow-y: auto; overscroll-behavior: contain;
}
.rp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rp-head h3 { font-size: 1.1rem; }
.rp-energy { display: grid; gap: 4px; margin: 10px 0 4px; font-size: .82rem; }
.rp-bar { position: relative; height: 10px; border-radius: 99px; background: #eadbcb; overflow: hidden; }
.rp-bar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #f2b632, #3fb46e); border-radius: 99px; }
.rp-bar b { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .6; }
.rp-stats { margin: 4px 0; font-size: .8rem; color: var(--muted); }
.rp-note { margin: 6px 0; padding: 8px 10px; border-radius: 12px; background: #fff1d6; color: #7a5200; font-size: .84rem; }
.rp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.rp-actions .btn { padding: 9px 14px; font-size: .9rem; }
.rp-actions .btn:disabled { opacity: .45; cursor: not-allowed; }
.drive-hint {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 40; display: flex; gap: 10px; align-items: center;
  max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 16px; background: rgba(46, 43, 99, .9); color: #fff; font-size: .9rem;
}
/* hint + bar stack at the bottom of the view (flex column) and the bar wraps to a second row when it doesn't fit:
   one fixed row ran off both sides of a tablet's ~800px view. The viewfinder and camera roll are absolute on top. */
.photo-ui { position: absolute; inset: 0; z-index: 15; pointer-events: none; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: center; gap: 6px; padding: 0 12px 18px; }
.photo-ui.flash { background: rgba(255, 255, 255, .7); }
.vf { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 2px solid rgba(255, 255, 255, .85);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); pointer-events: none; }
.vf-cross { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%);
  background: linear-gradient(#fff, #fff) center/2px 100% no-repeat, linear-gradient(#fff, #fff) center/100% 2px no-repeat; opacity: .7; }
.vf-meta { position: absolute; left: 10px; top: 8px; color: #fff; font: 700 .78rem var(--body); text-shadow: 0 1px 2px #000; }
.photo-bar { position: relative; z-index: 1; display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; justify-content: center; pointer-events: auto; padding: 8px 10px; border-radius: 18px; background: rgba(255, 250, 243, .92); max-width: 100%; }
.photo-bar .btn, .photo-bar .seg button { white-space: nowrap; }
.drive-hint .mini { color: var(--ink); }
.photo-bar .seg button.on { background: var(--dark); color: #fff; }
.ph-hint { position: relative; z-index: 1; order: -1; max-width: 100%; margin: 0; color: #fff; font-size: .8rem; text-align: center; text-shadow: 0 1px 2px #000; }
/* camera roll: left edge, between the logo and the photo bar (top right covered the language/Data/help buttons) */
.album-wrap { position: absolute; left: 12px; top: 120px; bottom: 130px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  pointer-events: none; color: #fff; font-size: .78rem; text-shadow: 0 1px 2px #000; }
/* a flex column, not a grid: grid rows let a %-width image shrink to nothing when the roll is short */
.album { display: flex; flex-direction: column; gap: 6px; min-height: 0; overflow-y: auto; pointer-events: auto; }
.thumb { flex: none; padding: 0; border: 2px solid #fff; border-radius: 8px; overflow: hidden; cursor: pointer; width: 96px; background: #000; }
.thumb img { display: block; width: 100%; }
#pv-img { display: block; width: auto; max-width: 100%; max-height: calc(100dvh - 150px); margin: 0 auto; border-radius: 12px; }
body.photo .labels, body.photo #resbar, body.photo .topbar .toolbar { display: none !important; }
/* the viewfinder's lens / sol / time line takes the logo's place (it was printed on top of it) */
body.photo .topbar .brand { visibility: hidden; }
.photo-bar .ph-crew { min-width: 11.5em; }            /* fixed width: the label changes, the button doesn't jump */
.photo-bar .ph-crew.on { background: #e3f5ea; color: #22794a; box-shadow: 0 4px 0 #a6dfbd; }
.photo-bar .ph-aim { padding-inline: 12px; }
body.photo .toasts, body.driving .toasts { display: none !important; } /* messages wait; they used to cover the controls */
body.photo #world { cursor: grab; }
body.photo #world:active { cursor: grabbing; }
@media (max-width: 900px) { .rover-panel { left: 50%; top: 90px; max-height: calc(100dvh - 100px); } }
.photo-bar .seg button { padding-inline: 10px; }

/* ---------- postcards (rover photo on the front, crew message on the back) ---------- */
.pc-wrap { display: grid; gap: 10px; justify-items: center; animation: pop .25s ease-out; }
.pc { display: block; width: min(760px, calc(100vw - 32px), calc((100dvh - 170px) * 1.5)); aspect-ratio: 3 / 2; padding: 0; border: 0;
  background: none; cursor: pointer; perspective: 1800px; }
.pc-inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.3, .7, .2, 1); }
.pc.flipped .pc-inner { transform: rotateY(180deg); }
.pc-face { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 3% / 4.5%; backface-visibility: hidden;
  background: var(--cream); box-shadow: 0 24px 60px rgba(30, 24, 72, .35); }
.pc-back { transform: rotateY(180deg); }
.pc-hint { margin: 0; color: #fff; font-size: .85rem; text-shadow: 0 1px 3px #000; }
.pc-actions { margin-top: 0; padding: 8px 10px; border-radius: 18px; background: rgba(255, 250, 243, .95); }
.pcs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.pcs-item { display: grid; gap: 6px; padding: 6px 6px 8px; border: 2px solid var(--line); border-radius: 14px; background: #fff;
  cursor: pointer; text-align: left; font: 700 .78rem var(--body); color: var(--ink); transition: transform .15s; }
.pcs-item:hover, .pcs-item:focus-visible { transform: rotate(-1.5deg) translateY(-2px); border-color: var(--orange); }
.pcs-item img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 9px; }
#postcard-view { z-index: 55; }   /* above the collection it was opened from */

/* Commander fine tuning: Life support cabin and exercise, Science lab benches */
.state-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.state-row .state { flex: 1; }
.tune-btn { padding: 4px 11px; font-size: .74rem; margin-top: 6px; }
.sys.tuning .tune-btn { background: var(--dark); border-color: var(--dark); color: #fff; }
.tune { display: none; margin-top: 10px; padding: 12px; border-radius: 16px; background: #fff; border: 1.5px solid var(--line); gap: 10px; }
.sys.tuning .tune { display: grid; }
.trow { display: grid; grid-template-columns: 74px 1fr; gap: 8px; align-items: center; font-weight: 800; font-size: .8rem; }
.tstat { margin: 0; font-size: .74rem; color: var(--muted); }
.tstat.warn { color: var(--red); font-weight: 600; }
.bench { border-radius: 14px; background: #f8f1e8; padding: 9px 10px; display: grid; gap: 6px; }
.bench.stalled { opacity: .65; }
.bhead { display: flex; gap: 8px; align-items: baseline; font-size: .8rem; }
.bhead .who { color: var(--muted); font-size: .74rem; }
.bhead .brate { margin-left: auto; font-weight: 800; color: var(--green); font-size: .74rem; }
.bench.stalled .brate { color: var(--red); }
.seg.exps button { font-size: .95rem; padding: 5px 2px; }
.bbar { height: 5px; border-radius: 9px; background: #eadbc9; overflow: hidden; }
.bbar i { display: block; height: 100%; width: 0; background: var(--orange); transition: width .25s; }
.bname { font-size: .74rem; color: var(--muted); }

/* ---------- opening cinematic (intro.js) ---------- */
html.intro-boot, html.intro-boot body { background: #000; }
html.intro-boot::after { content: ""; position: fixed; inset: 0; z-index: 1000; background: #000; }
#ov-intro.active { display: block; padding: 0; pointer-events: auto; z-index: 45; }
body.cinema .postcard, body.cinema .toasts, body.cinema .labels, body.cinema .what-pop { display: none !important; }
.topbar { transition: opacity .8s ease; }
body.cinema .topbar { opacity: 0; pointer-events: none; }
body.cinema .topbar > * { pointer-events: none; }
#ov-intro .bars i { position: absolute; left: 0; right: 0; height: 10vh; background: #0d0b12; transition: transform 1.2s cubic-bezier(.6, 0, .3, 1); }
#ov-intro.leaving .bars i:first-child { transform: translateY(-100%); }
#ov-intro.leaving .bars i:last-child { transform: translateY(100%); }
#ov-intro.leaving .intro-skip { opacity: 0; transition: opacity .6s; }
#ov-intro .bars i:first-child { top: 0; }
#ov-intro .bars i:last-child { bottom: 0; }
.intro-black { position: absolute; inset: 0; background: #000; opacity: 0; transition: opacity 1.6s ease; pointer-events: none; }
.intro-black.on { opacity: 1; transition: none; }
.intro-title { position: absolute; left: 50%; top: 24vh; transform: translate(-50%, 12px); text-align: center; color: #fff; opacity: 0;
  transition: opacity .9s ease, transform 1.2s ease; pointer-events: none; }
.intro-title.on { opacity: 1; transform: translate(-50%, 0); }
.intro-logo { font: 800 clamp(3.2rem, 10vw, 7rem)/.8 var(--head); letter-spacing: .02em; color: #fff; text-shadow: 0 0 40px rgba(234, 106, 51, .75), 0 4px 0 var(--orange-dk); }
.intro-sub { font: 800 clamp(1rem, 2.4vw, 1.35rem) var(--head); margin: 14px 0 12px; text-shadow: 0 2px 12px rgba(0, 0, 0, .6); }
.intro-badge { display: inline-block; padding: 5px 14px; border-radius: 999px; background: var(--dark); color: #ffcf8a; font-size: .78rem; font-weight: 800; letter-spacing: .05em; }
#ov-intro .intro-badge { border: 1.5px solid rgba(255, 207, 138, .5); background: rgba(13, 11, 18, .6); }
.intro-cap { position: absolute; left: 50%; bottom: calc(10vh + 20px); transform: translate(-50%, 10px); width: min(760px, calc(100vw - 32px)); text-align: center;
  color: #fff; opacity: 0; pointer-events: none; text-shadow: 0 2px 14px rgba(0, 0, 0, .75); }
.intro-cap.on { opacity: 1; transform: translate(-50%, 0); transition: opacity .6s ease, transform .6s ease; }
.intro-cap b { display: block; font: 800 clamp(1.4rem, 3.6vw, 2.2rem)/1.1 var(--head); }
.intro-cap span { display: block; margin-top: 6px; font-size: clamp(.9rem, 1.8vw, 1.05rem); opacity: .9; }
.intro-skip { position: absolute; right: 18px; top: calc(5vh - 18px); border: 1.5px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .1); color: #fff;
  border-radius: 999px; padding: 8px 16px; font-weight: 800; cursor: pointer; }
.intro-skip:hover { background: rgba(255, 255, 255, .22); }
/* language picker next to Skip (built in main.js); both leave with the letterbox */
.intro-corner { position: absolute; right: 18px; top: calc(5vh - 18px); display: flex; gap: 8px; align-items: center; }
.intro-corner .intro-skip { position: static; }
.intro-lang { --chev: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'/></svg>");
  width: 78px; border: 1.5px solid rgba(255, 255, 255, .35); color: #fff; border-radius: 999px; padding: 8px 0 8px 14px; background: rgba(255, 255, 255, .1); cursor: pointer; }
.intro-lang::after { right: 11px; width: 9px; }
.intro-lang:hover, .intro-lang[aria-expanded="true"] { background: rgba(255, 255, 255, .22); }
body:has(#ov-intro.leaving) #intro-lang-menu { display: none; }
#ov-intro.leaving .intro-lang { opacity: 0; transition: opacity .6s; pointer-events: none; }

/* ---------- mission briefing ---------- */
#ov-brief.active { place-items: center; background: rgba(42, 38, 86, .35); pointer-events: auto; }
/* language, Data and ? stay clickable above the briefing's dimmed background (the rest of the top bar stays dimmed) */
body:has(#ov-brief.active) .topbar .corner { position: relative; z-index: 31; }
#ov-brief.enter { animation: briefFade .9s ease both; }
#ov-brief.enter .sheet { animation: briefRise .9s cubic-bezier(.2, .8, .2, 1) .15s both; }
@keyframes briefFade { from { background: rgba(42, 38, 86, 0); } }
@keyframes briefRise { from { opacity: 0; transform: translateY(40px) scale(.97); } }
.sheet.brief { display: flex; flex-direction: column; max-height: calc(100vh - 36px); max-height: calc(100dvh - 36px); padding: 0; overflow: hidden; margin: 0; }
.brief-body { overflow-y: auto; padding: 24px 26px 8px; }
.brief h2 { font-size: 1.7rem; margin: 12px 0 10px; }
.brief-lead { font-size: 1.02rem; margin: 0 0 16px; }
.brief-nav { margin: 0; padding: 12px 26px 18px; border-top: 1px solid var(--line); }
.brief-nav .dots { margin-right: auto; display: flex; gap: 6px; }
.dots button { width: 10px; height: 10px; padding: 0; border: 0; border-radius: 9px; background: var(--line); cursor: pointer; transition: width .2s; }
.dots button.on { width: 26px; background: var(--orange); }
.brief-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.brief-tiles div, .trade { background: #fff; border: 2px solid var(--line); border-radius: 18px; }
.brief-tiles div { display: grid; gap: 4px; padding: 12px 14px; font-weight: 800; }
.brief-tiles span { font-size: 1.6rem; }
.trades { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trade { display: grid; grid-template-columns: 38px 1fr; gap: 5px 8px; padding: 12px 14px; }
.trade .ti { grid-row: span 3; font-size: 1.6rem; line-height: 1.2; }
.trade b { font: 800 1.02rem var(--head); }
.trade .gain, .trade .cost { font-size: .86rem; }
.trade i { font-style: normal; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 999px; margin-right: 6px; color: #fff; }
.trade .gain i { background: var(--green); }
.trade .cost i { background: var(--red); }
@media (max-width: 700px) {
  .brief-tiles, .trades { grid-template-columns: 1fr; }
    .brief-nav #brief-skip { order: 5; width: 100%; }
}

/* ---------- training mission coach (tutorial.js) ---------- */
.tut { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.tut.centre:not(.float)::before { content: ""; position: fixed; inset: 0; background: rgba(26, 22, 62, .42); }
.tut-ring { position: fixed; border-radius: 16px; box-shadow: 0 0 0 3px var(--orange), 0 0 0 200vmax rgba(26, 22, 62, .38); transition: left .25s, top .25s, width .25s, height .25s; }
.tut-ring::after { content: ""; position: absolute; inset: -4px; border: 3px solid var(--orange); border-radius: 20px; animation: tutPulse 1.3s ease-out infinite; }
@keyframes tutPulse { from { opacity: .9; transform: scale(1); } to { opacity: 0; transform: scale(1.1); } }
.tut-bubble { position: fixed; left: 0; top: 0; width: min(330px, calc(100vw - 20px)); pointer-events: auto; background: var(--cream); border: 2px solid var(--orange);
  border-radius: 22px; padding: 14px 18px 14px; box-shadow: 0 18px 50px rgba(30, 24, 72, .35); max-height: calc(100dvh - 20px); overflow-y: auto; }
.tut-bubble.pop { animation: pop .22s ease-out; }
.tut-who { font: 800 .82rem var(--head); color: var(--orange-dk); letter-spacing: .04em; text-transform: uppercase; }
.tut.centre:not(.float) .tut-who { font-size: 1.3rem; text-transform: none; letter-spacing: 0; }
.tut-text { margin: 4px 0 10px; font: 700 1.2rem/1.35 var(--head); }
.tut-btns { display: flex; justify-content: flex-end; gap: 8px; }
.tut-btns .btn { padding: 9px 16px; }

/* Debrief: mission replay timeline (replay-ui.js) */
.replay h3 { margin-bottom: 6px; }
.rp-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.rp-legend span { display: inline-flex; align-items: center; gap: 5px; }
.rp-legend i { width: 16px; height: 4px; border-radius: 2px; display: inline-block; }
.rp-legend i.band { height: 12px; width: 12px; border-radius: 3px; }
.rp-legend i.band.real { background: rgba(242, 182, 50, .4); }
.rp-band.real { fill: rgba(242, 182, 50, .4); }
.rp-legend i.band.sim { background: repeating-linear-gradient(45deg, rgba(155, 136, 118, .25) 0 3px, transparent 3px 6px); }
.rp-band.sim { fill: rgba(155, 136, 118, .16); }
.rp-legend i.dark, .rp-dark { background: var(--red); fill: var(--red); }
.rp-wrap { overflow-x: auto; background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 6px 6px 2px; }
.rp-svg { display: block; width: 100%; min-width: 560px; height: auto; font-family: var(--body); }
.rp-grid { stroke: var(--line); stroke-width: 1; }
.rp-ax { font-size: 11px; font-weight: 700; fill: var(--muted); }
.rp-line { fill: none; stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.rp-col { fill: transparent; }
.rp-col:hover { fill: rgba(42, 38, 86, .06); }
.rp-limit { stroke: var(--red); stroke-width: 1.2; stroke-dasharray: 5 4; }
.rp-limit-t { font-size: 10.5px; font-weight: 800; fill: var(--red); }
.rp-end { stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 3 3; }
.rp-end-t { font-size: 11px; font-weight: 800; fill: var(--ink); }
.rp-guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; pointer-events: none; }
.rp-dot { stroke: #fff; stroke-width: 1.3; pointer-events: none; }
.rp-pin { cursor: help; outline: none; }
.rp-pin circle { fill: #fff; stroke: var(--line); stroke-width: 1.5; }
.rp-pin:hover circle, .rp-pin:focus circle { stroke: var(--orange); stroke-width: 2.2; }
.rp-pin text { font-size: 11.5px; text-anchor: middle; }
.rp-pin text.rp-count { font-size: 9px; font-weight: 900; fill: var(--orange-dk); text-anchor: start; }
.rp-story { display: grid; gap: 6px; margin-top: 8px; }
.rp-story p { margin: 0; padding: 8px 12px; background: var(--orange-soft); border-radius: 14px; font-size: .92rem; font-weight: 700; color: var(--ink); }
.rp-story a { font-weight: 800; white-space: nowrap; }

/* Mission replay: Simple / Detailed switch and the simple view */
.rp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.rp-head h3 { margin-bottom: 6px; }
.rp-switch { display: inline-flex; background: var(--paper); border: 1.5px solid var(--line); border-radius: 999px; padding: 3px; }
.rp-switch button { display: inline-flex; align-items: center; border: 0; background: none; font: 800 .82rem var(--body); color: var(--muted); padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.rp-switch button.on { background: var(--orange); color: #fff; }
.rp-days { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 4px; }
.rp-day { position: relative; aspect-ratio: 1; min-width: 0; overflow: hidden; border-radius: 10px; background: #fff; border: 1.5px solid var(--line);
  display: grid; place-items: center; line-height: 1; }
.rp-day b { position: absolute; top: 6%; left: 9%; font: 800 .62rem var(--body); color: var(--muted); }
.rp-day .ri.main { width: 54%; height: 54%; margin-top: 14%; }
.rp-day .ri.badge { position: absolute; right: 5%; bottom: 5%; width: 34%; height: 34%; }
.ri { display: inline-block; width: 1.25em; height: 1.25em; flex: none; vertical-align: -.28em; }
.rp-legend .ri, .rp-key .ri, .rp-meter-t .ri, .rp-switch .ri { margin-right: 3px; }
.rp-key .ri + .ri { margin-left: -2px; }
.rp-day.storm { background: rgba(242, 182, 50, calc(.25 + .55 * var(--p))); border-color: rgba(234, 106, 51, calc(.3 + .7 * var(--p))); }
.rp-day.storm.sim { background: repeating-linear-gradient(45deg, rgba(155, 136, 118, .22) 0 4px, transparent 4px 8px); border-color: var(--line); }
.rp-day.dark:not(.storm) { background: #e8eefc; }
.rp-day.off { opacity: .35; border-style: dashed; color: var(--muted); }
.rp-key { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; font-weight: 700; color: var(--muted); margin: 6px 0 10px; }
.rp-moments { display: grid; gap: 8px; }
.rp-moment { background: var(--orange-soft); border-radius: 16px; padding: 8px 10px 10px; }
.rp-when { font: 800 .8rem var(--body); color: var(--orange-dk); margin: 0 0 6px 4px; }
.rp-panels { display: flex; align-items: stretch; gap: 6px; }
.rp-panel { flex: 1; min-width: 0; background: #fff; border-radius: 12px; padding: 8px 8px 10px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .86rem; font-weight: 700; color: var(--ink); line-height: 1.25; }
.rp-panel .ri.ico { width: 2.6rem; height: 2.6rem; }
.rp-panel.tone-good { box-shadow: inset 0 -4px 0 var(--green); }
.rp-panel.tone-bad { box-shadow: inset 0 -4px 0 var(--red); }
.rp-arrow { align-self: center; color: var(--orange); display: grid; }
.rp-arrow svg { width: 18px; height: 18px; }
.rp-src { display: inline-block; margin: 6px 0 0 4px; font-size: .8rem; font-weight: 800; }
.rp-meter { margin-top: 10px; }
.rp-meter-t { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .86rem; margin-bottom: 5px; }
.rp-meter-t b { color: var(--purple); }
.rp-meter-t b.good { color: var(--green); }
.rp-meter-t .lim { color: var(--red); font-weight: 800; margin-left: auto; }
.rp-meter-bar { position: relative; display: flex; height: 18px; background: #fff; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.rp-meter-bar i.got { background: var(--purple); }
.rp-meter-bar i.stop { background: repeating-linear-gradient(45deg, var(--green) 0 5px, #8fd6aa 5px 10px); }
.rp-meter-bar s { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--red); }
@media (max-width: 520px) {
  .rp-panels { flex-direction: column; }
  .rp-arrow { transform: rotate(90deg); }
  .rp-panel { flex-direction: row; text-align: left; }
  .rp-panel .ri.ico { width: 2rem; height: 2rem; }
}
@media (max-width: 520px) {
  .rp-days { grid-template-columns: repeat(10, 1fr); gap: 3px; }
  .rp-day { border-radius: 8px; }
  .rp-day b { top: 3%; left: 7%; font-size: .52rem; }
}

/* Our icons (icons.js) in the log feed and toasts */
.ri.log-ico { width: 1.15em; height: 1.15em; vertical-align: -.22em; margin-right: 2px; }
.toast .ri.log-ico { margin-right: 6px; }
#card-icon .ri.card-ico { width: 68%; height: 68%; }
/* emoji swapped for our icons anywhere on the page (emoji-ui.js) */
.ri.emo { width: 1.2em; height: 1.2em; vertical-align: -.24em; }

/* ---------- scrollbars: a slim rounded thumb drawn inside the box (the track is see-through and keeps
   clear of the rounded corners), instead of a grey bar with arrows stuck to the outside edge ---------- */
::-webkit-scrollbar { width: 14px; height: 14px; background: transparent; }
::-webkit-scrollbar-track { background: transparent; margin: 18px 0; }
::-webkit-scrollbar-thumb { background: rgba(120, 72, 40, .3); border: 4px solid transparent; background-clip: padding-box; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(120, 72, 40, .5); }
::-webkit-scrollbar-button, ::-webkit-scrollbar-corner { display: none; background: transparent; }
#dev::-webkit-scrollbar-thumb { background-color: rgba(255, 255, 255, .28); }       /* dark dev panel */
@supports not selector(::-webkit-scrollbar) {                                         /* Firefox */
  * { scrollbar-width: thin; scrollbar-color: rgba(120, 72, 40, .35) transparent; }
}

/* ---------- Mars-dusk signature details ---------- */
/* Panels read like embroidered mission patches: a stitched seam just inside the edge. */
.brand, .sheet, .card, .rover-panel { outline: 1.5px dashed var(--stitch); outline-offset: -7px; }
.sheet.brief { outline-offset: -8px; }
/* Logo lettering sits on an indigo drop, like a patch's raised thread. */
.logo { text-shadow: 0 2px 0 var(--dark); }
/* Mission-control logbook: faint dot grid on the side panel. */
.side { background: var(--cream) radial-gradient(rgba(46, 43, 99, .08) 1px, transparent 1.3px) 0 0 / 18px 18px; }

/* Tablets held sideways and small laptops (3D view ~600–920px wide): logo + time bar + speed bar didn't fit
   on one row, so the time and speed bars wrapped under the logo, right onto the building labels. Slim them so
   they stay on the logo's row. The language / Data / ? buttons and the data chip (just LIVE / SAVED, the
   DONKI dates move to its tooltip) share one short row on the right below it — two rows, not four.
   The resource tiles slim down so all six stay on one row at the bottom. */
@media (min-width: 901px) and (max-width: 1300px) {
  .topbar { top: 12px; left: 12px; right: 12px; gap: 8px; }
  .brand-name { display: none; }                 /* the sol counter stays */
  .brand { padding: 8px 12px 8px 10px; gap: 8px; border-radius: 20px; }
  .logo { font-size: 1.6rem; }
  .sol-read { font-size: .95rem; }
  .toolbar { gap: 8px; flex-wrap: nowrap; margin: 0; }
  .pill { padding: 4px 8px; }
  .daybar .tbtn:not(.on) { display: none; }      /* just the current part of the day, beside the clock */
  .clock { font-size: .92rem; min-width: 0; padding: 0 4px; }
  .tbtn { min-width: 38px; padding: 2px; font-size: .62rem; }
  .tbtn svg:not(.ri) { width: 28px; height: 28px; padding: 6px; }
  .corner { flex-direction: row; align-items: center; gap: 6px; }
  .corner-btns { gap: 6px; }
  .pill-btn { padding: 8px 12px; font-size: .88rem; border-radius: 14px; }
  .pill-btn.lang { width: 72px; padding-right: 0; }
  .pill-btn.lang::after { right: 10px; }
  .pill-btn.round { width: 36px; padding: 8px 0; }
  .datachip { order: -1; padding: 4px 9px; font-size: .7rem; cursor: help; }
  .datachip .dc-src { display: none; }
  .resbar { left: 12px; bottom: 12px; right: calc(var(--side) + 12px); flex-wrap: nowrap; gap: 6px; }
  .res { flex: 1 1 auto; min-width: 0; gap: 6px; padding: 5px 8px 5px 5px; border-radius: 16px; }
  .res > div:last-child { min-width: 0; flex: 1; }
  .res .ic { width: 28px; height: 28px; }
  .res .ic svg:not(.ri) { width: 16px; height: 16px; }
  .res .v { font-size: .9rem; }
  .res .v small { font-size: .64rem; }
}
/* narrower still: the speed buttons drop their words (pause / play / fast-forward icons, aria-label keeps the name)
   so logo + clock + speed still fit one row in every language */
@media (min-width: 901px) and (max-width: 1100px) {
  :root { --side: 340px; }
  .speedbar .tl { display: none; }
  .speedbar .tbtn { min-width: 30px; }
  .logo { font-size: 1.45rem; }
}

/* ---------- phones & short screens ----------
   Every sheet and card is capped at the screen height and scrolls inside (rules above). Here the
   Back / Next / Launch row sticks to the bottom of that scroll, and phones get tighter padding
   so less needs scrolling at all. */
@media (max-width: 900px), (max-height: 760px) {
  .sheet > .row.end, .card > .row.end {
    position: sticky; bottom: calc(-1 * var(--pb)); z-index: 2; margin: 16px calc(-1 * var(--px)) calc(-1 * var(--pb));
    padding: 12px var(--px) var(--pb); background: inherit; box-shadow: 0 -10px 14px -12px rgba(40, 34, 90, .25);
  }
}
@media (max-width: 600px) {
  .overlay { padding: 10px; }
  .modal { padding: 10px; }
  .sheet { --px: 16px; --pt: 18px; --pb: 14px; border-radius: 22px; margin-bottom: 0; max-height: calc(100dvh - 20px); }
  .card { --px: 16px; --pt: 18px; --pb: 14px; border-radius: 22px; max-height: calc(100dvh - 20px); }
  .sheet.scroll, .card.scroll, .sheet.brief { max-height: calc(100dvh - 20px); }
  .sheet h2 { font-size: 1.35rem; margin-bottom: 10px; }
  .sheet h3 { margin: 16px 0 8px; }
  .sheet-head { margin-bottom: 10px; }
  .card h2 { font-size: 1.25rem; }
  .card-icon { width: 44px; height: 44px; }
  .row { gap: 8px; margin-top: 12px; }
  .btn { padding: 11px 20px; font-size: 1rem; }
  .brief-body { padding: 18px 16px 8px; }
  .brief-nav { padding: 10px 16px 14px; }
  /* mission picker: chips back on one row so the three stacked cards stay short */
  .modes { gap: 8px; }
  .mode { padding: 10px 14px; gap: 6px; }
  .modes.tiers .chips { flex-direction: row; }
  /* crew: keep all four astronauts on one row, just smaller */
  .crew-pick { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .crew-card { padding: 6px 4px 8px; font-size: .8rem; border-radius: 16px; }
  .crew-card svg:not(.ri) { width: 40px; height: 44px; }
  .crew-edit { margin-top: 10px; }
  .crew-fields { gap: 8px; }
  .field { grid-template-columns: 52px 1fr; gap: 8px; }
  .swatch { width: 30px; height: 30px; }
  .crew-note { flex-basis: 100%; }
  /* landing site: smaller globe so the site list shows without much scrolling */
  .site-globe { max-height: min(300px, 40dvh); aspect-ratio: auto; height: min(300px, 40dvh, calc(100vw - 52px)); }
  /* rocket cargo: two per row */
  .cargo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .cargo { padding: 10px; border-radius: 16px; }
  .cargo .ci { width: 36px; height: 36px; font-size: 1.15rem; }
  /* side panel: systems list a little denser */
  .side { padding: 16px 12px 24px; }
  .side h1 { font-size: 1.5rem; margin-bottom: 12px; }
  .sys { grid-template-columns: 44px 1fr; padding: 12px 4px; }
  .sys .n { font-size: 1.7rem; }
}

/* Phones turned sideways (and other very short windows): stacking the panel under the 3D view left
   no room to scroll to it, so put Mission control back on the right as a narrower scrolling column,
   with the resource gauges pinned at its top and the speed buttons along the bottom of the view. */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --side: min(340px, 42vw); }
  body { overflow: hidden; }
  .app { display: grid; grid-template-columns: 1fr var(--side); grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
  .stage, body.menu .stage { grid-column: 1; grid-row: 1 / 3; height: auto; }
  .resbar { position: static; grid-column: 2; grid-row: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 10px;
    background: var(--cream); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .res { min-width: 0; padding: 4px 10px 4px 4px; gap: 7px; border-radius: 14px; }
  .res .ic { width: 26px; height: 26px; }
  .res .ic svg:not(.ri) { width: 15px; height: 15px; }
  .res .v { font-size: .92rem; }
  .side { grid-column: 2; grid-row: 2; min-height: 0; overflow-y: auto; border-top: 0; border-left: 1px solid var(--line); padding: 10px 12px 20px; }
  .side h1 { display: none; }
  .topbar { top: 8px; left: 8px; right: 8px; }
  .brand { padding: 6px 10px; gap: 8px; border-radius: 16px; }
  .logo { font-size: 1.2rem; }
  .brand-name, .daybar, .datachip, .postcard { display: none !important; }
  .toolbar { position: fixed; left: 0; right: var(--side); top: auto; bottom: 8px; justify-content: center; margin: 0; }
  body.menu .toolbar { right: 0; }
  .tbtn { min-width: 40px; font-size: .62rem; }
  .tbtn svg:not(.ri) { width: 28px; height: 28px; padding: 6px; }
  .pill-btn { padding: 8px 12px; }
  .pill-btn.round { width: 36px; }
  .label { font-size: .72rem; padding: 3px 8px; gap: 4px; }
  .label .nm { display: none; }
  .alarmbar { left: calc((100vw - var(--side)) / 2); top: 56px; }
  .toasts { left: calc((100vw - var(--side)) / 2); bottom: max(70px, var(--lift, 0px)); }
  .rover-panel { left: calc((100vw - var(--side)) / 2); top: 56px; max-height: calc(100dvh - 66px); }
  /* wide but short: the three mission cards fit side by side again */
  .modes.tiers { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .overlay { padding: 8px; }
  .sheet { --pt: 16px; --pb: 12px; margin-bottom: 0; max-height: calc(100dvh - 16px); }
  .card { --pt: 16px; --pb: 12px; max-height: calc(100dvh - 16px); }
  .sheet.scroll, .card.scroll, .sheet.brief { max-height: calc(100dvh - 16px); }
  .sheet h2 { font-size: 1.3rem; margin-bottom: 8px; }
}

/* Photo mode on phones: the one-line camera bar ran off the screen. Let it wrap into rows
   (lenses on top, then the buttons), move the hint up under the top bar, shrink the camera roll. */
@media (max-width: 600px), (orientation: landscape) and (max-height: 520px) {
  .photo-ui { padding: 8px; }
  .photo-bar { gap: 6px; width: 100%; max-width: 520px; padding: 6px; border-radius: 16px; }
  .photo-bar .seg { flex: 1 1 100%; }
  .photo-bar .seg button { padding: 6px 4px; }
  .photo-bar .btn { flex: 1 1 auto; padding: 9px 12px; font-size: .9rem; box-shadow: 0 3px 0 var(--line); }
  .photo-bar .btn.primary { box-shadow: 0 3px 0 var(--orange-dk); }
  .photo-bar .ph-crew { min-width: 0; }
  .ph-hint { max-width: 520px; }
  .album-wrap { left: 8px; bottom: 150px; }
  .thumb { width: 56px; }
}
/* phone held upright: photo mode gets the whole screen (the systems list below isn't needed while aiming) */
@media (max-width: 900px) and (orientation: portrait) {
  body.photo .stage { height: 100vh; height: 100dvh; }
}
/* phone sideways: lenses share a row with buttons (two rows, not three) */
@media (orientation: landscape) and (max-height: 520px) {
  .photo-bar .seg { flex: 1 1 auto; }
  .photo-bar .btn { padding: 8px 10px; font-size: .85rem; }
  /* photo preview: the whole picture plus its Postcard / Save / Close row on one screen */
  .modal { padding: 8px; }
  #pv-img { max-height: calc(100dvh - 116px); }
  /* postcard: card on the left, hint and buttons stacked beside it (below it, the card shrank to a stamp) */
  .pc-wrap { grid-template-columns: auto auto; align-items: center; column-gap: 14px; }
  .pc { grid-row: 1 / 3; width: min(760px, calc(100vw - 200px), calc((100dvh - 32px) * 1.5)); }
  .pc-hint { align-self: end; max-width: 160px; }
  .pc-actions { align-self: start; flex-direction: column; align-items: stretch; gap: 6px; margin: 0; padding: 6px; }
  .pc-actions .btn { padding: 8px 14px; font-size: .9rem; }
  /* landing site: the sheet scrolls; small map on the left stays in view while the site list scrolls past */
  .site-body { grid-template-columns: minmax(180px, 36%) minmax(0, 1fr); gap: 12px; }
  .site-left { position: sticky; top: 0; z-index: 1; align-self: start; }
  .site-globe { width: 100%; margin: 0; aspect-ratio: auto; max-height: none; height: min(300px, calc(100dvh - 130px)); }
}

/* Phones: alarms and toasts. Centred with left:50% + translate, a fixed box only gets half the
   screen to grow into, so on a 375px phone the alarm became a tall narrow column and a two-line
   toast a circle. Span the screen edge to edge instead and keep both compact. */
@media (max-width: 600px) {
  .alarmbar, body.menu .alarmbar { left: 8px; right: 8px; top: 62px; transform: none; max-width: none; justify-content: center; }
  .alarm-main { flex: 1; min-width: 0; gap: 10px; padding: 8px 14px 8px 10px; border-radius: 18px; }
  .alarm-main b { font-size: .95rem; }
  .alarm-main small { font-size: .78rem; margin-top: 1px; }
  .alarm-ic { font-size: 1.4rem; }
  .alarm-mute { width: 40px; border-radius: 18px; }
  .toasts, body.menu .toasts { left: 8px; right: 8px; transform: none; }
  .toast { max-width: 100%; padding: 6px 12px; border-radius: 16px; font-size: .8rem; line-height: 1.3; }
  /* top bar: logo and the language / Data / ? buttons share one row (they wrapped onto the 3D labels) */
  .topbar { flex-wrap: nowrap; gap: 6px; }
  .brand { padding: 6px 10px; }
  .logo { font-size: 1.2rem; }
  .sol-read { font-size: .9rem; }
  .corner-btns { gap: 6px; }
  .pill-btn { padding: 8px 10px; font-size: .85rem; border-radius: 14px; }
  .pill-btn.lang { width: 64px; padding-right: 0; }
  .pill-btn.lang::after { right: 9px; width: 9px; }
  .pill-btn.round { width: 34px; }
}

/* Phones, 3D view stacked above the panel: vertical swipes on the 3D view scroll the page (or you
   couldn't get back up), sideways drags still turn the camera, pinch still zooms. !important beats
   the touch-action OrbitControls writes inline. Aiming a photo or a drive needs every direction. */
@media (max-width: 900px) { #world { touch-action: pan-y !important; } }
@media (orientation: landscape) and (max-height: 520px) { #world { touch-action: none !important; } }
body.photo #world, body.driving #world { touch-action: none !important; }
