:root {
  color-scheme: dark;
  --bg: #0b1018;
  --panel: #121a26;
  --panel-2: #172131;
  --line: #29384b;
  --text: #edf3fc;
  --muted: #9ba9bd;
  --accent: #8ae0d0;
  --accent-strong: #53c9b7;
  --warning: #e2bd78;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: radial-gradient(ellipse at 50% -20%, #1c3140 0, var(--bg) 48rem); min-height: 100vh; }
button, input, select { font: inherit; }
button, select, input[type="checkbox"], input[type="range"] { accent-color: var(--accent-strong); }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.app-shell { width: min(100%, 860px); margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 14px max(28px, env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 12px; margin: 8px 0 18px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: #061815; font-weight: 900; letter-spacing: -1px; background: linear-gradient(135deg,#a6f4e5,#5db6bb); box-shadow: 0 6px 24px #65cfbf24; }
.brand-copy { flex: 1; min-width: 0; }
.brand-copy h1 { font-size: 1.12rem; margin: 0; font-weight: 780; letter-spacing: -.4px; }
.brand-copy h1 span { color: var(--accent); }
.brand-copy p { margin: 3px 0 0; font-size: .75rem; color: var(--muted); }
.privacy-badge, .state-badge { border: 1px solid #2b5a53; color: #b6f1e2; background: #16322e; padding: 6px 9px; border-radius: 999px; font-size: .71rem; white-space: nowrap; }
.privacy-badge span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #78dfb8; margin-left: 5px; }
.notice { display: flex; align-items: flex-start; gap: 9px; padding: 11px 13px; margin-bottom: 14px; border: 1px solid #4e452e; border-radius: 13px; background: #2a2418a8; color: #e5d6b2; font-size: .78rem; line-height: 1.65; }
.notice strong { white-space: nowrap; color: #f7dc9b; }
.viewer-card, .controls-card, .about-card { border: 1px solid var(--line); background: linear-gradient(160deg, #151f2d, #101722); border-radius: 20px; padding: 14px; box-shadow: 0 16px 42px #00000020; }
.viewer-head, .section-heading { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
h2 { margin: 0; font-size: 1rem; font-weight: 730; }
.muted { color: var(--muted); font-size: .75rem; line-height: 1.6; margin: 4px 0 0; }
.state-badge { border-color: #37465a; background: #202a39; color: #b7c4d6; font-size: .68rem; }
.stage { position: relative; width: 100%; aspect-ratio: var(--stage-ratio); max-height: 64dvh; overflow: hidden; border-radius: 15px; background: #05080c; isolation: isolate; touch-action: pan-y; }
.stage video, .stage canvas, #threeHost, #threeHost canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.stage video { object-fit: fill; background: #06080c; }
#depthCanvas { display: none; image-rendering: auto; }
#threeHost { display: none; overflow: hidden; }
#threeHost canvas { touch-action: none; }
.stage.mirror video, .stage.mirror #depthCanvas, .stage.mirror #threeHost { transform: scaleX(-1); }
.stage.mirror #threeHost canvas { transform: none; }
.stage-message { position: absolute; z-index: 4; left: 12px; right: 12px; top: 50%; transform: translateY(-50%); margin: auto; max-width: 270px; display: grid; justify-items: center; gap: 8px; text-align: center; color: #e6eef9; padding: 18px 14px; border: 1px solid #ffffff13; border-radius: 16px; background: #111a27d9; backdrop-filter: blur(16px); }
.stage-message strong { font-size: .96rem; }
.stage-message span { color: #aab7c9; font-size: .78rem; line-height: 1.7; }
.camera-glyph { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: #203342; font-size: 1.45rem; color: var(--accent); }
.stage-footer { display: flex; align-items: center; justify-content: space-between; position: absolute; z-index: 3; left: 10px; right: 10px; bottom: 10px; pointer-events: none; direction: ltr; }
.stage-footer span { font-size: .68rem; letter-spacing: .1px; padding: 5px 8px; border-radius: 999px; background: #07101bd4; border: 1px solid #ffffff1d; color: #e0e9f6; backdrop-filter: blur(8px); }
.primary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn { min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; font-size: .83rem; }
.btn.primary { background: linear-gradient(135deg,#a2f0df,#62c9bb); color: #09201d; }
.btn.secondary { color: #dce6f5; background: #202b3a; border-color: #35465a; }
.btn.ghost { grid-column: 1 / -1; color: #c0d0e3; background: #141e2b; border-color: #2e3c50; min-height: 38px; font-size: .76rem; }
.live-status { margin: 10px 2px 0; color: #aab7c9; font-size: .76rem; line-height: 1.7; min-height: 1.4em; }
.controls-card { margin-top: 14px; }
.mode-switch { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; margin: 12px 0 16px; }
.mode-btn { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; text-align: right; gap: 5px; min-height: 64px; padding: 9px 10px; border-radius: 12px; border: 1px solid #2b394d; color: #c0ccdc; background: #111a27; font-size: .77rem; font-weight: 670; }
.mode-btn span { font-size: .64rem; font-weight: 800; color: #71839a; }
.mode-btn.active { border-color: #63c8b8; color: #dffbf4; background: linear-gradient(140deg,#18382f,#14262c); box-shadow: inset 0 0 0 1px #69d5bf18; }
.mode-btn.active span { color: #7fe0cf; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.control-item { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 11px; background: #0d1520a8; border: 1px solid #243246; border-radius: 12px; font-size: .76rem; color: #d0dbea; }
.control-item select { width: 100%; padding: 8px 9px; border-radius: 8px; color: #ecf3fa; background: #1a2737; border: 1px solid #334258; }
.check-item { flex-direction: row; justify-content: space-between; align-items: center; gap: 10px; }
.check-item input { width: 19px; height: 19px; flex: 0 0 auto; }
.slider-item output { float: left; color: var(--accent); direction: ltr; font-variant-numeric: tabular-nums; }
.slider-item input { width: 100%; margin: 2px 0 0; }
.hint { margin: 13px 1px 0; color: #8f9fb3; font-size: .73rem; line-height: 1.8; }
.debug-panel { margin-top: 12px; border: 1px dashed #3c5067; border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: .72rem; color: #a9bacf; }
.debug-panel b { color: #e0ebfb; direction: ltr; font-variant-numeric: tabular-nums; }
.about-card { margin-top: 14px; padding: 14px; }
.about-card summary { cursor: pointer; font-size: .82rem; font-weight: 700; }
.about-content { padding-top: 10px; color: #9baabd; font-size: .76rem; line-height: 1.85; }
.about-content p { margin: 7px 0; }
.about-content b { color: #d8e4f4; }
.footer-note { padding: 16px 4px 0; text-align: center; color: #708096; font-size: .7rem; line-height: 1.7; }
@media (min-width: 680px) {
  .app-shell { padding-left: 22px; padding-right: 22px; }
  .viewer-card, .controls-card, .about-card { padding: 18px; }
  .stage { max-width: 700px; margin: 0 auto; }
  .primary-actions { grid-template-columns: 1fr 1fr auto; }
  .btn.ghost { grid-column: auto; min-width: 190px; }
  .mode-btn { align-items: center; text-align: center; }
}
@media (max-width: 390px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .viewer-card, .controls-card, .about-card { padding: 11px; }
  .state-badge { font-size: .61rem; padding: 5px 7px; }
  .mode-btn { padding: 8px 7px; font-size: .7rem; }
  .control-item { padding: 9px; }
}
.stage .debug-canvas { z-index: 2; pointer-events: none; }
.stage .debug-canvas[hidden] { display: none; }
