:root {
  --bg: #000;
  --fg: #fff;
  --accent: #fe2c55;
  --cyan: #25f4ee;
  --card: #1c1c22;
  --muted: #9a9aa8;
  --danger: #ff4d4d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body { position: fixed; inset: 0; }

#feed, #progress, #navbar {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0 auto;
  /* phone-shaped column on wide screens; full screen on phones */
  max-width: max(100vh * 9 / 16, 420px);
}
#feed {
  top: 0;
  bottom: calc(env(safe-area-inset-bottom) + 50px);  /* above the bottom bar, like TikTok */
  overflow: hidden;
  touch-action: none;
}

/* three slides moved by the finger (see the swipe pager in app.js) */
.slide {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000 center / cover no-repeat;
  will-change: transform;
  contain: layout paint;
}
.slide.animating { transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1); }
/* dark fade at the bottom so the caption is readable */
.slide::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40%;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

#player, .vid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;          /* fill the screen like TikTok (trims a little from the sides) */
  background: transparent;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
#player.ready, .vid.ready { opacity: 1; }
#player.landscape, .vid.landscape { object-fit: contain; }  /* videos filmed sideways: show all of it */
body > #player { display: none; }

/* the video of a slide: TikTok's embed player or the <video> of an own upload */
.media { position: absolute; inset: 0; overflow: hidden; container-type: size; }
.media iframe.tt {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  /* TikTok's player fits the 9:16 video inside its box, which leaves black strips on screens
     taller than 9:16 (most phones). So the box is made exactly 9:16 and just big enough to
     cover the screen, centred: the video fills it like TikTok's app (a little of the sides is
     cut off). Its top --tt-header (TikTok's header: channel picture, name, logo) is above the
     screen. 2% extra hides the player's thin edges. */
  --tt-header: 68px;
  inset: auto;
  left: 50%;
  top: 50%;
  width: calc(max(100cqw, (100cqh + var(--tt-header)) * 9 / 16) * 1.02);
  height: calc(max(100cqh + var(--tt-header), 100cqw * 16 / 9) * 1.02);
  transform: translate(-50%, calc(-50% - var(--tt-header) / 2));
  background: #000;
  opacity: 0;                 /* the cover picture shows until the video really plays */
  transition: opacity 0.15s;
  pointer-events: none;
}
.slide.started .media iframe.tt { opacity: 1; }
/* over the player: takes every touch, so swipes and taps are ours (and nothing opens TikTok) */
.shield { position: absolute; inset: 0; z-index: 1; }

.info {
  position: absolute;
  left: 14px;
  right: 84px;
  bottom: 16px;
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.user { font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.caption { font-size: 15px; line-height: 1.35; margin-bottom: 8px; }
.caption:empty { display: none; }
.music { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.marquee { overflow: hidden; white-space: nowrap; width: 160px; }
.marquee span { display: inline-block; padding-left: 100%; }
.slide.active .marquee span { animation: marquee 8s linear infinite; }
@keyframes marquee { to { transform: translateX(-100%); } }

.disc {
  position: absolute;
  right: 14px;
  bottom: 16px;
  z-index: 2;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--accent) 0 9px, #222 10px 13px, transparent 14px),
    repeating-radial-gradient(circle, #111 0 2px, #2a2a2a 3px 4px);
  border: 8px solid #1a1a1a;
  box-sizing: content-box;
  width: 32px;
  height: 32px;
  animation: spin 5s linear infinite;
  animation-play-state: paused;
  pointer-events: none;
}
.slide.active .disc { animation-play-state: running; }
body.is-paused .slide.active .disc { animation-play-state: paused; }
@keyframes spin { to { transform: rotate(360deg); } }

#topbar {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 0;
  right: 0;
  margin: 0 auto;
  max-width: max(100vh * 9 / 16, 420px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
#topbar .live {
  font-size: 11px;
  font-weight: 800;
  border: 2px solid #fff;
  border-radius: 6px;
  padding: 1px 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
#topbar .tabs { display: flex; gap: 18px; }
#topbar .tab {
  display: inline-block;
  font-size: 17px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.65);
  padding-bottom: 6px;
}
#topbar .tab.active {
  color: #fff;
  background: linear-gradient(#fff, #fff) bottom center / 28px 3px no-repeat;
}
#topbar .search { width: 26px; height: 26px; fill: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5)); }

/* bottom bar */
#navbar {
  bottom: 0;
  z-index: 10;
  height: calc(env(safe-area-inset-bottom) + 50px);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: #000;
  border-top: 1px solid #1a1a1a;
  pointer-events: none;
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 10px; color: rgba(255, 255, 255, 0.6); min-width: 48px; }
.nav-item.active { color: #fff; }
.nav-item svg { width: 24px; height: 24px; fill: currentColor; }
.create-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 30px;
  border-radius: 9px;
  background: #fff;
  color: #000;
  font-size: 20px;
  font-weight: 800;
  box-shadow: -4px 0 0 var(--cyan), 4px 0 0 var(--accent);
}

/* right side: avatar, like, comment, save, share */
.rail {
  position: absolute;
  right: 8px;
  bottom: 84px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.rail .act { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; }
.rail .act svg { width: 36px; height: 36px; fill: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45)); }
.rail .avatar {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}
.rail .avatar::after {
  content: "+";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  font-size: 16px;
  line-height: 19px;
  text-align: center;
}

#paused-icon {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10;
  width: 80px;
  height: 80px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
#paused-icon svg { width: 100%; height: 100%; fill: rgba(255, 255, 255, 0.6); }
#paused-icon[hidden] { display: none; }

#progress {
  bottom: calc(env(safe-area-inset-bottom) + 50px);
  height: 2px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.2);
  pointer-events: none;
}
#progress-bar { height: 100%; width: 0; background: rgba(255, 255, 255, 0.9); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  background: #000;
  font-size: 24px;
  font-weight: 600;
}
.overlay[hidden] { display: none; }
.overlay.modal {
  z-index: 40;
  background: rgba(0, 0, 0, 0.85);
  justify-content: flex-start;
  padding-top: calc(env(safe-area-inset-top) + 24px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 16px;
  font-weight: 400;
  text-align: left;
  -webkit-user-select: text;
  user-select: text;
}

.logo {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -1px;
  text-shadow: -2px -2px 0 var(--cyan), 2px 2px 0 var(--accent);
}
.logo .note { margin-right: 6px; }
.tap { font-size: 16px; font-weight: 500; opacity: 0.7; margin-top: 28px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.emoji { font-size: 80px; margin-bottom: 16px; }
.splash-logo { width: 110px; height: 110px; }
.hint { font-size: 14px; font-weight: 400; opacity: 0.8; margin-top: 24px; }

.card {
  width: 100%;
  max-width: 420px;
  margin: auto 0;
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
}
.card.wide { margin: 0; }
.card h2 { margin: 0 0 16px; font-size: 20px; }
.card h3 { margin: 24px 0 8px; font-size: 16px; color: var(--muted); font-weight: 600; }

.row { display: flex; gap: 10px; justify-content: flex-end; }
.row.between { justify-content: space-between; align-items: center; }
.row.between h2 { margin: 0; }

.btn {
  display: inline-block;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.btn.ghost { background: #2e2e38; }
.btn.block { display: block; width: 100%; margin-top: 12px; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 8px 12px; font-size: 14px; }

input, select {
  width: 100%;
  font-size: 20px;
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid #3a3a46;
  background: #111116;
  color: var(--fg);
}
#pin-input, #pin-input2 { text-align: center; letter-spacing: 8px; }
select { font-size: 16px; }

.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 12px; }
.muted { color: var(--muted); font-size: 14px; white-space: pre-line; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #2a2a33;
}
.list .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list .size { color: var(--muted); font-size: 13px; }

#channel-form input { margin: 0; font-size: 15px; }
#channel-form .btn { flex: none; }
.btn:disabled { opacity: 0.5; }
.btn[hidden] { display: none; }

.now { display: flex; gap: 12px; align-items: center; }
#now-thumb { width: 54px; height: 96px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.now-text { min-width: 0; }
#now-title { font-weight: 600; overflow-wrap: anywhere; }

.blocked-title { font-size: 30px; font-weight: 800; margin: 0 0 12px; }
.blocked-text { font-size: 18px; font-weight: 500; opacity: 0.85; margin: 0; white-space: pre-line; line-height: 1.5; }

/* pairing: the QR code a parent scans */
.pair-title { font-size: 24px; font-weight: 800; margin: 0 0 20px; }
.pair-qr { width: min(72vw, 300px); aspect-ratio: 1; background: #fff; border-radius: 16px; padding: 12px; }
.pair-qr svg { display: block; width: 100%; height: 100%; }
.pair-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 26px; letter-spacing: 3px; margin: 20px 0 8px; }
.pair-hint { font-size: 14px; font-weight: 400; opacity: 0.7; line-height: 1.5; max-width: 340px; margin: 0; }

/* ---------- parent panel (/parent) ---------- */

body.panel {
  position: static;
  height: auto;
  min-height: 100%;
  overflow: visible;
  background: #111116;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
html:has(body.panel) { overflow: auto; height: auto; }
.panel-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: rgba(17, 17, 22, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #24242c;
}
.panel-logo { font-weight: 800; font-size: 20px; text-shadow: -1px -1px 0 var(--cyan), 1px 1px 0 var(--accent); }
.panel-logo span { font-weight: 600; color: var(--muted); text-shadow: none; font-size: 15px; margin-left: 4px; }
.panel-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-main[hidden] { display: none; }
.panel-stack { display: flex; flex-direction: column; gap: 16px; }
.panel [hidden] { display: none !important; }
.panel-head .row { align-items: center; }
#who { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kid-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.kid-tab { border: 1px solid #3a3a46; background: #111116; color: var(--fg); border-radius: 999px; padding: 8px 16px; font-size: 15px; font-weight: 600; cursor: pointer; }
.kid-tab.active { background: var(--accent); border-color: var(--accent); }
.kid-tab .seen { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.kid-tab.active .seen { color: #ffe1e7; }
#rename-form input, #invite-new input { margin: 0; font-size: 15px; }
#rename-form .btn, #invite-new .btn { flex: none; }
#invite-new { margin-top: 10px; }
#invite-form input { margin: 0; font-size: 15px; }
#invite-form .btn { flex: none; }
.invite-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 24px; font-weight: 700; letter-spacing: 2px; margin: 4px 0 10px; user-select: all; -webkit-user-select: all; }
.switch { margin: 14px 0 0; text-align: center; }
.switch a { color: var(--cyan); }
.list .invite-status { color: var(--muted); font-size: 13px; }
.panel .card { max-width: none; margin: 0; }
.panel label { display: block; color: var(--muted); font-size: 14px; margin-top: 10px; }
.panel label input, .panel label select { margin-top: 6px; color: var(--fg); font-size: 16px; }
.panel label.check { display: flex; align-items: center; gap: 10px; color: var(--fg); font-size: 16px; margin: 14px 0 4px; }
.panel label.check input { width: 22px; height: 22px; margin: 0; }
.panel code { background: #24242c; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid2[hidden] { display: none; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; margin-top: 12px; }
select:disabled { opacity: 0.5; }

.today { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.big { font-size: 34px; font-weight: 800; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; background: #2e2e38; }
.pill.ok { background: #16422f; color: #6ee7a8; }
.pill.blocked { background: #4a1d27; color: #ff8fa6; }
.pill.break { background: #4a3b16; color: #ffd36e; }
.meter { height: 8px; border-radius: 4px; background: #2e2e38; margin: 12px 0 4px; overflow: hidden; }
#today-meter { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--accent)); transition: width 0.4s; }

.week { display: flex; align-items: flex-end; gap: 8px; height: 120px; }
.week .day { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.week .bar { width: 100%; max-width: 36px; border-radius: 6px 6px 2px 2px; background: var(--accent); min-height: 2px; }
.week .mins { font-size: 12px; color: var(--muted); }
.week .label { font-size: 12px; color: var(--muted); }

.list .thumb { width: 40px; height: 64px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.list.history li { align-items: flex-start; }
.list .day-head { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 18px; border-bottom: 0; }
.h-text { flex: 1; min-width: 0; }
.h-title { font-weight: 600; overflow-wrap: anywhere; margin-bottom: 4px; }
.h-actions { display: flex; flex-direction: column; gap: 6px; }
.panel #channel-form input { margin: 0; }

.chip {
  position: fixed;
  z-index: 15;
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  margin: 0;
  background: rgba(255, 255, 255, 0.92);
  color: #000;
  font: 700 15px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.chip[hidden] { display: none; }
.sound-btn { top: calc(env(safe-area-inset-top) + 56px); left: 50%; transform: translateX(-50%); }
.install-btn, .ios-hint { top: calc(env(safe-area-inset-top) + 50px); left: 12px; font-size: 13px; padding: 7px 12px; }
.install-btn[hidden], .hint[hidden] { display: none; }
