:root {
  --bg: #07070b;
  --panel: rgba(28, 28, 38, 0.62);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f4f4f8;
  --muted: #9a9ab0;
  --accent: #ff6a4d;
  --accent-2: #ff9a5c;
  --danger: #ff4d5e;
  --ok: #3ddc84;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif; overflow: hidden;
  -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
input { -webkit-user-select: text; user-select: text; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; border-radius: 10px; padding: 9px 16px;
  transition: transform .08s, background .15s, opacity .15s; }
button:active { transform: scale(.96); }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0b06; font-weight: 600; }
button.ghost { background: rgba(255,255,255,.08); }
button.ghost:hover { background: rgba(255,255,255,.15); }
button.danger { background: rgba(255,77,94,.18); color: #ff8b97; }
button.danger:hover { background: rgba(255,77,94,.3); }
button.small { padding: 7px 12px; font-size: 13px; }
button.icon { background: rgba(255,255,255,.08); width: 40px; height: 36px; padding: 0; font-size: 15px; }
button.icon:hover { background: rgba(255,255,255,.17); }
button.icon.big { width: 52px; height: 42px; font-size: 18px; background: rgba(255,255,255,.16); }
button.icon.off { background: rgba(255,77,94,.28); }

/* Lobby */
#lobby { height: 100%; display: grid; place-items: center;
  background: radial-gradient(900px 600px at 50% 30%, #1d1426 0%, var(--bg) 70%); }
.card { width: 380px; padding: 36px 32px; text-align: center; background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 22px;
  -webkit-backdrop-filter: blur(30px) saturate(1.4); backdrop-filter: blur(30px) saturate(1.4); }
.logo { display: block; margin: -6px auto 2px; filter: drop-shadow(0 10px 24px rgba(0,0,0,.45)); }
h1 { margin: 6px 0 2px; font-size: 26px; letter-spacing: -.02em; }
.sub { color: var(--muted); margin: 0 0 26px; }
label { display: block; text-align: left; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
#code, #name { width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--panel-border);
  background: rgba(0,0,0,.35); color: var(--text); font-size: 15px; outline: none; }
#code { font-family: ui-monospace, Menlo, monospace; font-size: 30px; font-weight: 600; text-align: center;
  letter-spacing: .4em; text-indent: .4em; text-transform: uppercase; padding: 8px 6px; }
#code:focus, #name:focus { border-color: var(--accent); }
#code::placeholder { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif; font-size: 15px; font-weight: 400; letter-spacing: .02em; text-indent: 0; text-transform: none; color: rgba(154,154,176,.7); }
label.second { margin-top: 16px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 18px; }
#join { width: 100%; padding: 12px; font-size: 15px; }
.status { min-height: 18px; margin: 10px 0 0; color: var(--accent-2); font-size: 13px; }

/* Room */
#room { position: fixed; inset: 0; background: #000; }
#room { --side: var(--sidew, 264px); }
#room.nosidebar { --side: 0px; }
#stage { position: absolute; top: 0; bottom: 0; left: 0; right: var(--side); display: grid; place-items: center; transition: right .25s; }
#stage video { width: 100%; height: 100%; object-fit: contain; background: #000; }
#empty { position: absolute; text-align: center; }
#empty .big { font-size: 60px; }
#empty p { color: var(--muted); }
#empty .hint { margin: 10px 0 0; }
#dropHint { position: absolute; inset: 14px; border: 2px dashed var(--accent); border-radius: 18px;
  display: grid; place-items: center; font-size: 20px; background: rgba(255,106,77,.12); pointer-events: none; }

/* Sidebar: people (JS-sized grid, speaker on top) + chat. Width is draggable via #divider. */
#side { position: absolute; top: 0; right: 0; bottom: 0; width: var(--side); padding: 38px 12px 12px;
  display: flex; flex-direction: column; gap: 12px; overflow: hidden;
  background: rgba(14, 12, 22, 0.94); border-left: 1px solid var(--panel-border); z-index: 5; transition: transform .25s, width .25s; }
#room.nosidebar #side { transform: translateX(100%); }
#tiles { flex: 1 1 auto; min-height: 0; display: grid; gap: 10px; justify-content: center; align-content: start; }
.tile { position: relative; border-radius: 14px; overflow: hidden; width: 100%; aspect-ratio: 16/10;
  background: #111118; border: 1px solid var(--panel-border); box-shadow: 0 6px 22px rgba(0,0,0,.45); transition: box-shadow .2s; }
.tile.speaking { box-shadow: 0 0 0 2px var(--accent), 0 0 22px rgba(255,106,77,.55); }

/* Chat */
#chat { flex: 0 0 clamp(150px, 30%, 300px); min-height: 0; display: flex; flex-direction: column; border-radius: 14px; overflow: hidden;
  background: rgba(255,255,255,.04); border: 1px solid var(--panel-border); }
.chatHead { padding: 7px 12px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--panel-border); }
#chatLog { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; -webkit-user-select: text; user-select: text; }
.msg { align-self: stretch; display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; border-radius: 10px;
  background: rgba(255,255,255,.07); font-size: 13px; line-height: 1.35; }
.msg .who { flex: 0 0 auto; max-width: 42%; font-weight: 600; color: var(--accent-2); overflow-wrap: anywhere; }
.msg .who::after { content: ":"; }
.msg .txt { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.msg.mine { background: rgba(255,106,77,.2); }
.msg.mine .who { color: #ffd2a8; }
#chatForm { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--panel-border); }
#chatInput { flex: 1; min-width: 0; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--panel-border);
  background: rgba(0,0,0,.35); color: var(--text); font-size: 13px; outline: none; }
#chatInput:focus { border-color: var(--accent); }

/* Draggable divider between movie and sidebar */
#divider { position: absolute; top: 0; bottom: 0; right: calc(var(--side) - 6px); width: 12px; cursor: col-resize; z-index: 8; touch-action: none; transition: right .25s; }
#divider::after { content: ""; position: absolute; left: 4px; top: 50%; width: 4px; height: 56px; margin-top: -28px; border-radius: 4px; background: rgba(255,255,255,.3); opacity: 0; transition: opacity .2s; }
#divider:hover::after, #room.dragging #divider::after { opacity: 1; }
#room.nosidebar #divider { display: none; }
#room.dragging, #room.dragging * { cursor: col-resize !important; -webkit-user-select: none; user-select: none; }
#room.dragging #stage, #room.dragging #side, #room.dragging #divider, #room.dragging #bar, #room.dragging #toast { transition: none !important; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.self video { transform: scaleX(-1); }
.tile .name { position: absolute; left: 8px; bottom: 6px; font-size: 11px; padding: 2px 8px; border-radius: 8px;
  background: rgba(0,0,0,.5); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.tile.noVideo::after { content: "Waiting…"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }

#bar { position: absolute; left: calc((100% - var(--side)) / 2); bottom: 18px; transform: translateX(-50%); width: min(920px, calc(100% - var(--side) - 32px)); transition: left .25s, opacity .35s, transform .35s;
  padding: 12px 16px 14px; border-radius: 20px; background: var(--panel); border: 1px solid var(--panel-border);
  -webkit-backdrop-filter: blur(28px) saturate(1.5); backdrop-filter: blur(28px) saturate(1.5);
  z-index: 6; }
.seekrow { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seekrow span { min-width: 44px; text-align: center; }
.btns { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 18px; }
.btns .left, .btns .mid, .btns .right { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; max-width: 100%; }
.btns { min-width: 0; }
.btns .left { order: 1; } .btns .mid { order: 0; } .btns .right { order: 2; }
.btns button { white-space: nowrap; }
.pill { font-size: 12px; padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,.08); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); }

input[type=range] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; background: rgba(255,255,255,.2); outline: none; }
.seekrow input { flex: 1; }
#vol { width: 80px; margin-left: 8px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; cursor: pointer; }
input[type=range]:disabled { opacity: .4; }

body.idle #bar { opacity: 0; transform: translate(-50%, 16px); pointer-events: none; }
body.idle { cursor: none; }

#toast { position: absolute; top: 40px; left: calc((100% - var(--side)) / 2); transform: translateX(-50%); padding: 10px 18px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-border); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); z-index: 9; }

/* Thumbs-up + big emoji messages */
#thumb { padding: 6px 10px; font-size: 16px; line-height: 1; }
.msg.big { align-items: center; }
.msg.big .txt { font-size: 32px; line-height: 1.1; }
.msg.big .who { font-size: 13px; }

/* Cinematic countdown (film leader) */
#countdown { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(ellipse at center, rgba(16,11,28,.9) 0%, rgba(0,0,0,.97) 78%);
  animation: cd-flicker .21s steps(2) infinite; }
@keyframes cd-flicker { 0% { opacity: 1; } 50% { opacity: .955; } 100% { opacity: .985; } }
.cd-frame { position: relative; width: min(56vh, 62%); aspect-ratio: 1; display: grid; place-items: center; color: #f6e9c8;
  animation: cd-jitter .6s steps(1) infinite; }
@keyframes cd-jitter { 0% { transform: translate(0,0); } 25% { transform: translate(1.5px,-1px); } 50% { transform: translate(-1px,1px); } 75% { transform: translate(1px,1.5px); } }
.cd-reticle { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.2; opacity: .7; }
.cd-reticle .thin { stroke-width: .6; }
.cd-sweep { position: absolute; inset: 2%; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(246,233,200,0) 0deg 245deg, rgba(246,233,200,.42) 359deg, rgba(246,233,200,0) 360deg);
  animation: cd-sweep 1s linear infinite; }
@keyframes cd-sweep { to { transform: rotate(360deg); } }
.cd-num { position: relative; font: 800 min(30vh, 34vw)/1 "Avenir Next Condensed", "Futura", "Helvetica Neue", sans-serif; letter-spacing: -.02em;
  color: #fff1d0; text-shadow: 0 0 28px rgba(255,190,110,.55), 0 0 90px rgba(255,106,77,.35); font-variant-numeric: tabular-nums; }
.cd-num.pop { animation: cd-pop 1s cubic-bezier(.16,.9,.3,1) both; }
@keyframes cd-pop { 0% { transform: scale(1.4); opacity: 0; filter: blur(12px); } 14% { opacity: 1; filter: blur(0); } 100% { transform: scale(.93); opacity: .9; } }
#countdown.last .cd-num { color: #ff6a4d; text-shadow: 0 0 40px rgba(255,106,77,.85), 0 0 100px rgba(255,106,77,.5); }
#countdown.last .cd-frame { color: #ff8a70; }
.cd-title { position: absolute; left: 0; right: 0; top: 9%; text-align: center; text-transform: uppercase; letter-spacing: .5em;
  font-size: 11px; color: rgba(246,233,200,.65); }
.cd-title b { display: block; margin-top: 10px; letter-spacing: .14em; font-size: 17px; font-weight: 600; color: #fff1d0; padding: 0 24px; overflow-wrap: anywhere; }
.cd-grain { position: absolute; inset: -50%; opacity: .17; mix-blend-mode: screen; pointer-events: none; animation: cd-grain .5s steps(6) infinite;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='220' height='220' filter='url(%23n)'/></svg>"); }
@keyframes cd-grain { 0% { transform: translate(0,0); } 20% { transform: translate(-6%,3%); } 40% { transform: translate(4%,-5%); } 60% { transform: translate(-3%,-2%); } 80% { transform: translate(5%,4%); } 100% { transform: translate(0,0); } }
#countdown.flash { animation: cd-flash .6s ease-out forwards; }
#countdown.flash > * { opacity: 0; }
@keyframes cd-flash { 0% { background: #fff; opacity: 1; } 100% { background: #fff; opacity: 0; } }

/* Admin vs guest */
#room:not(.admin) :is(#back10, #fwd10, #open, #openBig) { display: none; }
/* tiny admin link right under the Join room button + its popup */
.adminlink { display: block; margin: 14px auto 0; width: max-content; font-size: 10px; letter-spacing: .04em;
  color: rgba(154,154,176,.6); text-decoration: none; }
.adminlink:hover { color: var(--text); }
#adminModal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.modalcard { width: 340px; padding: 26px 24px 20px; border-radius: 18px; background: #16151f; border: 1px solid var(--panel-border);
  box-shadow: 0 24px 70px rgba(0,0,0,.6); }
.modalcard h3 { margin: 0 0 6px; font-size: 18px; }
.modalcard p { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
#adminPass { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--panel-border); background: rgba(0,0,0,.4); color: var(--text); font-size: 15px; outline: none; }
#adminPass:focus { border-color: var(--accent); }
.modalcard .status { min-height: 16px; margin: 8px 0 0; }
.modalbtns { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.modalbtns .spacer { flex: 1; }
