:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --live: #2ecc71;
  --warn: #f5a623;
  --err: #ff5c5c;
  color-scheme: dark;
}

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

/* Hide the untranslated page until i18n.js has applied the texts (shown anyway after 1.5 s). */
.i18n-pending body { animation: i18n-reveal 0s 1.5s both; }
@keyframes i18n-reveal { from { visibility: hidden; } to { visibility: visible; } }

.ui-lang { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); flex: none; }
.ui-lang svg { width: 16px; height: 16px; fill: currentColor; }
.ui-lang select {
  width: auto;
  padding: 3px 4px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  cursor: pointer;
}
.ui-lang select:hover, .ui-lang select:focus-visible { color: var(--text); border-color: var(--line); }
.ui-lang option { background: var(--panel); color: var(--text); }
.warn a { color: var(--accent); }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

header h1 { font-size: 18px; margin: 0; letter-spacing: 0.02em; }
header nav { display: flex; gap: 16px; }
header nav a { color: var(--muted); text-decoration: none; }
header nav a.active, header nav a:hover { color: var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 18px;
}

.panel h2 { margin: 0 0 12px; font-size: 16px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 4px; }

input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

textarea { min-height: 90px; resize: vertical; }

button, .button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button.secondary, .button.secondary { background: var(--line); color: var(--text); }
button.danger { background: var(--err); }
button:disabled { opacity: 0.5; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--line);
  color: var(--muted);
}

.chip.live { background: rgba(46, 204, 113, 0.15); color: var(--live); }
.chip.err { background: rgba(255, 92, 92, 0.15); color: var(--err); }
.notice { color: var(--warn); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); }

code, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
  word-break: break-all;
}

table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }

.player {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.player video { width: 100%; height: 100%; object-fit: contain; display: block; }

.subtitle {
  position: absolute;
  left: 50%;
  bottom: 6%;
  transform: translateX(-50%);
  max-width: 86%;
  text-align: center;
  font-size: clamp(16px, 2.4vw, 28px);
  line-height: 1.3;
  padding: 4px 12px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  pointer-events: none;
}

.subtitle:empty { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 18px;
}

.overlay[hidden] { display: none; }

.langs { display: flex; gap: 8px; flex-wrap: wrap; }
.langs button { background: var(--line); color: var(--text); }
.langs button.active { background: var(--accent); }

.transcript { max-height: 420px; overflow-y: auto; }
.transcript .item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.transcript .src { color: var(--muted); font-size: 13px; }

.meter { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; width: 200px; }
.meter > div { height: 100%; width: 0; background: var(--live); transition: width 80ms linear; }

.urls td:first-child { width: 90px; color: var(--muted); }
.hint { background: rgba(79, 140, 255, 0.1); border: 1px solid rgba(79, 140, 255, 0.3); border-radius: 8px; padding: 10px 14px; }
.warn { background: rgba(245, 166, 35, 0.1); border: 1px solid rgba(245, 166, 35, 0.35); border-radius: 8px; padding: 10px 14px; }

button.small, .button.small { padding: 4px 10px; }
a.share { color: var(--accent); word-break: break-all; }
.secret { margin-top: 16px; padding: 10px 14px; border: 1px dashed rgba(245, 166, 35, 0.55); border-radius: 8px; background: rgba(245, 166, 35, 0.06); }
.secret label { color: var(--warn); }
button.secret-button { color: var(--warn); border-color: rgba(245, 166, 35, 0.45); }

/* Admin: one card per session – header, info grid, actions row. */
.sessions { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.session { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: rgba(255, 255, 255, 0.015); }
.session-head { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; }
.session-title { min-width: 0; overflow-wrap: anywhere; }
.session-title b { font-size: 16px; margin-right: 4px; }
.session-head .delete { margin-left: auto; }
.session > .error { margin-top: 6px; }
.session-info {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) repeat(3, minmax(0, 1fr));
  gap: 10px 20px;
  margin-top: 10px;
}
.session-info .label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.session-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.icon-button { background: transparent; color: var(--muted); padding: 6px; line-height: 0; border-radius: 6px; }
.icon-button svg { width: 20px; height: 20px; fill: currentColor; }
.icon-button.delete:hover, .icon-button.delete:focus-visible { color: var(--err); background: rgba(255, 92, 92, 0.12); }

@media (max-width: 760px) {
  header { flex-wrap: wrap; gap: 6px 16px; padding: 10px 12px; }
  main { padding: 12px; }
  .session-info { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .session-link { grid-column: 1 / -1; }
  .session-actions > * { flex: 1 1 auto; text-align: center; }
}


/* Public player: full viewport, video left, chat right. */
body.watch { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.watch-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  transition: opacity 0.3s;
}
.watch-bar h1 { font-size: 16px; margin: 0; white-space: nowrap; }
.watch-title { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.watch-controls { display: flex; align-items: center; gap: 12px; margin-left: auto; flex: none; }
.watch-controls .langs { flex-wrap: nowrap; gap: 6px; }
.watch-controls button { padding: 4px 12px; font-size: 14px; }
.watch-subs { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 14px; white-space: nowrap; }
.watch-controls .chip { white-space: nowrap; }
.watch-controls[hidden] + .ui-lang { margin-left: auto; }
.audio-langs { display: flex; align-items: center; gap: 6px; }
.audio-langs > svg { width: 18px; height: 18px; fill: var(--muted); flex: none; }
.watch-main { flex: 1; min-height: 0; display: flex; position: relative; }
body.watch .player { flex: 1; min-width: 0; aspect-ratio: auto; border-radius: 0; }
body.chat-closed .chat { display: none; }

.vc {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 28px 10px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  z-index: 3;
  transition: opacity 0.25s;
}
.player.ctl-idle:not(.ctl-pinned) .vc { opacity: 0; pointer-events: none; }
.player.ctl-idle:not(.ctl-pinned) { cursor: none; }
.vc button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: #fff;
  border-radius: 8px;
}
.vc button:hover, .vc button:focus-visible { background: rgba(255, 255, 255, 0.14); }
.vc svg { width: 24px; height: 24px; fill: currentColor; }
.vc-spacer { flex: 1; }
.vc input[type="range"] {
  width: 110px;
  height: 4px;
  appearance: none;
  border-radius: 2px;
  background: linear-gradient(to right, #fff var(--level, 100%), rgba(255, 255, 255, 0.3) var(--level, 100%));
  cursor: pointer;
}
.vc input[type="range"]::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; }
.vc input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; }
body.watch .subtitle { bottom: max(6%, 64px); }

.gate {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  z-index: 2;
}
.gate[data-mode="play"] { background: rgba(0, 0, 0, 0.6); }
.gate-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 34px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.gate-btn:hover { background: rgba(0, 0, 0, 0.75); }
.gate-icon svg { width: 72px; height: 72px; fill: currentColor; display: block; }
.player:fullscreen { border-radius: 0; }
.player:fullscreen .subtitle { font-size: clamp(20px, 3vw, 40px); }

.chat {
  display: flex;
  flex-direction: column;
  width: 340px;
  flex: none;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  position: relative;
}
.chat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.chat-list { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.chat-empty { margin: auto; text-align: center; }
.chat-msg { max-width: 88%; align-self: flex-start; margin-top: 8px; }
.chat-msg.cont { margin-top: 0; }
.chat-msg.own { align-self: flex-end; text-align: right; }
.chat-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; }
.chat-msg.own .chat-meta { justify-content: flex-end; }
.chat-name { font-weight: 600; }
.chat-meta time { color: var(--muted); }
.chat-text {
  display: inline-block;
  text-align: left;
  background: var(--line);
  padding: 5px 10px;
  border-radius: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.4;
}
.chat-msg.own .chat-text { background: rgba(79, 140, 255, 0.28); }
.chat-more { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); border-radius: 999px; padding: 4px 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); }
.chat-foot { border-top: 1px solid var(--line); padding: 10px 14px; }
.chat-input { display: flex; gap: 8px; }
.chat-input input { flex: 1; min-width: 0; }
.chat-as { margin-top: 4px; }
.chat-as a { color: var(--muted); }


@media (orientation: portrait) and (max-width: 900px) {
  .watch-bar { flex-wrap: wrap; gap: 6px 10px; padding: 6px 10px; }
  .watch-bar h1 { display: none; }
  .watch-title { flex: 1; }
  .watch-controls { width: 100%; margin: 0; gap: 6px 8px; flex-wrap: wrap; order: 1; }
  .watch-controls .chip { margin-left: auto; font-size: 11px; }
  .watch-main { flex-direction: column; }
  body.watch .player { flex: none; width: 100%; aspect-ratio: 16 / 9; }
  body.chat-closed .player { flex: 1; aspect-ratio: auto; }
  .chat { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); }
  .gate-btn { padding: 12px 22px; font-size: 16px; gap: 6px; }
  .gate-icon svg { width: 44px; height: 44px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .watch-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    border: 0;
    background: linear-gradient(rgba(0, 0, 0, 0.75), transparent);
  }
  .watch-bar h1 { display: none; }
  body.bar-idle .watch-bar { opacity: 0; pointer-events: none; }
  .chat { display: none; position: absolute; top: 48px; right: 0; bottom: 0; width: min(340px, 50vw); z-index: 6; }
  body.chat-peek .chat { display: flex; }
}
