:root {
  color-scheme: dark;
  --bg: #080b10;
  --panel: #11161e;
  --panel-2: #171e28;
  --line: #26303d;
  --muted: #8793a3;
  --text: #f5f7fa;
  --accent: #4df0b3;
  --danger: #ff5b66;
  --amber: #ffca69;
  font-family: Inter, "Noto Sans TC", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar, .mobile-header {
  height: 72px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); background: rgba(8, 11, 16, .94); backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 750; letter-spacing: .02em; }
.brand-mark { width: 22px; height: 16px; border: 2px solid var(--accent); border-radius: 4px; position: relative; }
.brand-mark::after { content: ""; position: absolute; width: 7px; height: 8px; right: -8px; top: 2px; background: var(--accent); clip-path: polygon(0 50%, 100% 0, 100% 100%); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.status-badge, .silent-badge, .camera-count { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .875rem; }
.status-badge::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 8px; background: var(--amber); box-shadow: 0 0 10px color-mix(in srgb, var(--amber) 70%, transparent); }
.status-badge[data-state="ready"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.status-badge[data-state="ready"]::before { background: var(--accent); }
.status-badge[data-state="error"]::before { background: var(--danger); }
.secondary-button, .copy-row button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 9px 14px; border-radius: 8px; }
.secondary-button:hover, .copy-row button:hover:not(:disabled) { border-color: #455365; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.viewer-layout { min-height: calc(100vh - 72px); display: grid; grid-template-columns: minmax(0, 1fr) 370px; transition: grid-template-columns .24s ease; }
.viewer-layout.invite-collapsed { grid-template-columns: minmax(0, 1fr) 0; }
.stage { padding: 28px; min-width: 0; display: flex; flex-direction: column; }
.stage-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 20px; }
.stage-controls { display: flex; align-items: center; gap: 14px; }
.size-control { display: grid; grid-template-columns: auto minmax(120px, 190px) 52px; align-items: center; gap: 9px; color: var(--muted); font-size: .78rem; }
.size-control input { accent-color: var(--accent); cursor: ew-resize; }
.size-control output { color: #c7d0da; font-variant-numeric: tabular-nums; text-align: right; }
.eyebrow { display: block; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .18em; margin-bottom: 7px; }
h1, h2, p { margin-top: 0; }
.stage-heading h1 { font-size: clamp(1.65rem, 3vw, 2.45rem); margin-bottom: 0; letter-spacing: -.04em; }
.camera-grid { flex: 1; min-height: 460px; display: grid; gap: 12px; align-content: stretch; position: relative; }
.camera-grid.has-cameras { display: flex; flex-wrap: wrap; align-content: flex-start; align-items: flex-start; }
.empty-state { place-self: stretch; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; border: 1px dashed #2e3947; border-radius: 14px; background: radial-gradient(circle at 50% 30%, rgba(77, 240, 179, .06), transparent 36%), #0b0f15; }
.empty-state h2 { margin: 22px 0 8px; font-size: 1.25rem; }
.empty-state p { color: var(--muted); max-width: 420px; padding: 0 24px; line-height: 1.7; }
.empty-lens, .camera-symbol { width: 86px; height: 86px; border: 1px solid #2c3845; border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 0 30px rgba(77,240,179,.05), 0 0 0 12px rgba(255,255,255,.015); }
.empty-lens span, .camera-symbol span { width: 42px; height: 42px; border: 7px solid var(--accent); border-radius: 50%; box-shadow: 0 0 24px rgba(77,240,179,.18); position: relative; }
.empty-lens span::after, .camera-symbol span::after { content: ""; width: 7px; height: 7px; background: var(--accent); border-radius: 50%; position: absolute; inset: 0; margin: auto; }

.camera-card { flex: 0 0 min(var(--camera-width, 520px), 100%); width: min(var(--camera-width, 520px), 100%); height: min(var(--camera-height, 293px), 70vh); min-width: 0; min-height: 158px; position: relative; overflow: hidden; border-radius: 12px; background: #05070a; border: 1px solid var(--line); }
.camera-card video { width: 100%; height: 100%; object-fit: contain; display: block; }
.camera-title-editor { position: absolute; z-index: 3; top: 12px; left: 12px; width: min(190px, calc(100% - 70px)); padding: 7px 8px; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; background: rgba(4,7,10,.72); backdrop-filter: blur(8px); }
.camera-title-editor label { display: block; }
.camera-title-editor input { display: block; width: 100%; border: 0; border-bottom: 1px solid transparent; outline: 0; padding: 3px 2px; background: transparent; color: #fff; font-size: .9rem; font-weight: 750; text-shadow: 0 1px 3px #000; }
.camera-title-editor input::placeholder { color: rgba(255,255,255,.53); font-weight: 500; }
.camera-title-editor input:focus { border-bottom-color: var(--accent); }
.camera-meta { position: absolute; inset: auto 0 0; padding: 34px 14px 13px; display: flex; align-items: end; justify-content: space-between; background: linear-gradient(transparent, rgba(0,0,0,.84)); }
.camera-meta strong, .camera-meta span { display: block; }
.camera-meta strong { font-size: .95rem; }
.camera-meta span { color: #abb5c1; font-size: .75rem; margin-top: 4px; }
.icon-button { width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; background: rgba(8,11,16,.68); color: white; }
.waiting-layer { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
.waiting .waiting-layer { display: flex; }
.spinner { width: 17px; height: 17px; border: 2px solid #39424d; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.invite-panel { min-width: 0; padding: 28px; background: var(--panel); border-left: 1px solid var(--line); overflow: hidden; opacity: 1; transform: translateX(0); transition: opacity .18s ease, transform .24s ease, padding .24s ease, border .24s ease; }
.invite-collapsed .invite-panel { padding-left: 0; padding-right: 0; border-left-width: 0; opacity: 0; transform: translateX(100%); pointer-events: none; }
.panel-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }
.panel-heading > div { min-width: 0; }
.panel-heading h2 { margin: 0; font-size: 1.25rem; }
.panel-heading .eyebrow { margin-bottom: 3px; }
.panel-toggle { margin-left: auto; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: #0b1017; color: #cbd3dc; font-size: .75rem; }
.panel-toggle:hover { border-color: #455365; }
.step-number { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); color: var(--accent); border-radius: 9px; font: 800 .78rem ui-monospace, monospace; }
.qr-frame { aspect-ratio: 1; width: min(100%, 270px); margin: 0 auto 22px; padding: 12px; border-radius: 12px; background: #fff; display: grid; place-items: center; }
.qr-frame img { display: block; width: 100%; height: 100%; }
.qr-placeholder { color: #5b6572; text-align: center; line-height: 1.5; font-size: .9rem; padding: 20px; }
.instructions { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 11px; color: #c1c8d0; font-size: .9rem; }
.instructions li { display: flex; align-items: center; gap: 10px; }
.instructions li span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: #212a35; color: var(--accent); font-size: .72rem; font-weight: 800; }
.field-label { display: block; color: var(--muted); font-size: .8rem; margin-bottom: 8px; }
.copy-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.copy-row input { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: #090d12; color: #dfe5eb; padding: 10px 12px; font-size: .78rem; }
.copy-row button:disabled { cursor: wait; opacity: .45; }
.room-line { margin-top: 21px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--muted); font-size: .83rem; }
.room-line strong { color: var(--text); letter-spacing: .12em; font-family: ui-monospace, monospace; }
.privacy-note { color: #6f7a88; font-size: .78rem; line-height: 1.55; margin: 14px 0 0; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px); opacity: 0; background: var(--accent); color: #07110d; padding: 10px 16px; border-radius: 8px; font-weight: 800; transition: .2s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.camera-page { min-height: 100dvh; background: radial-gradient(circle at 50% 10%, rgba(77,240,179,.075), transparent 34%), var(--bg); }
.mobile-header { height: 64px; padding: 0 18px; }
.silent-badge { font-size: .75rem; padding: 6px 10px; }
.camera-main { min-height: calc(100dvh - 64px); }
.start-panel { min-height: calc(100dvh - 64px); width: min(100%, 560px); margin: auto; padding: 52px 24px 34px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.start-panel .camera-symbol { margin-bottom: 32px; }
.start-panel h1 { max-width: 500px; font-size: clamp(2rem, 8vw, 3.2rem); letter-spacing: -.05em; line-height: 1.08; margin-bottom: 16px; }
.start-panel > p { color: var(--muted); line-height: 1.65; }
.quality-choice { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 14px 15px; margin: 25px 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); text-align: left; }
.quality-choice select { border: 0; background: transparent; color: var(--accent); outline: 0; text-align: right; }
.quality-choice option { background: var(--panel); color: var(--text); }
.primary-button { width: 100%; border: 0; border-radius: 10px; padding: 16px; background: var(--accent); color: #06110d; font-weight: 850; font-size: 1.05rem; box-shadow: 0 12px 30px rgba(77,240,179,.13); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.permission-note { margin-top: 18px !important; font-size: .78rem; }
.error-box { width: 100%; margin-top: 14px !important; padding: 12px; color: #ffdadd !important; background: rgba(255,91,102,.1); border: 1px solid rgba(255,91,102,.25); border-radius: 8px; font-size: .87rem; }
.live-panel { position: fixed; inset: 0; background: #000; }
.live-panel video { width: 100%; height: 100%; object-fit: cover; }
.live-overlay { position: absolute; inset: env(safe-area-inset-top) 0 auto; display: flex; align-items: flex-start; justify-content: space-between; padding: 20px; background: linear-gradient(rgba(0,0,0,.72), transparent); }
.live-status, .quality-label { display: block; }
.live-status { font-weight: 800; }
.live-status::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; background: var(--amber); border-radius: 50%; }
.live-status[data-state="live"]::before { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.quality-label { color: rgba(255,255,255,.72); font-size: .78rem; margin-top: 6px; }
.round-button { width: 52px; height: 52px; border: 1px solid rgba(255,255,255,.32); border-radius: 50%; background: rgba(0,0,0,.44); color: white; }
.mobile-controls { position: absolute; inset: auto 0 max(22px, env(safe-area-inset-bottom)); display: flex; justify-content: center; }
.stop-button { border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 13px 20px; background: rgba(0,0,0,.68); color: white; backdrop-filter: blur(10px); }
.stop-button span { display: inline-block; width: 10px; height: 10px; margin-right: 9px; border-radius: 2px; background: var(--danger); }
.fatal { min-height: 100dvh; max-width: 560px; margin: auto; padding: 50px 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.fatal .camera-symbol { margin-bottom: 28px; }
.fatal p { color: var(--muted); line-height: 1.7; }

@media (max-width: 900px) {
  .viewer-layout { grid-template-columns: 1fr; }
  .viewer-layout.invite-collapsed { grid-template-columns: 1fr; }
  .invite-collapsed .invite-panel { display: none; }
  .invite-panel { border-left: 0; border-top: 1px solid var(--line); }
  .qr-frame { width: min(76vw, 290px); }
  .stage-heading { align-items: flex-start; gap: 14px; }
  .stage-controls { align-items: flex-end; flex-direction: column-reverse; gap: 8px; }
}
@media (max-width: 560px) {
  .topbar { height: auto; min-height: 68px; padding: 13px 16px; align-items: flex-start; }
  .topbar-actions { align-items: flex-end; flex-direction: column-reverse; gap: 6px; }
  .status-badge { font-size: .72rem; padding: 6px 9px; }
  .secondary-button { padding: 7px 10px; font-size: .78rem; }
  .viewer-layout { min-height: calc(100vh - 68px); }
  .stage, .invite-panel { padding: 20px 16px; }
  .stage-heading { display: grid; }
  .stage-controls { align-items: stretch; }
  .size-control { grid-template-columns: auto minmax(90px, 1fr) 48px; }
  .camera-grid { min-height: 430px; }
  .camera-card { width: 100%; flex-basis: 100%; height: clamp(180px, var(--camera-height, 293px), 70vh); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
