:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #2d2a32;
  --muted: #7a7682;
  --accent: #ff6b6b;
  --accent-2: #4d96ff;
  --good: #38b000;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.95rem; }
.view { min-height: 100vh; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
}
.logo {
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  margin: 0;
}
.parent-gear {
  font-size: 1.6rem;
  background: var(--card);
  border: none;
  border-radius: 50%;
  width: 54px;
  height: 54px;
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0.5;
}
.parent-gear:hover { opacity: 1; }

/* ---------- list switcher chips (kid grid + parent panel) ---------- */
.list-chips {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 0 22px 12px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: 999px;
  border: 2px solid #e3e0e6;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.chip.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.chip-new { border-style: dashed; color: var(--muted); }
.manage-chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.list-actions .btn { font-size: 0.9rem; padding: 8px 14px; }

/* ---------- video grid ---------- */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 22px;
  padding: 10px 22px 40px;
}
.tile {
  background: var(--card);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  padding: 0;
  transition: transform 0.12s ease;
}
.tile:hover, .tile:focus { transform: translateY(-4px) scale(1.02); outline: none; }
.tile:focus-visible { box-shadow: 0 0 0 4px var(--accent-2); }
.tile img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #ddd;
}
.tile .tile-title {
  padding: 12px 14px;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.empty-grid {
  text-align: center;
  font-size: 1.3rem;
  color: var(--muted);
  padding: 60px 22px;
}

/* ---------- player ---------- */
.player-stage {
  position: relative;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  /* How much of the iframe's top/bottom edge to crop away. YouTube pins its
     paused-state chrome (title bar up top; share / "More videos" / logo along
     the bottom) to those edges, while the video itself just letterboxes, so
     cropping the bars hides the chrome without shrinking the video. */
  --yt-crop: 80px;
}
/* The IFrame API replaces the #yt-player div with the iframe itself, so
   this selector styles the iframe directly. */
#yt-player {
  position: absolute;
  left: 0;
  top: calc(-1 * var(--yt-crop));
  width: 100%;
  height: calc(100% + 2 * var(--yt-crop));
  border: 0;
}
/* The shield sits ABOVE the iframe and eats every pointer event so the
   child cannot click YouTube's logo, title or related-video links. */
#player-shield {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: transparent;
  cursor: pointer;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 18px 0;
}
.time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 52px;
  text-align: center;
}
.seek-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 14px;
  border-radius: 999px;
  background: #e8e1d6;
  outline: none;
  cursor: pointer;
  margin: 0;
}
.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  cursor: grab;
}
.seek-bar::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  cursor: grab;
}
.seek-bar::-moz-range-track {
  height: 14px;
  border-radius: 999px;
  background: #e8e1d6;
}
.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px 16px 6px;
  flex-wrap: wrap;
}
.ctrl {
  font-size: 1.8rem;
  background: var(--card);
  border: none;
  border-radius: 50%;
  width: 72px;
  height: 72px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.ctrl:active { transform: scale(0.92); }
.ctrl-big {
  width: 92px;
  height: 92px;
  font-size: 2.4rem;
  background: var(--accent);
}
.ctrl-back {
  width: auto;
  border-radius: 40px;
  padding: 0 24px;
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--accent-2);
  color: #fff;
}
.now-playing {
  text-align: center;
  font-size: 1.2rem;
  padding: 4px 22px 10px;
  color: var(--muted);
}

/* ---------- in-player strip of other approved videos ---------- */
.up-next {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 18px 40px;
}
.up-next-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
}
.player-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 6px 2px 14px;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.strip-tile {
  flex: 0 0 180px;
  background: var(--card);
  border: none;
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  text-align: left;
  scroll-snap-align: center;
}
.strip-tile img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #ddd;
}
.strip-title {
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.strip-tile.current {
  outline: 4px solid var(--accent-2);
  outline-offset: -4px;
}

/* ---------- parent gate modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  width: min(420px, 100%);
  text-align: center;
}
.pin-input {
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.4em;
  padding: 12px;
  width: 200px;
  border: 2px solid #ddd;
  border-radius: 12px;
  margin: 10px 0;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 11px 20px;
  border-radius: 12px;
  border: 2px solid #e3e0e6;
  background: #f3f0f5;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-ghost { background: transparent; }

/* ---------- parent panel ---------- */
.parent-view { background: #f4f1f7; user-select: text; }
.parent-body {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 22px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card h3 { margin: 0 0 6px; }
.add-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.text-input {
  flex: 1 1 240px;
  font-size: 1rem;
  padding: 11px 14px;
  border: 2px solid #ddd;
  border-radius: 12px;
}
textarea.text-input {
  font: inherit;
  font-size: 1rem;
  resize: vertical;
  min-height: 48px;
}
.add-status { margin: 12px 0 0; font-weight: 600; }
.add-status.ok { color: var(--good); }
.add-status.err, .error { color: var(--accent); }
.error { margin: 6px 0; font-weight: 600; }

.parent-list { list-style: none; margin: 12px 0 0; padding: 0; }
.parent-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid #eee;
}
.parent-list li:first-child { border-top: none; }
.parent-list img {
  width: 96px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  background: #ddd;
}
.parent-list .li-title {
  flex: 1;
  font-weight: 600;
  line-height: 1.3;
}
.li-actions { display: flex; gap: 6px; }
.icon-btn {
  border: none;
  background: #f3f0f5;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
}
.icon-btn:hover { filter: brightness(0.95); }
.icon-btn.danger { background: #ffe3e3; }

/* Drag-to-reorder: touch-action none lets a finger drag the row instead
   of scrolling the page. */
.drag-handle {
  color: var(--muted);
  font-size: 1.2rem;
  padding: 8px 4px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.drag-ghost { opacity: 0.4; background: #f3f0f5; }

.channel-list li { padding: 8px 0; }

/* ---------- sync card ---------- */
.sync-code {
  font: inherit;
  display: block;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums;
  background: #f3f0f5;
  border: 2px dashed #d9d4df;
  border-radius: 12px;
  padding: 12px 18px;
  margin: 14px 0 4px;
  text-align: center;
  width: 100%;
  cursor: copy;
  color: var(--ink);
}
.sync-good { color: var(--good); }
.sync-bad { color: var(--accent); }

/* ---------- floating toast (share-link add feedback) ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  max-width: min(90vw, 480px);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  text-align: center;
  z-index: 60;
}

/* ---------- screen-time timer: parent setup card ---------- */
.timer-presets {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.timer-presets .chip.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.timer-finish {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-weight: 600;
  cursor: pointer;
}
.timer-finish input {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  accent-color: var(--accent-2);
}
.timer-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-weight: 700;
  color: var(--good);
}
.timer-status .btn { padding: 8px 14px; }

/* ---------- screen-time timer: the child's draining ring ----------
   An inline element that JS drops into the grid's top bar (beside the ⚙️)
   while browsing and into the player's control row while watching, so it's
   always in sight but never over the video. */
.timer-badge {
  position: relative;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  align-self: center;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.2));
}
/* On the grid: sit at the right, just before the gear. */
#grid-topbar .timer-badge { margin-left: auto; margin-right: 12px; }
/* In the player: ride along at the end of the control row. */
.player-controls .timer-badge { width: 60px; height: 60px; }
.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* start the arc at 12 o'clock */
}
.timer-ring-bg {
  fill: rgba(255, 255, 255, 0.9);
  stroke: rgba(0, 0, 0, 0.12);
  stroke-width: 5;
}
.timer-ring-fg {
  fill: none;
  stroke: var(--good);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.5s ease;
}
.timer-badge.warn .timer-ring-fg { stroke: #ffb703; }
.timer-badge.danger .timer-ring-fg { stroke: var(--accent); }
.timer-badge.danger { animation: timer-pulse 1s ease-in-out infinite; }
.timer-emoji {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}
@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* ---------- screen-time timer: the "time's up" lock screen ---------- */
.timeup-overlay {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(45, 42, 50, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: #fff;
  text-align: center;
}
.timeup-card { max-width: 420px; }
.timeup-emoji { font-size: 4.5rem; line-height: 1; }
.timeup-card h2 { font-size: clamp(2rem, 8vw, 2.6rem); margin: 10px 0 6px; }
.timeup-card p { font-size: 1.2rem; color: #e7e3ee; margin: 0 0 26px; }
#timeup-parent { opacity: 0.75; }
#timeup-parent:hover { opacity: 1; }

/* =========================================================================
   Responsive: phones
   ========================================================================= */

/* Respect the iPhone notch / home indicator. */
.view {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------- small screens: tighter spacing, smaller buttons ---------- */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .list-chips { padding: 0 14px 10px; }
  .chip { font-size: 0.9rem; padding: 7px 14px; }
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    padding: 6px 14px 30px;
  }
  .tile .tile-title { font-size: 0.9rem; padding: 8px 10px; }
  .progress-row { padding: 10px 12px 0; gap: 8px; }
  .time { min-width: 44px; font-size: 0.9rem; }
  .player-controls { gap: 10px; padding: 14px 10px 4px; }
  .ctrl { width: 56px; height: 56px; font-size: 1.4rem; }
  .ctrl-big { width: 74px; height: 74px; font-size: 1.9rem; }
  .player-controls .timer-badge { width: 52px; height: 52px; }
  .ctrl-back { font-size: 1rem; padding: 0 18px; }
  .now-playing { font-size: 1rem; padding: 2px 14px 8px; }
  .up-next { padding: 0 14px 24px; }
  .strip-tile { flex: 0 0 140px; }
  .card { padding: 16px; }
  .parent-body { padding: 0 14px 40px; }
}

/* ---------- phone landscape: everything on one screen ----------
   Video + seek bar + controls fill the left; the "More videos" picker
   becomes a vertical column on the right, like a mini YouTube sidebar. */
@media (orientation: landscape) and (max-height: 520px) {
  #player-view {
    display: grid;
    grid-template-columns: 1fr clamp(170px, 28vw, 250px);
    grid-template-rows: minmax(0, 1fr) auto auto;
    column-gap: 10px;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .player-stage {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    height: 100%;
    max-width: none;
    aspect-ratio: auto;   /* the iframe letterboxes inside the black stage */
    margin: 0;
    min-height: 0;
    border-radius: 12px;
    overflow: hidden;
  }
  .progress-row {
    grid-column: 1;
    grid-row: 2;
    padding: 8px 4px 0;
    margin: 0;
    width: 100%;
    max-width: none;
  }
  .player-controls {
    grid-column: 1;
    grid-row: 3;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 8px 4px 10px;
  }
  .ctrl { width: 46px; height: 46px; font-size: 1.15rem; }
  .ctrl-big { width: 56px; height: 56px; font-size: 1.45rem; }
  .ctrl-back { width: auto; font-size: 0.95rem; padding: 0 16px; }
  .player-controls .timer-badge { width: 46px; height: 46px; }
  .now-playing { display: none; }
  .up-next {
    grid-column: 2;
    grid-row: 1 / 4;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0;
    max-width: none;
    padding: 0 0 10px;
  }
  .up-next-title { font-size: 0.95rem; margin: 0 0 8px; }
  .player-strip {
    flex: 1;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 4px 6px 0;
    min-height: 0;
  }
  .strip-tile { flex: 0 0 auto; width: 100%; }
}
