:root {
  color-scheme: dark;
  --bg: #101211;
  --bg-soft: #141817;
  --surface: #1b201f;
  --surface-raised: #222827;
  --surface-input: #0c0f0e;
  --line: #343d3a;
  --line-strong: #4c5a55;
  --text: #f6f3ea;
  --muted: #aeb7b1;
  --subtle: #7f8d86;
  --accent: #38d996;
  --accent-blue: #5cb7ff;
  --accent-warm: #f4c95d;
  --danger: #ff927f;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 210px),
    linear-gradient(135deg, rgba(56, 217, 150, 0.08), rgba(92, 183, 255, 0.05) 48%, rgba(244, 201, 93, 0.06)),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar,
.workspace,
.app-footer {
  width: min(100%, 1480px);
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  margin-bottom: 16px;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2.35rem;
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
  line-height: 1.25;
}

h3 {
  margin-bottom: 5px;
  font-size: 0.98rem;
  line-height: 1.32;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.auth-status {
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(27, 32, 31, 0.86);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
}

.auth-status.is-authenticated {
  color: #092016;
  background: var(--accent);
  border-color: transparent;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.search-pane,
.player-pane {
  min-width: 0;
  background: rgba(27, 32, 31, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-pane {
  overflow: hidden;
}

.player-pane {
  padding: 14px;
}

.pane-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.pane-heading > span {
  flex-shrink: 0;
  color: var(--subtle);
  font-size: 0.82rem;
  font-weight: 700;
}

.player-heading {
  padding: 0 0 12px;
  border-bottom: 0;
}

.player-heading h2 {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.player-status {
  display: grid;
  gap: 4px;
  justify-items: end;
  flex-shrink: 0;
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 700;
}

.player-status strong {
  color: var(--muted);
  font-size: 0.82rem;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.search-field,
.search-form .primary-button {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  color: var(--text);
  background: var(--surface-input);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  outline: none;
}

input::placeholder {
  color: #78847d;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 217, 150, 0.18);
}

.primary-button,
.secondary-button,
.play-button,
.icon-button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  font-weight: 800;
}

.primary-button {
  color: #06150f;
  background: var(--accent);
  padding: 0 18px;
}

.primary-button:hover {
  background: #62e4ac;
}

.secondary-button {
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  padding: 0 16px;
}

.secondary-button:hover {
  border-color: var(--line-strong);
  background: #2a3230;
}

.accent-action {
  color: #06150f;
  background: var(--accent-warm);
  border-color: transparent;
}

.accent-action:hover {
  background: #ffd978;
}

.topbar-login {
  min-width: 118px;
}

.play-button {
  color: #06131a;
  background: var(--accent-blue);
  padding: 0 14px;
  white-space: nowrap;
}

.play-button:hover {
  background: #83caff;
}

.icon-button {
  width: 42px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 12px 14px;
  color: var(--muted);
  background: rgba(16, 18, 17, 0.35);
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

#statusText {
  color: var(--accent-warm);
  font-weight: 700;
}

.results {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 286px);
  min-height: 260px;
  overflow: auto;
  padding: 12px;
}

.results.has-detail {
  max-height: calc(100vh - 620px);
  min-height: 150px;
}

.result-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(34, 40, 39, 0.76);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.result-row:hover,
.result-row:focus-within,
.result-row:focus {
  border-color: var(--accent);
  background: rgba(38, 48, 44, 0.92);
  outline: none;
}

.result-row.is-selected {
  border-color: var(--accent-blue);
  background: rgba(38, 52, 60, 0.92);
}

.result-thumb {
  position: relative;
  width: 84px;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-input);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.result-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.result-thumb.has-image img {
  opacity: 1;
}

.result-thumb-placeholder {
  color: var(--subtle);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.file-detail {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(16, 18, 17, 0.35);
}

.file-detail-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.file-detail-image {
  width: 132px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-input);
}

.file-detail-heading {
  min-width: 0;
}

.file-detail-heading h3 {
  margin: 2px 0 4px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.file-detail-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.file-detail-status.is-error {
  color: var(--danger);
}

.file-detail-description {
  margin: 0;
  max-height: 120px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.file-detail-actions {
  display: flex;
  gap: 8px;
}

.result-info {
  min-width: 0;
}

.result-info h3 {
  overflow-wrap: anywhere;
}

.result-info p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.result-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 6px;
}

.quality-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--text);
  background: var(--surface-raised);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.quality-badge--sd {
  color: var(--muted);
}

.quality-badge--hd {
  color: #06131a;
  background: var(--accent-blue);
  border-color: transparent;
}

.quality-badge--fhd {
  color: #06150f;
  background: var(--accent);
  border-color: transparent;
}

.quality-badge--uhd {
  color: #1a1206;
  background: linear-gradient(135deg, #f4c95d, #ffb86b);
  border-color: transparent;
}

.quality-badge--codec {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}

.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #050605;
  border: 1px solid var(--line);
  border-radius: 8px;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  background: #050605;
}

.player-frame .video-js {
  width: 100%;
  height: 100%;
  color: var(--text);
  background: #050605;
}

.player-frame .vjs-fluid {
  height: 100% !important;
  padding-top: 0 !important;
}

.player-frame .vjs-tech {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-frame .vjs-control-bar {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  transform: none !important;
  bottom: 0 !important;
  height: 3.4em;
  z-index: 4;
  background: rgba(5, 6, 5, 0.86);
}

.player-frame .video-js.vjs-has-started.vjs-user-inactive.vjs-playing .vjs-control-bar,
.player-frame .video-js.vjs-user-inactive .vjs-control-bar,
.player-frame .video-js.vjs-controls-enabled .vjs-control-bar {
  visibility: visible !important;
  opacity: 1 !important;
}

.player-frame .video-js.ws-vod-controls .vjs-progress-control,
.player-frame .video-js.ws-vod-controls .vjs-current-time,
.player-frame .video-js.ws-vod-controls .vjs-time-divider,
.player-frame .video-js.ws-vod-controls .vjs-duration,
.player-frame .video-js.ws-vod-controls .vjs-live-control,
.player-frame .video-js.ws-vod-controls .vjs-seek-to-live-control {
  display: none !important;
}

.player-frame .vjs-play-progress,
.player-frame .vjs-volume-level {
  background-color: var(--accent);
}

.backend-timeline {
  display: grid;
  grid-template-columns: auto auto minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  margin-top: 10px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(12, 15, 14, 0.64);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 800;
}

.backend-timeline[hidden] {
  display: none !important;
}

.backend-timeline-track {
  position: relative;
  width: 100%;
  min-height: 18px;
  padding: 0;
  overflow: hidden;
  background: rgba(246, 243, 234, 0.22);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.backend-timeline-track:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.seek-button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.seek-button:hover {
  border-color: var(--accent);
}

/* Video.js control bar: -10 s / +10 s buttons next to play */
.player-frame .vjs-control-bar .ws-seek-button {
  width: auto;
  min-width: 3.2em;
  padding: 0 0.4em;
}

.player-frame .vjs-control-bar .ws-seek-button .vjs-icon-placeholder {
  font-family: inherit;
  font-size: 0.85em;
  font-weight: 800;
  line-height: 3.4em;
}

.player-frame .vjs-control-bar .ws-seek-button .vjs-icon-placeholder::before {
  content: none;
}

.backend-timeline-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-blue));
  border-radius: inherit;
  pointer-events: none;
}

.player-frame .vjs-big-play-button {
  border-color: var(--accent);
  background: rgba(34, 40, 39, 0.9);
}

.empty-player {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  pointer-events: none;
  color: var(--muted);
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 16px),
    #262b2a;
}

[hidden] {
  display: none !important;
}

.empty-player strong {
  color: var(--text);
  font-size: 1.12rem;
}

.empty-player span {
  color: var(--muted);
}

.now-playing {
  min-height: 110px;
  padding-top: 12px;
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.player-actions .secondary-button {
  min-width: 128px;
}

.player-actions .secondary-button:disabled {
  cursor: not-allowed;
}

.meta-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
  padding: 12px;
  background: rgba(16, 18, 17, 0.36);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.meta-list dt,
.meta-list dd {
  min-width: 0;
}

.meta-list dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.meta-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.notice {
  margin: 12px 0 0;
  color: var(--muted);
}

.notice.is-error {
  color: var(--danger);
}

.diagnostics-panel {
  margin-top: 12px;
  background: rgba(12, 15, 14, 0.5);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.diagnostics-panel summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.diagnostic-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 7px 12px;
  margin: 0;
  padding: 0 12px 12px;
}

.diagnostic-list dt {
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 800;
}

.diagnostic-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.84rem;
}

.diagnostic-log {
  max-height: 170px;
  margin: 0 12px 12px;
  overflow: auto;
  padding: 10px;
  color: var(--muted);
  background: #080a09;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.empty-results {
  display: grid;
  min-height: 160px;
  place-items: center;
  padding: 20px;
  color: var(--muted);
  background: rgba(12, 15, 14, 0.42);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.settings-dialog {
  width: min(520px, calc(100vw - 28px));
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.66);
}

.settings-panel {
  display: grid;
  gap: 16px;
  padding: 6px;
}

.settings-panel header,
.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-panel h2 {
  margin-bottom: 0;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.settings-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.settings-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.25;
}

/* The one checkbox in the settings dialog: the library sharing switch. */
.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 40px;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: none;
}

.checkbox-field span {
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.35;
}

.settings-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.login-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.login-status.is-error {
  color: var(--danger);
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px 0;
  color: var(--subtle);
  font-size: 0.78rem;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.player-heading-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.cinema-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.8rem;
}

.cinema-button[aria-pressed="true"] {
  color: #06150f;
  background: var(--accent);
  border-color: transparent;
}

/* Cinema mode: the search pane is hidden and the player takes the whole width (toggle: T). */
body.is-cinema .search-pane {
  display: none;
}

body.is-cinema .workspace {
  grid-template-columns: 1fr;
}

body.is-cinema .player-pane {
  width: min(100%, 1480px);
  margin-inline: auto;
}

/* Embedded player mode (?embed=1): only the player pane is shown, used by the series page. */
body.is-embed {
  background: var(--bg);
}

body.is-embed .app-shell {
  padding: 0;
}

body.is-embed .topbar,
body.is-embed .search-pane,
body.is-embed .cinema-button,
body.is-embed .app-footer {
  display: none;
}

body.is-embed .workspace {
  grid-template-columns: 1fr;
  width: 100%;
}

body.is-embed .player-pane {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

@media (max-width: 1060px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .results {
    max-height: none;
    min-height: 180px;
  }

  .results.has-detail {
    max-height: 240px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .topbar-actions,
  .status-row,
  .settings-actions {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 1.8rem;
  }

  .search-form,
  .meta-list,
  .diagnostic-list {
    grid-template-columns: 1fr;
  }

  .result-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .result-row .play-button {
    grid-column: 1 / -1;
  }

  .file-detail-image {
    width: 96px;
  }

  .player-status {
    justify-items: start;
  }

  .auth-status,
  .account-status,
  .topbar-login {
    width: 100%;
  }

  .account-status {
    justify-content: center;
    white-space: normal;
  }
}

.quality-badge--chip {
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.backend-load {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--subtle);
}

.backend-load::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--subtle);
}

.backend-load.is-busy {
  color: var(--accent);
}

.backend-load.is-busy::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 217, 150, 0.2);
}

.backend-load.is-full {
  color: var(--accent-warm);
}

.backend-load.is-full::before {
  background: var(--accent-warm);
  box-shadow: 0 0 0 3px rgba(244, 201, 93, 0.2);
}

/* The same chip as .backend-load, only sitting in the topbar next to .auth-status, so it takes
   the pill chrome of its neighbour and keeps the dot and the is-busy colours of .backend-load. */
.account-status {
  min-height: 34px;
  padding: 0 12px;
  background: rgba(27, 32, 31, 0.86);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
