:root {
  --bg: #f3efe6;
  --bg-2: #e8e1d4;
  --ink: #1c1915;
  --muted: #6b645b;
  --card: #fffdf8;
  --line: rgba(28, 25, 21, 0.08);
  --accent: #2f6f64;
  --accent-ink: #f6f1e8;
  --coral: #c26e4a;
  --warn: #8a4b2b;
  --warn-bg: #f8eadf;
  --shadow: 0 10px 30px rgba(28, 25, 21, 0.08);
  --radius: 20px;
  --tap: 52px;
  --font: "Nunito", "Avenir Next", "Segoe UI", ui-rounded, system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff8ec 0%, transparent 50%),
    radial-gradient(900px 400px at 100% 0%, #e7efe9 0%, transparent 45%),
    var(--bg);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; display: block; }

#app { min-height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 20px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.35rem;
}
.logo {
  width: 36px; height: 36px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 1.1rem;
  flex: none;
}
.spacer { flex: 1; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  border: 0; border-radius: 16px;
  background: var(--card); color: var(--ink);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  font-size: 1.15rem;
}
.icon-btn.quiet { background: transparent; box-shadow: none; }
.pill {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 0;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-weight: 700;
}

.page { padding: 8px 20px calc(28px + var(--safe-bottom)); max-width: 1200px; margin: 0 auto; }
.hero {
  padding: 12px 4px 28px;
}
.hero h1 {
  font-size: clamp(2rem, 6vw, 3.4rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin: 0 0 8px;
}
.hero p { margin: 0; color: var(--muted); font-size: 1.1rem; max-width: 32rem; }

.profiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  max-width: 720px;
}
.profile-card {
  appearance: none;
  border: 0;
  background: var(--card);
  border-radius: 28px;
  padding: 28px 18px 22px;
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform 0.15s ease;
  min-height: 200px;
}
.profile-card:active { transform: scale(0.98); }
.avatar {
  width: 96px; height: 96px; border-radius: 50%;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 2.2rem;
  letter-spacing: -0.04em;
}
.profile-card h2 { margin: 0; font-size: 1.4rem; letter-spacing: -0.03em; }
.profile-card span { color: var(--muted); font-size: 0.95rem; }

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 16px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 0;
  background: var(--bg-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  min-height: 44px;
}
.chip[aria-pressed="true"], .chip.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.search-row {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
}
.search-row input {
  flex: 1;
  min-height: var(--tap);
  border: 0;
  border-radius: 16px;
  padding: 0 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  outline: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

.video-card {
  display: block;
  text-decoration: none;
  background: var(--card);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  color: inherit;
}
.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #d8d0c4;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.duration {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(20, 16, 12, 0.82);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 8px;
}
.video-meta { padding: 12px 14px 16px; }
.video-meta h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-meta p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.player-page { max-width: 1100px; }
.player-wrap {
  position: relative;
  background: #111;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  aspect-ratio: 16 / 9;
}
.player-wrap iframe, .player-wrap .upnext {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
/* When the player is replaced, let the up-next panel grow instead of clipping. */
.player-wrap:has(.upnext) {
  aspect-ratio: auto;
  min-height: 260px;
}
.player-wrap:has(.upnext) .upnext {
  position: relative;
  height: auto;
  min-height: 260px;
}
/* Up next REPLACES the player. It must never sit on top of a live iframe. */
.upnext {
  background: #17211f;
  color: #f6f1e8;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 22px 22px;
  gap: 14px;
}
.upnext h2 { margin: 0; font-size: clamp(1.2rem, 3vw, 2rem); letter-spacing: -0.03em; }
.upnext .next-card {
  display: flex;
  gap: 16px;
  align-items: center;
  background: #24322f;
  border-radius: 18px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  min-height: 96px;
}
.upnext .next-card img { width: 42%; max-width: 280px; aspect-ratio: 16/9; object-fit: cover; }
.upnext .next-card div { padding-right: 16px; }
.upnext .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: 0;
  border-radius: 16px;
  font-weight: 800;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.secondary { background: #e8e1d4; color: var(--ink); }
.btn.danger { background: var(--coral); color: #fff; }
.btn.ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,0.2); }

.watch-info { padding: 18px 4px 8px; }
.watch-info h1 { margin: 0 0 6px; font-size: clamp(1.2rem, 3vw, 1.8rem); letter-spacing: -0.03em; }
.watch-info p { margin: 0; color: var(--muted); }
.upnext-list { margin-top: 8px; }

.empty {
  background: var(--card);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  color: var(--muted);
  box-shadow: var(--shadow);
}

.banner {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 0 0 16px;
  font-weight: 600;
}
.banner a { text-decoration: underline; }

.parent { max-width: 980px; }
.panel {
  background: var(--card);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; letter-spacing: -0.03em; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  background: #fff;
  outline: none;
}
.stack { display: grid; gap: 10px; }

.kid-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.kid-row:first-of-type { border-top: 0; }
.dot { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.kid-row h3 { margin: 0; font-size: 1.05rem; }
.kid-row p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.pin-wrap { max-width: 360px; margin: 40px auto; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 10px; margin: 18px 0 22px; }
.pin-dots i {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg-2); display: block;
}
.pin-dots i.on { background: var(--accent); }
.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
}
.pad button {
  min-height: 72px;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.6rem;
  font-weight: 800;
}
.pad button.muted { font-size: 1rem; color: var(--muted); }

.channel-list { display: grid; gap: 12px; }
.channel-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}
.channel-card h3 { margin: 0; font-size: 1rem; }
.channel-card p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.letter {
  width: 56px; height: 56px; border-radius: 16px;
  display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 1.2rem;
}

.preview-grid { display: grid; gap: 8px; margin-top: 10px; }
.preview-item {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 0.92rem;
}
.preview-item img { width: 120px; border-radius: 10px; aspect-ratio: 16/9; object-fit: cover; }

.toggle {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700;
}

.err { color: var(--coral); font-weight: 700; min-height: 1.2em; }

footer.note {
  padding: 8px 20px calc(20px + var(--safe-bottom));
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .video-meta { padding: 10px 10px 12px; }
  .video-meta h3 { font-size: 0.92rem; }
  .profiles { grid-template-columns: 1fr 1fr; }
  .preview-item { grid-template-columns: 96px 1fr; }
  .preview-item .btn { grid-column: 1 / -1; }
  .upnext .next-card { flex-direction: column; align-items: stretch; }
  .upnext .next-card img { width: 100%; max-width: none; }
}
