/* Aiden's Tube — player-on-top + sidebar + 2-col list layout */
:root {
  --bg:        #1c1624;
  --bg-2:      #241a32;
  --card:      #2e2347;
  --card-hi:   #3a2c5a;
  --coral:     #ff6b35;
  --yellow:    #ffd166;
  --sky:       #4cc9f0;
  --pink:      #ff6b9d;
  --green:     #6bcf7f;
  --purple:    #a78bfa;
  --text:      #f8f4ff;
  --text-dim:  rgba(248,244,255,.65);
  --shadow:    0 12px 32px rgba(0,0,0,.45);
  --shadow-sm: 0 4px 14px rgba(0,0,0,.3);
  --ease:      cubic-bezier(.22,1,.36,1);
}

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@600;700;800;900&display=swap');

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

html, body { height: 100%; -webkit-user-select: none; user-select: none; touch-action: manipulation; overscroll-behavior: none; }
body {
  font: 16px/1.4 'Nunito', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 700; color: var(--text);
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(255,107,53,.18), transparent 60%),
    radial-gradient(900px 500px at 95% 110%, rgba(76,201,240,.16), transparent 60%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  display: grid; grid-template-rows: auto auto 1fr auto;
  grid-template-columns: minmax(0,1fr);
  height: 100dvh; overflow: hidden;
}
#topbar, #stage, #browse, #carousel { min-width: 0; }

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }

/* ===== Header ===== */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px;
  background: rgba(28,22,36,.85); backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,.05);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 52px; height: 52px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.4));
  animation: bob 4s ease-in-out infinite;
}
@keyframes bob {
  0%,100% { transform: translateY(0) rotate(-3deg); }
  50%     { transform: translateY(-4px) rotate(3deg); }
}
#topbar h1 {
  font-size: 28px; font-weight: 900; letter-spacing: -.3px;
  background: linear-gradient(95deg, var(--yellow) 0%, var(--coral) 50%, var(--pink) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#parentBtn {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,.08); font-size: 22px;
  display: grid; place-items: center;
  transition: transform .2s var(--ease), background .2s;
}
#parentBtn:active { transform: scale(.9) rotate(-15deg); background: rgba(255,255,255,.18); }

/* ===== Stage (player + controls) ===== */
#stage {
  background: linear-gradient(180deg, #000 0%, var(--bg) 100%);
  display: flex; flex-direction: column;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
#playerWrap {
  position: relative;
  height: clamp(200px, 30vh, 360px);
  background: #000;
  overflow: hidden;
}
#ytFrame, #ytFrame iframe {
  position: absolute; inset: 0;
  width: 100% !important; height: 100% !important;
  border: 0;
}
#ytFrame iframe { pointer-events: none; }
#clickShield {
  position: absolute; inset: 0; z-index: 5;
  background: transparent; cursor: pointer;
}
#progress {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: 11;
  padding: 14px 14px 8px;       /* big tap area */
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,.55) 100%);
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
#progressTrack {
  position: relative; flex: 1;
  height: 8px;
  background: rgba(255,255,255,.18);
  border-radius: 999px;
  overflow: visible;
}
#progressBuffer {
  position: absolute; inset: 0; right: auto;
  width: 0;
  background: rgba(255,255,255,.30);
  border-radius: 999px;
  pointer-events: none;
}
#progressFill {
  position: absolute; inset: 0; right: auto;
  width: 0;
  background: linear-gradient(90deg, var(--yellow), var(--coral), var(--pink));
  box-shadow: 0 0 10px rgba(255,107,53,.55);
  border-radius: 999px;
  transition: width .25s linear;
  pointer-events: none;
}
#progressThumb {
  position: absolute; top: 50%; left: 0;
  width: 22px; height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  background: var(--yellow);
  border: 3px solid var(--coral);
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0,0,0,.5);
  transition: transform .12s var(--ease);
  pointer-events: none;
}
#progress.dragging #progressFill,
#progress.seeking #progressFill { transition: none; }
#progress.dragging #progressThumb { transform: scale(1.2); }
#timeRead {
  font-size: 12px; font-weight: 800;
  color: var(--text); opacity: .85;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 84px; text-align: right;
}
#welcome {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,107,53,.18), transparent 60%),
    radial-gradient(circle at 70% 70%, rgba(76,201,240,.18), transparent 60%),
    #0a0612;
}
.welcome-inner { text-align: center; padding: 24px; }
.welcome-mark {
  font-size: 88px; line-height: 1; margin-bottom: 12px;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.5));
  animation: bob 3.5s ease-in-out infinite;
}
.welcome-text {
  font-size: 32px; font-weight: 900;
  background: linear-gradient(95deg, var(--yellow), var(--coral), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-sub { font-size: 16px; color: var(--text-dim); margin-top: 6px; font-weight: 700; }

#controls {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px 20px;
  background: linear-gradient(180deg, #000 0%, var(--bg) 100%);
}
.ctrl {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--coral), var(--pink));
  font-size: 24px;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm), inset 0 -4px 0 rgba(0,0,0,.18);
  transition: transform .12s var(--ease);
  color: #fff;
}
.ctrl.big {
  width: 76px; height: 76px; font-size: 32px;
  background: linear-gradient(135deg, var(--yellow), var(--coral));
  color: #1c1624;
}
.ctrl.wide {
  width: auto; height: 56px;
  padding: 0 20px;
  font-size: 16px; font-weight: 900;
  border-radius: 28px;
  background: linear-gradient(135deg, var(--purple), var(--sky));
  margin-left: 12px;
  letter-spacing: .3px;
}
.ctrl:active { transform: scale(.88); }

/* ===== Browse: sidebar + video list ===== */
#browse {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 0; /* allow children to scroll */
}
#sidebar, #videoList { min-width: 0; }

/* Sidebar */
#sidebar {
  overflow-y: auto; overflow-x: hidden;
  padding: 14px 12px 24px;
  border-right: 1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.18);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.chan {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 16px;
  margin-bottom: 6px;
  text-align: left;
  transition: background .15s var(--ease), transform .12s var(--ease);
}
.chan:hover { background: rgba(255,255,255,.05); }
.chan:active { transform: scale(.97); }
.chan.active {
  background: linear-gradient(90deg, rgba(255,107,53,.18), rgba(255,107,157,.10));
  box-shadow: inset 0 0 0 2px rgba(255,209,102,.5);
}
.chan-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}
.chan-name {
  font-size: 17px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chan-count {
  margin-left: auto; font-size: 13px; color: var(--text-dim); font-weight: 700;
  flex: 0 0 auto;
}

/* Video list */
#videoList {
  overflow-y: auto;
  padding: 18px 24px 32px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: min-content;
  gap: 14px;
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
#videoList::-webkit-scrollbar { width: 8px; }
#videoList::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.section-head {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 4px 6px;
  font-size: 22px; font-weight: 900;
  color: var(--coral);
}
.section-head .badge {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 20px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

/* List-style video tile (thumb left + details right) */
.tile {
  display: flex; align-items: stretch; gap: 14px;
  width: 100%;
  background: var(--card);
  border-radius: 18px;
  padding: 10px;
  text-align: left;
  border: 3px solid transparent;
  box-shadow: var(--shadow-sm);
  transition: transform .15s var(--ease), border-color .15s, background .2s;
  position: relative; overflow: hidden;
}
.tile:hover { background: var(--card-hi); }
.tile:active { transform: scale(.96); border-color: var(--yellow); }
.tile.playing { border-color: var(--yellow); background: linear-gradient(135deg, rgba(255,209,102,.12), rgba(255,107,53,.08)); }

.tile .thumb {
  flex: 0 0 auto;
  width: 180px; aspect-ratio: 16/9;
  background-size: cover; background-position: center;
  background-color: #444;
  border-radius: 12px; overflow: hidden;
  position: relative;
}
.tile .thumb::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,.4) 100%);
}
.tile .play-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  opacity: 0; transition: opacity .2s var(--ease);
  z-index: 2;
}
.tile .play-overlay svg { width: 56px; height: 56px; filter: drop-shadow(0 4px 12px rgba(0,0,0,.7)); }
.tile:hover .play-overlay, .tile:active .play-overlay { opacity: 1; }

.tile .meta {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; justify-content: center;
  padding: 6px 8px 6px 0;
}
.tile .title {
  font-size: 16px; font-weight: 800;
  line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
  color: var(--text);
}
.tile .channel {
  font-size: 13px; font-weight: 700;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.tile .channel .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--coral);
}

/* Empty state */
.empty {
  grid-column: 1 / -1;
  text-align: center; padding: 40px;
  color: var(--text-dim); font-weight: 700;
}

/* ===== Now playing (title + channel chip under player) ===== */
#nowPlaying {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 24px 4px;
  background: linear-gradient(180deg, var(--bg) 0%, transparent 100%);
}
.np-title {
  flex: 1; min-width: 0;
  font-size: 18px; font-weight: 800; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.np-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px;
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  flex: 0 0 auto;
}
.np-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--coral), var(--yellow));
  font-size: 16px;
}
.np-channel { font-size: 14px; font-weight: 800; color: var(--text); }

/* ===== Auto-advance countdown ===== */
#autoNext {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  color: var(--text);
  text-align: center;
  padding: 20px;
  animation: fadein .25s var(--ease);
}
.auto-ring { width: 84px; height: 84px; }
#autoRingFill { transition: stroke-dashoffset .25s linear; }
.auto-text { font-size: 16px; font-weight: 800; color: var(--yellow); }
.auto-title { font-size: 18px; font-weight: 800; max-width: 80%; }
.auto-actions { display: flex; gap: 10px; margin-top: 8px; }
.auto-actions button {
  padding: 10px 18px; border-radius: 14px; font-weight: 800; font-size: 14px;
  background: rgba(255,255,255,.1); color: #fff;
  border: 1px solid rgba(255,255,255,.15);
  cursor: pointer;
}
.auto-actions button:nth-child(2) {
  background: linear-gradient(135deg, var(--yellow), var(--coral));
  color: #1c1624; border: none;
}

/* perf: skip layout for offscreen tiles */
.tile, .car-tile {
  content-visibility: auto;
  contain-intrinsic-size: 0 100px;
}

/* ===== Fullscreen mode ===== */
#stage:fullscreen,
#stage:-webkit-full-screen {
  display: flex; flex-direction: column;
  background: #000;
  width: 100vw; height: 100vh;
}
#stage:fullscreen #playerWrap,
#stage:-webkit-full-screen #playerWrap {
  flex: 1; height: auto;
}
#stage:fullscreen #controls,
#stage:-webkit-full-screen #controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,.85) 60%);
  padding: 18px 24px;
  z-index: 20;
  opacity: 0;
  transition: opacity .25s var(--ease);
  pointer-events: none;
}
#stage:fullscreen:hover #controls,
#stage:-webkit-full-screen:hover #controls,
#stage:fullscreen.show-ctrls #controls,
#stage:-webkit-full-screen.show-ctrls #controls {
  opacity: 1; pointer-events: auto;
}

/* ===== Bottom carousel ===== */
#carousel {
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,.35) 100%);
  border-top: 1px solid rgba(255,255,255,.06);
  padding: 10px 0 14px;
  user-select: none;
}
.carousel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 0 24px 8px;
}
.carousel-head .badge {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--yellow), var(--coral));
  display: grid; place-items: center; font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.carousel-head h3 {
  font-size: 18px; font-weight: 900;
  background: linear-gradient(95deg, var(--yellow), var(--coral));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.carousel-head .hint {
  margin-left: auto;
  font-size: 12px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .8px;
}

.carousel-track {
  display: flex; gap: 12px;
  padding: 6px 24px 8px;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  cursor: grab;
  scroll-behavior: smooth;
  mask-image: linear-gradient(90deg, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track.dragging { cursor: grabbing; scroll-behavior: auto; }

.car-tile {
  flex: 0 0 auto;
  width: 168px;
  scroll-snap-align: start;
  border-radius: 16px; overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  border: 3px solid transparent;
  transition: transform .2s var(--ease), border-color .2s;
  position: relative; cursor: pointer;
}
.car-tile:hover { transform: translateY(-3px); }
.car-tile:active { transform: scale(.95); border-color: var(--yellow); }
.car-tile .thumb {
  width: 100%; aspect-ratio: 16/9;
  background-size: cover; background-position: center;
  background-color: #444;
}
.car-tile .label {
  padding: 8px 10px; font-size: 12px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: rgba(0,0,0,.3);
}

@media (max-width: 700px) {
  .car-tile { width: 160px; }
  .car-tile .label { font-size: 11px; }
}

/* ===== Dialogs ===== */
dialog {
  border: none; border-radius: 24px; padding: 32px;
  max-width: 400px; width: calc(100% - 32px);
  background: linear-gradient(160deg, var(--bg-2) 0%, var(--card) 100%);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
  animation: dialogin .25s var(--ease);
}
@keyframes dialogin { from { transform: translateY(20px) scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(6px); }
dialog h2 { margin-bottom: 14px; font-size: 24px; font-weight: 900; }
dialog p { margin-bottom: 16px; opacity: .85; }
dialog input, dialog button {
  width: 100%; padding: 14px 16px; font-size: 16px; border-radius: 14px;
  border: 1px solid rgba(255,255,255,.1); margin-bottom: 10px;
  background: rgba(0,0,0,.3); color: var(--text);
  font-family: inherit; font-weight: 700;
}
dialog button {
  cursor: pointer; background: linear-gradient(135deg, var(--yellow), var(--coral));
  color: #1c1624; font-weight: 900; border: none;
}
dialog button:active { transform: scale(.96); }
dialog .row { display: flex; gap: 10px; margin-top: 8px; }
dialog .row button { margin-bottom: 0; }
.meta { font-size: 13px; opacity: .65; margin-bottom: 16px; font-weight: 600; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  #browse { grid-template-columns: 220px 1fr; }
  .chan-name { font-size: 15px; }
  .tile .thumb { width: 140px; }
  .tile .title { font-size: 14px; }
}
@media (max-width: 700px) {
  #browse { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar {
    border-right: none; border-bottom: 1px solid rgba(255,255,255,.06);
    display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden;
    padding: 10px 14px;
  }
  .chan {
    flex-direction: column; align-items: center; gap: 4px;
    padding: 8px; min-width: 80px;
    margin-bottom: 0;
  }
  .chan-icon { width: 44px; height: 44px; font-size: 20px; }
  .chan-name { font-size: 12px; }
  .chan-count { display: none; }
  #videoList { grid-template-columns: 1fr; padding: 12px; }
  .tile .thumb { width: 120px; }
  .ctrl { width: 60px; height: 60px; font-size: 24px; }
  .ctrl.big { width: 76px; height: 76px; font-size: 32px; }
  .ctrl.wide { height: 56px; font-size: 16px; padding: 0 16px; }
  .welcome-text { font-size: 24px; }
  .welcome-mark { font-size: 64px; }
  #topbar h1 { font-size: 22px; }
  .avatar { width: 44px; height: 44px; }
}
