:root {
  --bg: #0b0b10; --card: #15151d; --line: #262633; --tx: #ececf1; --mut: #9a9aab;
  --acc: #ff4f7b; --ok: #3ddc84; --warn: #ffc04d; --bad: #ff5d5d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--tx); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--acc); color: #fff; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.ghost { background: #ffffff14; border-radius: 10px; padding: 10px 14px; }
.ghost:hover { background: #ffffff22; }
.danger { color: #ff8a8a; }
.sm { padding: 6px 10px; font-size: 13px; }
.big { padding: 14px 22px; font-size: 17px; }
.mut { color: var(--mut); }
.small, small { font-size: 13px; }
input, select { font: inherit; color: var(--tx); background: #0f0f15; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--acc); outline-offset: -1px; }
h1 { font-size: 22px; margin: 6px 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card h2 { margin-top: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* login */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; }
.login label { display: grid; gap: 4px; text-align: left; font-size: 13px; color: var(--mut); }
.login .logo { font-size: 48px; }
.err { color: var(--bad); margin: 0; }

/* library */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: #0b0b10e6; backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; }
.who { display: flex; gap: 10px; align-items: center; }
.who form { margin: 0; }
.wrap { max-width: 860px; margin: 0 auto; padding: 14px 16px 60px; }
.banner { display: flex; align-items: center; gap: 10px; background: linear-gradient(120deg, #ff4f7b33, #7b5cff33); border: 1px solid #ff4f7b55; border-radius: 16px; padding: 12px 14px; margin: 10px 0; }
.bn-txt { flex: 1; min-width: 0; display: grid; }
.bn-txt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop { display: block; border: 2px dashed var(--line); border-radius: 14px; padding: 22px 12px; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--acc); background: #ff4f7b11; }
.drop input { display: none; }
.drop small { display: block; color: var(--mut); margin-top: 4px; }
#up-detail { margin-top: 12px; display: grid; gap: 8px; }
.file-line { word-break: break-all; }
.notes { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 13px; }
.notes li { padding: 6px 10px; border-radius: 8px; background: #ffffff0a; }
.notes .ok { color: var(--ok); } .notes .warn { color: var(--warn); } .notes .bad { color: var(--bad); }
.progress { height: 8px; background: #ffffff14; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--acc); transition: width .3s; }
.list { display: grid; gap: 10px; }
.movie { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.m-main { flex: 1 1 220px; min-width: 0; }
.m-title { font-weight: 650; overflow-wrap: anywhere; }
.m-meta { font-size: 13px; }
.m-last { font-size: 13px; color: var(--acc); }
.m-warn { font-size: 12px; color: var(--warn); }
.m-act { display: flex; gap: 6px; }
.subs-box { flex-basis: 100%; display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.sub-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.sub-form { display: grid; gap: 6px; }
.sub-form input[type=file] { padding: 8px; }

/* people chips */
.people { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #ffffff12; border-radius: 99px; padding: 4px 10px 4px 8px; font-size: 13px; border: 1px solid transparent; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip.wait i { background: var(--warn); animation: blink 1s infinite; }
.chip.off { opacity: .55; } .chip.off i { background: #777; }
.chip b { color: var(--c); font-weight: 650; }
.chip small { color: var(--mut); font-size: 11px; }
.chip.pulse { animation: pulse .7s; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--c); border-color: var(--c); } 100% { box-shadow: 0 0 0 12px transparent; } }
@keyframes blink { 50% { opacity: .3; } }
.net { font-size: 12px; font-weight: 600; }
.net.warn { color: var(--warn); } .net.bad { color: var(--bad); }

/* player */
#player-view { min-height: 100vh; min-height: 100dvh; background: #000; }
#stage { position: relative; width: 100%; max-width: 1280px; margin: 0 auto; aspect-ratio: 16 / 9; max-height: 100vh; max-height: 100dvh; background: #000; overflow: hidden; user-select: none; -webkit-user-select: none; --ss: 1; }
body.fs #stage, #stage:fullscreen { position: fixed; inset: 0; max-width: none; max-height: none; width: 100%; height: 100vh; height: 100dvh; aspect-ratio: auto; z-index: 50; }
#stage:-webkit-full-screen { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }
#vid { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#ui { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 6; }
#stage.ui-on #ui { opacity: 1; pointer-events: auto; }
#stage:not(.ui-on) { cursor: none; }
.ui-top, .ui-bottom { padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
.ui-top { display: flex; align-items: center; gap: 10px; background: linear-gradient(#000c, transparent); padding-top: max(10px, env(safe-area-inset-top)); }
.ui-bottom { background: linear-gradient(transparent, #000d); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.p-title { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.icon:hover { background: #ffffff1c; }
.icon svg { width: 26px; height: 26px; fill: #fff; }
.icon svg text { fill: #fff; }
.ctrls { display: flex; align-items: center; gap: 2px; }
.ctrls .sp { flex: 1; }
.time { font-size: 13px; font-variant-numeric: tabular-nums; margin-left: 6px; white-space: nowrap; }

#bar { position: relative; height: 26px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
#marks { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 6px; pointer-events: none; }
.track { position: relative; width: 100%; height: 4px; background: #ffffff30; border-radius: 99px; transition: height .15s; }
#bar:hover .track, #bar.drag .track { height: 7px; }
#bar-buf, #bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
#bar-buf { background: #ffffff50; }
#bar-fill { background: var(--acc); }
#bar-knob { position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: #fff; box-shadow: 0 0 6px #0008; }
#bar-tip { position: absolute; bottom: 26px; transform: translateX(-50%); background: #000d; padding: 2px 8px; border-radius: 6px; font-size: 12px; opacity: 0; pointer-events: none; }
#bar-tip.show { opacity: 1; }

.emojis { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-bottom: 4px; }
.emo { font-size: 24px; width: 44px; height: 44px; border-radius: 50%; background: #ffffff14; transition: transform .1s; line-height: 1; }
.emo:active { transform: scale(1.3); background: #ffffff30; }
#below { padding: 14px 16px 30px; display: grid; gap: 12px; justify-items: center; text-align: center; }
.emojis.big .emo { width: 52px; height: 52px; font-size: 28px; }
/* Portrait phone, not fullscreen: emojis live below the video, not over it. */
@media (orientation: landscape), (min-width: 900px) { #below { display: none; } }
@media (orientation: portrait) and (max-width: 899px) { body:not(.fs) #emojis { display: none; } }
body.fs #below { display: none; }

#subs { position: absolute; left: 4%; right: 4%; bottom: 7%; text-align: center; pointer-events: none; z-index: 5; transition: bottom .25s; }
#stage.ui-on #subs { bottom: calc(var(--ub, 120px) + 6px); }
#subs span { display: inline-block; font-size: calc(clamp(15px, 4.4vmin, 38px) * var(--ss)); line-height: 1.3; font-weight: 600; color: #fff; padding: .1em .45em; border-radius: 6px; background: #0007; text-shadow: 0 0 4px #000, 0 2px 3px #000; }

#fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 7; }
.rx { position: absolute; bottom: 24%; display: flex; flex-direction: column; align-items: center; animation: rise 3s cubic-bezier(.2, .7, .3, 1) forwards; will-change: transform, opacity; }
.rx.theirs { left: var(--x); }
.rx.mine { right: var(--x); }
.rx-e { font-size: calc(clamp(34px, 9vmin, 72px) * var(--s, 1)); line-height: 1; filter: drop-shadow(0 4px 12px #000a); }
.rx.mine .rx-e { font-size: calc(clamp(24px, 6vmin, 44px) * var(--s, 1)); }
.rx-n { margin-top: 4px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--c); color: #111; white-space: nowrap; }
.rx.mine .rx-n { font-size: 10px; opacity: .8; }
.rx.theirs .rx-e { animation: wob 0.6s ease-in-out 2; }
@keyframes rise {
  0% { transform: translate(0, 30px) scale(.3); opacity: 0; }
  12% { transform: translate(0, 0) scale(1.2); opacity: 1; }
  22% { transform: translate(calc(var(--dx) * .2), -4%) scale(1); }
  75% { opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--sh, 400px) * -.6)) rotate(var(--rot)); opacity: 0; }
}
@keyframes wob { 50% { transform: rotate(-12deg) scale(1.1); } }

#note { position: absolute; top: 18%; left: 50%; transform: translate(-50%, -10px); background: #000b; padding: 8px 16px; border-radius: 99px; font-weight: 600; opacity: 0; transition: .3s; pointer-events: none; z-index: 8; white-space: nowrap; }
#note.show { opacity: 1; transform: translate(-50%, 0); }
#msg { font-size: clamp(13px, 3.6vmin, 17px); position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 10px; background: #000b; padding: 16px 20px; border-radius: 16px; z-index: 8; text-align: center; white-space: pre-line; max-width: 90%; }
.spin { width: 30px; height: 30px; border: 3px solid #fff3; border-top-color: var(--acc); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#gate { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: #000a; z-index: 20; text-align: center; }

.panel { position: absolute; right: 10px; bottom: 90px; width: min(300px, calc(100% - 20px)); max-height: calc(100% - 110px); overflow: auto; background: #15151df2; border: 1px solid var(--line); border-radius: 14px; padding: 12px; z-index: 9; display: grid; gap: 8px; }
.pt { font-size: 12px; color: var(--mut); text-transform: uppercase; letter-spacing: .05em; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.opt { background: #ffffff14; border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.opt.on { background: var(--acc); color: #fff; }
.val { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }

/* small screens */
@media (max-width: 520px) {
  .icon { width: 38px; height: 38px; }
  .icon svg { width: 23px; height: 23px; }
  #b-rw, #b-ff { display: none; }
  .ui-top .people { display: none; }
  .emo { width: 38px; height: 38px; font-size: 21px; }
  .m-act { width: 100%; } .m-act .primary { flex: 1; }
}
@media (max-height: 420px) {
  .emo { width: 36px; height: 36px; font-size: 20px; }
  .ui-top, .ui-bottom { padding-top: 4px; padding-bottom: 4px; }
}
body.fs #b-rw, body.fs #b-ff { display: grid; }

#modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 100; padding: 16px; }
#modal .card { width: min(380px, 100%); }
#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #222230; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .25s; pointer-events: none; z-index: 200; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .rx { animation-duration: 2s; } .rx.theirs .rx-e { animation: none; } }
