:root {
  --bg: #0f1013;
  --glass: rgba(18, 19, 23, 0.66);
  --glass-strong: rgba(18, 19, 23, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #f2f1ee;
  --muted: rgba(242, 241, 238, 0.58);
  --accent: #e9c27d;
  --accent-ink: #1c1710;
  --rec: #ff4d3d;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
body { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; cursor: grab; background: #c9d6e2; }
#view.dragging { cursor: grabbing; }
body.exporting #view { object-fit: contain; background: #000; }

.glass { background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28); }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }

/* top */
.top { position: fixed; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; z-index: 5; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 44px; }
.lefts { display: flex; align-items: flex-start; gap: 8px; pointer-events: none; }
.lefts > * { pointer-events: auto; }
.modesw { display: flex; padding: 4px; gap: 2px; min-height: 44px; align-items: center; }
.modesw button { height: 34px; min-width: 58px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-weight: 650; font-size: 13px; letter-spacing: .01em; cursor: pointer; transition: background .15s, color .15s; }
.modesw button:hover { color: var(--text); }
.modesw button.on { background: var(--accent); color: var(--accent-ink); }
.modesw button:disabled { cursor: progress; }
body.switching .modesw { opacity: .75; }
.brand-name { font-weight: 650; letter-spacing: 0.01em; }
.room { color: var(--muted); font-size: 13px; padding-left: 10px; border-left: 1px solid var(--line-2); white-space: nowrap; }
.tools { display: flex; gap: 2px; padding: 4px; }
.ib { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 36px; padding: 0 8px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer; color: var(--text); transition: background .15s, color .15s; }
.ib:hover { background: rgba(255, 255, 255, 0.08); }
.ib.on { background: rgba(233, 194, 125, 0.18); color: var(--accent); }
.ib.txt { font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; min-width: 46px; }
.ib.small { min-width: 34px; height: 32px; }
.ib:disabled { opacity: .35; cursor: default; }

/* bottom bar */
.bottom { position: fixed; left: 0; right: 0; bottom: calc(12px + var(--safe-b)); display: flex; justify-content: center; pointer-events: none; z-index: 5; }
.bar { display: flex; align-items: center; gap: 6px; padding: 5px; pointer-events: auto; border-radius: 999px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 999px; border: 0;
  background: transparent; cursor: pointer; font-weight: 600; font-size: 13px; }
.pill:hover, .pill.on { background: rgba(255, 255, 255, 0.09); }
.recbtn { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 18px 0 14px; border-radius: 999px; border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.06); cursor: pointer; font-weight: 650; font-size: 13.5px; min-width: 92px; justify-content: center; }
.recbtn .dot, .btn.rec .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 0 3px rgba(255, 77, 61, 0.18); transition: border-radius .2s; }
.recbtn.on, .btn.rec.on { background: var(--rec); border-color: var(--rec); color: #fff; }
.recbtn.on .dot, .btn.rec.on .dot { background: #fff; border-radius: 3px; box-shadow: none; }
.recbtn .t { font-variant-numeric: tabular-nums; }

/* sheets */
.sheet { position: fixed; z-index: 7; padding: 12px 14px 14px; overflow: auto; overscroll-behavior: contain; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.closebtn { display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 8px 0 12px; border-radius: 9px; border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.06); cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text); flex: none; }
.closebtn svg { width: 16px; height: 16px; }
.closebtn:hover { background: rgba(255, 255, 255, 0.12); }
.sheet h2 { font-size: 15px; margin: 0; font-weight: 650; }
.sheet h3 { font-size: 11.5px; margin: 10px 0 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.places, .help { top: calc(64px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: min(380px, calc(100vw - 20px)); max-height: calc(100vh - 150px - var(--safe-t) - var(--safe-b)); background: var(--glass-strong); }
.path { left: 50%; transform: translateX(-50%); bottom: calc(72px + var(--safe-b)); width: min(620px, calc(100vw - 20px)); max-height: calc(100vh - 150px - var(--safe-t) - var(--safe-b)); background: var(--glass-strong); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); cursor: pointer; font-size: 13px; white-space: nowrap; }
.chip:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--line-2); }
.chip small { color: var(--muted); margin-left: 6px; font-size: 11.5px; }
.chip.photo { min-width: 50px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.muted { color: var(--muted); font-size: 12.5px; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 4px 0 0; font-size: 13px; }
.keys dt { color: var(--accent); font-weight: 600; white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
body.is-touch .keys.desk { display: none; }
body:not(.is-touch) .keys.touch { display: none; }

/* popover */
.pop { position: fixed; z-index: 7; bottom: calc(72px + var(--safe-b)); left: 50%; transform: translateX(-50%); width: min(340px, calc(100vw - 20px)); padding: 12px 14px; background: var(--glass-strong); }
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap-top { margin-top: 14px; }
.grow { flex: 1; }
.lbl { font-size: 12.5px; color: var(--muted); }
.val { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 11px; border-radius: 8px; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: rgba(255, 255, 255, 0.14); color: var(--text); }
#lens-presets { display: flex; width: 100%; margin-top: 8px; }
#lens-presets button { flex: 1; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; cursor: pointer; margin: 0; touch-action: pan-x; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--text); margin-top: -7px; border: 0; box-shadow: 0 1px 6px rgba(0,0,0,.4); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 0; }
input[type=range]:disabled { opacity: .35; cursor: default; }

.btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 13px; border-radius: 10px; border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.08); cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn.ghost { background: transparent; }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.accent:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .38; cursor: default; }
.btn.rec { min-width: 110px; justify-content: center; }
.dur { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-left: auto; }
.dur input { width: 64px; height: 34px; border-radius: 8px; border: 1px solid var(--line-2); background: rgba(0,0,0,.25); padding: 0 8px; text-align: right; color: var(--text); }
.sel { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.sel select { height: 32px; border-radius: 8px; border: 1px solid var(--line-2); background: #1d1e23; padding: 0 6px; color: var(--text); max-width: 170px; }
#saved { width: 130px; }
@media (max-width: 400px) { #saved { width: 96px; } }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }
.keys-list { margin-top: 6px; min-height: 34px; }
.keys-list .chip { min-width: 40px; }
.timeline { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.timeline .play { width: 42px; height: 42px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); flex: none; }
.timeline .play .i-pause { display: none; }
.timeline .play.playing .i-play { display: none; }
.timeline .play.playing .i-pause { display: block; }
.time { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.actions { margin-top: 10px; }

/* frame guide */
.frame { position: fixed; z-index: 2; pointer-events: none; box-shadow: 0 0 0 200vmax rgba(8, 9, 11, 0.5); outline: 1px solid rgba(255, 255, 255, 0.28); }
.frame.off { box-shadow: none; outline: 0; }
.frame.off .c, .frame.off .frame-tag { display: none; }
.frame .c { position: absolute; width: 18px; height: 18px; border: 0 solid rgba(255, 255, 255, 0.85); }
.frame .tl { top: 6px; left: 6px; border-top-width: 2px; border-left-width: 2px; }
.frame .tr { top: 6px; right: 6px; border-top-width: 2px; border-right-width: 2px; }
.frame .bl { bottom: 6px; left: 6px; border-bottom-width: 2px; border-left-width: 2px; }
.frame .br { bottom: 6px; right: 6px; border-bottom-width: 2px; border-right-width: 2px; }
.frame-tag { position: absolute; left: 30px; top: 7px; font-size: 11px; font-weight: 600; letter-spacing: .06em; color: rgba(255, 255, 255, 0.75); text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.rec-tag { position: absolute; right: 30px; top: 6px; display: none; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; color: #fff; background: var(--rec); padding: 2px 7px; border-radius: 5px; font-variant-numeric: tabular-nums; }
body.recording .rec-tag { display: block; }
body.recording .frame { outline-color: rgba(255, 77, 61, 0.9); }

/* labels */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
#labels span { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); padding: 3px 8px; border-radius: 7px; font-size: 12px; font-weight: 600;
  background: rgba(15, 16, 19, 0.72); border: 1px solid var(--line); white-space: nowrap; will-change: transform; }

/* minimap */
#minimap { position: fixed; z-index: 4; right: calc(10px + var(--safe-r)); bottom: calc(76px + var(--safe-b)); width: 180px; height: 220px;
  border-radius: 12px; background: rgba(18, 19, 23, 0.72); border: 1px solid var(--line); cursor: pointer; touch-action: none; }

/* touch */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.joy { position: fixed; left: calc(30px + var(--safe-l)); bottom: calc(96px + var(--safe-b)); width: 124px; height: 124px; border-radius: 50%;
  background: rgba(18, 19, 23, 0.32); border: 1px solid rgba(255, 255, 255, 0.22); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); transition: opacity .2s; opacity: .8; }
.joy.active { opacity: 1; transition: none; }
.knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255, 255, 255, 0.82); box-shadow: 0 2px 10px rgba(0,0,0,.35); }
.updown { position: fixed; right: calc(14px + var(--safe-r)); bottom: calc(110px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; pointer-events: auto; }
.updown button { width: 52px; height: 52px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.22); background: rgba(18, 19, 23, 0.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; touch-action: none; }
.updown button.on { background: rgba(255, 255, 255, 0.3); }
.updown svg { width: 24px; height: 24px; }
body.has-map .updown { bottom: calc(300px + var(--safe-b)); }

/* toast */
#toast { position: fixed; left: 50%; top: calc(66px + var(--safe-t)); transform: translate(-50%, -8px); z-index: 9; padding: 8px 14px; border-radius: 10px;
  background: var(--glass-strong); border: 1px solid var(--line); font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 30px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* overlays */
#busy { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.35); }
.busy-card { width: min(340px, calc(100vw - 40px)); padding: 18px; background: var(--glass-strong); display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.busy-card .btn { align-self: flex-end; }
.busy-title { font-weight: 650; }
.busy-sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.bar-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

#loader { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 30%, #23252b 0%, #0f1013 70%); transition: opacity .5s; }
#loader.done { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .4s, visibility 0s linear .4s; }
.load-card { width: min(300px, calc(100vw - 60px)); display: flex; flex-direction: column; gap: 12px; }
.load-title { font-size: 22px; font-weight: 650; letter-spacing: .01em; }
.load-sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.nojs { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 40; background: var(--bg); margin: 0; }

/* phones */
@media (max-width: 640px) {
  .brand { padding: 6px 10px; min-height: 40px; gap: 8px; }
  .brand-name { font-size: 13px; }
  .room { font-size: 12px; padding-left: 8px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
  .tools { padding: 3px; }
  .ib { min-width: 36px; height: 34px; padding: 0 6px; }
  .ib.txt { min-width: 40px; font-size: 12px; }
  .top { flex-direction: column; align-items: flex-end; }
  .top .brand { align-self: flex-start; }
  .places, .help { top: auto; bottom: calc(68px + var(--safe-b)); left: 10px; right: 10px; width: auto; max-height: 62vh; }
  .path { bottom: calc(68px + var(--safe-b)); max-height: 64vh; }
  #minimap { width: 140px; height: 172px; bottom: calc(68px + var(--safe-b)); }
  body.has-map .updown { bottom: calc(256px + var(--safe-b)); }
  .pill { padding: 0 12px; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
}
@media (max-width: 640px) and (orientation: portrait) {
  .top { flex-direction: row; flex-wrap: nowrap; }
}
@media (max-width: 640px) {
  .lefts { flex-direction: column; gap: 6px; }
  .modesw { min-height: 40px; padding: 3px; }
  .modesw button { height: 32px; min-width: 54px; }
}
@media (max-width: 430px) {
  .brand-name { display: none; }
  .room { border-left: 0; padding-left: 0; color: var(--text); font-weight: 600; max-width: 30vw; }
  .tools .ib { min-width: 34px; padding: 0 5px; }
  .tools .ib.txt { min-width: 38px; }
}
