:root {
  --bg: #050507;
  --ink: #f3ede4;
  --muted: #a79f93;
  --accent: #ffa334;
  --accent-2: #ffd875;
  --panel: rgba(16, 14, 12, 0.88);
  --line: rgba(255, 190, 120, 0.18);
  --ok: #57e38a;
  --warn: #ffb347;
  --off: #6b645b;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font); touch-action: none; user-select: none; -webkit-user-select: none; }
body.running { cursor: none; }
body.running #hud, body.running .panel, body.running button, body.running input, body.running label, body.running a { cursor: auto; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

#bg { position: fixed; inset: 0; background:
  radial-gradient(1200px 700px at 50% 110%, rgba(255, 120, 30, 0.10), transparent 60%),
  radial-gradient(900px 600px at 50% -20%, rgba(90, 110, 255, 0.07), transparent 60%),
  var(--bg); }

#portalView { position: fixed; inset: 0; z-index: 1; visibility: hidden; overflow: hidden; pointer-events: none; will-change: clip-path; }
#ytWrap { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; pointer-events: none; background: #000; }
#ytHosts, .ythost { position: absolute; inset: 0; }
.ythost { opacity: 0; transition: opacity .25s ease; }
.ythost.active { opacity: 1; }
.ythost iframe, #ytWrap iframe { width: 100%; height: 100%; border: 0; display: block; pointer-events: none; }
.slot-sub { position: absolute; inset: 0; }
video.own-video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; pointer-events: none; }
#dropOverlay { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(5,5,7,.72); border: 3px dashed var(--accent); font-size: clamp(20px, 3vmin, 36px); color: var(--accent-2); pointer-events: none; }
#debug { position: fixed; z-index: 9; left: 12px; top: 64px; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; color: #cfe; background: rgba(0,0,0,.65); padding: 8px 10px; border-radius: 8px; white-space: pre; pointer-events: none; max-width: 60vw; }
.badge.own { background: #1f8f5a; color: #fff; }
body.rec #hud, body.rec #hint, body.rec #toast, body.rec #camPreview, body.rec #debug { display: none !important; }
body.rec #label .lname { font-size: clamp(28px, 4.2vmin, 64px); }
/* OBS browser source: everything outside the portal is transparent so the portal floats over the stream */
html.obs, body.obs { background: transparent !important; }
body.obs #bg, body.obs #start, body.obs #ambient { display: none !important; }
#ambient { position: fixed; inset: 0; z-index: 1; display: none; pointer-events: none; }
#offlineScene { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }

#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 2; pointer-events: none; }

#label { position: fixed; z-index: 3; transform: translateX(-50%); text-align: center; pointer-events: none; text-shadow: 0 2px 18px rgba(0,0,0,.9); animation: fadeUp .6s ease both; max-width: min(90vw, 900px); }
#label .lname { font-size: clamp(22px, 3.2vmin, 48px); font-weight: 700; letter-spacing: .01em; }
#label .lsub { margin-top: .35em; font-size: clamp(13px, 1.7vmin, 24px); color: #e8dccb; display: flex; gap: .8em; justify-content: center; align-items: center; flex-wrap: wrap; }
.badge { font-size: .78em; font-weight: 800; letter-spacing: .08em; padding: .18em .55em; border-radius: 999px; }
.badge.live { background: #e3262e; color: #fff; }
.badge.rec { background: #555; color: #fff; }
.badge.demo { background: rgba(140, 98, 255, .8); color: #fff; }
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

#hint { position: fixed; z-index: 3; left: 50%; bottom: 9vh; transform: translateX(-50%); font-size: clamp(16px, 2.4vmin, 32px); color: var(--accent-2); text-shadow: 0 0 22px rgba(255, 150, 40, .7); animation: pulse 2.4s ease-in-out infinite; pointer-events: none; text-align: center; padding: 0 16px; }
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

#toast { position: fixed; z-index: 30; left: 50%; top: 22px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; font-size: 15px; backdrop-filter: blur(8px); max-width: calc(100vw - 32px); text-align: center; }

#cam { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#camPreview { position: fixed; z-index: 5; right: 16px; bottom: 16px; width: 200px; height: 150px; border-radius: 12px; border: 1px solid var(--line); background: #000; opacity: .85; }

/* HUD */
#hud { position: fixed; z-index: 10; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; transition: opacity .6s; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud.dim { opacity: 0.08; }
#hud.dim:hover { opacity: 1; }
.hud-status { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.chip.ok i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.chip.warn i { background: var(--warn); }
.chip.busy i { background: var(--accent); animation: pulse 1s infinite; }
.chip em { font-style: normal; color: var(--muted); }
.hud-btns { display: flex; gap: 6px; }
.hud-btns button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 18px; cursor: pointer; }
.hud-btns button:hover { border-color: var(--accent); }

/* start overlay */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(5,5,7,.55), rgba(5,5,7,.92)); padding: 16px; }
.start-inner { text-align: center; max-width: 720px; }
.ring-logo { width: 120px; height: 120px; margin: 0 auto 8px; border-radius: 50%; border: 3px solid var(--accent-2); box-shadow: 0 0 24px 4px rgba(255, 150, 40, .8), inset 0 0 24px 4px rgba(255, 150, 40, .6); animation: spin 3s linear infinite; border-top-color: #fff; border-left-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.logo { font-size: clamp(48px, 10vmin, 120px); margin: 0; letter-spacing: .18em; font-weight: 900; background: linear-gradient(180deg, #fff 10%, var(--accent-2) 45%, var(--accent) 90%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 0 18px rgba(255, 140, 30, .55)); }
.tag { font-size: clamp(16px, 2.4vmin, 24px); color: #eadfcf; margin: 6px 0 26px; }
.start-btns { display: flex; flex-direction: column; gap: 12px; align-items: center; }
button.big { min-width: min(420px, 90vw); padding: 16px 22px; font-size: 18px; font-weight: 700; border-radius: 16px; border: 1px solid rgba(255, 190, 120, .45); background: linear-gradient(180deg, rgba(255, 160, 60, .28), rgba(255, 110, 20, .12)); cursor: pointer; transition: transform .15s, box-shadow .15s; }
button.big:hover { transform: translateY(-2px); box-shadow: 0 0 28px rgba(255, 140, 30, .45); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.big.ghost { background: rgba(255,255,255,.03); }
.fine { margin-top: 26px; font-size: 13px; color: var(--muted); line-height: 1.5; }

/* panels */
.panel { position: fixed; z-index: 15; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px 20px 20px; backdrop-filter: blur(12px); box-shadow: 0 20px 80px rgba(0,0,0,.6); user-select: text; }
.panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel h2 { margin: 0; font-size: 20px; }
.panel .x { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
.phone-body { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.qr { background: #fff; border-radius: 12px; padding: 10px; aspect-ratio: 1; display: grid; place-items: center; }
.qr svg { width: 100%; height: auto; display: block; }
.qr-wait { color: #333; font-size: 32px; }
.steps ol { margin: 0 0 10px; padding-left: 20px; line-height: 1.55; }
.code b { font-size: 26px; letter-spacing: .2em; color: var(--accent-2); }
.st { margin-left: 8px; font-size: 13px; color: var(--muted); }
.st-connected { color: var(--ok); }
.url code { font-size: 12px; word-break: break-all; color: var(--muted); }
.warn { color: var(--warn); font-size: 14px; }
.note { color: var(--muted); font-size: 13px; }
.rows { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.col { flex-direction: column; align-items: stretch; }
.lbl { min-width: 150px; color: var(--muted); font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 12px; cursor: pointer; font-size: 14px; }
.seg button.on { background: rgba(255, 160, 60, .28); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chipbox { border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 14px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.tog { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
input[type=range] { width: 200px; accent-color: var(--accent); }
.val { font-size: 13px; color: var(--muted); }
.addcam { display: flex; gap: 6px; flex-wrap: wrap; }
.addcam input { flex: 1 1 200px; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--ink); font: inherit; }
.addcam button, .row > button { border: 1px solid rgba(255, 190, 120, .45); background: rgba(255, 160, 60, .2); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.uclist { list-style: none; margin: 6px 0 0; padding: 0; }
.uclist li { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
button.sm { padding: 3px 10px; font-size: 13px; border-radius: 8px; cursor: pointer; }
.link { color: var(--accent-2); font-size: 14px; }
.gestures { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.gestures li { display: grid; grid-template-columns: 40px minmax(160px, 1fr) 1.3fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.gi { font-size: 24px; text-align: center; }
.ga { font-weight: 600; }
.gb { color: var(--muted); font-size: 14px; }
.keys { font-size: 13px; color: var(--muted); line-height: 1.6; }

@media (max-width: 640px) {
  .phone-body { grid-template-columns: 1fr; }
  .qr { max-width: 240px; margin: 0 auto; }
  .gestures li { grid-template-columns: 34px 1fr; }
  .gb { grid-column: 2; }
  #camPreview { width: 120px; height: 90px; }
  .lbl { min-width: 100%; }
}
