:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #211f1b;
  --muted: #6d665c;
  --line: #ded6c8;
  --accent: #006d77;
  --accent-strong: #004f58;
  --warm: #c8553d;
  --gold: #c99a2e;
  --shadow: 0 18px 40px rgba(49, 40, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 0;
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: #28241f;
  color: #fffaf0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--gold);
  color: #1f1b16;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: #cfc4b1;
  font-size: 12px;
}

.source-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.source-item {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(255, 250, 240, 0.12);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.06);
  overflow-wrap: anywhere;
}

.source-item strong,
.source-item span {
  display: block;
}

.source-item span {
  margin-top: 4px;
  color: #cfc4b1;
  font-size: 13px;
  line-height: 1.45;
}

.source-state {
  color: #8bd0b5;
}

.source-state.is-off {
  color: #f2b38f;
}

.source-state.is-limited {
  color: #f4d06f;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  gap: 14px;
  padding: 22px 26px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 234, 0.94);
  backdrop-filter: blur(14px);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  max-width: 760px;
}

.search-form input {
  min-width: 0;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

.search-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 109, 119, 0.16);
}

.search-form button,
.tab,
.episode-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
  text-decoration: none;
}

.search-form button:hover,
.episode-button:hover {
  background: var(--accent-strong);
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
}

.tab[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(360px, 1.05fr);
  gap: 24px;
  align-items: start;
  padding: 26px;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.video-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  overflow: hidden;
  text-align: left;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.02);
}

.video-card:hover,
.video-card.is-active {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.poster-wrap {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: #d9d0bf;
}

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

.poster[src=""] {
  display: none;
}

.poster-fallback {
  display: none;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(135deg, rgba(0, 109, 119, 0.88), rgba(200, 85, 61, 0.9)),
    linear-gradient(45deg, #e8dfcf 25%, transparent 25%);
}

.poster[src=""] + .poster-fallback {
  display: block;
}

.badge {
  position: absolute;
  right: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  border-radius: 6px;
  background: rgba(33, 31, 27, 0.82);
  color: #fffaf0;
  padding: 4px 7px;
  font-size: 12px;
  font-weight: 700;
}

.card-body {
  display: grid;
  gap: 5px;
  padding: 0 12px 14px;
}

.card-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  color: var(--muted);
  font-size: 13px;
}

.detail-pane {
  position: sticky;
  top: 118px;
  display: grid;
  gap: 18px;
  min-width: 0;
}

.player-frame {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  box-shadow: var(--shadow);
}

.player-frame video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111;
}

.detail-copy {
  display: grid;
  gap: 12px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.detail-copy h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: 1;
}

.detail-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.meta-line,
.tag-row,
.episode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill,
.tag {
  border-radius: 999px;
  background: #e5ddd0;
  color: #3b352d;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
}

.tag {
  background: rgba(0, 109, 119, 0.1);
  color: var(--accent-strong);
}

.episode-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.share-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.6);
}

.search-empty {
  display: grid;
  grid-column: 1 / -1;
  gap: 8px;
}

.search-empty strong {
  color: var(--ink);
  font-size: 18px;
}

.search-empty span {
  line-height: 1.6;
}

.empty-detail {
  border-bottom: 0;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.7);
}

@media (max-width: 980px) {
  .app-shell,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 250, 240, 0.12);
  }

  .source-panel {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  }

  .detail-pane {
    position: static;
  }
}

@media (max-width: 560px) {
  .app-shell,
  .sidebar,
  .workspace,
  .toolbar,
  .content-grid {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar,
  .toolbar,
  .content-grid {
    padding: 18px;
  }

  .source-panel {
    grid-template-columns: 1fr;
  }

  .source-item {
    max-width: calc(100vw - 36px);
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .video-grid {
    grid-template-columns: 1fr;
  }
}
