:root {
  --bg: #09090d; --panel: rgba(255,255,255,.045); --panel-2: rgba(255,255,255,.08); --line: rgba(255,255,255,.09);
  --text: #f4f4f8; --muted: #8d8d9e; --a1: #ff4d8d; --a2: #8b5cf6; --grad: linear-gradient(135deg, var(--a1), var(--a2));
  --r: 18px; --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }
.hidden { display: none !important; }

.backdrop { position: fixed; inset: -10%; z-index: -1; background-size: cover; background-position: center; filter: blur(70px) saturate(1.4) brightness(.35); opacity: .9; transition: background-image .6s; }
.backdrop::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at top, transparent, var(--bg) 75%); }

.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 18px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; transition: transform .12s, background .2s, opacity .2s; white-space: nowrap; }
.btn:hover { background: rgba(255,255,255,.13); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: 0; box-shadow: 0 8px 30px -8px rgba(255,77,141,.6); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.sm { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.input { width: 100%; height: 46px; padding: 0 16px; border-radius: 12px; background: rgba(0,0,0,.35); border: 1px solid var(--line); outline: none; transition: border-color .2s, box-shadow .2s; }
.input:focus { border-color: var(--a1); box-shadow: 0 0 0 4px rgba(255,77,141,.15); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); backdrop-filter: blur(20px); }
.logo { font-weight: 800; letter-spacing: -.02em; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.logo i { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; font-style: normal; font-size: 15px; }
.muted { color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--a1); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(5,5,8,.7); backdrop-filter: blur(14px); animation: fade .2s; }
.modal > .card { width: min(440px, 100%); padding: 28px; display: grid; gap: 16px; animation: pop .25s cubic-bezier(.2,1.4,.4,1); }
.modal h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }

.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: 999px; background: rgba(20,20,28,.9); border: 1px solid var(--line); backdrop-filter: blur(12px); font-size: 14px; font-weight: 500; animation: toast 3.2s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- room ---------- */
.room { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 20px; }
.topbar .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.avatars { display: flex; }
.av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; border: 2px solid var(--bg); margin-left: -8px; position: relative; text-transform: uppercase; }
.av.buf::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid transparent; border-top-color: #fff; animation: spin 1s linear infinite; }
.stage { display: grid; grid-template-columns: 1fr 360px; gap: 16px; padding: 0 20px 20px; min-height: 0; }
.stage.nochat { grid-template-columns: 1fr 0; gap: 0; }
.stage.nochat .chat { display: none; }

.player { position: relative; background: #000; border-radius: var(--r); overflow: hidden; min-height: 0; display: grid; place-items: center; box-shadow: 0 30px 80px -20px rgba(0,0,0,.8); }
.player video { width: 100%; height: 100%; object-fit: contain; display: block; }
.player.idle { cursor: none; }
.player.idle .controls, .player.idle .topfade { opacity: 0; pointer-events: none; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; gap: 14px; align-content: center; background: rgba(0,0,0,.45); }
.overlay .big { font-size: 20px; font-weight: 700; }
.empty-poster { width: 160px; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }

.controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 18px 14px; background: linear-gradient(transparent, rgba(0,0,0,.85)); transition: opacity .3s; display: grid; gap: 8px; }
.seek { position: relative; height: 18px; cursor: pointer; display: flex; align-items: center; }
.seek .track { position: absolute; left: 0; right: 0; height: 4px; border-radius: 4px; background: rgba(255,255,255,.2); overflow: hidden; transition: height .15s; }
.seek:hover .track { height: 6px; }
.seek .buf, .seek .fill { position: absolute; top: 0; bottom: 0; left: 0; }
.seek .buf { background: rgba(255,255,255,.3); }
.seek .fill { background: var(--grad); }
.seek .knob { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #fff; transform: translateX(-50%) scale(0); transition: transform .15s; box-shadow: 0 0 0 4px rgba(255,77,141,.35); }
.seek:hover .knob { transform: translateX(-50%) scale(1); }
.seek .tip { position: absolute; bottom: 22px; transform: translateX(-50%); padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.85); font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0; pointer-events: none; }
.seek:hover .tip { opacity: 1; }
.row { display: flex; align-items: center; gap: 6px; }
.row .sp { flex: 1; }
.ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; transition: background .15s; }
.ic:hover { background: rgba(255,255,255,.12); }
.ic svg { width: 22px; height: 22px; fill: #fff; }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: #ddd; margin-left: 6px; }
.vol { width: 80px; accent-color: var(--a1); }
.reacts { display: flex; gap: 2px; }
.reacts button { font-size: 20px; width: 36px; height: 36px; border-radius: 10px; transition: transform .15s, background .15s; }
.reacts button:hover { transform: scale(1.25); background: rgba(255,255,255,.1); }
.floater { position: absolute; bottom: 90px; font-size: 42px; pointer-events: none; animation: float 2.6s ease-out forwards; text-align: center; z-index: 5; }
.floater small { display: block; font-size: 11px; font-weight: 600; opacity: .8; }
@keyframes float { 0% { transform: translateY(0) scale(.6); opacity: 0; } 15% { transform: translateY(-30px) scale(1.15); opacity: 1; } 100% { transform: translateY(-320px) scale(1); opacity: 0; } }

.chat { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; overflow: hidden; }
.chat header { padding: 16px 18px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.chat header .dot { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 10px #3ddc84; }
.msgs { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; scrollbar-width: thin; }
.msg { max-width: 85%; align-self: flex-start; display: grid; gap: 2px; animation: pop .2s; }
.msg .who { font-size: 12px; font-weight: 600; padding: 0 10px; }
.msg .bubble { padding: 8px 12px; border-radius: 16px 16px 16px 4px; background: var(--panel-2); word-wrap: break-word; white-space: pre-wrap; }
.msg .at { font-size: 10px; color: var(--muted); padding: 0 10px; }
.msg.mine { align-self: flex-end; }
.msg.mine .who { display: none; }
.msg.mine .bubble { background: var(--grad); border-radius: 16px 16px 4px 16px; }
.msg.mine .at { text-align: right; }
.sys { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 10px; }
.typing { font-size: 12px; color: var(--muted); padding: 0 18px; height: 18px; }
.composer { padding: 6px 12px 12px; display: flex; gap: 8px; }
.composer .input { height: 44px; border-radius: 22px; }
.composer .btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--a1); font-size: 11px; font-weight: 700; display: grid; place-items: center; position: absolute; top: 2px; right: 0; }

.player:fullscreen, .stage:fullscreen { border-radius: 0; }
.stage:fullscreen { padding: 0; gap: 0; background: #000; }
.stage:fullscreen .player { border-radius: 0; }
.stage:fullscreen .chat { border-radius: 0; border-width: 0 0 0 1px; background: rgba(12,12,18,.96); }

@media (max-width: 900px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  .stage, .stage.nochat { grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding: 0 0 0; gap: 0; }
  .stage.nochat .chat { display: grid; }
  .player { border-radius: 0; aspect-ratio: 16/9; }
  .chat { border-radius: 0; border-width: 1px 0 0; }
  .vol, .hide-m, #chatToggle { display: none; }
  .controls { padding: 30px 8px 6px; gap: 4px; }
  .row { gap: 2px; }
  .ic { width: 34px; height: 34px; }
  .time { font-size: 11px; white-space: nowrap; margin-left: 2px; }
  .reacts button { width: 28px; height: 30px; font-size: 16px; }
}

/* ---------- host ---------- */
.host { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; display: grid; gap: 28px; }
.host header { display: flex; align-items: center; gap: 12px; }
.host header .sp { flex: 1; }
.host h3 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.rooms { display: grid; gap: 10px; }
.roomrow { display: flex; align-items: center; gap: 14px; padding: 12px 14px; }
.roomrow.sel { border-color: var(--a1); box-shadow: 0 0 0 1px var(--a1), 0 10px 40px -10px rgba(255,77,141,.4); }
.roomrow img { width: 40px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--panel-2); }
.roomrow .info { flex: 1; min-width: 0; cursor: pointer; }
.roomrow .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.tile { text-align: left; display: grid; gap: 8px; transition: transform .2s; }
.tile:hover { transform: translateY(-4px); }
.tile .pic { aspect-ratio: 2/3; border-radius: 14px; background: linear-gradient(160deg, rgba(255,77,141,.18), rgba(139,92,246,.18)) center/cover; display: grid; place-items: center; font-size: 40px; position: relative; overflow: hidden; box-shadow: 0 14px 40px -12px rgba(0,0,0,.8); }
.tile .pic::after { content: ""; position: absolute; inset: 0; border-radius: inherit; border: 1px solid var(--line); }
.tile:hover .pic { box-shadow: 0 0 0 2px var(--a1), 0 20px 50px -12px rgba(255,77,141,.5); }
.tile .name { font-size: 13px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.live { position: absolute; top: 8px; left: 8px; padding: 3px 8px; border-radius: 6px; background: var(--grad); font-size: 11px; font-weight: 800; letter-spacing: .05em; }
.list { display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; }
.opt { text-align: left; padding: 10px 14px; border-radius: 12px; background: rgba(0,0,0,.25); border: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.opt:hover { border-color: rgba(255,255,255,.25); }
.opt.on { border-color: var(--a1); background: rgba(255,77,141,.1); }
.opt span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt small { color: var(--muted); }

.search { display: flex; gap: 10px; }
.search .btn { height: 46px; }
.qf { display: flex; gap: 6px; align-items: center; margin: 12px 0 10px; }
.qf button { height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; font-weight: 600; color: var(--muted); }
.qf button.on { color: var(--text); border-color: var(--a1); background: rgba(255,77,141,.12); }
.qf .muted { margin-left: 6px; font-size: 13px; }
.results { display: grid; gap: 6px; max-height: 60vh; overflow-y: auto; }
.res { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; text-align: left; padding: 12px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); transition: border-color .2s, background .2s; }
.res:hover { border-color: rgba(255,77,141,.5); background: rgba(255,77,141,.06); }
.res.busy { opacity: .5; cursor: progress; }
.res .t { font-weight: 600; font-size: 14px; line-height: 1.35; }
.res .tags { grid-column: 1; display: flex; flex-wrap: wrap; gap: 5px; font-size: 12px; }
.res .tags b, .res .tags i { font-style: normal; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.res .tags b { color: var(--text); background: rgba(139,92,246,.25); }
.res .tags b.hdr { background: rgba(255,180,0,.2); color: #ffd36b; }
.res .seed { grid-column: 2; grid-row: 1 / 3; align-self: center; font-weight: 700; font-size: 14px; }
.seed.good { color: #3ddc84; } .seed.ok { color: #ffc14d; } .seed.bad { color: #ff6b6b; }
@media (max-width: 640px) { .res { padding: 10px 12px; } .res .t { font-size: 13px; } }

/* grid items default to min-width:auto, so one long nowrap title would widen the whole page on phones */
.host, .rooms { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 640px) {
  .host { padding: 16px 14px 40px; gap: 22px; }
  .roomrow { flex-wrap: wrap; gap: 10px 12px; }
  .roomrow .info { flex: 1 1 calc(100% - 60px); }
  .roomrow .btn { flex: 1; }
  .roomrow .btn.ghost { flex: 0 0 34px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 12px; }
  .search .btn { padding: 0 14px; }
  .qf { overflow-x: auto; }
  .modal > .card { padding: 20px; }
}
/* phone held sideways: video takes the full height, chat on the side */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { display: none; }
  .room { grid-template-rows: 1fr; height: 100dvh; }
  .stage, .stage.nochat { grid-template-columns: minmax(0, 1fr) 270px; grid-template-rows: minmax(0, 1fr); padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
  .player { aspect-ratio: auto; height: 100%; }
  .chat { border-width: 0 0 0 1px; }
  .chat header { padding: 8px 12px; }
  .msgs { padding: 8px; }
  .composer { padding: 4px 8px 8px; }
}

/* torrent panel */
.tsstat { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tsstat > div { padding: 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); display: grid; gap: 2px; }
.tsstat b { font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tsstat small, .tsgrid small { color: var(--muted); font-size: 11px; }
.tsstat > .row, .tsstat > .muted { grid-column: 1 / -1; }
.tsgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tsgrid label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; }
.tsgrid .input { height: 40px; }
@media (max-width: 640px) { .tsstat { grid-template-columns: 1fr 1fr; } }

/* same min-width:auto trap as the host page: a long title must not push the chat off screen */
.room { grid-template-columns: minmax(0, 1fr); }
.stage { grid-template-columns: minmax(0, 1fr) 360px; }
.stage.nochat { grid-template-columns: minmax(0, 1fr) 0; }
@media (max-width: 900px) { .stage, .stage.nochat { grid-template-columns: minmax(0, 1fr); } }
@media (orientation: landscape) and (max-height: 500px) { .stage, .stage.nochat { grid-template-columns: minmax(0, 1fr) 270px; } }
