:root {
  --bg: #0d0c11;
  --panel: #16141c;
  --panel-2: #1f1c27;
  --line: #2d2938;
  --text: #f3eff8;
  --muted: #9b94a9;
  --accent: #ff6b57;
  --accent-2: #ffb35c;
  --ok: #4ade80;
  --danger: #f05252;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: #29253a; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #1a0f0a; font-weight: 650; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password] {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
input:focus { border-color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; font-size: 14px; }

.logo { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 20px; letter-spacing: -.02em; white-space: nowrap; }
.logo img { width: 30px; height: 30px; }

/* login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at top, #2a1520 0%, transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 26px; display: grid; gap: 14px; }
.login-card .logo { justify-content: center; font-size: 24px; margin-bottom: 6px; }
.login-card p { margin: 0; text-align: center; }

/* library */
.page { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.topnav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.disk { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.disk-bar { width: 120px; height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.disk-bar span { display: block; height: 100%; background: var(--accent-2); }
.dropzone {
  display: block;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s; margin-bottom: 18px;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: #1a1219; }
.dropzone strong { display: block; font-size: 16px; margin-bottom: 2px; }
.dropzone.compact { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.dropzone.compact strong { display: inline; margin: 0; font-size: 15px; }
.dropzone.compact strong::before { content: "+ "; color: var(--accent); }
.dropzone.compact span { font-size: 14px; }
.uploads { display: grid; gap: 10px; margin-bottom: 18px; }
.uploads:empty { display: none; }
.upload { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; }
.upload:has(.upload-thumb) { grid-template-columns: 96px 1fr auto; align-items: center; gap: 14px; }
.upload-thumb { width: 96px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: linear-gradient(135deg, #3a1d2b, #1d1a33); display: grid; place-items: center; font-size: 22px; }
.upload-thumb img { width: 100%; height: 100%; object-fit: cover; }
.upload-main { display: grid; gap: 6px; min-width: 0; }
.upload-pct { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent-2); }
.upload-status { font-size: 13px; color: var(--muted); }
.upload-actions { display: flex; gap: 6px; }
.upload.done { border-color: #1f5135; }
.upload.done .progress span { background: var(--ok); width: 100% !important; }
.upload.done .upload-status { color: var(--ok); }
.upload.failed .upload-status { color: var(--danger); }
.upload-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.upload-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.warn { background: #2b1d10; border: 1px solid #5c3b15; color: #ffd8a8; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.warn code { display: block; margin-top: 6px; padding: 8px; background: #000; border-radius: 6px; font-size: 12px; overflow-x: auto; white-space: pre; user-select: all; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.poster { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, #3a1d2b, #1d1a33); display: grid; place-items: center; overflow: hidden; }
.poster img { width: 100%; height: 100%; object-fit: cover; }
.poster .initial { font-size: 44px; font-weight: 800; opacity: .35; }
.poster .play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.35); opacity: 0; transition: opacity .15s; text-decoration: none; }
.poster:hover .play { opacity: 1; }
.poster .play span { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f0a; }
.badge { position: absolute; top: 8px; left: 8px; background: rgba(13,12,17,.85); border-radius: 999px; padding: 3px 10px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.card-body { padding: 12px 14px 14px; display: grid; gap: 8px; flex: 1; }
.card-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.empty { text-align: center; color: var(--muted); padding: 50px 16px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(440px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 14px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.sub-list { display: grid; gap: 6px; margin: 10px 0; }
.sub-row { display: flex; justify-content: space-between; align-items: center; background: var(--panel-2); border-radius: 8px; padding: 6px 10px; }
.field { display: grid; gap: 6px; margin-bottom: 10px; font-size: 14px; }

/* watch */
body.watch { overflow: hidden; background: #000; }
.stage { position: fixed; inset: 0; background: #000; display: flex; }
.screen { position: relative; flex: 1; min-width: 0; display: grid; place-items: center; overflow: hidden; }
.screen video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.screen video::cue { background: rgba(0,0,0,.6); font-size: var(--cue-size, 100%); }
.stage.idle .screen { cursor: none; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; transition: opacity .25s; }
.stage.idle .overlay { opacity: 0; }
.overlay > * { pointer-events: auto; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 16px 30px; background: linear-gradient(rgba(0,0,0,.75), transparent); }
.topbar .title { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people { display: flex; gap: 4px; }
.person { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--panel-2); border: 2px solid var(--bg); }
.bottombar { padding: 30px 16px 14px; background: linear-gradient(transparent, rgba(0,0,0,.8)); display: grid; gap: 8px; }
.controls { display: flex; align-items: center; gap: 4px; }
.controls .spacer { flex: 1; }
.icon-btn { width: 42px; height: 42px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; position: relative; flex-shrink: 0; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.off { color: var(--danger); }
.icon-btn.on { color: var(--accent-2); }
.time { font-size: 13px; font-variant-numeric: tabular-nums; color: #ddd; padding: 0 6px; white-space: nowrap; }
.divider { width: 1px; height: 22px; background: rgba(255,255,255,.18); margin: 0 6px; }

.seek { position: relative; height: 18px; cursor: pointer; touch-action: none; }
.seek-track { position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.2); overflow: hidden; transition: height .1s, top .1s; }
.seek:hover .seek-track { top: 6px; height: 6px; }
.seek-buffer { position: absolute; inset: 0 auto 0 0; background: rgba(255,255,255,.3); }
.seek-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.seek-thumb { position: absolute; top: 3px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: #fff; }
.seek-tip { position: absolute; bottom: 22px; transform: translateX(-50%); background: rgba(0,0,0,.85); padding: 2px 7px; border-radius: 5px; font-size: 12px; pointer-events: none; }

.sheet {
  position: absolute; right: 16px; bottom: 96px; width: 340px; max-height: calc(100% - 120px); overflow-y: auto; z-index: 8;
  background: rgba(22,20,28,.97); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 48px rgba(0,0,0,.6);
  backdrop-filter: blur(10px); animation: sheetIn .18s ease-out;
}
@keyframes sheetIn { from { opacity: 0; transform: translateY(8px); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 18px; }
.sheet section { padding: 10px 18px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.sheet section:last-child { border-bottom: 0; }
.sheet h4 { margin: 0; font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.slider-row { display: grid; grid-template-columns: 36px 56px 1fr 40px; align-items: center; gap: 6px; }
.slider-row .icon-btn { width: 36px; height: 36px; }
.slider-row .icon-btn svg { width: 20px; height: 20px; }
.slider-label { font-size: 14px; }
.pct { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; cursor: pointer; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row i { flex-shrink: 0; width: 40px; height: 24px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); position: relative; transition: background .15s; }
.switch-row i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #cfc9d9; transition: transform .15s, background .15s; }
.switch-row input:checked + i { background: var(--accent); border-color: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(16px); background: #fff; }
.switch-row input:focus-visible + i { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 5px 13px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: #4a4458; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #1a0f0a; font-weight: 650; }
.step-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.step-row b { color: var(--accent-2); font-weight: 600; margin-left: 4px; }
.steps { display: flex; gap: 4px; }
.steps button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 4px 11px; cursor: pointer; font-size: 13px; }
.steps button:hover { border-color: #4a4458; }
.sheet .btn { justify-self: start; }

.rel { position: relative; }
.icon-btn[data-unread]:not([data-unread=""])::after { content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.subtitles { position: absolute; left: 5%; right: 5%; bottom: 7%; display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; z-index: 2; transition: bottom .25s; text-align: center; }
.stage:not(.idle) .subtitles { bottom: 120px; }
.cue { background: rgba(0,0,0,.65); padding: 1px 10px; border-radius: 4px; white-space: pre-line; font-weight: 500; line-height: 1.35;
  font-size: calc(var(--sub-scale, 1) * clamp(16px, 2.6vw, 34px)); text-shadow: 0 1px 2px #000; }

.center-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,.7); padding: 12px 20px; border-radius: 12px; font-weight: 600; pointer-events: none; }
.tap-start { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.5); z-index: 6; }

.tiles { position: absolute; top: 70px; right: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 4; touch-action: none; }
.tiles.collapsed .tile { display: none; }
.tiles.big .tile { width: 340px; }
.tile { position: relative; width: 200px; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden; background: var(--panel-2); box-shadow: 0 6px 24px rgba(0,0,0,.5); border: 2px solid transparent; transition: border-color .15s; cursor: grab; }
.tile.speaking { border-color: var(--ok); }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.self video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: grid; place-items: center; font-size: 32px; font-weight: 800; background: linear-gradient(135deg, #3a1d2b, #1d1a33); }
.tile .label { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); border-radius: 6px; padding: 1px 7px; font-size: 12px; display: flex; gap: 4px; align-items: center; }
.tile .label svg { width: 12px; height: 12px; color: var(--danger); }

.chat { width: 320px; flex-shrink: 0; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; font-weight: 650; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 14px; word-wrap: break-word; }
.msg b { color: var(--accent-2); margin-right: 6px; }
.msg.system { color: var(--muted); font-size: 13px; font-style: italic; }
.chat-form { padding: 10px; border-top: 1px solid var(--line); display: flex; gap: 6px; }
.reactions { display: flex; gap: 2px; padding: 6px 10px 0; flex-wrap: wrap; }
.reactions button { background: none; border: 0; font-size: 22px; cursor: pointer; border-radius: 8px; padding: 2px 5px; }
.reactions button:hover { background: rgba(255,255,255,.08); }
.quick-react { position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%); background: rgba(22,20,28,.97); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; z-index: 5; }

.floaty { position: absolute; bottom: 90px; font-size: 40px; pointer-events: none; animation: floatUp 2.6s ease-out forwards; z-index: 3; }
@keyframes floatUp {
  0% { transform: translateY(0) scale(.6); opacity: 0; }
  15% { transform: translateY(-30px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-340px) scale(1); opacity: 0; }
}
.chat-pop { position: absolute; left: 16px; bottom: 110px; display: grid; gap: 6px; max-width: min(380px, 70%); pointer-events: none; z-index: 3; }
.chat-pop .msg { background: rgba(0,0,0,.7); padding: 6px 12px; border-radius: 10px; animation: fadeIn .2s; }

.join { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(8,7,11,.92); backdrop-filter: blur(6px); }
.join-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 26px; display: grid; gap: 12px; }
.join-card h2 { margin: 0; font-size: 20px; }
.join-card .btn { width: 100%; }

.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 30; pointer-events: none; width: max-content; max-width: calc(100% - 32px); }
.toast { background: rgba(22,20,28,.96); border: 1px solid var(--line); padding: 9px 16px; border-radius: 10px; font-size: 14px; animation: fadeIn .2s; text-align: center; }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } }

@media (max-width: 760px) {
  .chat { position: absolute; inset: 0; width: auto; z-index: 10; }
  .tile { width: 120px; }
  .tiles.big .tile { width: 200px; }
  .tiles { top: 60px; right: 8px; }
  .hide-sm, .disk-bar { display: none; }
  .upload:has(.upload-thumb) { grid-template-columns: 72px 1fr; }
  .upload-thumb { width: 72px; }
  .upload-actions { grid-column: 1 / -1; }
  .sheet { left: 0; right: 0; bottom: 0; width: auto; max-height: 75%; border-radius: 18px 18px 0 0; border-bottom: 0; }
  .time { font-size: 12px; padding: 0 2px; }
  .disk { font-size: 12px; }
  .icon-btn { width: 38px; height: 38px; }
  .bottombar { padding: 24px 8px 10px; }
  .topbar { padding: 10px 10px 24px; }
}
@media (max-height: 500px) {
  .tile { width: 110px; }
}
