:root {
  --accent: #4d7ea6;
  --bg: #10161d;
  --bg2: #151e28;
  --panel: #18232e;
  --panel2: #202d39;
  --line: #31414e;
  --text: #e3e9ee;
  --muted: #a3afb9;
  --danger: #d97979;
  --radius: 8px;
  --sidebar-w: 340px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}
html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: rgba(255, 255, 255, .08); padding: 1px 5px; border-radius: 5px; }

/* ============================== Top bar ============================== */

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #0c1218;
  position: relative;
  z-index: 30;
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 90px; height: 60px;
  display: block;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  flex: 0 0 auto;
}

.brand-text h1 { margin: 0; font-size: 17px; letter-spacing: .3px; }
.brand-text p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }

.tabs {
  display: flex; justify-self: center; gap: 8px; min-width: 0;
  max-width: min(44vw, 650px); margin: 0;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 9px 18px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.tab:hover { color: var(--text); border-color: var(--accent); }
.tab.active {
  color: #fff;
  background: #315f80;
  border-color: #315f80;
}

.top-actions { display: flex; justify-self: end; gap: 8px; margin-left: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--accent); background: var(--panel2); }
.btn.ghost { background: transparent; }
.btn-ico { font-size: 15px; }
.btn.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ============================== Layout ============================== */

.layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.stage { flex: 1 1 auto; min-width: 0; padding: 22px; display: flex; }

.player {
  position: relative;
  flex: 1;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  align-items: stretch;
  min-height: 300px;
  outline: none;
}

.player:fullscreen, .player:-webkit-full-screen { border-radius: 0; }

.videos { position: absolute; inset: 0; }

.videos video {
  width: 100%; height: 100%;
  background: #000;
  object-fit: contain;
  cursor: pointer;
}
.videos video:focus { outline: none; }
.videos video.hidden { display: none; }

/* ============================== Big play / overlays ============================== */

.big-play {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  transition: opacity .25s ease;
  z-index: 4;
}
.big-play::before {
  content: "";
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .12);
  pointer-events: none;
}
.big-play span {
  width: 92px; height: 92px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 34px;
  color: #fff;
  background: rgba(20, 31, 42, .88);
  border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .28);
  transform: translateX(2px);
  transition: transform .15s ease;
  pointer-events: none;
}
.big-play:hover span, .big-play.hot span { transform: translateX(2px) scale(1.07); }
.big-play.hidden, .video-playing .big-play { opacity: 0; pointer-events: none; }

.chip {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  background: rgba(10, 15, 26, .82);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 12.5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  pointer-events: none;
}
.chip b { color: var(--accent); }

.hint {
  position: absolute; bottom: 96px; left: 50%; transform: translateX(-50%);
  z-index: 5;
  background: rgba(10, 15, 26, .85);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .4s ease;
  pointer-events: none;
}
.hint.show { opacity: 1; }

.video-error {
  position: absolute; inset: 0; z-index: 4;
  display: grid; place-content: center; place-items: center;
  gap: 8px; padding: 24px; text-align: center;
  background: rgba(10, 15, 26, .92);
}
.video-error[hidden] { display: none; }
.video-error strong { font-size: 20px; color: var(--danger); }
.video-error span { color: var(--muted); word-break: break-all; }
.video-error em { color: var(--muted); font-size: 12.5px; font-style: normal; }

/* ============================== Controls ============================== */

.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 26px 16px 12px;
  background: rgba(5, 8, 14, .78);
  opacity: 0;
  transition: opacity .2s ease;
}
.player.controls-on .controls { opacity: 1; }

@media (hover: hover) and (pointer: fine) {
  .player.controls-idle,
  .player.controls-idle * { cursor: none !important; }
}

.ctrl-row { display: flex; align-items: center; gap: 8px; }

.ctrl {
  min-width: 34px; height: 34px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 9px;
  font-size: 14px;
  color: var(--text);
  padding: 0 8px;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.ctrl:hover { background: rgba(255, 255, 255, .14); border-color: var(--accent); }
.ctrl.on { color: var(--accent); border-color: var(--accent); }
.ctrl.wide { display: none; }

.spacer { flex: 1; }

.time { color: var(--text); font-variant-numeric: tabular-nums; font-size: 13px; margin: 0 4px; }

.settings-wrap { position: relative; }
.settings-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: 250px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  color: var(--text);
}
.settings-menu[hidden] { display: none; }
.settings-title { margin: 0 0 8px; font-weight: 700; }
.quality-info { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.settings-field { display: grid; gap: 5px; font-size: 12px; }
.settings-field select {
  width: 100%;
  padding: 7px 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}
.settings-field option { background: var(--panel); }
.settings-volume { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; }
.settings-volume .ctrl { flex: 0 0 auto; }
.settings-volume .vol { min-width: 0; flex: 1; accent-color: var(--accent); }

/* ============================== Progress bar ============================== */

.progress {
  position: relative;
  height: 24px;
  margin: 0 2px 10px;
  cursor: pointer;
  touch-action: pan-y;
}

.track {
  position: absolute; top: 50%; left: 0; right: 0; height: 5px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, .16);
  border-radius: 99px;
  overflow: visible;
}
.buffered {
  position: absolute; top: 50%; left: 0; height: 5px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, .28);
  border-radius: 99px;
}
.played {
  position: absolute; top: 50%; left: 0; height: 5px;
  transform: translateY(-50%);
  background: var(--accent);
  border-radius: 99px;
}
.thumb {
  position: absolute; top: 50%;
  width: 13px; height: 13px;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
  transition: transform .12s ease;
  pointer-events: none;
}
.progress:hover .thumb { transform: translate(-50%, -50%) scale(1.3); }

.markers { position: absolute; inset: 0; }

.marker {
  position: absolute; top: 0; bottom: 0;
  width: 3px;
  transform: translateX(-1.5px);
  background: var(--mc, var(--accent));
  border-radius: 3px;
  cursor: pointer;
  z-index: 2;
}
.marker::after {
  content: "";
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 11px; height: 11px;
  background: var(--mc, var(--accent));
  border: 2px solid #04121a;
  border-radius: 50%;
}
.marker:hover { width: 5px; transform: translateX(-2.5px); }
.marker.active { z-index: 3; filter: brightness(1.5); }
.marker.active::after { border-color: #fff; }

.tip {
  position: absolute; bottom: 26px;
  transform: translateX(-50%);
  background: #0b1424;
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  pointer-events: none;
  z-index: 20;
}
.tip b { color: var(--accent); }

/* ============================== Sidebar ============================== */

.sidebar {
  flex: 0 0 0;
  width: 0;
  overflow: hidden;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: width .28s ease, flex-basis .28s ease;
}
.layout.sidebar-open .sidebar {
  flex-basis: var(--sidebar-w);
  width: var(--sidebar-w);
}

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}
.side-head h2 { margin: 0; font-size: 15px; }
.side-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.tc-list {
  list-style: none; margin: 0; padding: 10px;
  overflow-y: auto;
  flex: 1;
}

.side-hidden { display: none; }

.tc-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  margin-bottom: 4px;
  transition: background .15s ease;
}
.tc-item:hover { background: var(--panel2); }
.tc-item.active { background: rgba(77, 126, 166, .12); border-color: var(--accent); }
.tc-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--tcc, var(--accent));
  flex: 0 0 auto;
}
.tc-label { flex: 1; color: var(--text); font-size: 13.5px; min-width: 0; }
.tc-label small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.tc-time { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; font-size: 13px; }
.tc-playing { flex: 0 0 auto; color: var(--accent); font-size: 11px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2 } }

.empty-tc {
  color: var(--muted); text-align: center;
  padding: 30px 14px; font-size: 13px;
}

.side-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ============================== Fatal error ============================== */

.fatal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 8, 14, .9);
  display: grid; place-items: center;
  padding: 24px;
}
.fatal[hidden] { display: none; }
.fatal-box {
  background: var(--panel);
  border: 1px solid var(--danger);
  border-radius: 16px;
  max-width: 440px;
  padding: 26px;
  text-align: center;
  box-shadow: var(--shadow);
}
.fatal-box strong { font-size: 18px; color: var(--danger); }
.fatal-box p { color: var(--muted); }
.fatal-box .btn { margin-top: 8px; }

/* ============================== Responsive ============================== */

@media (max-width: 900px) {
  .topbar { display: flex; flex-wrap: wrap; gap: 8px; }
  .tabs { order: 3; justify-self: auto; width: 100%; max-width: none; margin: 2px 0 0; }
  .top-actions { margin-left: auto; }
  .hide-sm { display: none; }
  .stage { padding: 10px; }
  .ctrl.wide { display: grid; }
  .vol { display: none; }
  :root { --sidebar-w: min(320px, 92vw); }
}

@media (max-width: 700px) {
  body {
    height: auto;
    min-height: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .logo { width: 64px; height: 46px; }
  .brand { gap: 8px; }
  .brand-text h1 { font-size: 15px; }
  .brand-text p { font-size: 11px; }
  .top-actions { gap: 5px; }
  .top-actions .btn { padding: 7px 9px; font-size: 12px; }

  .layout {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    min-height: 0;
  }

  .stage {
    display: block;
    flex: 0 0 auto;
    padding: 8px;
  }

  .player {
    width: 100%;
    min-height: 0;
    aspect-ratio: 16 / 9;
  }

  .controls {
    padding: 20px 10px 8px;
    background: linear-gradient(transparent, rgba(5, 8, 14, .9) 35%);
  }

  .ctrl-row { gap: 5px; }
  .ctrl { min-width: 32px; height: 34px; padding: 0 6px; }
  .time { font-size: 12px; margin: 0 2px; }

  .sidebar,
  .layout.sidebar-open .sidebar {
    display: flex;
    flex: 0 0 auto;
    width: auto;
    max-height: 48vh;
    max-height: 48dvh;
    border-left: 0;
    border-top: 1px solid var(--line);
    transition: none;
  }

  .sidebar { display: none; }
}

@media (max-width: 380px) {
  .stage { padding: 6px; }
  .topbar { padding-right: 8px; padding-left: 8px; }
  .brand-text h1 { font-size: 13px; }
  .brand-text p { font-size: 10px; }
  .top-actions .btn { padding: 6px 7px; }
  .ctrl-row { flex-wrap: wrap; }
  .spacer { display: none; }
  .time { margin-right: auto; }
}

@media (hover: none), (pointer: coarse) {
  .controls {
    opacity: 1;
    transform: none;
  }
}