:root {
  --paper: #f3ece1;
  --card: #fffaf2;
  --ink: #1f1a14;
  --muted: #6b5e50;
  --line: #d8cbb8;
  --ember: #c45c26;
  --ember-ink: #fff8f1;
  --herb: #3d5a3c;
  --ok: #2f6b3a;
  --bad: #9b2c2c;
  --shadow: 0 18px 40px rgba(47, 32, 16, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 44px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, #f7d9b8 0%, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: Outfit, system-ui, sans-serif;
}

body {
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: Fraunces, Georgia, serif;
  font-weight: 620;
  letter-spacing: -0.02em;
  margin: 0;
}

button, a, input {
  touch-action: manipulation;
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto 64px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

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

.mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ember);
  color: var(--ember-ink);
  font-size: 22px;
}

.eyebrow {
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--muted);
}

h1 { font-size: 42px; line-height: 1; }

.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.tab.is-active {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f0d8c4;
  color: var(--ember);
  font-family: Outfit, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ember);
  color: var(--ember-ink);
  font-size: 12px;
  font-weight: 600;
}

.badge[hidden] { display: none; }

.panel { display: none; padding-top: 28px; }
.panel.is-active { display: block; }

.browse-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  padding: 12px 16px;
  font: inherit;
  font-size: 16px;
}

.more {
  display: block;
  width: 100%;
  margin-top: 18px;
}

.search-bar, .add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input[type="search"], input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  padding: 12px 16px;
  font: inherit;
  font-size: 16px;
}

button, .actions a {
  border: 0;
  border-radius: 16px;
  background: var(--ink);
  color: var(--ember-ink);
  min-height: var(--tap);
  padding: 12px 18px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.hint, .status, .meta, .desc {
  color: var(--muted);
  line-height: 1.5;
}

.hint { margin: 12px 0 0; }
.status { margin: 16px 0; }
.status.is-error { color: var(--bad); }
.status.is-ok { color: var(--ok); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
  margin-top: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #ded3c3;
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.card h3 {
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card .meta {
  font-size: 13px;
  margin: 0;
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.card-actions button,
.card-actions a {
  flex: 1;
  text-align: center;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
}

.card-actions .ghost,
.actions a {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.channel-list, .download-list {
  list-style: none;
  margin: 22px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.channel, .job {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
}

.channel img, .job img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  background: #ded3c3;
}

.channel strong, .job strong {
  display: block;
  overflow-wrap: anywhere;
}

.channel button, .job a, .job .ghost {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--line);
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 12px;
}

.job a, .job .ghost { color: var(--ink); }

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

.job-actions button {
  background: var(--ink);
  color: var(--ember-ink);
  border: 0;
}

.job-actions .danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--line);
}

.player-sheet {
  max-width: 860px;
}

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

.bar {
  height: 6px;
  background: #eadfce;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--herb);
  width: 0;
}

.empty {
  padding: 36px 8px;
  color: var(--muted);
  text-align: center;
}

.sheet {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 560px;
  width: calc(100% - 24px);
}

.sheet::backdrop { background: rgba(31, 26, 20, 0.45); }

.sheet article {
  position: relative;
  background: var(--card);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.sheet img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.sheet h2, .sheet .meta, .sheet .desc, .sheet .actions {
  padding: 0 22px;
}

.sheet h2 {
  padding-top: 18px;
  font-size: 28px;
  overflow-wrap: anywhere;
}

.sheet .desc {
  white-space: pre-wrap;
  max-height: 180px;
  overflow: auto;
  overflow-wrap: anywhere;
}

.sheet .actions {
  display: flex;
  gap: 10px;
  padding: 18px 22px 22px;
}

.sheet .actions a,
.sheet .actions button {
  flex: 1;
  text-align: center;
}

.close {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 2;
  background: var(--card);
  color: var(--ink);
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border-radius: 50%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 720px) {
  .app {
    width: 100%;
    margin: 0 auto;
    padding: calc(16px + var(--safe-top)) 16px calc(96px + var(--safe-bottom));
  }

  .masthead {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-bottom: 16px;
    border-bottom: 0;
  }

  .brand { gap: 12px; }
  .mark { width: 40px; height: 40px; font-size: 18px; }
  h1 { font-size: 32px; }

  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 6px;
    margin: 0;
    padding: 8px 10px calc(8px + var(--safe-bottom));
    background: color-mix(in srgb, var(--card) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(47, 32, 16, 0.06);
  }

  .tab {
    min-height: 48px;
    padding: 8px 6px;
    border-radius: 14px;
    font-size: 12px;
  }

  .panel { padding-top: 8px; }

  .search-bar, .add-row, .browse-bar {
    grid-template-columns: 1fr;
  }

  .search-bar button,
  .add-row button {
    width: 100%;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 16px;
  }

  .card { border-radius: 18px; }

  .card h3 {
    font-size: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .card-actions button {
    min-height: var(--tap);
  }

  .channel, .job {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 12px;
  }

  .channel button,
  .job a,
  .job .ghost,
  .job-actions {
    grid-column: 1 / -1;
    width: 100%;
    text-align: center;
  }

  .job-actions button { flex: 1; }

  .player-sheet {
    max-width: 100%;
  }

  .sheet {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
  }

  .sheet article {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    border-radius: 0;
  }

  .sheet img { flex: 0 0 auto; }

  .sheet h2 {
    font-size: 22px;
    padding-right: 64px;
  }

  .sheet .desc {
    flex: 1;
    max-height: none;
  }

  .sheet .actions {
    flex-direction: column;
    padding-bottom: calc(18px + var(--safe-bottom));
  }

  .close {
    top: calc(10px + var(--safe-top));
  }
}

.watch-page {
  background: #1a1510;
  color: #fff8f1;
}

.watch {
  width: min(960px, calc(100% - 24px));
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 0 calc(24px + var(--safe-bottom));
}

.watch .back {
  display: inline-block;
  margin-bottom: 14px;
  color: #f0d8c4;
  text-decoration: none;
  min-height: var(--tap);
  line-height: var(--tap);
}

.watch video {
  display: block;
  width: 100%;
  max-height: 70dvh;
  background: #000;
  border-radius: 16px;
}

.watch h1 {
  margin-top: 16px;
  font-size: clamp(22px, 6vw, 34px);
  color: #fff8f1;
}

.watch .meta { color: #d8cbb8; }

@media (max-width: 380px) {
  h1 { font-size: 28px; }
  .tab { font-size: 12px; }
  .pill { display: block; margin: 6px 0 0; width: fit-content; }
}
