:root {
  color-scheme: dark;
  --glass: rgba(0, 0, 0, .42);
  --glass-strong: rgba(10, 10, 12, .78);
  --line: rgba(255, 255, 255, .22);
  --accent: #4fc3f7;
  --live: #ff3b30;
  --sa-t: env(safe-area-inset-top); --sa-b: env(safe-area-inset-bottom);
  --sa-l: env(safe-area-inset-left); --sa-r: env(safe-area-inset-right);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: #f2f2f2;
  font: 15px/1.35 -apple-system, system-ui, sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Login ---------- */
#login { max-width: 460px; margin: 0 auto; padding: calc(24px + var(--sa-t)) 18px calc(24px + var(--sa-b));
  height: 100%; overflow: auto; }
#login h1 { font-weight: 700; letter-spacing: .02em; margin: 0 0 18px; }
.field { display: block; margin-bottom: 16px; font-size: 13px; color: #bbb; }
.field input, .field select, #relayUrl { display: block; width: 100%; margin-top: 6px; padding: 11px 12px;
  background: #16161a; border: 1px solid #333; border-radius: 10px; color: #fff; font-size: 16px; }
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 6px;
  max-height: 46vh; overflow: auto; padding: 2px; }
.chars button { background: #16161a; border: 2px solid transparent; border-radius: 10px; padding: 4px; aspect-ratio: 1; }
.chars button.sel { border-color: var(--accent); background: #1e2a31; }
.chars img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.primary { background: var(--accent); color: #000; border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600; }
#enter { width: 100%; font-size: 17px; }
.error { color: #ff8a80; }
.adv { margin-top: 18px; color: #888; font-size: 13px; }

/* ---------- Camera ---------- */
#cam { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#preview.mirror { transform: scaleX(-1); }

.pill, .icon { background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.pill { padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.icon { width: 44px; height: 44px; display: inline-grid; place-items: center; font-size: 19px; padding: 0; }
.icon.on { background: var(--accent); color: #000; border-color: var(--accent); }
.icon.off { background: rgba(255, 59, 48, .75); border-color: transparent; }

#topbar { position: absolute; top: calc(10px + var(--sa-t)); left: calc(10px + var(--sa-l)); right: calc(10px + var(--sa-r));
  display: flex; gap: 8px; align-items: center; }
#topbar .spacer { flex: 1; }
.status.is-live { background: var(--live); border-color: var(--live); font-weight: 700; }
.status.is-live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fff; margin-right: 6px; vertical-align: 1px; }
.status.warn { background: rgba(255, 149, 0, .85); color: #000; border-color: transparent; }

#pad { position: absolute; left: calc(12px + var(--sa-l)); top: 40%; transform: translateY(-50%);
  display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); gap: 4px;
  grid-template-areas: ". up ." "left pos right" ". down ."; touch-action: none; }
#pad button { border-radius: 14px; border: 1px solid var(--line); background: var(--glass); font-size: 18px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); user-select: none; -webkit-user-select: none; }
#pad button.held { background: var(--accent); color: #000; }
#pad [data-dir=up] { grid-area: up; } #pad [data-dir=down] { grid-area: down; }
#pad [data-dir=left] { grid-area: left; } #pad [data-dir=right] { grid-area: right; }
#padPos { grid-area: pos; display: grid; place-items: center; font-size: 11px; color: #ddd; text-shadow: 0 1px 2px #000; }
#side { position: absolute; right: calc(10px + var(--sa-r)); top: 40%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 10px; }

#bottom { position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 calc(12px + var(--sa-r)) calc(14px + var(--sa-b)) calc(12px + var(--sa-l)); }
#bottom .row { display: flex; align-items: center; justify-content: space-between; }
.icon-spacer { width: 44px; }
#zooms { display: flex; justify-content: center; gap: 6px; margin-bottom: 12px; }
#zooms button { min-width: 42px; height: 34px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--glass); font-size: 13px; padding: 0 8px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#zooms button.sel { color: #ffd60a; font-weight: 700; }
.live { min-width: 150px; height: 56px; border-radius: 999px; border: 3px solid #fff; background: rgba(255, 59, 48, .85);
  font-size: 17px; font-weight: 700; }
.live.on { background: transparent; border-color: var(--live); color: var(--live); }

/* Semi-transparent chat over the video */
#chatFeed { position: absolute; left: calc(10px + var(--sa-l)); right: 70px; bottom: calc(130px + var(--sa-b));
  max-height: 38vh; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
  pointer-events: none; overflow: hidden; }
.msg { align-self: flex-start; max-width: 100%; background: rgba(0, 0, 0, .38); border-radius: 12px;
  padding: 4px 9px; font-size: 14px; text-shadow: 0 1px 2px #000; transition: opacity .8s; word-wrap: break-word; }
.msg b { color: var(--accent); font-weight: 600; margin-right: 6px; }
.msg.sys { color: #ffd60a; font-style: italic; }
.msg.fade { opacity: 0; }

#chatPanel { position: absolute; left: 0; right: 0; bottom: 0; top: 35%;
  background: linear-gradient(transparent, rgba(0, 0, 0, .7) 12%); display: flex; flex-direction: column;
  padding: 0 calc(10px + var(--sa-r)) calc(10px + var(--sa-b)) calc(10px + var(--sa-l)); }
#chatLog { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 30px;
  touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#chatForm { display: flex; gap: 6px; margin-top: 8px; }
#chatInput { flex: 1; min-width: 0; padding: 11px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .55); font-size: 16px; }
#chatForm .primary { border-radius: 999px; }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 75%; overflow: auto; touch-action: pan-y;
  background: var(--glass-strong); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: 16px 16px 0 0; padding: 14px calc(16px + var(--sa-r)) calc(16px + var(--sa-b)) calc(16px + var(--sa-l)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet .field select { background: #222; }
.wrap { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.wrap button { background: #222; border: 1px solid #444; border-radius: 999px; padding: 7px 11px; font-size: 13px; }
.wrap button.sel { background: var(--accent); color: #000; border-color: var(--accent); }
.stats { font: 12px/1.45 ui-monospace, Menlo, monospace; white-space: pre-wrap; color: #9a9a9a; }
.danger { width: 100%; padding: 12px; border-radius: 10px; background: #3a1414; border: 1px solid #6b2020; color: #ff8a80; }
#roomsList button { display: flex; width: 100%; justify-content: space-between; gap: 8px; padding: 11px 12px; margin-bottom: 6px;
  background: #1c1c20; border: 1px solid #333; border-radius: 10px; text-align: left; }
#roomsList button.here { border-color: var(--accent); }
#roomsList small { color: #999; }

#toast { position: absolute; left: 50%; top: calc(64px + var(--sa-t)); transform: translateX(-50%); max-width: 88%;
  background: var(--glass-strong); padding: 9px 14px; border-radius: 12px; font-size: 14px; text-align: center; }
