:root {
  --bg: #14171c; --panel: rgba(22, 26, 32, 0.92); --ink: #f2f4f7; --quiet: #a9b1bc;
  --line: rgba(255,255,255,0.14); --blue: #0072B2; --sky: #56B4E9; --orange: #E69F00; --verm: #D55E00;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
canvas#scene { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.topbar { position: fixed; top: 0; left: 0; right: 0; padding: calc(8px + var(--safe-t)) 16px 8px;
  display: flex; justify-content: space-between; align-items: center; pointer-events: none;
  background: linear-gradient(rgba(20,23,28,0.85), rgba(20,23,28,0)); }
.brand { display: flex; flex-direction: column; pointer-events: auto; }
.brand span { color: var(--quiet); font-size: 12px; }
.icon { pointer-events: auto; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); font-weight: 700; font-style: italic; }

.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 12px calc(10px + var(--safe-b));
  background: linear-gradient(rgba(20,23,28,0), rgba(20,23,28,0.92) 30%); display: flex; flex-direction: column; gap: 8px; }
.chips, .tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip, .tool, .seg button, .presets button { min-height: 40px; padding: 0 12px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--panel); }
.chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.chip[aria-pressed="true"], .tool[aria-pressed="true"] { border-color: var(--sky); background: rgba(86,180,233,0.22); }
.chip[aria-pressed="true"]::after, .tool[aria-pressed="true"]::after { content: " ✓"; }
.sw { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }
.sw-sterile { background: repeating-linear-gradient(45deg, var(--blue) 0 3px, rgba(0,114,178,0.35) 3px 6px); }
.sw-rad { background: linear-gradient(90deg, var(--verm), var(--orange), var(--sky)); }
.seg { display: inline-flex; border-radius: 20px; overflow: hidden; border: 1px solid var(--line); }
.seg button { border: 0; border-radius: 0; background: var(--panel); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: rgba(86,180,233,0.28); font-weight: 600; }

.sheet { position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); max-height: 72dvh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px 16px 18px; z-index: 20;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.sheet h1 { font-size: 20px; margin: 0 0 8px; } .sheet h2 { font-size: 18px; margin: 0 32px 10px 0; }
.sheet h3 { font-size: 14px; margin: 14px 0 6px; color: var(--quiet); text-transform: uppercase; letter-spacing: .04em; }
.intro { top: calc(64px + var(--safe-t)); bottom: auto; }
.hints { padding-left: 18px; color: var(--quiet); } .hints b { color: var(--ink); }
.primary { width: 100%; min-height: 48px; border-radius: 12px; border: 0; background: var(--blue); color: #fff; font-weight: 700; margin-top: 6px; }
.close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; font-size: 20px; line-height: 1; }
.card dl { margin: 0; } .card dt { color: var(--quiet); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
.card dd { margin: 2px 0 0; }
.fine { color: var(--quiet); font-size: 12px; margin: 10px 0 0; }
.list ul { list-style: none; padding: 0; margin: 0; }
.list li button { width: 100%; text-align: left; min-height: 44px; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 8px 4px; }

.layer-info { position: fixed; top: calc(56px + var(--safe-t)); left: 8px; right: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; z-index: 10; }
.layer-head { display: flex; justify-content: space-between; align-items: center; }
.layer-info .close { position: static; width: 30px; height: 30px; }
.layer-info p { margin: 6px 0 0; }
.legend { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 18px; height: 14px; border: 1px solid rgba(255,255,255,0.3); }

.rad-panel { position: fixed; left: 8px; right: 8px; bottom: calc(var(--dock-h, 182px) + 4px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; z-index: 9; display: flex; flex-direction: column; gap: 6px; }
.rad-panel label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--quiet); }
.rad-panel input[type=range] { flex: 1; accent-color: var(--orange); min-height: 32px; }
.rad-panel output { width: 40px; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.presets { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.presets button { min-height: 34px; padding: 0 10px; white-space: nowrap; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.row .seg button { min-height: 34px; font-size: 13px; }
select { min-height: 34px; border-radius: 17px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); padding: 0 10px; }

.toast { position: fixed; top: calc(60px + var(--safe-t)); left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: #22303c; border: 1px solid var(--sky); border-radius: 12px; padding: 10px 12px; z-index: 30; display: flex; gap: 10px; align-items: center; }
.toast button { min-height: 34px; border-radius: 17px; border: 1px solid var(--line); background: var(--panel); padding: 0 10px; }
.here { position: fixed; left: 50%; transform: translateX(-50%); top: calc(50dvh - 14px); pointer-events: none; z-index: 5;
  background: rgba(20,23,28,0.75); border: 1px solid var(--line); border-radius: 12px; padding: 4px 10px; font-size: 13px; }
.check { display: flex; gap: 10px; align-items: flex-start; } .check input { width: 22px; height: 22px; margin-top: 1px; }
.err { position: fixed; inset: auto 8px 50% 8px; background: #3a2a10; border: 1px solid var(--orange); padding: 12px; border-radius: 12px; z-index: 50; }
[hidden] { display: none !important; }
@media (min-width: 720px) { .sheet, .layer-info, .rad-panel { left: auto; right: 16px; width: 380px; } }

.stepper { display: flex; gap: 6px; align-items: stretch; }
.step-arrow { width: 48px; min-height: 56px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 28px; line-height: 1; }
.step-arrow:disabled { opacity: 0.35; }
.step-mid { flex: 1; min-width: 0; text-align: left; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.step-top { display: flex; gap: 8px; align-items: center; min-width: 0; }
.step-top strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#step-count { color: var(--quiet); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.step-short { color: var(--quiet); font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.beam-badge { flex: none; margin-left: auto; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; color: #111; background: #F0E442; border: 1px solid #111; }
.beam-badge.cine { background: var(--orange); }
.beam-badge::before { content: "☢ "; }
.who { margin: 0; padding-left: 18px; } .who b { color: var(--ink); }

.closeup { margin: 4px 0 6px; } .closeup canvas { width: 100%; height: 240px; display: block; border-radius: 12px;
  background: radial-gradient(circle at 50% 40%, #2b3440, #161a20); }
.closeup figcaption { color: var(--quiet); font-size: 12px; margin-top: 4px; }
.parts, .links { margin: 0; padding-left: 0; list-style: none; }
.parts li { margin: 4px 0; } .parts b { color: var(--ink); }
.links li { margin: 2px 0; } .links a { display: flex; gap: 8px; align-items: center; min-height: 40px; color: var(--sky); text-decoration: none; }
.links a:hover span:first-child { text-decoration: underline; }
.src { flex: none; font-size: 11px; color: var(--quiet); border: 1px solid var(--line); border-radius: 8px; padding: 1px 6px; }
.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-chips button { min-height: 34px; border-radius: 17px; border: 1px solid #CC79A7; background: rgba(204,121,167,0.15); padding: 0 10px; font-size: 13px; }

.now { border: 1px solid var(--sky); background: rgba(86,180,233,0.12); border-radius: 12px; padding: 8px 10px; margin: 0 0 8px; }
.now-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--quiet); text-transform: uppercase; letter-spacing: .04em; }
.now p { margin: 4px 0 0; }
.meter { letter-spacing: 2px; color: var(--ink); text-transform: none; }
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline button { width: 100%; display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; text-align: left;
  min-height: 40px; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 4px 2px; font-size: 13px; }
.timeline .n { color: var(--quiet); font-variant-numeric: tabular-nums; }
.timeline .lvl { color: var(--quiet); white-space: nowrap; }
.timeline li.cur button { background: rgba(86,180,233,0.18); font-weight: 600; }
.timeline li.cur .n::before { content: "▶"; color: var(--sky); }
.timeline li.cur .n span { display: none; }

.linkish { border: 0; background: none; color: var(--sky); padding: 6px 0; min-height: 36px; font-size: 14px; }
.step-icon { color: var(--sky); flex: none; }
.timeline .lvl.beam { color: #111; background: #F0E442; border: 1px solid #111; border-radius: 8px; padding: 0 6px; font-size: 11px; font-weight: 700; }
.timeline .lvl.beam.cine { background: var(--orange); }

.viewsw { position: relative; display: flex; gap: 6px; }
.vs-main { flex: 1; min-width: 0; min-height: 48px; display: flex; align-items: center; gap: 10px; text-align: left;
  border-radius: 14px; border: 1px solid var(--line); background: var(--panel); padding: 4px 12px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.vs-main .sw { width: 22px; height: 22px; flex: none; border: 1px solid rgba(255,255,255,0.3); }
.vs-text { display: flex; flex-direction: column; min-width: 0; }
.vs-label { font-size: 11px; color: var(--quiet); text-transform: uppercase; letter-spacing: .04em; }
#vs-count { font-variant-numeric: tabular-nums; text-transform: none; margin-left: 2px; }
.vs-next { margin-left: auto; font-size: 13px; color: var(--quiet); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vs-menu { width: 48px; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 18px; }
.vs-menu[aria-expanded="true"] { border-color: var(--sky); }
.vs-list { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 25; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.vs-list button { width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; min-height: 52px; border: 0; border-radius: 10px; background: none; padding: 6px 8px; }
.vs-list button + button { border-top: 1px solid var(--line); border-radius: 0; }
.vs-list button[aria-checked="true"] { background: rgba(86,180,233,0.18); }
.vs-list button[aria-checked="true"] strong::after { content: " ✓"; color: var(--sky); }
.vs-list .sw { width: 22px; height: 22px; flex: none; border: 1px solid rgba(255,255,255,0.3); }
.vs-item { display: flex; flex-direction: column; } .vs-item span { font-size: 13px; color: var(--quiet); }
.sw-room { background: #5b6470; }
.sw-equip { background: transparent; box-shadow: inset 0 0 0 3px var(--sky); }
.sw-privacy { background: transparent; box-shadow: inset 0 0 0 3px var(--verm); }
@media (max-width: 420px) {
  .tools { flex-wrap: nowrap; gap: 6px; }
  .tools .seg button, .tools .tool { padding: 0 9px; font-size: 14px; }
}
