:root {
  --bg: #0d0d12;
  --bg2: #16161e;
  --bg3: #20202b;
  --line: #2a2a37;
  --text: #ececf1;
  --dim: #9a9aab;
  --accent: #7c5cff;
  --accent2: #a48bff;
  --ok: #3ecf8e;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

/* header */
#top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 28px;
  padding: 12px 32px; background: linear-gradient(var(--bg) 60%, rgba(13,13,18,.85)); backdrop-filter: blur(8px); }
.logo { font-size: 20px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.logo b { color: var(--accent2); }
.logo-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); font-size: 12px; }
nav { display: flex; gap: 6px; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--dim); }
nav a:hover { color: var(--text); }
nav a.active { color: var(--text); background: var(--bg3); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
#search { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; width: 220px; outline: none; }
#search:focus { border-color: var(--accent); }
.gear { font-size: 20px; color: var(--dim); }
.gear.active, .gear:hover { color: var(--text); }
body.playing #top { display: none; }

main { padding: 8px 32px 60px; }
.loading, .empty { color: var(--dim); padding: 60px 0; text-align: center; }
.empty a { color: var(--accent2); }
h1 { font-size: 28px; margin: 12px 0 18px; }
h2 { font-size: 19px; margin: 28px 0 12px; }

/* rows + grids */
.row { display: grid; grid-auto-flow: column; grid-auto-columns: 160px; gap: 16px; overflow-x: auto;
  padding-bottom: 10px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.row.wide-row { grid-auto-columns: 300px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; }
.card { scroll-snap-align: start; min-width: 0; }
.card .art { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--bg3);
  aspect-ratio: 2/3; transition: transform .15s, box-shadow .15s; }
.card.wide .art { aspect-ratio: 16/9; }
.card:hover .art { transform: translateY(-3px); box-shadow: 0 0 0 2px var(--accent); }
.card img { width: 100%; height: 100%; object-fit: cover; }
.noart { display: grid; place-items: center; height: 100%; padding: 12px; text-align: center; color: var(--dim);
  font-weight: 600; background: linear-gradient(135deg, #252535, #191924); }
.card .t { margin-top: 8px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .s { color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.6); }
.bar i { display: block; height: 100%; background: var(--accent); }
.check { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; display: grid;
  place-items: center; background: var(--ok); color: #062; font-size: 13px; font-weight: 900; }
.badge { position: absolute; top: 8px; right: 8px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px;
  display: grid; place-items: center; background: var(--accent); font-size: 12px; font-weight: 700; }
.card .play-ico { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px;
  background: rgba(0,0,0,.35); opacity: 0; transition: opacity .15s; }
.card:hover .play-ico { opacity: 1; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar h1 { margin: 0; margin-right: auto; }
.toolbar .count { color: var(--dim); }
select, .input { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; }
.input:focus, select:focus { border-color: var(--accent); }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 9px; border: 0;
  background: var(--bg3); cursor: pointer; font-weight: 600; }
.btn:hover { background: #2b2b3a; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: #8c70ff; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger:hover { background: #5a2330; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--dim); font-size: 18px; padding: 6px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--bg3); }
.icon-btn.on { color: var(--ok); }

/* detail hero */
.hero { position: relative; margin: -8px -32px 0; padding: 70px 32px 30px; min-height: 420px; display: flex; gap: 32px;
  align-items: flex-end; }
.hero-bg { position: absolute; inset: 0; background-size: cover; background-position: center 20%; z-index: -1; }
.hero-bg::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, var(--bg) 15%, rgba(13,13,18,.75) 55%, rgba(13,13,18,.35)),
              linear-gradient(0deg, var(--bg), transparent 50%); }
.hero .poster { width: 230px; flex-shrink: 0; border-radius: var(--radius); overflow: hidden; background: var(--bg3);
  aspect-ratio: 2/3; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.hero .poster img { width: 100%; height: 100%; object-fit: cover; }
.hero-info { max-width: 760px; }
.hero h1 { font-size: 38px; margin: 0 0 6px; line-height: 1.1; }
.meta { color: var(--dim); display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 14px; }
.overview { color: #cfcfdb; margin: 0 0 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.file-info { margin-top: 26px; color: var(--dim); font-size: 13px; display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.file-info b { color: var(--text); font-weight: 500; word-break: break-all; }

/* seasons + episodes */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 26px 0 16px; }
.tab { padding: 7px 14px; border-radius: 20px; background: var(--bg2); border: 1px solid var(--line); cursor: pointer; }
.tab.active { background: var(--accent); border-color: var(--accent); }
.tab small { color: var(--dim); margin-left: 4px; }
.tab.active small { color: #ddd; }
.season-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.ep { display: flex; gap: 18px; padding: 14px; border-radius: var(--radius); align-items: flex-start; }
.ep:hover { background: var(--bg2); }
.ep-art { position: relative; width: 240px; flex-shrink: 0; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: var(--bg3); }
.ep-art img { width: 100%; height: 100%; object-fit: cover; }
.ep-art .play-ico { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px;
  background: rgba(0,0,0,.35); opacity: 0; transition: opacity .15s; }
.ep-art:hover .play-ico { opacity: 1; }
.ep-info { flex: 1; min-width: 0; }
.ep-title { font-weight: 600; font-size: 16px; }
.ep-meta { color: var(--dim); font-size: 13px; margin: 2px 0 6px; }
.ep-info p { margin: 0; color: #c4c4d0; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* settings */
.settings { max-width: 860px; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { color: var(--dim); font-size: 13px; }
.field .hint { color: var(--dim); font-size: 12px; }
.field .hint a { color: var(--accent2); }
.lib { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; background: var(--bg); }
.lib-head { display: flex; gap: 10px; margin-bottom: 10px; }
.lib-head .input { flex: 1; }
.path { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--bg2); border-radius: 8px; margin-bottom: 6px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.path span { flex: 1; word-break: break-all; }
.status-line { color: var(--dim); font-size: 14px; margin-top: 12px; }
.status-line .prog { height: 6px; background: var(--bg3); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.status-line .prog i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.err-list { margin-top: 10px; font-size: 12px; color: #ff9aa8; max-height: 160px; overflow: auto; white-space: pre-wrap; }
.ok { color: var(--ok); } .bad { color: #ff7a8a; }

/* matching */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.tile { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.tile-label { color: var(--dim); font-size: 13px; }
.tile-num { font-size: 28px; font-weight: 700; margin: 2px 0 8px; }
.tile-num small { font-size: 14px; color: var(--dim); font-weight: 500; }
.tile-bar { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.tile-bar i { display: block; height: 100%; background: var(--ok); }
.tile-sub { font-size: 13px; color: var(--dim); }
.mrow { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 10px; border-bottom: 1px solid var(--line); }
.mrow:hover { background: var(--bg2); }
.mthumb { width: 40px; height: 60px; border-radius: 5px; overflow: hidden; background: var(--bg3); flex-shrink: 0; }
.mthumb img { width: 100%; height: 100%; object-fit: cover; }
.mmain { flex: 1; min-width: 0; }
.mtitle { font-weight: 600; }
.mtitle:hover { color: var(--accent2); }
.msrc { color: var(--dim); font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.dim { color: var(--dim); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 5px; background: var(--bg3); color: var(--dim); margin-left: 4px; }
.skip-ico { display: grid; place-items: center; color: #ffb454; font-size: 20px; }
.mrow.ignored { opacity: .5; }
.ig-toggle { display: inline-flex; gap: 8px; align-items: center; color: var(--dim); font-size: 13px; margin-bottom: 8px; cursor: pointer; }
.panel.bad, .panel.dim { padding: 12px 16px; }

/* casting */
.p-castbtn { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; }
.p-castbtn.on { color: var(--accent2); }
.p-castbtn.dim { opacity: .5; }
.cast-help p { margin: 0 0 12px; line-height: 1.5; }
.cast-help code { background: var(--bg3); padding: 2px 6px; border-radius: 5px; word-break: break-all; user-select: all; }
.p-casting { position: absolute; inset: 0; display: none; place-content: center; text-align: center; gap: 8px;
  background: radial-gradient(circle, rgba(13,13,18,.6), rgba(13,13,18,.95)); }
.p-casting small { color: var(--dim); display: block; }
.cast-big { font-size: 64px; }
.player.is-casting .p-casting { display: grid; }
.player.is-casting .p-top, .player.is-casting .p-bottom { z-index: 2; }
.player.is-casting video, .player.is-casting .p-subs, .player.is-casting #fs { visibility: hidden; }
#castbar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%) translateY(150%); z-index: 40; display: flex; align-items: center;
  gap: 12px; background: var(--bg3); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
  transition: transform .25s; max-width: calc(100vw - 24px); }
#castbar.show { transform: translateX(-50%); }
.cb-ico { font-size: 22px; }
.cb-text { display: grid; min-width: 0; }
.cb-text b, .cb-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.cb-text small, .cb-time { color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }

/* modal */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.65); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; width: min(620px, 100%); max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-body { padding: 16px 20px; overflow: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.dir { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.dir:hover { background: var(--bg3); }
.crumb { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--dim); margin-bottom: 10px; word-break: break-all; }
.result { display: flex; gap: 12px; padding: 8px; border-radius: 8px; cursor: pointer; align-items: flex-start; }
.result:hover { background: var(--bg3); }
.result img, .result .ph { width: 46px; height: 69px; object-fit: cover; border-radius: 4px; background: var(--bg3); flex-shrink: 0; }
.result p { margin: 2px 0 0; color: var(--dim); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--bg3);
  border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* player */
body.playing main { padding: 0; }
.player { position: fixed; inset: 0; background: #000; z-index: 30; user-select: none; }
.player video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.player.idle { cursor: none; }
.p-top, .p-bottom { position: absolute; left: 0; right: 0; padding: 18px 28px; transition: opacity .25s; }
.p-top { top: 0; display: flex; align-items: center; gap: 16px; background: linear-gradient(rgba(0,0,0,.75), transparent); }
.p-bottom { bottom: 0; background: linear-gradient(transparent, rgba(0,0,0,.85)); padding-top: 50px; }
.player.idle .p-top, .player.idle .p-bottom { opacity: 0; pointer-events: none; }
.p-title { font-size: 18px; font-weight: 600; }
.p-sub { color: var(--dim); font-size: 13px; }
.p-mode { margin-left: auto; font-size: 12px; color: var(--dim); background: rgba(255,255,255,.08); padding: 4px 10px; border-radius: 6px; }
.p-btn { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 6px 10px; border-radius: 8px; line-height: 1; }
.p-btn:hover { background: rgba(255,255,255,.12); }
.p-seek { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.p-seek span { font-variant-numeric: tabular-nums; font-size: 13px; color: #ddd; min-width: 56px; }
.p-seek span:last-child { text-align: right; }
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; flex: 1; height: 18px; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--pct, 0%), rgba(255,255,255,.25) var(--pct, 0%)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: #fff; margin-top: -5px; }
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: rgba(255,255,255,.25); }
input[type=range]::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 15px; height: 15px; border: 0; border-radius: 50%; background: #fff; }
.p-controls { display: flex; align-items: center; gap: 6px; }
.p-controls .spacer { flex: 1; }
.p-controls select { background: rgba(255,255,255,.08); border: 0; color: #fff; max-width: 220px; }
.p-controls select option { background: var(--bg2); }
.p-vol { width: 100px; flex: none; }
.p-subs { position: absolute; left: 50%; bottom: 9%; transform: translateX(-50%); width: 86%; text-align: center; pointer-events: none;
  transition: bottom .25s; }
.player:not(.idle) .p-subs { bottom: 20%; }
.p-subs span { display: inline; background: rgba(0,0,0,.6); color: #fff; font-size: clamp(18px, 2.6vw, 34px); line-height: 1.4;
  padding: 2px 10px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone; white-space: pre-line;
  text-shadow: 0 1px 3px #000; }
.p-center { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner { width: 54px; height: 54px; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; display: none; }
.player.buffering .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.p-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(20,20,28,.95); padding: 22px 26px;
  border-radius: 12px; text-align: center; max-width: 440px; display: none; }
.p-msg.show { display: block; }
.p-log { text-align: left; max-width: 520px; max-height: 180px; overflow: auto; white-space: pre-wrap; word-break: break-all;
  font-size: 12px; color: #ff9aa8; background: rgba(0,0,0,.4); padding: 10px; border-radius: 8px; }
.p-msg { max-width: 600px !important; }
.p-msg .actions { justify-content: center; margin-top: 14px; }
.upnext { position: absolute; right: 28px; bottom: 120px; background: rgba(20,20,28,.95); border: 1px solid var(--line);
  padding: 16px 18px; border-radius: 12px; width: 320px; display: none; }
.upnext.show { display: block; }
.upnext small { color: var(--dim); }
.upnext .actions { margin-top: 12px; }

@media (max-width: 760px) {
  #top { padding: 10px 14px; gap: 12px; flex-wrap: wrap; }
  #search { width: 140px; }
  main { padding: 8px 14px 50px; }
  .hero { margin: -8px -14px 0; padding: 50px 14px 20px; flex-direction: column; align-items: flex-start; }
  .hero .poster { width: 140px; }
  .hero h1 { font-size: 28px; }
  .ep { flex-direction: column; gap: 10px; padding: 10px 0; }
  .ep-art { width: 100%; }
  .p-top, .p-bottom { padding-left: 14px; padding-right: 14px; }
  .p-vol { display: none; }
}

/* subtitle timing */
.p-subdelay { position: relative; }
.p-subdelay.on #sdbtn { color: var(--accent2, #e5a00d); }
.sd-pop { display: none; position: absolute; bottom: calc(100% + 10px); right: 0; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; width: 300px; box-shadow: 0 10px 40px rgba(0,0,0,.5); z-index: 5; }
.p-subdelay.open .sd-pop { display: block; }
.sd-head { font-weight: 600; margin-bottom: 10px; }
.sd-row { display: flex; align-items: center; gap: 6px; }
.sd-row b { flex: 1; text-align: center; font-variant-numeric: tabular-nums; font-size: 18px; }
.sd-row button, .sd-reset { background: rgba(255,255,255,.08); border: 0; color: #fff; border-radius: 8px; padding: 8px 9px; cursor: pointer; font-size: 13px; }
.sd-row button:hover, .sd-reset:hover { background: rgba(255,255,255,.18); }
.sd-hint { font-size: 12px; color: #aaa; margin: 10px 0 8px; line-height: 1.4; }
.sd-reset { width: 100%; }

.sd-sync { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.sd-auto { width: 100%; background: var(--accent2); color: #fff; border: 0; border-radius: 8px; padding: 9px; cursor: pointer; font-weight: 600; }
.sd-auto:disabled { opacity: .6; cursor: progress; }
.sd-auto[data-state="done"] { background: rgba(255,255,255,.08); font-weight: 400; }
.sd-sync .sd-hint { margin-bottom: 0; }

/* online subtitle search */
.os-hint { font-size: 13px; color: var(--dim); margin-bottom: 12px; line-height: 1.4; }
.os-list { display: flex; flex-direction: column; gap: 8px; }
.os-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg3); border-radius: 10px; }
.os-main { flex: 1; min-width: 0; }
.os-rel { font-size: 14px; word-break: break-all; }
.os-meta { font-size: 12px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.os-meta .tag { margin-left: 0; }
.os-meta .tag.ok { color: #6fdc8c; }
.os-meta .tag.bad { color: #ff8a80; }
.os-meta .dim { color: var(--dim); }

/* subtitle style */
.player { --sub-scale: 1; }
.p-subs span { font-size: calc(clamp(18px, 2.6vw, 34px) * var(--sub-scale)); font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif; }
.player[data-sub-font="serif"] .p-subs span { font-family: Georgia, "Times New Roman", serif; }
.player[data-sub-color="yellow"] .p-subs span { color: #ffe14d; }
.player[data-sub-bg="shadow"] .p-subs span { background: none; text-shadow: 0 0 3px #000, 0 0 3px #000, 1px 1px 2px #000, -1px -1px 2px #000; }
.player[data-sub-bg="solid"] .p-subs span { background: #000; }
.sd-style { display: grid; grid-template-columns: 48px 1fr; gap: 6px 8px; align-items: center; font-size: 13px; color: #ccc; }
.seg { display: flex; gap: 4px; }
.seg button { flex: 1; background: rgba(255,255,255,.08); border: 0; color: #fff; border-radius: 7px; padding: 6px 4px; cursor: pointer; font-size: 12px; }
.seg button.sel { background: var(--accent2); }
#sdbtn { font-size: 17px; font-weight: 700; }
.sd-pop { max-height: 70vh; overflow-y: auto; }

/* accounts */
body:not(.is-admin) .admin-only { display: none; }
body.login #top { display: none; }
.login-card { max-width: 420px; margin: 14vh auto 0; text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 36px 28px; }
.logo.big { font-size: 30px; justify-content: center; display: inline-flex; margin-bottom: 14px; }
.login-card p { color: var(--dim); line-height: 1.5; margin: 0 0 22px; }
.plex-btn { background: #e5a00d; color: #111; font-weight: 700; padding: 12px 22px; font-size: 16px; }
.plex-btn:hover { background: #f0b52c; }
.login-msg { margin-top: 16px; color: var(--dim); font-size: 14px; min-height: 20px; }
.login-msg a { color: var(--accent2); }
#me { position: relative; }
.me-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; overflow: hidden; padding: 0; cursor: pointer; background: var(--accent2); color: #fff; font-weight: 700; }
.me-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.me-menu { display: none; position: absolute; right: 0; top: calc(100% + 8px); background: var(--bg3); border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-width: 240px; z-index: 45; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#me.open .me-menu { display: block; }
.me-name { padding: 6px 10px 10px; font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.me-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text, #fff); padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.me-menu button:hover { background: rgba(255,255,255,.08); }
.users-head { font-weight: 600; margin: 14px 0 8px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.user-row img, .user-row .ph { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--bg3); flex: none; }
.u-main { flex: 1; min-width: 0; }
.u-main .dim { font-size: 12px; color: var(--dim); }

/* playback settings */
.p-pset { position: relative; }
.p-pset.open .sd-pop { display: block; width: 340px; }
.p-pset .sd-style { grid-template-columns: 56px 1fr; }
.ps-scope { font-size: 12px; color: var(--dim); margin: -4px 0 10px; }
.seg.big button { padding: 12px; font-size: 15px; }
@media (max-width: 760px) { .p-pset.open .sd-pop { width: min(340px, 92vw); right: -40px; } }

/* ===== player layout (v2: mobile-first) ===== */
.p-btn { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 6px; }
.p-btn svg { display: block; }
.p-tt { min-width: 0; flex: 1; }
.p-title, .p-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-mode { margin-left: 0; flex: none; }
.p-controls { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.pc-left, .pc-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
#sdbtn.on { color: var(--accent2); }
/* big centre controls (shown with the rest of the controls) */
.p-mid { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 36px;
  transition: opacity .25s; z-index: 2; }
.p-mid .p-btn { background: rgba(0,0,0,.45); border-radius: 50%; backdrop-filter: blur(4px); }
.p-mid .mid-sm { width: 56px; height: 56px; }
.p-mid .mid-sm svg { width: 30px; height: 30px; }
.p-mid .mid-play { width: 78px; height: 78px; font-size: 32px; }
.player.idle .p-mid, .player.buffering .p-mid, .player.is-casting .p-mid { opacity: 0; pointer-events: none; }
.player.is-casting .p-mid { opacity: 1; pointer-events: auto; }
.player.is-casting .p-casting { pointer-events: none; }
@media (pointer: fine) and (min-width: 761px) { .p-mid { display: none; } }   /* desktop: bottom bar is enough */

/* settings sheet: bottom sheet on phones, corner panel on desktop */
.p-sheet { position: absolute; z-index: 6; background: var(--bg2); border: 1px solid var(--line); box-shadow: 0 10px 50px rgba(0,0,0,.6);
  display: flex; flex-direction: column; opacity: 0; pointer-events: none; transition: transform .22s ease, opacity .18s; }
.p-sheet.open { opacity: 1; pointer-events: auto; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 0 12px; border-bottom: 1px solid var(--line); }
.sheet-tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.sheet-tabs button { background: none; border: 0; color: var(--dim); font-size: 15px; padding: 12px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; }
.sheet-tabs button.sel { color: #fff; border-bottom-color: var(--accent2); }
.sheet-body { overflow-y: auto; padding: 14px 16px 18px; }
.sheet-body section { display: none; }
.sheet-body section.show { display: block; }
.sh-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 14px 0 8px; }
.sh-label:first-child { margin-top: 2px; }
.sh-select { width: 100%; background: var(--bg3); color: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 15px; }
.sh-select option { background: var(--bg2); }
.p-sheet .sd-style { grid-template-columns: 56px 1fr; gap: 8px 10px; }
.p-sheet .seg button { padding: 9px 4px; font-size: 13px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 28%; }
.p-sheet .sd-row button { padding: 10px 10px; }
.p-sheet .sd-reset { margin-top: 4px; }
.p-sheet .ps-scope { margin: 0 0 8px; }
@media (min-width: 761px) {
  .p-sheet { right: 20px; bottom: 96px; width: 380px; max-height: calc(100% - 140px); border-radius: 14px; transform: translateY(8px); }
  .p-sheet.open { transform: none; }
}
@media (max-width: 760px) {
  .p-sheet { left: 0; right: 0; bottom: 0; max-height: 72%; border-radius: 18px 18px 0 0; transform: translateY(100%);
    padding-bottom: env(safe-area-inset-bottom); }
  .p-sheet.open { transform: none; }
  .player.sheet-open .p-bottom, .player.sheet-open .p-mid { opacity: 0; pointer-events: none; }
  .p-top, .p-bottom { padding-left: 10px; padding-right: 10px; }
  .p-top { padding-top: 10px; gap: 8px; }
  .p-title { font-size: 16px; }
  .p-mode { font-size: 11px; padding: 3px 8px; }
  .p-bottom { padding-bottom: calc(8px + env(safe-area-inset-bottom)); padding-top: 40px; }
  .p-seek { gap: 8px; margin-bottom: 2px; }
  .p-seek span { min-width: 44px; font-size: 12px; }
  .pc-skip, .p-vol, #mute { display: none; }   /* phones: skip lives in the big centre buttons, volume on the phone's keys */
  .p-btn { min-width: 42px; min-height: 42px; padding: 4px; }
  .p-subs { width: 94%; }
}

/* subtitles tab: compact, everything visible without scrolling */
.sd-actions { display: flex; gap: 8px; margin-top: 8px; }
.sd-actions .sd-reset { width: auto; flex: 0 0 auto; padding: 9px 16px; margin: 0; }
.sd-actions .sd-auto { flex: 1; margin: 0; }
.p-sheet .sd-hint { font-size: 12px; margin: 6px 0 0; line-height: 1.35; }
@media (max-width: 760px) {
  .p-sheet { max-height: 86%; }
  .sheet-tabs button { padding: 10px 10px; font-size: 14px; }
  .sheet-body { padding: 10px 14px 14px; }
  .sh-label { font-size: 11px; margin: 10px 0 6px; }
  .sh-select { padding: 8px 10px; font-size: 14px; }
  .p-sheet .sd-style { gap: 5px 8px; font-size: 13px; }
  .p-sheet .seg button { padding: 7px 4px; font-size: 13px; }
  .p-sheet .sd-row button { padding: 7px 9px; font-size: 13px; }
  .p-sheet .sd-row b { font-size: 16px; }
  .sd-actions .sd-reset, .sd-actions .sd-auto { padding: 8px 10px; font-size: 13px; }
}

/* casting screen: device info up top, big controls in the middle, no overlap */
.player.is-casting .p-casting { place-content: start center; padding-top: 18vh; }
.player.is-casting .p-casting .cast-big { font-size: 56px; }
@media (max-width: 760px) { .player.is-casting .p-casting { padding-top: 14vh; } }
