:root {
  --bg: #FFF4E6;
  --card: #FFFFFF;
  --ink: #3A2E4D;
  --soft: #8A7C99;
  --shadow: 0 6px 0 rgba(58, 46, 77, .08), 0 10px 24px rgba(58, 46, 77, .10);
  --songs: #FF7A59;
  --stories: #2BB5A0;
  --shows: #8C6CF2;
  --learning: #F5B700;
  --all: #FF5D8F;
  --again: #E8508A;
  --gap: clamp(12px, 2vw, 22px);
  --radius: 26px;
  font-family: 'Baloo 2', 'PingFang HK', 'Noto Sans HK', 'Microsoft JhengHei', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B1838; --card: #2A2650; --ink: #F4EEFF; --soft: #A9A0C8;
    --shadow: 0 6px 0 rgba(0, 0, 0, .25), 0 10px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1B1838; --card: #2A2650; --ink: #F4EEFF; --soft: #A9A0C8;
  --shadow: 0 6px 0 rgba(0, 0, 0, .25), 0 10px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  min-height: 100dvh;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
img { -webkit-user-drag: none; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--gap);
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 26px; letter-spacing: .5px; white-space: nowrap; }
.logo {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, #FF8A5B, #FF5D8F);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.12);
  position: relative;
}
.logo::after { content: ''; position: absolute; left: 15px; top: 11px; border-left: 14px solid #fff; border-top: 9px solid transparent; border-bottom: 9px solid transparent; }
.cats { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; flex: 1; padding: 4px 2px 10px; margin-bottom: -6px; }
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: none; display: flex; align-items: center; gap: 8px;
  height: 58px; padding: 0 20px 0 10px; border-radius: 999px;
  background: var(--card); box-shadow: var(--shadow);
  font-weight: 800; font-size: 22px;
  transition: transform .15s;
}
.cat .ic { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; background: var(--c); }
.cat[aria-pressed="true"] { background: var(--c); color: #fff; transform: translateY(-2px); }
.cat[aria-pressed="true"] .ic { background: rgba(255,255,255,.25); }
.cat:active { transform: scale(.94); }

.lock {
  position: relative; flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; color: var(--soft); opacity: .55;
}
.lock svg { width: 22px; height: 22px; }
.lock .ring { position: absolute; inset: 0; border-radius: 50%; border: 4px solid var(--all); clip-path: inset(0 100% 0 0); }
.lock.holding .ring { animation: ring 1.6s linear forwards; }
.lock.holding { opacity: 1; }
@keyframes ring { to { clip-path: inset(0 0 0 0); } }

/* ---------- grid ---------- */
.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  padding: 8px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
@media (max-width: 560px) { .grid { grid-template-columns: 1fr 1fr; } }
.card {
  display: block; text-align: left; padding: 0; border-radius: var(--radius); overflow: hidden;
  background: var(--card); box-shadow: var(--shadow);
  transition: transform .15s;
  animation: pop .35s both;
}
.card:active { transform: scale(.95); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.97); } }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--c, #ddd); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transform: scale(1.02); }
.thumb .len {
  position: absolute; right: 8px; bottom: 8px; padding: 0 8px; border-radius: 8px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 22px; font-weight: 600;
}
.thumb .dot { position: absolute; left: 10px; top: 10px; width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 3px solid #fff; }
.card .title {
  margin: 8px 14px 12px; padding: 0; font-size: 16px; line-height: 1.3; font-weight: 600; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; height: calc(2 * 1.3em);
}
@media (max-width: 560px) { .card .title { font-size: 13px; margin: 6px 10px 10px; } }
.empty { text-align: center; padding: 60px 20px; color: var(--soft); font-size: 20px; }

/* ---------- player ---------- */
.player { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
.stageWrap { flex: none; background: #000; padding-top: env(safe-area-inset-top); display: flex; justify-content: center; }
.stage { position: relative; width: min(100%, calc(60dvh * 16 / 9)); aspect-ratio: 16 / 9; }
.player.full .stageWrap { flex: 1; }
.player.full .stage { width: 100%; height: 100%; aspect-ratio: auto; }
.player.full .side { display: none; }
#yt, .stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.shield { position: absolute; inset: 0; z-index: 2; }
.shield.pass { pointer-events: none; }
.cover {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center;
  background: #000 center / cover no-repeat;
}
.cover::before { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.big {
  position: relative; width: 140px; height: 140px; border-radius: 50%;
  background: #fff; color: #FF5D8F; box-shadow: 0 10px 0 rgba(0,0,0,.25);
  display: grid; place-items: center;
}
.big svg { width: 70px; height: 70px; margin-left: 8px; }
.big:active { transform: scale(.93); }
.tapHint { position: absolute; z-index: 4; left: 50%; top: 50%; pointer-events: none; font-size: 64px; transform: translate(10px, 40px); animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(10px, 25px); } }

.controls {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  opacity: 0; transition: opacity .25s;
}
.controls.on { opacity: 1; }
.controls.on .ctl { pointer-events: auto; }
.ctl {
  position: absolute; width: 76px; height: 76px; border-radius: 50%;
  background: rgba(255,255,255,.92); color: #3A2E4D; display: grid; place-items: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
}
.ctl svg { width: 40px; height: 40px; }
.ctl:active { transform: scale(.92); }
.controls .back { left: max(20px, env(safe-area-inset-left)); top: calc(20px + env(safe-area-inset-top)); }
.controls .pp { left: 50%; top: 50%; width: 120px; height: 120px; margin: -60px 0 0 -60px; }
.controls .pp svg { width: 60px; height: 60px; }
.controls .next { right: max(20px, env(safe-area-inset-right)); top: 50%; margin-top: -38px; }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; background: rgba(255,255,255,.25); }
.bar i { display: block; height: 100%; width: 0; background: #FF5D8F; }

.controls .full { right: max(20px, env(safe-area-inset-right)); top: calc(20px + env(safe-area-inset-top)); }
.player:not(.full) .controls .back, .player:not(.full) .controls .full { top: 14px; }
.end .big b {
  position: absolute; top: -8px; right: -8px; min-width: 52px; height: 52px; border-radius: 26px; padding: 0 10px;
  display: grid; place-items: center; background: #FF5D8F; color: #fff; font-size: 28px; font-weight: 800; border: 4px solid #fff;
}
.end .big b:empty { display: none; }

.side {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 14px max(16px, env(safe-area-inset-right)) calc(30px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.nowBar { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.homeBtn { flex: none; width: 60px; height: 60px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; }
.homeBtn svg { width: 32px; height: 32px; }
.homeBtn:active { transform: scale(.92); }
.nowTitle { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 800; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.related { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.related .card.now { outline: 5px solid #FF5D8F; outline-offset: -5px; }
@media (max-width: 560px) {
  .related { grid-template-columns: 1fr 1fr; }
  .nowTitle { font-size: 16px; }
  .homeBtn { width: 50px; height: 50px; }
  .player:not(.full) .ctl { width: 56px; height: 56px; }
  .player:not(.full) .ctl svg { width: 30px; height: 30px; }
  .player:not(.full) .controls .pp { width: 84px; height: 84px; margin: -42px 0 0 -42px; }
  .player:not(.full) .controls .next { margin-top: -28px; }
  .player:not(.full) .big { width: 84px; height: 84px; }
  .player:not(.full) .big svg { width: 44px; height: 44px; }
}

/* ---------- rest ---------- */
.rest {
  position: fixed; inset: 0; z-index: 30; display: grid; place-content: center; text-align: center; gap: 8px;
  background: radial-gradient(circle at 50% 30%, #3B3570, #15122C); color: #F4EEFF;
}
.rest h1 { margin: 20px 0 0; font-size: 56px; }
.rest p { margin: 0; font-size: 22px; opacity: .8; }
.moon { width: 140px; height: 140px; margin: 0 auto; border-radius: 50%; box-shadow: -28px 10px 0 0 #FFD86B; transform: translateX(14px); animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translate(14px, -10px); } }
body.resting .lock { position: fixed; z-index: 31; right: 16px; top: calc(16px + env(safe-area-inset-top)); color: #fff; }

/* ---------- PIN ---------- */
.pinDlg { border: 0; border-radius: 24px; padding: 24px; width: min(340px, 90vw); background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.pinDlg::backdrop { background: rgba(20, 16, 40, .5); }
.pinDlg h2 { margin: 0; font-size: 26px; }
.pinDlg p { margin: 4px 0 14px; color: var(--soft); }
.pinDlg input { width: 100%; font: inherit; font-size: 32px; letter-spacing: 10px; text-align: center; padding: 10px; border-radius: 14px; border: 2px solid color-mix(in srgb, var(--soft) 40%, transparent); background: var(--bg); color: var(--ink); }
.pinBtns { display: flex; gap: 10px; margin-top: 16px; }
.pinBtns button { flex: 1; height: 50px; border-radius: 14px; font-weight: 800; font-size: 18px; background: var(--bg); }
.pinBtns .primary { background: var(--all); color: #fff; }

@media (max-width: 560px) {
  .brand { font-size: 0; gap: 0; }
  .cat { height: 50px; font-size: 18px; padding: 0 14px 0 6px; }
  .cat .ic { width: 38px; height: 38px; font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Full screen (the default): video fills the screen; tapping it slides a row of more videos up from the bottom. */
.player.full { background: #000; }
.player.full .stageWrap { padding-top: 0; }
.player.full .side {
  display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  padding: 28px max(16px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,.45) 70%, transparent);
  transform: translateY(105%); transition: transform .3s ease; pointer-events: none;
}
.player.full.peek .side { transform: none; pointer-events: auto; }
.player.full .side::-webkit-scrollbar { display: none; }
.player.full .nowBar { display: none; }
.player.full .related { display: flex; gap: 14px; }
.player.full .related .card {
  flex: none; width: clamp(150px, calc(24dvh * 16 / 9), 300px);
  background: none; box-shadow: none; border-radius: 16px; animation: none;
}
.player.full .related .card .title { display: none; }
.player.full .related .card .thumb { border-radius: 16px; }
.player.full .related .card.now { outline-width: 4px; outline-offset: -4px; }
/* the middle buttons move up out of the strip's way while it shows */
.player.full .controls .next, .player.full .controls .pp, .player.full .end .big, .player.full .bar { transition: transform .3s ease, opacity .3s; }
.player.full.peek .controls .next, .player.full.peek .controls .pp, .player.full.peek .end .big { transform: translateY(-12dvh); }
.player.full.peek .bar { opacity: 0; }
@media (max-height: 520px) { .player.full .related .card { width: calc(30dvh * 16 / 9); } }
