:root {
  --bg: #141210;
  --surface: #1e1b18;
  --surface-2: #29251f;
  --line: #3a342c;
  --text: #f1ebe2;
  --muted: #a99f92;
  --accent: #e8a33d;
  --accent-text: #1b1408;
  --danger: #e2655a;
  --ok: #7cc48a;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f2ec; --surface: #fffdf9; --surface-2: #efe8de; --line: #ddd3c5;
    --text: #221d17; --muted: #6f655a; --accent: #b56e12; --accent-text: #fff;
    --shadow: 0 6px 24px rgba(60, 40, 10, .12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
a { color: inherit; }
img { display: block; }
h1 { font-size: 1.6rem; margin: .2rem 0 .4rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error { color: var(--danger); }
.empty { color: var(--muted); padding: 2rem 0; }

/* header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { text-decoration: none; font-weight: 700; letter-spacing: .02em; display: flex; gap: .45rem; align-items: center; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--accent-text); font-size: 12px; }
#nav { display: flex; align-items: center; gap: .9rem; flex: 1; flex-wrap: wrap; }
#nav > a:not(.btn) { text-decoration: none; color: var(--muted); }
#nav > a:not(.btn):hover { color: var(--text); }
.header-search { margin-left: auto; }
.header-search input { width: min(260px, 40vw); }
.me { color: var(--muted); font-size: .9em; }

main { max-width: 1400px; margin: 0 auto; padding: 1rem 16px 4rem; }

/* controls */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 600;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .55rem; font-size: .85em; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .8rem 0; }
.mpv { display: inline-flex; gap: .25rem; align-items: center; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.row .cards { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 150px;
  overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x proximity; }
.card { position: relative; text-decoration: none; display: block; scroll-snap-align: start; min-width: 0; }
.poster { aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.poster img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.card:hover .poster img { transform: scale(1.03); }
.poster-fallback { width: 100%; height: 100%; display: grid; place-items: center; font-size: 2rem;
  font-weight: 700; color: var(--muted); text-transform: uppercase; }
.card-title { margin-top: .4rem; font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { position: absolute; top: 6px; right: 6px; background: var(--accent); color: var(--accent-text);
  border-radius: 999px; width: 22px; height: 22px; display: grid; place-items: center; font-size: .75rem; font-weight: 700; }
.progress { position: absolute; left: 6px; right: 6px; top: calc((100% - 3rem) - 10px); height: 4px;
  border-radius: 2px; background: rgba(0,0,0,.5); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); }

/* search / browse */
.big-search { width: 100%; font-size: 1.15rem; padding: .8rem 1rem; margin-bottom: 1rem; }
.crumbs { color: var(--muted); font-size: .9em; }
.crumbs a { color: var(--muted); }

/* detail */
.detail { display: grid; grid-template-columns: minmax(160px, 280px) 1fr; gap: 1.6rem; align-items: start; margin-top: .5rem; }
.detail-poster .poster { box-shadow: var(--shadow); }
.kicker { color: var(--accent); text-decoration: none; font-weight: 600; }
.facts { color: var(--muted); margin: .3rem 0; }
.overview { max-width: 70ch; line-height: 1.6; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: 1.5rem 0 .5rem; border-bottom: 1px solid var(--line); }
.tab { font: inherit; background: none; border: 0; color: var(--muted); padding: .5rem .8rem; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.episodes { display: flex; flex-direction: column; }
.episode { display: grid; grid-template-columns: 1fr auto auto; gap: 1rem; align-items: center;
  padding: .55rem .2rem; border-bottom: 1px solid var(--line); }
.episode.played .ep-title { color: var(--muted); }
.ep-title { text-decoration: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-code { color: var(--muted); font-variant-numeric: tabular-nums; }
.ep-actions { display: flex; gap: .3rem; }

/* player */
.video { width: 100%; max-height: 78vh; background: #000; border-radius: var(--radius); display: block; }
.watch-bar { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: start; margin-top: .6rem; }

/* login */
.login { max-width: 380px; margin: 3rem auto; display: flex; flex-direction: column; gap: .8rem;
  background: var(--surface); padding: 1.6rem; border-radius: var(--radius); border: 1px solid var(--line); }
.login label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; }

/* toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--surface-2); border: 1px solid var(--line); padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { border-color: var(--danger); }

/* parties */
.room { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
.room-side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; height: min(82vh, 900px); min-height: 420px; }
.room-side .tabs { margin: 0; padding: 0 .4rem; }
.pane { flex: 1; overflow: auto; padding: .6rem .8rem; display: none; }
.pane.active { display: block; }
.room-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.room-head h1 { margin: 0; }
.now { margin-top: .6rem; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: center; }
.queue-item { display: grid; grid-template-columns: 1fr auto; gap: .3rem .6rem; padding: .5rem .4rem; border-radius: 8px; border: 1px solid transparent; }
.queue-item.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.queue-item.done { opacity: .55; }
.queue-item .q-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .q-meta { grid-column: 1 / -1; color: var(--muted); font-size: .8rem; }
.queue-item .q-btns { display: flex; gap: .2rem; }
.bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin-top: .3rem; }
.bar span { display: block; height: 100%; background: var(--accent); }
.add-box { display: flex; flex-direction: column; gap: .4rem; padding: .6rem .8rem; border-top: 1px solid var(--line); }
.add-box input { width: 100%; }
.suggest { max-height: 220px; overflow: auto; display: flex; flex-direction: column; }
.suggest button { text-align: left; background: none; border: 0; color: var(--text); padding: .35rem .3rem; border-radius: 6px; cursor: pointer; font: inherit; }
.suggest button:hover, .suggest button:focus-visible { background: var(--surface-2); }
.chat-log { display: flex; flex-direction: column; gap: .35rem; }
.msg { line-height: 1.35; overflow-wrap: anywhere; }
.msg .who { font-weight: 700; margin-right: .35rem; }
.msg.system { color: var(--muted); font-size: .85rem; font-style: italic; }
.msg time { color: var(--muted); font-size: .72rem; margin-left: .3rem; }
.chat-form { display: flex; gap: .4rem; padding: .6rem .8rem; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }
.member { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: .45rem; vertical-align: middle; }
.dot.on { background: var(--ok); }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); border-radius: var(--radius); }
.player-box { position: relative; }
.join { max-width: 420px; margin: 3rem auto; background: var(--surface); padding: 1.6rem; border-radius: var(--radius); border: 1px solid var(--line); display: flex; flex-direction: column; gap: .8rem; }
.room-list { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }
.room-card { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); flex-wrap: wrap; }
.popover { position: absolute; z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: .3rem; display: flex; flex-direction: column; min-width: 200px; }
.popover button { text-align: left; background: none; border: 0; color: var(--text); padding: .45rem .6rem; border-radius: 6px; cursor: pointer; font: inherit; }
.popover button:hover { background: var(--surface-2); }

@media (max-width: 900px) {
  .room { grid-template-columns: 1fr; }
  .room-side { height: 70vh; }
}
@media (max-width: 640px) {
  .detail { grid-template-columns: 1fr; }
  .detail-poster { max-width: 200px; }
  .header-search { margin-left: 0; width: 100%; }
  .header-search input { width: 100%; }
  .episode { grid-template-columns: 1fr auto; }
  .episode > .muted { display: none; }
}

[hidden] { display: none !important; }
.pane-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pane-wrap .pane { display: block; flex: 1; overflow: auto; }
.tab .count { color: var(--muted); }
.tab.unread .count { color: var(--accent); font-weight: 700; }
.overlay-text { background: rgba(0, 0, 0, .65); color: #fff; padding: .8rem 1.1rem; border-radius: 8px; max-width: 80%; text-align: center; }
.now-title { font-weight: 600; }
.add-box select { align-self: flex-start; }

.error:empty { display: none; }
/* queue: show whole titles (two lines), keep controls visible under the video */
.queue-item .q-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.room .video { max-height: calc(100vh - 290px); min-height: 200px; }

/* Services hub (home page tiles) */
.hub { margin-bottom: .5rem; }
.hub-group h2 { margin-top: .6rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; }
.tile { display: flex; align-items: center; gap: .65rem; padding: .6rem .8rem; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; min-width: 0; }
.tile:hover { border-color: var(--accent); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-text { display: flex; flex-direction: column; min-width: 0; }
.tile-name { font-weight: 600; }
.tile-desc { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); }
.dot.up { background: #3fae5a; }
.dot.down { background: #d9534f; box-shadow: 0 0 0 3px color-mix(in srgb, #d9534f 25%, transparent); }
.tile.down .tile-name { color: var(--muted); }
.hub-alert { color: #d9534f; font-size: .9rem; margin: .4rem 0 0; }
.hub-tunnel { margin-top: .8rem; padding: .7rem .9rem; border: 1px dashed var(--line); border-radius: 10px;
  color: var(--muted); font-size: .9rem; }
.hub-tunnel p { margin: 0 0 .5rem; }
.hub-tunnel summary { cursor: pointer; margin-top: .5rem; }
.hub-code { display: flex; gap: .5rem; align-items: flex-start; margin-top: .4rem; }
.hub-code code, .hub-code pre { flex: 1; margin: 0; padding: .45rem .6rem; border-radius: 6px; background: var(--surface-2);
  color: var(--text); font: .85rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: pre; }
