/* Kiddies Corner: the kids' screen.
   Mobile first. Sizes are deliberately modest (16px body text, 44px touch targets); the grid and the player
   scale up on tablets. UI icons are inline SVG (see the sprite in the page); emoji are kept for the
   children's own content (categories, profiles, the "that's all for today" moon). */

:root {
    --bg: #faf7f2;
    --surface: #ffffff;
    --ink: #231f33;
    --muted: #6f6a85;
    --line: #e6e1f0;
    --accent: #6c5ce7;
    --accent-soft: #eeebfd;
    --accent-light: #a99dfa;
    --pink: #ef6f8d;
    --green: #2fb67c;
    --danger: #d6455d;
    --r-sm: 10px;
    --r: 14px;
    --r-lg: 22px;
    --sh-1: 0 1px 2px rgba(35, 31, 51, .06), 0 2px 8px rgba(35, 31, 51, .06);
    --sh-2: 0 4px 16px rgba(35, 31, 51, .14);
    --ease: cubic-bezier(.2, .8, .2, 1);
    --gutter: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html {
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
    color-scheme: light;
}
html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.35;
    -webkit-font-smoothing: antialiased;
}
body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Icons: <svg class="i"><use href="#i-name"/></svg> */
.i { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.fill { fill: currentColor; stroke: none; }

/* ---------- App bar: logo, child, time left, grown-ups; search bar underneath ---------- */

.appbar {
    position: sticky; top: 0; z-index: 10;
    background: rgba(250, 247, 242, .94);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    padding-bottom: 8px;
}
.top {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px var(--gutter) 6px;
}
.top h1 { margin: 0; line-height: 0; }
.brand { height: 38px; width: auto; display: block; }
.right { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.who { font-weight: 700; font-size: 13px; color: var(--ink); background: var(--surface); border-radius: 999px; padding: 6px 12px; box-shadow: var(--sh-1); }
#timeleft:not(:empty) {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px;
    padding: 6px 12px; border-radius: 999px;
}
#timeleft:not(:empty)::before {
    content: ""; width: 14px; height: 14px; background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E") center / contain no-repeat;
}
.icon {
    width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%;
    background: var(--surface); color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center;
    transition: transform .12s var(--ease), background .15s;
}
.icon:active { transform: scale(.92); background: var(--accent-soft); }

/* Search */
.searchbar {
    display: flex; align-items: center; gap: 4px;
    margin: 4px var(--gutter) 0; padding: 4px 4px 4px 12px;
    background: var(--surface); border: 1.5px solid var(--line); border-radius: 999px;
    box-shadow: var(--sh-1);
    transition: border-color .15s, box-shadow .15s;
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(108, 92, 231, .14); }
.sb-go { border: 0; background: transparent; color: var(--muted); padding: 6px; display: inline-flex; }
.searchbar input {
    flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
    font: inherit; font-size: 16px; padding: 9px 4px; color: var(--ink);
    -webkit-user-select: text; user-select: text;
}
.searchbar input::placeholder { color: #9a95b3; }
.searchbar input::-webkit-search-cancel-button { display: none; }
.sb-clear { border: 0; background: var(--accent-soft); color: var(--muted); width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.sb-clear .i { width: 14px; height: 14px; }
.mic {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent); color: #fff;
    transition: transform .12s var(--ease), background .2s;
}
.mic:active { transform: scale(.92); }
.mic.on { background: var(--pink); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 111, 141, .5); } 50% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(239, 111, 141, 0); } }
.search-status { margin: 6px calc(var(--gutter) + 6px) 0; min-height: 20px; font-size: 14px; color: var(--muted); }
body.searching #cats, body.searching #grid, body.searching #empty { display: none !important; }

/* Update banner */
.update-banner {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: calc(100% - 2 * var(--gutter)); margin: 8px var(--gutter) 0; padding: 10px 14px;
    border: 0; border-radius: var(--r); background: #ffefbd; color: #5b4300;
    font-size: 14px; font-weight: 600; text-align: center;
    animation: rise .3s var(--ease);
}

/* ---------- Category chips ---------- */

.cats {
    display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity;
    padding: 10px var(--gutter) 4px; scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.chip {
    flex: 0 0 auto; scroll-snap-align: start;
    height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px;
    font-size: 14px; font-weight: 600; background: var(--surface); color: var(--ink);
    transition: background .15s, color .15s, transform .12s var(--ease), border-color .15s;
}
.chip:active { transform: scale(.95); }
.chip.on { color: #fff; background: var(--chip, var(--accent)); border-color: transparent; }

/* ---------- Video grid ---------- */

.grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
    padding: 10px var(--gutter) 40px;
}
.tile {
    display: flex; flex-direction: column; justify-content: flex-start;
    width: 100%; border: 0; padding: 0;
    background: var(--surface); border-radius: var(--r); overflow: hidden;
    text-align: left; cursor: pointer;
    box-shadow: var(--sh-1);
    animation: rise .35s var(--ease) both;
    transition: transform .15s var(--ease), box-shadow .2s;
}
.tile:active { transform: scale(.97); }
.thumb {
    position: relative; aspect-ratio: 16 / 9; overflow: hidden;
    background: linear-gradient(100deg, #ece8f6 30%, #f6f3fb 50%, #ece8f6 70%) 0 0 / 220% 100%;
    animation: shimmer 1.4s linear infinite;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s ease; }
.thumb img.loaded { opacity: 1; }
.thumb:has(img.loaded) { animation: none; }
.dur {
    position: absolute; right: 6px; bottom: 6px;
    background: rgba(20, 18, 30, .72); color: #fff;
    font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px;
    font-variant-numeric: tabular-nums;
}
/* margin, not padding: padding inside a line-clamped box lets a sliver of the third line show */
.tile h3 {
    margin: 9px 11px 11px; padding: 0;
    font-size: 14px; line-height: 1.3; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 34px; background: linear-gradient(135deg, #8a7bf5, #f08cb0); }
.empty { text-align: center; color: var(--muted); font-size: 16px; padding: 56px 24px; }
.sentinel { grid-column: 1 / -1; height: 1px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position: -220% 0; } }

/* ---------- Player ---------- */

.player {
    position: fixed; inset: 0; z-index: 20;
    display: flex; flex-direction: column; background: #0e0d14;
    animation: fadeIn .2s ease;
}
/* The player section is "hidden" but still laid out, invisible and untouchable, so YouTube loads and sets up its
   player in the background (a display:none frame may not finish starting up). */
#player[hidden] { display: flex !important; visibility: hidden; pointer-events: none; animation: none; }

.stage { position: relative; flex: 1; min-height: 0; background: #000; }
.stage iframe, .stage video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.stage video { background: #000; object-fit: contain; }
.ytwrap { position: absolute; inset: 0; }
.ytwrap.front { z-index: 1; }
.ytwrap.back { visibility: hidden; pointer-events: none; z-index: 0; }
#shield { position: absolute; inset: 0; z-index: 2; }

.cover {
    position: absolute; inset: 0; z-index: 3; background: #15141c;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.cover span {
    width: 76px; height: 76px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .14); color: #fff;
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    transition: transform .15s var(--ease);
}
.cover:active span { transform: scale(.92); }
.cover .i { width: 34px; height: 34px; margin-left: 4px; }

/* Controls: title, then the progress bar with times, then Back / Play / Next. Same layout on every screen size. */
.bar {
    background: linear-gradient(#17161f, #100f17); color: #fff;
    padding: 10px max(var(--gutter), 12px) calc(12px + env(safe-area-inset-bottom));
}
.bar-inner { max-width: 900px; margin: 0 auto; }
.now {
    display: block; text-align: center; font-size: 13px; color: #bdb8d6;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px 2px;
}
.seekrow { display: flex; align-items: center; gap: 10px; }
.time { flex: 0 0 auto; min-width: 38px; font-size: 12px; color: #bdb8d6; font-variant-numeric: tabular-nums; }
.time:last-child { text-align: right; }
.seek {
    --p: 0%;
    flex: 1; min-width: 0; height: 28px; margin: 0; background: transparent;
    -webkit-appearance: none; appearance: none; cursor: pointer;
}
.seek::-webkit-slider-runnable-track { height: 5px; border-radius: 999px; background: linear-gradient(to right, var(--accent-light) var(--p), rgba(255, 255, 255, .2) var(--p)); }
.seek::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5.5px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .5); transition: transform .12s; }
.seek:active::-webkit-slider-thumb { transform: scale(1.3); }
.seek::-moz-range-track { height: 5px; border-radius: 999px; background: rgba(255, 255, 255, .2); }
.seek::-moz-range-progress { height: 5px; border-radius: 999px; background: var(--accent-light); }
.seek::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; }

.ctrlrow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 4px; }
.ctrlrow > :first-child { justify-self: start; }
.ctrlrow > :last-child { justify-self: end; }
.ctl {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 40px; padding: 0 14px; border: 0; border-radius: 999px;
    background: rgba(255, 255, 255, .1); color: #fff; font-size: 14px; font-weight: 600; white-space: nowrap;
    transition: transform .12s var(--ease), background .15s;
}
.ctl:active { transform: scale(.94); background: rgba(255, 255, 255, .2); }
.ctl .i { width: 18px; height: 18px; }
.ctl.play { width: 56px; height: 56px; padding: 0; background: #fff; color: #17161f; }
.ctl.play:active { background: #e8e5f5; }
.ctl.play .i { width: 26px; height: 26px; }
.ctl.play .i-pause { display: none; }
.ctl.play.on .i-play { display: none; }
.ctl.play.on .i-pause { display: block; }
.simple #shield, .simple #cover, .simple #pp, .simple .seekrow { display: none; }

/* Loading spinner shown while a video gets ready or stalls to buffer */
.spinner { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: #15141c; color: #fff; pointer-events: none; }
.spinner.mid { background: rgba(0, 0, 0, .35); }
.spinner p { margin: 0; min-height: 22px; font-size: 15px; font-weight: 600; text-align: center; padding: 0 24px; }
.ring { width: 52px; height: 52px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .16); border-top-color: #ffd166; border-right-color: var(--pink); border-bottom-color: #4cb782; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ---------- Sheets and dialogs ---------- */

.overlay {
    position: fixed; inset: 0; z-index: 30;
    display: flex; align-items: center; justify-content: center;
    background: rgba(20, 18, 30, .55);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    animation: fadeIn .2s ease;
}
.overlay.top-layer { z-index: 40; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

.card {
    width: calc(100% - 32px); max-width: 360px; padding: 22px 20px 18px;
    background: var(--surface); border-radius: var(--r-lg); text-align: center;
    box-shadow: var(--sh-2); max-height: 90vh; overflow-y: auto;
    animation: popIn .26s var(--ease);
}
.card h2 { margin: 0 0 6px; font-size: 19px; line-height: 1.25; }
.card p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.card.wide { max-width: 560px; }
.big { font-size: 44px; line-height: 1.1; margin-bottom: 4px; }
.card input {
    width: 100%; padding: 12px; font: inherit; font-size: 22px; text-align: center; letter-spacing: 8px;
    border: 1.5px solid var(--line); border-radius: var(--r); margin: 8px 0 2px; background: var(--bg);
    -webkit-user-select: text; user-select: text;
}
.card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(108, 92, 231, .14); }
.msg { min-height: 20px; color: var(--danger) !important; margin: 2px 0 8px !important; font-size: 13px !important; }
.env-note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px;
    font-size: 15px; font-weight: 600; background: var(--accent); color: #fff;
    transition: transform .12s var(--ease), background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; transform: none; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }

/* Phones: dialogs rise from the bottom like a native sheet */
@media (max-width: 599px) {
    .overlay { align-items: flex-end; }
    .card {
        width: 100%; max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0;
        padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
        animation: sheetUp .3s var(--ease);
        max-height: 92vh;
    }
    .card::before { content: ""; display: block; width: 36px; height: 4px; margin: -8px auto 12px; border-radius: 4px; background: #d9d4e8; }
    .overlay.centered { align-items: center; }
    .overlay.centered .card { width: calc(100% - 32px); border-radius: var(--r-lg); padding: 22px 20px 18px; animation: popIn .26s var(--ease); }
    .overlay.centered .card::before { display: none; }
}

/* Grown-ups menu */
.menu { text-align: left; max-width: 400px; padding-top: 14px; }
.menu-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.menu-head h2 { margin: 0; font-size: 18px; }
.menu-close { width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--accent-soft); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.menu-close .i { width: 16px; height: 16px; }
.sec { margin: 14px 4px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.item {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 14px;
    border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left;
    font-size: 15px; font-weight: 500; color: var(--ink);
    transition: background .12s;
}
.list > :first-child { border-top: 0; }
.item:active { background: var(--accent-soft); }
.item .i { color: var(--muted); }
.item .chev { margin-left: auto; width: 16px; height: 16px; opacity: .5; }
.item.danger, .item.danger .i { color: var(--danger); }
.item-label { flex: 1; }
.switch {
    position: relative; flex: 0 0 auto; width: 44px; height: 26px; border-radius: 999px; background: #d4cfe3;
    transition: background .2s;
}
.switch::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .22s var(--ease);
}
[aria-checked="true"] .switch { background: var(--green); }
[aria-checked="true"] .switch::after { transform: translateX(18px); }
.seg { display: flex; gap: 4px; padding: 4px; margin: 0; background: #ece8f6; border-radius: var(--r); }
.seg .btn { flex: 1; min-height: 38px; padding: 0 10px; font-size: 14px; border-radius: 10px; background: transparent; color: var(--muted); }
.seg .btn:not(:disabled) { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }
.seg .btn:disabled { opacity: 1; background: transparent; color: var(--accent); font-weight: 700; }
.seg .btn:disabled .i { color: var(--accent); }
.menu .env-note { text-align: center; }
.menu-foot { margin-top: 14px; text-align: center; font-size: 12px; color: var(--muted); }

/* Who is watching */
.kids { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 12px; }
.kid {
    border: 0; border-radius: 18px; padding: 14px 18px; min-width: 104px; background: var(--kid, var(--accent)); color: #fff;
    display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--sh-1);
    transition: transform .12s var(--ease);
}
.kid:active { transform: scale(.95); }
.kid-emoji { font-size: 40px; line-height: 1; }
.kid-name { font-size: 15px; font-weight: 700; }

/* Update progress */
.update-bar { width: 100%; height: 8px; margin: 4px 0 2px; accent-color: var(--accent); }
.update-status { min-height: 20px; }

/* Toast */
.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    z-index: 50; max-width: calc(100% - 32px);
    background: #2b2740; color: #fff; padding: 11px 18px; border-radius: 999px;
    font-size: 14px; font-weight: 500; text-align: center; box-shadow: var(--sh-2);
    animation: toastIn .28s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Larger screens ---------- */

@media (min-width: 600px) {
    :root { --gutter: 22px; }
    .brand { height: 44px; }
    .top { padding-top: 14px; }
    .searchbar { max-width: 640px; margin-left: auto; margin-right: auto; }
    .search-status { max-width: 640px; margin-left: auto; margin-right: auto; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; padding-top: 14px; }
    .tile h3 { font-size: 15px; margin: 10px 13px 13px; }
    .chip { height: 38px; font-size: 15px; padding: 0 18px; }
    .ctl { height: 44px; padding: 0 18px; font-size: 15px; }
    .ctl.play { width: 62px; height: 62px; }
    .bar { padding-top: 12px; }
    .now { font-size: 14px; }
    .time { font-size: 13px; min-width: 44px; }
    .cover span { width: 92px; height: 92px; }
    .cover .i { width: 42px; height: 42px; }
    .ring { width: 64px; height: 64px; border-width: 6px; }
    .spinner p { font-size: 17px; }
}
@media (min-width: 1000px) {
    .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
    .tile:hover { transform: translateY(-3px); box-shadow: var(--sh-2); }
}
@media (hover: none) { .tile:hover { transform: none; } }

/* Less motion for anyone who asks for it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
    .ring { animation: breathe 1.6s ease-in-out infinite !important; animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
    .mic.on { animation: none !important; }
}
