:root {
  --bg: #0e1014;
  --bg2: #151820;
  --bg3: #1d212b;
  --line: #2a2f3b;
  --text: #e7e9ee;
  --muted: #8b92a3;
  --accent: #ff7a59;
  --accent2: #ffa24c;
  --ok: #3ecf8e;
  --warn: #f5c542;
  --bad: #ff5a6a;
  --radius: 10px;
  --side-w: 360px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg3);
  border-radius: 8px;
  padding: 6px 12px;
}
button:hover { border-color: #3a4152; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a0e08; font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 3px 10px; font-size: 13px; }
input, select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; display: block; }
kbd { background: var(--bg3); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 12px; }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(380px, 100%);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0; font-size: 24px; }
.card p { margin: 0; }
.card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.card input { color: var(--text); font-size: 16px; }
.error { color: var(--bad); min-height: 1.2em; }

/* ---------- каркас ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg2);
  padding-top: max(8px, env(safe-area-inset-top));
}
.brand { font-weight: 700; white-space: nowrap; }
.now-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr var(--side-w); }
.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 12px; gap: 8px; overflow: auto; }
.side { min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg2); }

/* ---------- плеер ---------- */
.player {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 130px);
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
}
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.player canvas.JASSUB { z-index: 1; }
.player:fullscreen, .player.pseudo-fs { max-height: none; border-radius: 0; aspect-ratio: auto; }
.player.pseudo-fs { position: fixed; inset: 0; z-index: 1000; width: 100vw; height: 100dvh; }
.player:fullscreen { width: 100vw; height: 100vh; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 2; padding: 20px; text-align: center; }

.state-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 4; background: rgba(14, 16, 20, 0.85); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px; font-size: 14px; white-space: nowrap; max-width: 92%;
  overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.overlay {
  position: absolute; inset: 0; z-index: 5; border: 0; border-radius: 0;
  background: rgba(0, 0, 0, 0.6); font-size: 18px; color: #fff; display: grid; place-items: center; padding: 20px;
}
.overlay:hover { border: 0; }

.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 26px 12px 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
  transition: opacity 0.25s;
}
.player.idle .controls { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }
.controls .row { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.controls .spacer { flex: 1; }
.controls select {
  background: rgba(20, 22, 28, 0.85); border-color: #333a48; padding: 4px 6px; font-size: 13px; max-width: 170px;
}
button.icon {
  background: transparent; border: 0; font-size: 18px; padding: 4px 6px; min-width: 34px; line-height: 1;
  color: #fff;
}
button.icon:hover { color: var(--accent2); }
button.icon svg { display: block; margin: 0 auto; }
.time { font-variant-numeric: tabular-nums; font-size: 13.5px; white-space: nowrap; }
.badge {
  font-size: 12px; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.1);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }
.badge:empty { display: none; }

.seek { position: relative; height: 18px; margin-bottom: 4px; }
.seek-buffered { position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.seek-buffered span { position: absolute; top: 0; bottom: 0; background: rgba(255, 255, 255, 0.35); }
.seek input[type=range] { position: absolute; inset: 0; width: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; border: 0; padding: 0; }
.seek input[type=range]::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.seek input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); margin-top: -5px; }
.seek input[type=range]::-moz-range-track { height: 4px; background: transparent; }
.seek input[type=range]::-moz-range-progress { height: 4px; background: var(--accent); border-radius: 2px; }
.seek input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--accent); }
.seek-tip { position: absolute; bottom: 22px; transform: translateX(-50%); background: rgba(0,0,0,.85); padding: 2px 6px; border-radius: 4px; font-size: 12px; pointer-events: none; }
#volume { width: 80px; padding: 0; }
input[type=range], input[type=checkbox] { accent-color: var(--accent); }

.media-info { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.media-info .warn { color: var(--warn); }

.tag {
  display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); white-space: nowrap;
}
.tag.re { border-color: var(--warn); color: var(--warn); }
.tag.ok { border-color: #2d6b52; color: var(--ok); }
.tag.err { border-color: var(--bad); color: var(--bad); }
.tag.proc { border-color: #5a4a9a; color: #b8a8ff; }

/* ---------- вкладки ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 10px 6px; color: var(--muted); border-bottom: 2px solid transparent; position: relative; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.count { color: var(--muted); font-size: 12px; }
.unread { position: absolute; top: 8px; margin-left: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.tab-body { flex: 1; min-height: 0; position: relative; }
.tab { display: none; position: absolute; inset: 0; overflow: auto; padding: 10px 12px; }
.tab.active { display: flex; flex-direction: column; }
#tab-chat { padding: 0; }

/* ---------- чат ---------- */
.chat-list { list-style: none; margin: 0; padding: 10px 12px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.chat-list li { word-wrap: break-word; overflow-wrap: anywhere; }
.chat-list .nick { font-weight: 600; margin-right: 6px; }
.chat-list .ts { color: var(--muted); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.chat-list li.sys { color: var(--muted); font-style: italic; font-size: 13.5px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.chat-form input { flex: 1; font-size: 16px; }

/* ---------- зрители ---------- */
table.peers { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.peers th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 4px 6px; }
.peers td { padding: 6px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
.peers td:first-child { white-space: normal; }
.peers .st { font-size: 11.5px; color: var(--muted); display: block; }
.peers .me { color: var(--accent2); }
.peers .ok { color: var(--ok); }
.peers .warn { color: var(--warn); }
.peers .bad { color: var(--bad); }
.peers button { padding: 0 6px; font-size: 11px; margin-left: 4px; }

/* ---------- библиотека ---------- */
.library { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.library li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.library li.ready { cursor: pointer; }
.library li.ready:hover { border-color: #3a4152; }
.library li.current { border-color: var(--accent); }
.library .name { font-weight: 600; overflow-wrap: anywhere; }
.library .meta { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 4px; align-items: center; font-size: 12.5px; color: var(--muted); }
.library .bar { height: 4px; background: var(--bg3); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.library .bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.5s; }
.library .errtext { color: var(--bad); font-size: 12px; white-space: pre-wrap; margin-top: 4px; max-height: 6em; overflow: auto; }
.library .empty-lib { color: var(--muted); border: 0; background: none; }

/* ---------- настройки ---------- */
.settings h3 { margin: 6px 0 8px; font-size: 14px; }
.settings label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.settings label.check { display: flex; align-items: center; gap: 8px; }
.settings input, .settings select { color: var(--text); }
.debug { font-size: 11.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; white-space: pre-wrap; margin: 0 0 12px; }

/* ---------- телефон ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .stage { padding: 0; overflow: visible; }
  .player { border-radius: 0; max-height: 60vh; }
  .media-info { padding: 4px 10px; }
  .side { border-left: 0; border-top: 1px solid var(--line); min-height: 280px; }
  .now-title { display: none; }
}
@media (max-width: 560px) {
  .hide-xs { display: none; }
  .controls { padding-left: 6px; padding-right: 6px; }
  .controls .row { gap: 4px; }
  .controls select { max-width: 92px; font-size: 12px; }
  button.icon { min-width: 30px; font-size: 17px; }
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
}
@media (hover: none) {
  .player.idle .controls { opacity: 0; }
}

/* ---------- встраивание (клиенты тестовой страницы) ---------- */
.embed .topbar, .embed .side, .embed .media-info { display: none; }
.embed .layout { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.embed .stage { padding: 0; overflow: hidden; }
.embed .player { max-height: 100vh; height: 100vh; aspect-ratio: auto; border-radius: 0; }
.embed .controls .row > :not(.time):not(.badge):not(.spacer) { display: none; }
