:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --panel: #fffdf8;
  --ink: #20201f;
  --muted: #6d6a64;
  --line: #ddd6ca;
  --accent: #0b7a75;
  --accent-strong: #075f5b;
  --warm: #c25b38;
  --soft: #eaf4f1;
  --shadow: 0 24px 70px rgba(42, 35, 26, 0.15);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(11, 122, 117, 0.09), transparent 32%),
    linear-gradient(315deg, rgba(194, 91, 56, 0.12), transparent 38%),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
.icon-button,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf2;
}

button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover,
.icon-button:hover,
select:hover {
  border-color: #bba98f;
}

button:active,
.icon-button:active {
  transform: translateY(1px);
}

button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-strong);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(390px, 460px);
  gap: 18px;
  width: min(1500px, 100%);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: 18px;
}

.player-panel,
.library-panel {
  border: 1px solid rgba(125, 109, 83, 0.28);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.player-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar,
.library-header,
.now-playing {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.topbar {
  border-bottom: 1px solid var(--line);
}

.topbar > div,
.library-header > div {
  min-width: 0;
}

.topbar h1,
.library-header h2 {
  margin: 3px 0 0;
  font-size: clamp(1.1rem, 2vw, 1.85rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar h1 {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow,
.meta-label {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.video-frame {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 0;
  background: #131313;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  background: #111;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  color: #f6efe5;
  text-align: center;
  background: radial-gradient(circle at center, rgba(54, 54, 49, 0.92), rgba(17, 17, 17, 0.98));
}

.empty-state[hidden] {
  display: none;
}

.control-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
}

.control-strip button {
  min-width: 0;
  overflow: hidden;
  padding-inline: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.now-playing {
  min-width: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.now-playing > div {
  min-width: 0;
}

#currentMeta {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.library-header {
  border-bottom: 1px solid var(--line);
}

.library-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 224px;
}

.compact-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select {
  width: 100%;
  padding: 0 10px;
}

.search-stack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: grid;
  gap: 7px;
  padding: 14px 18px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.search-box + .search-box {
  border-left: 1px solid var(--line);
}

.search-box input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.search-box input:focus,
button:focus-visible,
.icon-button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(11, 122, 117, 0.2);
  outline-offset: 2px;
}

.metadata-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.metadata-filter {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metadata-filter select {
  min-width: 0;
  height: 38px;
  min-height: 38px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
}

.playlist {
  position: relative;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.playlist-item {
  display: flex;
  align-items: center;
  height: 82px;
  margin: 0;
}

.playlist-spacer {
  height: var(--spacer-height, 0px);
  pointer-events: none;
}

.playlist-button {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 74px;
  min-height: 74px;
  margin: 0;
  border: 0;
  border-radius: 8px;
  padding: 8px;
  background: transparent;
  text-align: left;
}

.playlist-button:hover,
.playlist-button[aria-current="true"] {
  background: #f0ebe1;
}

.playlist-button[aria-current="true"] {
  box-shadow: inset 3px 0 0 var(--accent);
}

.thumbnail {
  position: relative;
  display: block;
  width: 92px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  background: #25231f;
}

.thumbnail img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-missing::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6px;
  color: #d8d0c1;
  content: "No image";
  font-size: 0.68rem;
  font-weight: 750;
  text-align: center;
}

.duration-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 38px;
  border-radius: 5px;
  padding: 3px 5px;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.video-copy {
  min-width: 0;
}

.video-title,
.video-url {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-title {
  color: var(--ink);
  font-weight: 760;
}

.video-url {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.pill.saved {
  border-color: rgba(194, 91, 56, 0.4);
  color: var(--warm);
  background: #fff0e9;
}

.pill.watched {
  border-color: rgba(11, 122, 117, 0.35);
  color: var(--accent-strong);
  background: var(--soft);
}

.pill.failed {
  border-color: rgba(127, 31, 25, 0.35);
  color: #7f1f19;
  background: #ffe9e5;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 56%) minmax(0, 44%);
    padding: 10px;
  }

  .control-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .library-panel {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .topbar,
  .library-header,
  .now-playing {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .library-controls,
  .search-stack,
  .metadata-filters {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .search-box + .search-box {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .topbar-actions > * {
    flex: 1;
  }

  .control-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-strip button {
    min-width: 0;
    padding-inline: 8px;
  }

  .playlist-button {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .thumbnail {
    width: 74px;
  }

  .status-pills {
    grid-column: 2;
    justify-content: flex-start;
  }
}
