:root {
  color-scheme: dark;
  --bg: #101010;
  --panel: #181818;
  --raised: #242424;
  --line: rgba(255, 255, 255, 0.11);
  --text: rgba(255, 255, 255, 0.94);
  --muted: rgba(255, 255, 255, 0.64);
  --accent: #00a4dc;
  --accent-hover: #29b6f6;
  --error: #ff8a80;
  font-family: "Noto Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-weight: 400;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .62; cursor: wait; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { margin: 0; font-size: clamp(1.6rem, 3.6vw, 2.5rem); font-weight: 600; letter-spacing: -.025em; }
p { margin: 0; line-height: 1.5; }
.muted { color: var(--muted); }

/* Header (Jellyfin skinHeader style) */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 58px;
  padding: 0 clamp(1rem, 4vw, 3.5rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .85rem;
  background: rgba(16, 16, 16, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.brand, .top-actions { display: inline-flex; align-items: center; gap: .6rem; }
.brand { font-size: 1rem; font-weight: 600; white-space: nowrap; letter-spacing: -.01em; }
.brand-detail { color: var(--muted); font-weight: 400; font-size: .9rem; }
.brand-mark {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 7px;
  background: linear-gradient(135deg, #aa5cc3 0%, #00a4dc 100%);
  box-shadow: 0 2px 10px rgba(0, 164, 220, 0.28);
}
.brand-mark::after {
  position: absolute;
  content: "";
  left: 11px;
  top: 8px;
  border: 6px solid transparent;
  border-right: 0;
  border-left: 9px solid #fff;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid transparent;
  border-radius: 4px;
  min-height: 36px;
  padding: .42rem .9rem;
  font-size: .86rem;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease;
}
.quiet { border-color: var(--line); background: var(--raised); }
.quiet:hover, .minimal:hover { background: rgba(255, 255, 255, 0.12); }
.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

#app { max-width: 1760px; margin: 0 auto; padding: clamp(1.1rem, 3vw, 2.2rem) clamp(1rem, 4vw, 3.5rem) 3rem; }

/* Auth / Setup Forms */
.setup {
  max-width: 430px;
  margin: clamp(.5rem, 8vh, 4.5rem) auto 0;
  padding: clamp(1.5rem, 5vw, 2.4rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.setup-mark { margin-bottom: 1rem; }
.setup h1 { font-size: 1.75rem; }
.setup h1 + p { margin-top: .5rem; font-size: .92rem; }
.setup form { margin-top: 1.5rem; display: grid; gap: 1rem; }
label { display: grid; gap: .4rem; color: var(--text); font-size: .85rem; font-weight: 500; }
input:not([type=range]) {
  max-width: 100%;
  width: 100%;
  min-height: 40px;
  padding: .5rem .75rem;
  color: var(--text);
  background: #242424;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
}
input:not([type=range]):focus { border-color: var(--accent); outline: none; }
input::placeholder { color: rgba(255, 255, 255, 0.4); }
input[type=file] { padding: .6rem; }
input::file-selector-button {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .3rem .6rem;
  margin-right: .6rem;
  color: var(--text);
  background: #303030;
  cursor: pointer;
}
.form-actions { display: flex; justify-content: space-between; gap: .7rem; }
.form-error { min-height: 0; color: var(--error); font-size: .86rem; }
.form-error:empty { display: none; }

/* Library & Breadcrumbs */
.crumbs {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: .88rem;
}
.crumbs button { border: 0; background: none; color: var(--accent); padding: .15rem 0; font-weight: 500; }
.crumbs button:hover { text-decoration: underline; }

.library-title {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.library-title.has-featured {
  min-height: clamp(200px, 26vw, 310px);
  padding: clamp(1.2rem, 3.5vw, 2.2rem);
  border-radius: 8px;
  overflow: hidden;
  background: #181818;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.library-backdrop {
  z-index: -2;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 35%;
}
.library-title.has-featured::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, rgba(16, 16, 16, 0.94) 0%, rgba(16, 16, 16, 0.72) 42%, rgba(16, 16, 16, 0.18) 100%),
              linear-gradient(0deg, rgba(16, 16, 16, 0.92) 0%, transparent 65%);
}
.library-intro { min-width: 0; }
.library-title h1 { font-size: clamp(1.75rem, 4.2vw, 3.1rem); overflow-wrap: anywhere; line-height: 1.08; }
.summary { margin-top: .4rem; font-size: .88rem; }
.featured-action { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; }
.featured-play { padding-inline: 1.15rem; border-radius: 999px; }
.featured-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .86rem; color: var(--muted); }
.filter { width: min(100%, 16rem); flex: none; }
.has-featured .filter input { background: rgba(16, 16, 16, 0.78); backdrop-filter: blur(8px); border-color: rgba(255, 255, 255, 0.22); }
.filter span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Jellyfin-style Card Grid */
.library h2 {
  margin: 0 0 .85rem;
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: -.01em;
  color: rgba(255, 255, 255, 0.92);
}
.folder-grid, .video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 275px), 1fr));
  gap: 1.1rem .95rem;
}
.folder-group:not([hidden]) + .video-group:not([hidden]) { margin-top: 2.2rem; }

/* Clean borderless Jellyfin cards */
.folder-card, .video-card {
  display: flex;
  flex-direction: column;
  gap: .52rem;
  padding: 0;
  margin: 0;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--text);
  text-align: center;
}
.card-media {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 5px;
  background: #1c1c1c;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  transition: box-shadow .18s ease, transform .18s ease;
}
.folder-card:hover .card-media,
.video-card:hover .card-media,
.folder-card:focus-visible .card-media,
.video-card:focus-visible .card-media {
  box-shadow: 0 0 0 2px var(--accent), 0 10px 26px rgba(0, 0, 0, 0.65);
}
.folder-card:focus-visible, .video-card:focus-visible { outline: none; }

.video-image, .card-preview {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .24s ease;
}
.folder-card:hover .video-image { transform: scale(1.03); }

/* Folder top-right Jellyfin badges (folder icon + cyan count circle) */
.folder-badges {
  position: absolute;
  top: .45rem;
  right: .45rem;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: .32rem;
}
.folder-icon-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(18, 18, 18, 0.72);
  backdrop-filter: blur(4px);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.folder-count-badge {
  min-width: 28px;
  height: 28px;
  padding: 0 .4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

/* Fallback placeholder when folder has no cover */
.folder-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #22252b 0%, #16181c 100%);
  color: rgba(255, 255, 255, 0.22);
}

/* Video card hover play + on-media trickplay scrub bar */
.card-play-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.32) 0%, rgba(0, 0, 0, 0.08) 65%);
  opacity: 0;
  transition: opacity .16s ease;
  pointer-events: none;
}
.card-play-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  border: 2px solid rgba(255, 255, 255, 0.88);
  color: #fff;
  display: grid;
  place-items: center;
  padding-left: 2px;
}
.video-card:hover .card-play-overlay { opacity: 1; }
.video-card.is-scrubbing .card-play-overlay { opacity: 0; }

.media-badge {
  position: absolute;
  bottom: .45rem;
  right: .45rem;
  z-index: 3;
  border-radius: 4px;
  padding: .16rem .42rem;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: .74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.card-scrub-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  opacity: 0;
  transition: opacity .12s ease;
  pointer-events: none;
}
.video-card.is-scrubbing .card-scrub-track { opacity: 1; }
.card-scrub-fill { height: 100%; width: 0%; background: var(--accent); }

.card-text { display: grid; min-width: 0; gap: .16rem; padding: 0 .2rem; text-align: center; }
.item-name {
  font-size: .92rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-card:hover .item-name, .video-card:hover .item-name { color: #fff; }
.item-meta { font-size: .78rem; color: var(--muted); }
.empty { padding: 2.5rem 0; }

/* =========================================================
   Jellyfin-Style Fullscreen Video Player OSD
   ========================================================= */
.player, body:has(.watch) { background: #000; }
body:has(.watch) .top { display: none; }
#app:has(.watch) { width: 100%; max-width: none; margin: 0; padding: 0; }
.player { isolation: isolate; position: relative; width: 100%; height: 100svh; overflow: hidden; user-select: none; }
.player:focus { outline: none; }
.player video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }

.watch-header, .controls {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  transition: opacity .22s ease, visibility .22s ease;
}
.watch-header {
  top: 0;
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: clamp(.75rem, 2.5vw, 1.4rem) clamp(.85rem, 3.5vw, 2.2rem) 2.8rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.86) 0%, rgba(0, 0, 0, 0.42) 58%, transparent 100%);
}
.watch-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 500;
  letter-spacing: -.01em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85);
}

.osd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 .45rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  transition: background-color .15s ease, color .15s ease, transform .1s ease;
}
.osd-btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.osd-btn:active { transform: scale(0.93); }
.osd-btn.speed {
  border-radius: 999px;
  padding: 0 .65rem;
  font-size: .82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.osd-btn.scenes[aria-expanded=true] { color: var(--accent); background: rgba(0, 164, 220, 0.16); }

.center-play {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  transform: translate(-50%, -50%);
  display: grid;
  place-content: center;
  width: clamp(60px, 8vw, 78px);
  aspect-ratio: 1;
  padding-left: 3px;
  color: #fff;
  background: rgba(16, 16, 16, 0.62);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.65);
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}
.center-play:hover {
  background: rgba(0, 164, 220, 0.85);
  border-color: var(--accent);
  transform: translate(-50%, -50%) scale(1.06);
}
.player.is-playing .center-play { display: none; }

.osd-feedback {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  transform: translate(-50%, -50%);
  padding: .55rem 1.05rem;
  border-radius: 999px;
  background: rgba(16, 16, 16, 0.78);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  pointer-events: none;
}

.player.is-playing:not(.show-controls) .watch-header,
.player.is-playing:not(.show-controls) .controls {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}
.player.is-playing:not(.show-controls) { cursor: none; }

.controls {
  bottom: 0;
  padding: 2.6rem clamp(.85rem, 3.5vw, 2.2rem) max(.7rem, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.65) 55%, transparent 100%);
}
.controls .form-error { margin-bottom: .55rem; text-shadow: 0 1px 4px #000; }

/* Toggleable Trickplay Scene Strip (sits ON the bottom of the video) */
.scene-panel { margin-bottom: .6rem; }
.scene-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(92px, 11vw, 152px);
  gap: .5rem;
  width: fit-content;
  max-width: 100%;
  padding: .35rem;
  border-radius: 8px;
  background: rgba(16, 16, 16, 0.78);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow-x: auto;
  scrollbar-width: thin;
}
.scene {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border-radius: 5px;
  border: 2px solid transparent;
  background: #181818;
  color: #fff;
  transition: border-color .14s ease, transform .14s ease;
}
.scene:hover { border-color: var(--accent); transform: translateY(-1px); }
.scene:focus-visible { outline-offset: 1px; }
.scene img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.scene time {
  position: absolute;
  bottom: .25rem;
  right: .25rem;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 3px;
  padding: .1rem .3rem;
  font-size: .7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Jellyfin Timeline & Floating Trickplay Preview */
.timeline { position: relative; display: flex; align-items: center; height: 24px; margin-bottom: .25rem; }
.timeline input {
  appearance: none;
  width: 100%;
  height: 4px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--seek-progress, 0%), rgba(255, 255, 255, 0.25) var(--seek-progress, 0%));
  cursor: pointer;
  transition: height .12s ease;
}
.timeline:hover input { height: 6px; }
.timeline input::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.75);
  transition: transform .12s ease;
}
.timeline:hover input::-webkit-slider-thumb { transform: scale(1.18); background: #fff; }
.timeline input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.preview {
  position: absolute;
  z-index: 6;
  bottom: 2rem;
  transform: translateX(-50%);
  width: min(220px, 48vw);
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  overflow: hidden;
  pointer-events: none;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.78);
}
.preview img { width: 100%; aspect-ratio: 16 / 9; display: block; object-fit: cover; }
.preview time {
  position: absolute;
  bottom: .35rem;
  left: 50%;
  transform: translateX(-50%);
  padding: .14rem .45rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.control-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.control-left, .control-right { display: flex; align-items: center; gap: .2rem; }
.time {
  margin-left: .45rem;
  color: rgba(255, 255, 255, 0.85);
  font-variant-numeric: tabular-nums;
  font-size: .86rem;
  font-weight: 500;
  white-space: nowrap;
}
.volume-wrap { display: inline-flex; align-items: center; gap: .25rem; }
.volume { display: inline-flex; align-items: center; width: clamp(60px, 7vw, 96px); }
.volume span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.volume input { width: 100%; height: 4px; accent-color: var(--accent); cursor: pointer; }
.player:fullscreen { width: 100%; height: 100%; }

#notice {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 30;
  padding: .75rem 1rem;
  background: #242424;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  font-size: .88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

@media (max-width: 560px) {
  .brand-detail { display: none; }
  .brand, .top-actions { gap: .4rem; }
  .top { flex-wrap: wrap; padding-block: .5rem; }
  .top .button { padding-inline: .6rem; font-size: .8rem; min-height: 32px; }
  .library-title { align-items: stretch; flex-direction: column; }
  .filter { width: 100%; }
  .folder-grid, .video-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 155px), 1fr)); gap: .85rem .65rem; }
  .osd-btn { min-width: 34px; height: 34px; }
  .volume { display: none; }
  .osd-btn.speed { display: none; }
  .time { font-size: .78rem; margin-left: .2rem; }
}
@media (max-height: 430px) and (orientation: landscape) {
  .watch-header { padding-bottom: 1.15rem; }
  .controls { padding-top: 1.1rem; }
  .scene-strip { grid-auto-columns: clamp(72px, 13vw, 112px); }
}
@media (prefers-reduced-motion: reduce) {
  .watch-header, .controls, .card-media, .video-image { transition: none; }
}
