/* SyncCinema - shared styles (viewer + host).  Themes are CSS variables. */
:root, [data-theme="dark"] {
  --bg: #14151a; --surface: #1b1d24; --surface2: #23262f; --border: #2f3340;
  --text: #e7e9ef; --muted: #8e94a3; --accent: #7c6cf0; --accent-ink: #fff;
  --accent-soft: rgba(124,108,240,.16); --video-bg: #050507;
  --good: #3ecf8e; --bad: #ff6b6b; --warn: #f5b94a; --shadow: 0 8px 30px rgba(0,0,0,.45);
  --overlay: rgba(14,15,19,.92); color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f3f4f8; --surface: #ffffff; --surface2: #eceef3; --border: #d8dbe4;
  --text: #1b1e27; --muted: #5b6272; --accent: #3b6fe0; --accent-ink: #fff;
  --accent-soft: rgba(59,111,224,.12); --video-bg: #0a0b0f;
  --good: #1f9d68; --bad: #d64545; --warn: #b87a10; --shadow: 0 8px 26px rgba(30,40,70,.16);
  --overlay: rgba(255,255,255,.94); color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; }

/* ---------- controls ---------- */
.btn { background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 7px 12px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: transparent; border: 1px solid transparent; border-radius: 9px; padding: 6px 9px; cursor: pointer;
  color: inherit; min-width: 36px; min-height: 36px; }
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
input[type=text], input[type=search], input[type=number], select, .field {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; min-width: 0; }
input[type=range] { accent-color: var(--accent); min-width: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.good { background: var(--good); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

/* ---------- join screen ---------- */
.join { min-height: 100%; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent), var(--bg); }
.join-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 26px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.join-card h1 { font-size: 24px; }
.join-card form { display: grid; gap: 12px; }
.join-card label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
.join-card input { font-weight: 400; }
#joinError { color: var(--bad); min-height: 1.2em; margin: 0; }
.theme-row { display: flex; align-items: center; justify-content: space-between; color: var(--muted); }

/* ---------- cinema layout ---------- */
.cinema { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 350px; background: var(--bg); }
.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 12px 0 12px 12px; gap: 10px; }
.screen { position: relative; flex: 1; min-height: 0; background: var(--video-bg); border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; border: 1px solid var(--border); }
.screen video { width: 100%; height: 100%; object-fit: contain; background: var(--video-bg); display: block; }
.status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; gap: 10px; align-items: center;
  background: rgba(8,8,12,.72); color: #eee; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 86%;
  text-align: center; pointer-events: none; backdrop-filter: blur(4px); }
.status.error { background: rgba(120,20,20,.85); pointer-events: auto; }
.status.hidden { opacity: 0; transition: opacity .6s; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin 1s linear infinite; flex: none; }
.spinner.off { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.gesture { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); }

.bar { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: flex-end; gap: 6px; padding: 8px;
  opacity: 0; transition: opacity .25s; background: linear-gradient(rgba(0,0,0,.55), transparent); }
.screen:hover .bar, .bar:focus-within, .cinema.show-bar .bar { opacity: 1; }
.bar .icon-btn { color: #fff; background: rgba(20,20,28,.6); border-color: rgba(255,255,255,.14); }
.badge { position: absolute; top: 2px; right: 2px; background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 11px; min-width: 17px; height: 17px; display: grid; place-items: center; padding: 0 4px; }
.icon-btn.rel { position: relative; }

.toasts { position: absolute; left: 12px; bottom: 12px; display: grid; gap: 6px; max-width: min(360px, 80%); pointer-events: none; }
.toast { background: rgba(10,10,14,.78); color: #f1f1f4; border-radius: 10px; padding: 6px 10px; font-size: 13px;
  animation: fadein .25s; }
.toast b { color: #b9afff; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ---------- side panel (voice + chat) ---------- */
.side { min-width: 0; min-height: 0; padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.side-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; background: var(--surface); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.voice-panel { display: grid; gap: 8px; }
.voice-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mic { font-weight: 600; }
.mic.live { background: color-mix(in srgb, var(--good) 22%, var(--surface2)); border-color: var(--good); }
.mic.muted { background: color-mix(in srgb, var(--bad) 18%, var(--surface2)); border-color: var(--bad); }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 150px; overflow: auto; }
.person { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px;
  color: #fff; flex: none; box-shadow: 0 0 0 2px transparent; transition: box-shadow .15s; }
.person.speaking .avatar { box-shadow: 0 0 0 2px var(--good); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 40%, transparent); } }
.person .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; background: var(--accent-soft); color: var(--accent);
  border-radius: 6px; padding: 1px 5px; }
.devices { font-size: 13px; } .devices summary { cursor: pointer; color: var(--muted); }
.devices label { display: grid; gap: 3px; margin-top: 6px; }
.slider-row { display: flex; align-items: center; gap: 8px; } .slider-row input { flex: 1; }

.chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.chat-log { flex: 1; min-height: 120px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; scroll-behavior: smooth; }
.msg { display: grid; gap: 1px; }
.msg .meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
.msg .meta .name { color: var(--text); font-weight: 600; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.react .text { font-size: 22px; line-height: 1.1; }
.msg.mine .meta .name { color: var(--accent); }
.new-pill { align-self: center; position: sticky; bottom: 0; }
.reactions { display: flex; gap: 4px; flex-wrap: wrap; }
.reactions .icon-btn { font-size: 18px; padding: 2px 6px; min-width: 34px; }
.chat-form { display: flex; gap: 6px; position: relative; }
.chat-form input { flex: 1; min-width: 0; }
.emoji-pop { position: absolute; bottom: 44px; right: 0; width: min(300px, 92vw); max-height: 220px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; z-index: 5; }
.emoji-pop button { background: none; border: 0; font-size: 20px; padding: 3px; border-radius: 6px; cursor: pointer; }
.emoji-pop button:hover, .emoji-pop button:focus-visible { background: var(--accent-soft); }
.only-fs { display: none; }

/* ---------- immersive: native fullscreen (viewer + host) / theatre (host) ---------- */
.cinema.immersive { display: block; position: relative; background: #000; }
.cinema.immersive .stage { padding: 0; height: 100%; }
.cinema.immersive .screen { border: 0; border-radius: 0; }
.cinema.immersive .side { position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); z-index: 20;
  background: var(--overlay); backdrop-filter: blur(8px); border-left: 1px solid var(--border);
  transform: translateX(105%); transition: transform .22s ease; visibility: hidden; }
.cinema.immersive.drawer-open .side { transform: none; visibility: visible; }
.cinema.immersive .only-fs { display: inline-flex; }
.cinema.immersive .bar { opacity: 0; }
.cinema.immersive.show-bar .bar, .cinema.immersive .bar:focus-within { opacity: 1; }
.cinema.immersive:not(.show-bar) .screen { cursor: none; }

/* ---------- host dashboard ---------- */
.topbar { height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--surface);
  border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 16px; flex: 1; white-space: nowrap; }
.host-page { height: 100%; display: grid; grid-template-rows: 52px minmax(0, 1fr); }
.host-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; min-height: 0; height: 100%; }
.panel { min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 12px; overflow: hidden; }
.library { border-right: 1px solid var(--border); }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; font-size: 13px; }
.crumbs button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.crumbs button:hover { background: var(--accent-soft); }
.lib-tools { display: flex; gap: 6px; } .lib-tools input { flex: 1; }
.lib-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; display: grid; align-content: start; gap: 2px; }
.lib-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.lib-item:hover { background: var(--surface2); }
.lib-item.current { border-color: var(--accent); background: var(--accent-soft); }
.lib-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .sz { color: var(--muted); font-size: 12px; flex: none; }
.lib-item.disabled { opacity: .45; cursor: not-allowed; }
.center { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.host-grid .stage { padding: 12px; flex: 1; }
.transport { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.transport .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.transport .seek { flex: 1; width: 100%; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 6.5em; }
.now { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.now .title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding-bottom: 6px; flex-wrap: wrap; }
.tab { background: none; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tabpanel { flex: 1; min-height: 0; overflow: auto; display: none; }
.tabpanel.active { display: flex; flex-direction: column; gap: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.form-grid { display: grid; gap: 10px; }
.form-grid label { display: grid; gap: 4px; font-size: 13px; }
.invite { display: flex; gap: 6px; } .invite input { flex: 1; }
.note { font-size: 12px; color: var(--muted); }
.warn-box { border: 1px solid var(--warn); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.sec-title { font-weight: 700; margin-bottom: 4px; }
.host-grid.cinema.immersive .library, .host-grid.cinema.immersive .tabs, .host-grid.cinema.immersive .tabpanel:not(#tab-chat),
.host-grid.cinema.immersive .topbar { display: none; }
.host-grid.cinema.immersive .center { height: 100%; }
.host-grid.cinema.immersive .transport { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 10; opacity: 0;
  transition: opacity .25s; background: var(--overlay); backdrop-filter: blur(6px); }
.host-grid.cinema.immersive.show-bar .transport, .host-grid.cinema.immersive .transport:focus-within { opacity: 1; }
.host-grid.cinema.immersive .now { display: none; }
.host-grid.cinema.immersive .side .tabpanel#tab-chat { display: flex; }
body.theatre .topbar { display: none; }
body.theatre .host-page { grid-template-rows: minmax(0, 1fr); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .cinema:not(.immersive) { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; min-height: 100%; }
  .stage { padding: 0; }
  .screen { flex: none; aspect-ratio: 16 / 9; border-radius: 0; border-left: 0; border-right: 0; }
  .side { overflow: visible; }
  .chat-log { min-height: 220px; max-height: 45vh; }
  .cinema.collapsed .chat-panel { display: none; }
  .host-grid { grid-template-columns: 1fr; height: auto; }
  .host-page { height: auto; }
  .library { border-right: 0; border-bottom: 1px solid var(--border); max-height: 40vh; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- host extras ---------- */
button.lib-item { width: 100%; text-align: left; background: transparent; color: inherit; font: inherit; }
.lib-item .ic { flex: none; width: 1.4em; text-align: center; }
.lib-list li { list-style: none; }
.seek { width: 100%; }
#tab-chat { gap: 10px; }
.host-grid .side { padding: 12px; }

/* ---------- fullscreen / immersive: fill the screen, keep the picture ratio (never stretch) ---------- */
.cinema.immersive { height: 100vh; height: 100dvh; background: #000; }
.cinema.immersive:not(.host-grid) { position: fixed; inset: 0; z-index: 50; }
.cinema.immersive .stage { height: 100%; padding: 0; }
.cinema.immersive .screen { flex: 1; width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; background: #000; }
.cinema.immersive .screen video { width: 100%; height: 100%; object-fit: contain; }
