/* Sap flow sensor viewer. Dark theme for the hologram looks; body[data-look="realistic"] switches to light.
   With content.overview, the stage gets .with-info: the info panel takes its own column on the right (on phones, the
   bottom of the screen) and the canvas fills the rest, so the model is centred in what's left without a view offset. */

:root {
  --bg: #04090f;
  --ink: #e6f3fa;
  --dim: #87a3b4;
  --line: rgba(var(--holo-rgb, 110, 200, 255), .2);
  --panel: rgba(5, 14, 22, .78);
  --accent: var(--holo, #3fc9ff);
  --heat: #ff9a4d;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --info-w: 0px;
}
body[data-look="realistic"] {
  --bg: #e4e8eb;
  --ink: #12181d;
  --dim: #56646e;
  --line: rgba(0, 0, 0, .14);
  --panel: rgba(255, 255, 255, .86);
  --accent: #0b6fa4;
}

[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); transition: background .4s; }
.stage { position: relative; width: 100%; height: 100%; overflow: hidden; }
/* no visible scrollbars anywhere: anything that can overflow still scrolls by touch/wheel, without a bar */
.stage * { scrollbar-width: none; }
.stage *::-webkit-scrollbar { display: none; }
canvas#c { position: absolute; top: 0; left: 0; width: calc(100% - var(--info-w)); height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.title { position: absolute; top: 24px; left: 28px; max-width: 420px; pointer-events: none; }
.links { display: flex; gap: 14px; margin: 0 0 10px; pointer-events: auto; font-size: 13px; }
.links a { color: var(--dim); text-decoration: none; }
.links a:hover { color: var(--accent); }
.kicker { margin: 0; font: 600 11px/1.4 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 4px 0 6px; font-size: 30px; font-weight: 600; letter-spacing: -.01em; }
.subtitle { margin: 0; color: var(--dim); }
body:not([data-look="realistic"]) h1 { text-shadow: 0 0 18px rgba(var(--holo-rgb, 63, 201, 255), .35); }

.subsystems { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; }
.subsystems button { text-align: left; background: none; border: 0; padding: 5px 10px; border-left: 2px solid var(--line); color: var(--dim); }
.subsystems button:hover, .subsystems button.hover { color: var(--ink); border-left-color: var(--accent); }
.subsystems button[aria-pressed="true"] { color: var(--ink); border-left-color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- info panel (overview + subsystem card) */
.info { position: absolute; right: 28px; top: 50%; transform: translateY(-50%); width: 300px; pointer-events: none; }
.info > section { pointer-events: auto; padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); backdrop-filter: blur(8px); }
.info h2 { margin: 4px 0 8px; font-size: 21px; font-weight: 600; line-height: 1.25; }
.info p { margin: 0 0 12px; }
.info-hint { color: var(--dim); font-size: 12px; }
.back { margin: -4px 0 12px -8px; padding: 4px 8px; border: 0; border-radius: 6px; background: none; color: var(--accent); font-size: 13px; }
.back:hover { background: rgba(var(--holo-rgb, 63, 201, 255), .1); }
.facts { margin: 0 0 14px; padding: 0; list-style: none; }
.facts li { position: relative; padding: 7px 0 7px 18px; border-top: 1px solid var(--line); }
.facts li::before { content: ""; position: absolute; left: 2px; top: 15px; width: 6px; height: 6px; border: 1px solid var(--accent); transform: rotate(45deg); }

.stage.with-info { --info-w: 400px; }
.with-info .info { top: 0; right: 0; bottom: 0; transform: none; width: var(--info-w); overflow-y: auto; pointer-events: auto;
  border-left: 1px solid var(--line); background:
    linear-gradient(var(--panel), var(--panel)),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(var(--holo-rgb, 63, 201, 255), .05) 23px 24px),
    repeating-linear-gradient(90deg, transparent 0 23px, rgba(var(--holo-rgb, 63, 201, 255), .05) 23px 24px); }
.with-info .info > section { border: 0; border-radius: 0; background: none; backdrop-filter: none; padding: 26px 26px 20px; }

/* graphics */
.graphic { margin: 4px 0 16px; padding: 10px 10px 8px; border: 1px solid var(--line); border-radius: 10px; position: relative; }
.graphic::before, .graphic::after { content: ""; position: absolute; width: 10px; height: 10px; border: 1px solid var(--accent); }
.graphic::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.graphic::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }
.graphic svg { display: block; width: 100%; height: auto; overflow: visible; }
.graphic figcaption { margin-top: 6px; color: var(--dim); font-size: 12px; line-height: 1.45; }
.graphic .ln { fill: none; stroke: var(--accent); stroke-width: 1.2; stroke-opacity: .85; }
.graphic .fill-sap { fill: rgba(var(--holo-rgb, 63, 201, 255), .07); }
.graphic .fill-dim { fill: rgba(var(--holo-rgb, 63, 201, 255), .02); stroke-opacity: .4; }
.graphic .head { fill: rgba(var(--holo-rgb, 63, 201, 255), .12); }
.graphic .needle line { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; opacity: .9; }
.graphic .pulse-line { stroke: var(--heat); stroke-width: 1.6; stroke-linecap: round; }
.graphic .lbl, .graphic .lbl text { fill: var(--ink); font: 600 10px var(--mono); letter-spacing: .02em; }
.graphic .lbl.dim { fill: var(--dim); font-weight: 400; }
.graphic .lbl.hot { fill: var(--heat); }
.graphic .flow { stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 3 9; opacity: .55; animation: flow 1.4s linear infinite; }
.graphic .heat { transform-box: fill-box; transform-origin: center; animation: heat 3.2s ease-out infinite; }
.graphic .waves circle { fill: none; stroke: var(--accent); stroke-width: 1.2; transform-box: fill-box; transform-origin: center; opacity: 0; animation: wave 2.4s ease-out infinite; }
.graphic .waves circle:nth-child(2) { animation-delay: .8s; }
.graphic .waves circle:nth-child(3) { animation-delay: 1.6s; }
.graphic .link { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 2 4; opacity: .45; }
.graphic .packet { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; stroke-dasharray: 4 400; stroke-dashoffset: 0;
  filter: drop-shadow(0 0 3px var(--accent)); animation: packet 2.4s linear infinite; }
.graphic .packet.p2 { animation-delay: .8s; opacity: 0; animation-name: packet2; }
.graphic .packet.p3 { animation-delay: 1.4s; opacity: 0; animation-name: packet2; }
.graphic .spark { stroke-width: 1.4; }
@keyframes flow { to { stroke-dashoffset: 24; } }
@keyframes heat { 0% { transform: translateY(6px) scale(.35); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(-30px) scale(1.15); opacity: 0; } }
@keyframes wave { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(3.4); opacity: 0; } }
@keyframes packet { from { stroke-dashoffset: 4; } to { stroke-dashoffset: -120; } }
@keyframes packet2 { 0% { stroke-dashoffset: 4; opacity: 1; } 60% { stroke-dashoffset: -64; opacity: 1; } 61%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .graphic .flow, .graphic .heat, .graphic .waves circle, .graphic .packet { animation: none; }
  .graphic .heat { transform: translateY(-14px); opacity: .9; }
  .graphic .waves circle:first-child { opacity: .6; transform: scale(2); }
}

/* ---------------------------------------------------------------- controls, hint, tooltip, loading */
.controls { position: absolute; left: calc((100% - var(--info-w)) / 2); bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 16px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); backdrop-filter: blur(8px); }
.looks { display: flex; gap: 2px; }
.looks button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; color: var(--dim); }
.looks button[aria-checked="true"] { background: var(--accent); color: #fff; }
body:not([data-look="realistic"]) .looks button[aria-checked="true"] { color: #02131d; }
.explode { display: flex; align-items: center; gap: 8px; color: var(--dim); white-space: nowrap; }
.explode input { width: 140px; accent-color: var(--accent); }
.reset { border: 1px solid var(--line); background: none; padding: 6px 12px; border-radius: 999px; }
.controls button { white-space: nowrap; }

.hint { position: absolute; left: 0; right: var(--info-w); bottom: 76px; margin: 0; text-align: center; font-size: 12px; color: var(--dim); pointer-events: none; }
.tip { position: absolute; pointer-events: none; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(8px); font-size: 13px; white-space: nowrap; transform: translate(14px, 14px); }
.tip small { display: block; color: var(--dim); }

.loading { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; color: var(--dim); background: var(--bg); transition: opacity .5s;
  font: 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; padding: 0 24px; }
.loading i { display: block; width: 220px; height: 2px; margin: 0 auto; background: var(--line); }
.loading b { display: block; height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.loading.done { opacity: 0; pointer-events: none; }

@media (max-width: 1100px) {
  .stage.with-info { --info-w: 340px; }
  .with-info .subsystems { display: none; }
  .with-info .explode input { width: 90px; }
}

@media (max-width: 900px) {
  .title { top: 16px; left: 16px; right: 16px; }
  h1 { font-size: 22px; }
  .subsystems { display: none; }
  .info { left: 12px; right: 12px; top: auto; bottom: 178px; width: auto; transform: none; }
  .info > section { padding: 14px 16px; }
  .controls { left: 12px; right: 12px; transform: none; flex-wrap: wrap; justify-content: center; border-radius: 16px; }
  .hint { display: none; }
  .looks button { padding: 5px 9px; }
  .explode input { width: 80px; }

  /* with the info panel: model on top, panel as a scrolling sheet below */
  .stage.with-info { --info-w: 0px; --sheet: 44%; }
  .with-info canvas#c { bottom: var(--sheet); height: calc(100% - var(--sheet)); width: 100%; }
  .with-info .info { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet); border-left: 0; border-top: 1px solid var(--line); }
  .with-info .info > section { padding: 16px 18px; }
  .with-info .controls { left: 8px; right: 8px; bottom: calc(var(--sheet) + 8px); gap: 8px; padding: 6px; }
  .with-info .reset { display: none; }
  .with-info .controls { flex-wrap: nowrap; justify-content: space-between; border-radius: 999px; font-size: 12px; }
  .with-info .looks button { padding: 4px 8px; }
  .with-info .explode span { display: none; }
  .with-info .explode input { width: 64px; }
  .with-info .title p.subtitle { display: none; }
}

/* ---------------------------------------------------------------- embedded preview (?preview=1): the model only */
body[data-mode="preview"] .stage.with-info, body[data-mode="preview"] .stage { --info-w: 0px; }
body[data-mode="preview"] :is(.title, .subsystems, .info, .controls, .hint, .tip) { display: none !important; }
body[data-mode="preview"] canvas#c { width: 100%; height: 100%; bottom: auto; }
.exit { border: 1px solid var(--accent); background: none; padding: 6px 14px; border-radius: 999px; color: var(--accent); }
.exit:hover { background: rgba(var(--holo-rgb, 63, 201, 255), .12); }
@media (max-width: 900px) {
  .with-info .exit { padding: 4px 10px; }
}

/* ---------------------------------------------------------------- info panel fits the screen (no scrolling needed)
   The overview is a flex column: text at its natural size, the two graphics share what's left and scale down. */
.with-info .info > section { box-sizing: border-box; height: 100%; display: flex; flex-direction: column; }
.with-info .info > section > * { flex: none; }
.with-info .back { align-self: flex-start; }
.with-info .overview p#ov-text { font-size: clamp(12px, 1.55vh, 14px); }
.with-info .info > section > .graphics { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.with-info .graphic { flex: 1 1 0; min-height: 0; margin: 0; display: flex; flex-direction: column; }
.with-info .graphic svg { flex: 1 1 0; min-height: 0; width: 100%; height: 100%; }
.with-info .graphic figcaption { flex: none; }
@media (max-height: 760px) { .with-info .graphic figcaption { display: none; } .with-info .info h2 { font-size: 18px; } }
@media (max-width: 900px) {
  .with-info .info > section > .graphics { flex-direction: row; gap: 8px; }
  .with-info .graphic { padding: 6px; }
  .with-info .graphic figcaption, .with-info .info-hint { display: none; }
  .with-info .overview p#ov-text { font-size: clamp(11px, 1.5vh, 12.5px); line-height: 1.4; margin-bottom: 8px; }
  .with-info .overview .kicker { display: none; }
  .with-info .info h2 { font-size: 17px; margin: 2px 0 6px; }
}
@media (max-width: 900px) and (max-height: 760px) {
  .with-info .info > section { padding: 12px 16px; }
  .with-info .card p, .with-info .facts li { font-size: 12.5px; line-height: 1.4; }
  .with-info .facts li { padding: 4px 0 4px 16px; }
  .with-info .facts li::before { top: 10px; }
  .with-info .back { margin-bottom: 4px; }
  .with-info .card .kicker { display: none; }
}
@media (max-width: 900px) { .with-info .title .kicker, .with-info .title .subtitle { display: none; } .with-info h1 { font-size: 20px; } }
/* three or more overview graphics on a phone: a swipeable strip (each graphic most of the width), no scrollbar */
@media (max-width: 900px) {
  .with-info .info > section > .graphics:has(> .graphic:nth-child(3)) { overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
  .with-info .graphics:has(> .graphic:nth-child(3))::-webkit-scrollbar { display: none; }
  .with-info .graphics:has(> .graphic:nth-child(3)) > .graphic { flex: 0 0 82%; scroll-snap-align: start; }
}

/* ---------------------------------------------------------------- floating info panel (desktop, 2026-11-14)
   Detached from the edges and twice the old width, over the canvas; the canvas fills the whole stage and the viewer
   frames the model in the uncovered part (app.js updateReserve -> viewer.setReserve). */
@media (min-width: 901px) {
  .stage.with-info { --info-w: 0px; --panel-w: min(800px, 50vw); --panel-gap: 20px; }
  .with-info canvas#c { width: 100%; }
  .with-info .info { top: var(--panel-gap); right: var(--panel-gap); bottom: var(--panel-gap); width: var(--panel-w); border: 1px solid var(--line);
    border-radius: 20px; overflow: hidden; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .45), 0 0 40px rgba(var(--holo-rgb, 63, 201, 255), .06); }
  .with-info .info > section { padding: 28px 32px 22px; }
  .with-info .controls { left: calc((100% - var(--panel-w) - 2 * var(--panel-gap)) / 2); }
  .with-info .hint { right: calc(var(--panel-w) + 2 * var(--panel-gap)); }
  .with-info .overview p#ov-text { font-size: clamp(13px, 1.7vh, 15px); max-width: 68ch; }
  .with-info .info h2 { font-size: 24px; }
  .with-info .graphic figcaption { font-size: 12.5px; }
}
@media (min-width: 901px) and (max-width: 1100px) {
  .stage.with-info { --panel-w: 48vw; }
}

/* ---------------------------------------------------------------- graphic option switch (content.overview.graphics[].options) */
.g-opts { display: flex; align-items: center; gap: 4px; margin: 8px 0 2px; flex: none; }
.g-opts span { margin-right: 8px; color: var(--dim); font: 600 10px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.g-opts button { min-width: 44px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--dim);
  font: 600 11px/1.2 var(--mono); letter-spacing: .06em; }
.g-opts button:hover { color: var(--ink); border-color: var(--accent); }
.g-opts button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: #02131d; }
.info-hint { letter-spacing: .02em; }
@media (max-width: 900px) { .g-opts span { display: none; } .g-opts button { min-width: 0; padding: 3px 7px; font-size: 10px; } }

/* ---------------------------------------------------------------- spacing on short and narrow screens (Jack, 2026-11-16)
   - Subsystem list: its own slot between the title block and the controls/hint, a 20px margin on each side (app.js
     layoutNav sets --nav-top/--nav-bottom). Centred when it fits; when it doesn't, it scrolls with no visible bar.
   - Side panel (wide screens): the graphics keep their natural size and the panel scrolls vertically, with a thin
     accent-coloured scrollbar (the one visible scrollbar in the viewer). Phones keep the bottom sheet as it was. */
.subsystems.fit { top: var(--nav-top); bottom: var(--nav-bottom); transform: none; overflow-y: auto; overscroll-behavior: contain; padding-right: 6px; }
.subsystems.fit > :first-child { margin-top: auto; }
.subsystems.fit > :last-child { margin-bottom: auto; }
.subsystems.fit button { flex: none; }
.subsystems.fit.more-below { -webkit-mask-image: linear-gradient(#000 calc(100% - 36px), transparent); mask-image: linear-gradient(#000 calc(100% - 36px), transparent); }
.subsystems.fit.more-above { -webkit-mask-image: linear-gradient(transparent, #000 36px); mask-image: linear-gradient(transparent, #000 36px); }
.subsystems.fit.more-above.more-below { -webkit-mask-image: linear-gradient(transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(transparent, #000 36px, #000 calc(100% - 36px), transparent); }
@media (min-width: 901px) {
  .with-info .title { max-width: min(420px, calc(100% - var(--panel-w) - 2 * var(--panel-gap) - 56px)); }
  .stage.with-info .info { overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: rgba(var(--holo-rgb, 63, 201, 255), .45) transparent; }
  .stage.with-info .info::-webkit-scrollbar { display: block; width: 10px; }
  .stage.with-info .info::-webkit-scrollbar-track { background: transparent; margin: 16px 0; }
  .stage.with-info .info::-webkit-scrollbar-thumb { background: rgba(var(--holo-rgb, 63, 201, 255), .4); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
  .stage.with-info .info::-webkit-scrollbar-thumb:hover { background-color: rgba(var(--holo-rgb, 63, 201, 255), .65); }
  .with-info .info > section { height: auto; min-height: 100%; display: block; }
  .with-info .info > section > .graphics { display: flex; flex-direction: column; gap: 14px; margin-bottom: 14px; }
  .with-info .graphic { flex: none; display: block; margin: 0; }
  .with-info .graphic svg { flex: none; width: 100%; height: auto; }
  .with-info .overview p#ov-text { font-size: 15px; }
}
@media (min-width: 901px) and (max-height: 760px) { .with-info .graphic figcaption { display: block; } .with-info .info h2 { font-size: 24px; } }
