:root {
  --bg: #04060b;
  --glass: rgba(14, 18, 28, 0.62);
  --glass-strong: rgba(14, 18, 28, 0.82);
  --line: rgba(255, 255, 255, 0.11);
  --text: #eef2f8;
  --dim: #9aa6b8;
  --sun: #ffc65a;
  --earth: #5db4ff;
  --accent: #ffc65a;
  --good: #58e0a0;
  --bad: #ff6b6b;
  --r: 14px;
  --tbh: 72px;
  --above: calc(var(--tbh) + 28px);
  font-family: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
body { font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
button, select, input { font: inherit; color: inherit; }

.glass, #layers, #panel, #timebar, #legend, #actions button, #aboutBtn, #scaleBtn, #hover, #hint {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

/* Intro */
#intro { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(ellipse at center, #0a0f1c 0%, #020308 70%); transition: opacity 1.4s ease, visibility 1.4s; }
#intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-inner { text-align: center; padding: 24px; max-width: 640px; }
.intro-mark { font-size: clamp(34px, 7vw, 68px); font-weight: 700; letter-spacing: 0.34em; margin-right: -0.34em; background: linear-gradient(90deg, #fff 0%, #fff 46%, #2b3242 54%, #2b3242 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.intro-sub { margin-top: 18px; color: var(--dim); font-size: clamp(14px, 2.2vw, 18px); line-height: 1.5; }
.intro-load { margin-top: 30px; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sun); }

/* Brand */
#brand { position: fixed; top: 18px; left: 22px; z-index: 5; pointer-events: none; }
#brand .mark { font-weight: 700; letter-spacing: 0.3em; font-size: 15px; }
#brand .tag { color: var(--dim); font-size: 11.5px; margin-top: 4px; letter-spacing: 0.04em; }

/* Layer tabs */
#layers { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; gap: 2px; padding: 4px; border-radius: 999px; }
#layers button { border: 0; background: transparent; padding: 8px 15px; border-radius: 999px; cursor: pointer; color: var(--dim); font-size: 13px; white-space: nowrap; }
#layers button:hover { color: var(--text); }
#layers button.on { background: rgba(255, 255, 255, 0.92); color: #0a0d14; font-weight: 600; }

/* Legend */
#legend { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 5; padding: 9px 14px 10px; border-radius: var(--r); width: min(340px, 80vw); }
.legend-title { font-size: 12px; color: var(--dim); margin-bottom: 6px; text-align: center; }
.legend-bar { height: 8px; border-radius: 4px; }
.legend-ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); margin-top: 4px; }
.legend-progress { font-size: 11px; color: var(--sun); text-align: center; min-height: 14px; }

/* Actions */
#actions { position: fixed; left: 22px; bottom: var(--above); z-index: 6; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
#actions button { border-radius: 999px; padding: 9px 16px; cursor: pointer; font-size: 13px; transition: transform .15s, background .2s; }
#actions button:hover { transform: translateY(-1px); background: var(--glass-strong); }
button.primary { background: linear-gradient(135deg, #ffd27a, #ffab3d) !important; color: #1b1203 !important; border: 0 !important; font-weight: 650; box-shadow: 0 6px 24px rgba(255, 180, 70, 0.28); }

/* Site panel */
#panel { position: fixed; top: 76px; right: 18px; bottom: var(--above); width: 360px; z-index: 6; border-radius: 18px; padding: 14px; overflow-y: auto; scrollbar-width: thin; }
#pinTabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; padding-right: 36px; min-height: 34px; }
.pin-tab { display: flex; align-items: center; gap: 7px; padding: 6px 10px 6px 6px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 12.5px; }
.pin-tab.on { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.3); }
.pin-dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #0a0d14; }
.pin-tab .x { color: var(--dim); margin-left: 2px; padding: 0 2px; }
.pin-tab .x:hover { color: var(--bad); }

.site-head { display: flex; gap: 14px; align-items: center; }
.score-ring { flex: none; width: 82px; height: 82px; position: relative; }
.score-ring svg { width: 82px; height: 82px; transform: rotate(-90deg); }
.score-ring .num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 25px; font-weight: 700; }
.score-ring .num small { display: block; font-size: 9.5px; color: var(--dim); font-weight: 500; letter-spacing: .1em; margin-top: -4px; }
.site-name { font-size: 17px; font-weight: 650; line-height: 1.2; }
.site-coord { color: var(--dim); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.verdict { margin-top: 6px; font-size: 12.5px; line-height: 1.4; }
.score-key { margin-top: 5px; font-size: 11px; color: var(--dim); line-height: 1.4; }
.metrics.one .metric .v { font-size: 16px; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.metric { border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; background: rgba(255, 255, 255, 0.03); }
.metric .k { font-size: 11px; color: var(--dim); }
.metric .v { font-size: 19px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric .s { font-size: 11px; color: var(--dim); margin-top: 1px; }
.metric.sun .v { color: var(--sun); }
.metric.earth .v { color: var(--earth); }

.block-title { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); margin: 16px 0 6px; display: flex; justify-content: space-between; }
.block-title span { text-transform: none; letter-spacing: 0; }
canvas.chart { width: 100%; display: block; border-radius: 10px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); }
canvas#strip { cursor: pointer; }
.now-row { display: flex; gap: 8px; margin-top: 10px; }
.now-chip { flex: 1; border-radius: 10px; padding: 7px 10px; font-size: 12px; border: 1px solid var(--line); }
.now-chip b { display: block; font-size: 13px; }
.now-chip em { display: block; font-style: normal; font-weight: 650; font-size: 12.5px; margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line); color: var(--text); }
.now-chip span { color: var(--dim); }
.now-chip.on.sun { background: rgba(255, 198, 90, 0.16); border-color: rgba(255, 198, 90, 0.5); }
.now-chip.on.earth { background: rgba(93, 180, 255, 0.16); border-color: rgba(93, 180, 255, 0.5); }
.now-chip.off b { color: var(--dim); }
.note { color: var(--dim); font-size: 11px; line-height: 1.45; margin-top: 12px; }

/* Hint + hover */
#hint { position: fixed; left: 50%; bottom: var(--above); transform: translateX(-50%); z-index: 5; padding: 9px 18px; border-radius: 999px; font-size: 13px; color: var(--text); transition: opacity .6s; pointer-events: none; white-space: nowrap; }
#hint.gone { opacity: 0; }
#hover { position: fixed; z-index: 7; pointer-events: none; padding: 6px 10px; border-radius: 10px; font-size: 11.5px; line-height: 1.45; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Time bar */
#timebar { position: fixed; left: 18px; right: 18px; bottom: 16px; z-index: 6; border-radius: 18px; padding: 12px 16px; display: flex; gap: 16px; align-items: center; }
#play { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; background: #fff; color: #0a0d14; font-size: 15px; cursor: pointer; }
.time-main { flex: 1; min-width: 0; }
.time-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
#clock { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sky-read { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sky-read .src-tag { color: var(--good); }
.sky-read .s { color: var(--sun); } .sky-read .e { color: var(--earth); }
#scrub { width: 100%; margin: 8px 0 0; accent-color: var(--sun); height: 18px; }
.scrub-axis { display: flex; justify-content: space-between; font-size: 10.5px; color: #c3ccd9; margin-top: 1px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scrub-axis #winMid { color: var(--dim); }
.time-opts { display: flex; gap: 12px; flex: none; }
.time-opts label { display: flex; flex-direction: column; font-size: 10.5px; color: var(--dim); gap: 3px; letter-spacing: .04em; }
.time-opts select, .time-opts input { background: rgba(255, 255, 255, 0.13); border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 8px; padding: 5px 7px; font-size: 12.5px; color-scheme: dark; color: var(--text); opacity: 1; cursor: pointer; }
.time-opts label { color: #c3ccd9; }

/* Map labels */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.lbl { position: absolute; transform: translate(-50%, -50%); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: rgba(255, 255, 255, 0.55); text-shadow: 0 1px 6px #000, 0 0 2px #000; white-space: nowrap; will-change: transform; }
.lbl.pole { color: #fff; font-weight: 700; }
.lbl.sky { font-weight: 700; letter-spacing: .18em; }
.lbl.sky.sun { color: var(--sun); } .lbl.sky.earth { color: var(--earth); }
.lbl.pin { font-size: 12px; font-weight: 700; color: #0a0d14; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; letter-spacing: 0; box-shadow: 0 0 0 3px rgba(0, 0, 0, .35), 0 0 22px currentColor; text-shadow: none; transform: translate(-50%, -150%); }

/* About */
dialog.modal { background: #0c111c; color: var(--text); border: 1px solid var(--line); border-radius: 18px; max-width: 620px; width: calc(100vw - 32px); max-height: 86vh; max-height: 86dvh; overflow-y: auto; padding: 22px 24px; line-height: 1.55; -webkit-user-select: text; user-select: text; }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
dialog.modal h2 { margin: 0 0 8px; font-size: 20px; }
dialog.modal p { margin: 10px 0; font-size: 13.5px; color: #cdd5e2; }
dialog.modal p b { color: #fff; }
dialog.modal .src { font-size: 12px; color: var(--dim); }
dialog.modal button { border-radius: 999px; padding: 9px 20px; cursor: pointer; margin-top: 6px; }

/* Layer tabs: short names are shown on narrow screens */
#layers button::after { content: none; }

/* Panel collapse */
#panelToggle { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); cursor: pointer; font-size: 13px; line-height: 1; display: grid; place-items: center; z-index: 2; }
#panelToggle:hover { background: rgba(255, 255, 255, 0.14); }
#panel.mini { bottom: auto; }
#panel.mini #siteBody { display: none; }
#panel.mini #pinTabs { margin-bottom: 0; }
#siteBody { -webkit-user-select: text; user-select: text; }

/* Report steps */
.step { margin-top: 14px; }
.step-h { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.step-h i { flex: none; width: 20px; height: 20px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); display: grid; place-items: center; font-style: normal; font-size: 11px; font-weight: 700; }
.step-h span { color: var(--dim); font-size: 11.5px; margin-left: auto; text-align: right; }
.step .metrics { margin-top: 7px; }
.metrics.one { grid-template-columns: 1fr; }
.axis { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--dim); padding: 3px 6px 0 44px; font-variant-numeric: tabular-nums; }
.key { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 10.5px; color: var(--dim); margin-top: 5px; }
.key i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.key .dimkey { margin-left: auto; opacity: .8; }
table.sum { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.sum td { padding: 5px 2px; border-bottom: 1px solid var(--line); }
table.sum td:nth-child(2) { color: var(--dim); text-align: right; }
table.sum td:nth-child(3) { text-align: right; width: 52px; font-weight: 600; }
table.sum tr.tot td { border-bottom: 0; font-weight: 700; font-size: 14px; padding-top: 7px; }
table.sum tr.pen td { color: var(--bad); }
.export { display: flex; gap: 8px; margin-top: 14px; }
.export button { flex: 1; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); padding: 9px 8px; cursor: pointer; font-size: 12.5px; }
.export button:hover { background: rgba(255, 255, 255, 0.14); }

/* Help button */
#aboutBtn { position: fixed; top: 16px; right: 18px; z-index: 6; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-weight: 700; font-size: 15px; display: grid; place-items: center; padding: 0; }
#aboutBtn:hover { background: var(--glass-strong); }

/* Which grid the visible surface is drawn from */
#detail { position: fixed; top: 60px; left: 22px; z-index: 5; pointer-events: none; color: var(--dim); font-size: 11px; letter-spacing: 0.02em; max-width: 300px; text-shadow: 0 1px 3px #000; }
#detail b { color: var(--text); font-weight: 600; }

/* Vertical scale switch */
#scaleBtn { position: fixed; top: 16px; right: 64px; z-index: 6; height: 36px; border-radius: 999px; cursor: pointer; padding: 0 14px; display: flex; align-items: center; gap: 7px; font-size: 12.5px; white-space: nowrap; }
#scaleBtn:hover { background: var(--glass-strong); }
#scaleBtn span { color: var(--sun); font-size: 11px; }
#scaleBtn.true span { color: var(--good); }

/* Add-a-site dialog */
.modal-h { display: flex; justify-content: space-between; align-items: center; }
.modal-h button { margin: 0 !important; width: 34px; height: 34px; padding: 0 !important; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); border-radius: 50% !important; }
#coordForm { display: grid; grid-template-columns: 1fr 1fr 0.9fr auto; gap: 8px; align-items: end; }
#coordForm label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--dim); min-width: 0; }
#coordForm input, #coordForm select { width: 100%; min-width: 0; height: 40px; font-size: 16px; padding: 6px 9px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); color-scheme: dark; -webkit-user-select: text; user-select: text; }
#coordForm button { height: 40px; margin: 0; padding: 0 16px; border-radius: 10px; white-space: nowrap; }
#coordMsg.err { color: var(--bad); }
#presetList { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#presetList button { margin: 0; text-align: left; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); padding: 9px 11px; cursor: pointer; }
#presetList button:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.3); }
#presetList b { display: block; font-size: 13px; }
#presetList span { display: block; font-size: 11.5px; color: var(--dim); margin-top: 2px; line-height: 1.35; }
#presetList i { display: block; font-style: normal; font-size: 11px; color: var(--sun); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* Compare */
.pin-tab.cmp { padding: 6px 12px; font-weight: 600; }
.cmp-wrap { overflow-x: auto; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.cmp th { text-align: left; font-weight: 400; color: var(--dim); padding: 6px 6px 6px 0; white-space: nowrap; }
table.cmp td { text-align: center; padding: 6px 4px; font-weight: 600; min-width: 58px; }
table.cmp tbody tr { border-top: 1px solid var(--line); }
table.cmp thead td { cursor: pointer; padding-bottom: 8px; vertical-align: top; }
table.cmp thead .pin-dot { margin: 0 auto; width: 24px; height: 24px; font-size: 12px; }
.cmp-name { font-size: 10.5px; font-weight: 400; color: var(--dim); margin-top: 4px; line-height: 1.25; }
table.cmp tr.sec th { color: var(--text); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; padding-top: 12px; }
table.cmp tr.sec { border-top: 0; }
table.cmp td.best { color: var(--good); }
table.cmp tr.big td { font-size: 17px; }
table.cmp td small { display: block; font-weight: 400; color: var(--dim); font-size: 10.5px; line-height: 1.3; }
table.cmp td .on-s { color: var(--sun); } table.cmp td .on-e { color: var(--earth); } table.cmp td .off { color: var(--dim); }

/* Eye-level horizon view */
#hview { position: fixed; top: 66px; left: 18px; right: 396px; bottom: var(--above); z-index: 7; display: flex; flex-direction: column; border-radius: 18px; overflow: hidden; background: rgba(6, 8, 14, 0.96); border: 1px solid var(--line); }
#hview[hidden] { display: none; }
.hv-bar { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.hv-bar b { font-size: 13.5px; white-space: nowrap; }
#hvRead { font-size: 12px; color: var(--dim); flex: 1; min-width: 0; }
#hvRead .s { color: var(--sun); } #hvRead .e { color: var(--earth); }
.hv-btns { display: flex; gap: 6px; }
.hv-btns button { border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); padding: 6px 11px; cursor: pointer; font-size: 12px; white-space: nowrap; }
.hv-btns button.on { background: rgba(255, 255, 255, 0.9); color: #0a0d14; font-weight: 600; }
#hvCanvas { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; cursor: grab; }
.hv-note { font-size: 11px; color: var(--dim); padding: 7px 12px 9px; border-top: 1px solid var(--line); line-height: 1.4; }

/* View-from-site buttons */
.look { display: flex; gap: 8px; margin-top: 8px; }
.look button { flex: 1; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); padding: 9px 8px; cursor: pointer; font-size: 12.5px; }
.look button:first-child { flex: 1.5; background: rgba(255, 198, 90, 0.16); border-color: rgba(255, 198, 90, 0.5); font-weight: 600; }
.look button:hover { background: rgba(255, 255, 255, 0.14); }

.site-coord .res { display: inline-block; font-size: 10.5px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); margin-right: 7px; color: var(--dim); }
.site-coord .res.hi { color: var(--good); border-color: rgba(88, 224, 160, 0.5); }

/* Mission scenario */
.mis-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 8px; flex-wrap: wrap; }
.mis-row label { font-size: 12.5px; color: var(--dim); }
.mis-row input { width: 62px; height: 34px; font-size: 16px; text-align: center; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); color-scheme: dark; margin: 0 4px; -webkit-user-select: text; user-select: text; }
.mis-row button { border-radius: 999px; border: 0; padding: 9px 14px; cursor: pointer; font-size: 12.5px; font-weight: 650; background: linear-gradient(135deg, #ffd27a, #ffab3d); color: #1b1203; }
table.mis { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.mis th { text-align: left; font-weight: 600; padding: 6px 6px 6px 0; white-space: nowrap; }
table.mis thead th, table.mis thead td { color: var(--dim); font-weight: 400; font-size: 11px; }
table.mis td { text-align: center; padding: 6px 3px; font-weight: 600; }
table.mis tbody tr { border-top: 1px solid var(--line); }
table.mis small { display: block; font-weight: 400; color: var(--dim); font-size: 10.5px; }
table.mis td small { display: inline; margin-left: 3px; }
table.mis td small.up { color: var(--good); } table.mis td small.down { color: var(--bad); }
table.mis thead .pin-dot { margin: 0 auto; }
table.mis .on-s { color: var(--sun); } table.mis .on-e { color: var(--earth); }
.arrbars { display: flex; align-items: flex-end; gap: 1px; height: 54px; padding: 4px 6px 0; border-radius: 10px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); }
.arrbars i { flex: 1; background: rgba(88, 224, 160, 0.45); border-radius: 2px 2px 0 0; cursor: pointer; }
.arrbars i:hover { background: #fff; }
.arrbars i.top { background: var(--good); }
.arrlist { display: grid; gap: 6px; margin-top: 8px; }
.arrlist button { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; text-align: left; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); padding: 8px 11px; cursor: pointer; }
.arrlist button:hover { background: rgba(255, 255, 255, 0.12); }
.arrlist b { font-size: 13px; }
.arrlist span { font-size: 11.5px; color: var(--dim); grid-column: 1; }
.arrlist em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; font-size: 11.5px; color: var(--sun); }
.arrlist .on-s { color: var(--sun); } .arrlist .on-e { color: var(--earth); }

/* Large desktop */
@media (min-width: 1700px) {
  body { font-size: 15px; }
  #panel { width: 400px; }
}

/* Narrow desktop / tablet landscape: keep the legend clear of the report */
@media (min-width: 900px) and (max-width: 1180px) {
  #legend { left: 22px; transform: none; top: 70px; width: 280px; }
}

/* Tablet portrait and phones */
@media (max-width: 899px) {
  :root { --above: calc(var(--tbh) + 18px); }
  #brand { top: calc(10px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left)); }
  #brand .mark { font-size: 13px; }
  #brand .tag { display: none; }
  #layers { top: calc(38px + env(safe-area-inset-top)); max-width: calc(100vw - 16px); }
  #legend { top: calc(90px + env(safe-area-inset-top)); width: min(300px, 78vw); padding: 7px 12px 8px; }
  #timebar { flex-wrap: wrap; left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right)); bottom: 8px; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  #play { width: 44px; height: 44px; }
  #clock { font-size: 15.5px; }
  #scrub { height: 28px; margin-top: 4px; }
  .time-opts { width: 100%; display: grid; grid-template-columns: 1.5fr 1.1fr 0.9fr; gap: 6px; }
  .time-opts label { min-width: 0; }
  /* 16px stops iOS Safari zooming the page when a field is focused */
  .time-opts select, .time-opts input { width: 100%; min-width: 0; font-size: 16px; padding: 6px 6px; height: 36px; }
  .sky-read { display: none; }
  #actions { bottom: var(--above); left: calc(8px + env(safe-area-inset-left)); flex-direction: row; flex-wrap: wrap; }
  #actions button { padding: 10px 15px; }
  #panel { top: auto; left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right)); bottom: calc(var(--above) + 50px); width: auto; max-height: 40vh; max-height: 40dvh; padding: 12px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  #panel.mini { bottom: calc(var(--above) + 50px); }
  #hint { bottom: calc(var(--above) + 50px); white-space: normal; text-align: center; width: max-content; max-width: calc(100vw - 32px); }
  #hover { display: none; }
  #hview { top: calc(84px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right)); bottom: calc(var(--above) + 108px); }
  .hv-btns button { padding: 7px 10px; }
  .look { flex-wrap: wrap; }
  .look button:first-child { flex-basis: 100%; }
  .lbl { font-size: 9.5px; }
  .export button { padding: 11px 8px; }
  dialog.modal { padding: 18px 16px; }
  #aboutBtn { top: calc(6px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); width: 30px; height: 30px; font-size: 13px; }
  #scaleBtn { top: calc(6px + env(safe-area-inset-top)); right: calc(48px + env(safe-area-inset-right)); height: 30px; padding: 0 11px; font-size: 11.5px; gap: 5px; }
  #scaleBtn span { font-size: 10.5px; }
  #coordForm { grid-template-columns: 1fr 1fr; }
  #detail { top: calc(86px + env(safe-area-inset-top)); left: 0; right: 0; max-width: none; text-align: center; font-size: 10.5px; padding: 0 10px; }
  #legend:not([hidden]) ~ #detail { top: calc(168px + env(safe-area-inset-top)); }
}

/* Phones: short tab names so all five fit without scrolling */
@media (max-width: 560px) {
  #layers { width: calc(100vw - 16px); justify-content: space-between; }
  #layers button { padding: 9px 0; flex: 1; text-align: center; }
  #layers button span { display: none; }
  #layers button::after { content: attr(data-short); }
  .score-ring, .score-ring svg { width: 68px; height: 68px; }
  .score-ring .num { font-size: 21px; }
  .site-name { font-size: 15.5px; }
}

/* Phone held sideways: report on the right, one-line time bar */
@media (max-height: 520px) and (min-width: 600px) {
  #brand { display: none; }
  #layers { top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); transform: none; width: auto; }
  #legend { top: calc(56px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); transform: none; width: 240px; }
  #timebar { flex-wrap: nowrap; padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .time-opts { width: auto; display: flex; }
  .time-opts label { font-size: 0; gap: 0; }
  .time-opts label:first-child { display: none; }
  .time-opts select { width: auto; max-width: 130px; }
  #panel, #panel.mini { top: calc(8px + env(safe-area-inset-top)); left: auto; right: calc(8px + env(safe-area-inset-right)); width: min(320px, 46vw); max-height: none; bottom: var(--above); }
  #panel.mini { bottom: auto; }
  #actions { bottom: var(--above); }
  #hint { bottom: var(--above); left: 35%; }
  #aboutBtn { top: auto; right: auto; left: calc(8px + env(safe-area-inset-left)); bottom: calc(var(--above) + 48px); }
  #scaleBtn { top: auto; right: auto; left: calc(46px + env(safe-area-inset-left)); bottom: calc(var(--above) + 48px); }
}
