/* ═══════════════════════════════════════════════════════
   KidTube  ·  Cartoonish Neo-Brutalism Stylesheet
   Kid-Friendly Color Palette  ·  Light + Dark Themes
═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ──────────────────────────────────────────────────────
   LIGHT THEME (default)
────────────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:        #FFF7ED;
  --surface:   #FFFFFF;
  --card:      #FFF3E0;
  --border:    #1A1A1A;
  --text:      #1A1A1A;
  --muted:     #78716C;

  /* Accent swatches (color + light variant) */
  --brand:     #EA580C;   /* orange */
  --brand-lt:  #FED7AA;
  --teal:      #0891B2;
  --teal-lt:   #CFFAFE;
  --coral:     #DC2626;
  --coral-lt:  #FEE2E2;
  --sun:       #C07908;
  --sun-lt:    #FEF3C7;
  --sky:       #2563EB;
  --sky-lt:    #DBEAFE;
  --pink:      #DB2777;
  --pink-lt:   #FCE7F3;
  --lime:      #4D7C0F;
  --lime-lt:   #ECFCCB;

  /* Neo-brutalism shadows (offset, no blur) */
  --sh:        4px 4px 0 #1A1A1A;
  --sh-sm:     2px 2px 0 #1A1A1A;
  --sh-lg:     6px 6px 0 #1A1A1A;

  /* Sizing tokens */
  --bw:        2.5px;
  --r:         10px;
  --r-lg:      18px;
  --r-xl:      24px;

  color-scheme: light;
}

/* ──────────────────────────────────────────────────────
   DARK THEME — system preference
────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #08131F;
    --surface:   #0D1E30;
    --card:      #122740;
    --border:    #3D7AAF;
    --text:      #E2F0FF;
    --muted:     #6B9EC2;

    --brand:     #FB923C;
    --brand-lt:  #1C0A00;
    --teal:      #22D3EE;
    --teal-lt:   #082830;
    --coral:     #F87171;
    --coral-lt:  #3B0E0E;
    --sun:       #FCD34D;
    --sun-lt:    #3A2500;
    --sky:       #60A5FA;
    --sky-lt:    #0E2040;
    --pink:      #F472B6;
    --pink-lt:   #380E25;
    --lime:      #A3E635;
    --lime-lt:   #1A2E04;

    --sh:        4px 4px 0 rgba(0,0,0,0.75);
    --sh-sm:     2px 2px 0 rgba(0,0,0,0.75);
    --sh-lg:     6px 6px 0 rgba(0,0,0,0.75);

    color-scheme: dark;
  }
}

/* ──────────────────────────────────────────────────────
   DARK THEME — manual toggle ([data-theme="dark"] on <html>)
────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:        #08131F;
  --surface:   #0D1E30;
  --card:      #122740;
  --border:    #3D7AAF;
  --text:      #E2F0FF;
  --muted:     #6B9EC2;

  --brand:     #FB923C;
  --brand-lt:  #1C0A00;
  --teal:      #22D3EE;
  --teal-lt:   #082830;
  --coral:     #F87171;
  --coral-lt:  #3B0E0E;
  --sun:       #FCD34D;
  --sun-lt:    #3A2500;
  --sky:       #60A5FA;
  --sky-lt:    #0E2040;
  --pink:      #F472B6;
  --pink-lt:   #380E25;
  --lime:      #A3E635;
  --lime-lt:   #1A2E04;

  --sh:        4px 4px 0 rgba(0,0,0,0.75);
  --sh-sm:     2px 2px 0 rgba(0,0,0,0.75);
  --sh-lg:     6px 6px 0 rgba(0,0,0,0.75);

  color-scheme: dark;
}

/* ──────────────────────────────────────────────────────
   BASE
────────────────────────────────────────────────────── */
html, body {
  min-height: 100%;
  font-family: 'Nunito', sans-serif;
  background-color: var(--bg);
  /* Subtle polka-dot texture on the page background */
  background-image: radial-gradient(circle, rgba(234, 88, 12, 0.09) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
  color: var(--text);
}

body { padding: 16px; }

/* ──────────────────────────────────────────────────────
   APP SHELL
────────────────────────────────────────────────────── */
.app-shell {
  width: min(1360px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100vh - 32px);
  max-height: calc(100vh - 32px);
}

/* ──────────────────────────────────────────────────────
   TOPBAR
────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--brand-lt);
  border-bottom: var(--bw) solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
  font-size: 1.4rem;
  font-family: 'Nunito', sans-serif;
  display: grid;
  place-items: center;
  border: var(--bw) solid var(--border);
  box-shadow: var(--sh-sm);
  flex-shrink: 0;
}

.brand h1 {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand p {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ──────────────────────────────────────────────────────
   BUTTONS  (neo-brutalism: hard offset shadow, lift on hover)
────────────────────────────────────────────────────── */
.btn {
  border: var(--bw) solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  font-size: 0.84rem;
  font-weight: 800;
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  box-shadow: var(--sh-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  white-space: nowrap;
}

.btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* Per-button accent colors */
#adminModeBtn  { background: var(--coral-lt); color: var(--coral); }
#addFilesBtn   { background: var(--sky-lt);   color: var(--sky);   }
#addFolderBtn  { background: var(--teal-lt);  color: var(--teal);  }
#refreshBtn    { background: var(--sun-lt);   color: var(--sun);   }

#themeToggleBtn {
  background: var(--surface);
  color: var(--text);
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  border-radius: var(--r);
}

/* ──────────────────────────────────────────────────────
   LAYOUT
────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

.player-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

/* ──────────────────────────────────────────────────────
   VIDEO WRAP
────────────────────────────────────────────────────── */
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border: var(--bw) solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* ──────────────────────────────────────────────────────
   CONTROLS OVERLAY
────────────────────────────────────────────────────── */
.controls {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 3;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s, transform 0.25s;
  padding: 10px 14px 14px;
  background: linear-gradient(to top, rgba(0,0,0,0.82), rgba(0,0,0,0.45) 55%, transparent);
  display: grid;
  gap: 8px;
}

.video-wrap:hover .controls,
.video-wrap.show-controls .controls,
.video-wrap.paused .controls {
  opacity: 1;
  transform: translateY(0);
}

/* ──────────────────────────────────────────────────────
   PROGRESS BAR
────────────────────────────────────────────────────── */
.progress-wrap {
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.progress-buffered,
.progress-fill {
  position: absolute;
  left: 0;
  top: 50%;
  height: 8px;
  transform: translateY(-50%);
  border-radius: 999px;
}

.progress-buffered {
  width: 0%;
  background: rgba(255, 255, 255, 0.3);
}

.progress-fill {
  width: 0%;
  background: var(--brand);
}

.progress-thumb {
  position: absolute;
  left: 0%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 0 3px var(--brand);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.progress-wrap:hover .progress-thumb { opacity: 1; }

/* ──────────────────────────────────────────────────────
   CONTROL ROW
────────────────────────────────────────────────────── */
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-btn {
  border: 0;
  width: 46px;
  height: 46px;
  border-radius: var(--r);
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.ctrl-btn:hover  { background: rgba(255, 255, 255, 0.28); transform: scale(1.08); }
.ctrl-btn:active { transform: scale(0.94); }

.time-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 500;
  white-space: nowrap;
}

.spacer { flex: 1; }

/* ──────────────────────────────────────────────────────
   VOLUME
────────────────────────────────────────────────────── */
.vol-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vol-slider-wrap {
  width: 100px;
  height: 28px;
  display: grid;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.vol-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.vol-fill {
  height: 100%;
  border-radius: inherit;
  background: #fff;
}

/* ──────────────────────────────────────────────────────
   SPEED BUTTON
────────────────────────────────────────────────────── */
.speed-btn {
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--r);
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 46px;
  backdrop-filter: blur(6px);
  transition: background 0.15s;
}

.speed-btn:hover { background: rgba(255, 255, 255, 0.28); }

/* ──────────────────────────────────────────────────────
   PLAY OVERLAY
────────────────────────────────────────────────────── */
.play-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.video-wrap:hover .play-overlay,
.video-wrap.paused .play-overlay { opacity: 1; }

.play-btn-big {
  width: 86px;
  height: 86px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  border: 3px solid #fff;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  transition: transform 0.15s;
}

.play-btn-big:hover { transform: scale(1.08); }

/* ──────────────────────────────────────────────────────
   GESTURE TOAST
────────────────────────────────────────────────────── */
.gesture-toast {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translate(-50%, -12px);
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--brand);
  border: 2.5px solid #fff;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 0.84rem;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 6;
  white-space: nowrap;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
  letter-spacing: 0.02em;
}

.gesture-toast.show { opacity: 1; transform: translate(-50%, 0); }
.gesture-toast.seek { background: var(--teal); }

/* ──────────────────────────────────────────────────────
   SEEK PULSE OVERLAYS
────────────────────────────────────────────────────── */
.seek-pulse {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 42%;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

.seek-pulse.left {
  left: 0;
  background:
    radial-gradient(circle at 28% 50%, rgba(234, 88, 12, 0.55), rgba(234, 88, 12, 0) 62%),
    linear-gradient(to right, rgba(234, 88, 12, 0.32), transparent);
}

.seek-pulse.right {
  right: 0;
  background:
    radial-gradient(circle at 72% 50%, rgba(8, 145, 178, 0.55), rgba(8, 145, 178, 0) 62%),
    linear-gradient(to left, rgba(8, 145, 178, 0.32), transparent);
}

.seek-pulse.show { animation: seekPulseFlash 0.28s ease-out; }

@keyframes seekPulseFlash {
  0%   { opacity: 0; transform: scale(1); }
  20%  { opacity: 1; transform: scale(1.01); }
  100% { opacity: 0; transform: scale(1.03); }
}

/* ──────────────────────────────────────────────────────
   META (video title / description below player)
────────────────────────────────────────────────────── */
.meta {
  display: grid;
  gap: 4px;
  padding: 2px 6px;
  flex: 0 0 auto;
}

.meta h2 {
  font-size: clamp(1rem, 2vw, 1.4rem);
  font-weight: 800;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.meta p {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ──────────────────────────────────────────────────────
   SIDEBAR
────────────────────────────────────────────────────── */
.sidebar {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  background: var(--card);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh);
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 10px;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-head h3 {
  font-size: 1rem;
  font-weight: 900;
}

.count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--brand-lt);
  color: var(--brand);
  border: 1.5px solid var(--brand);
  border-radius: 999px;
  padding: 2px 9px;
}

/* ──────────────────────────────────────────────────────
   PLAYLIST TOOLS (search + sort)
────────────────────────────────────────────────────── */
.playlist-tools { display: grid; gap: 8px; }

.playlist-search,
.playlist-sort {
  border: var(--bw) solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.83rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  width: 100%;
  box-shadow: var(--sh-sm);
}

.playlist-search::placeholder { color: var(--muted); }

.playlist-search:focus,
.playlist-sort:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 3px 3px 0 var(--brand);
}

/* ──────────────────────────────────────────────────────
   HINT TEXT
────────────────────────────────────────────────────── */
.hint {
  font-size: 0.77rem;
  font-weight: 700;
  line-height: 1.5;
  padding: 9px 12px;
  border-radius: var(--r);
  border: var(--bw) dashed var(--border);
  background: var(--sun-lt);
  color: var(--sun);
}

/* ──────────────────────────────────────────────────────
   PLAYLIST
────────────────────────────────────────────────────── */
.playlist {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 8px;
  align-content: start;
  padding-right: 2px;
}

.playlist::-webkit-scrollbar         { width: 8px; }
.playlist::-webkit-scrollbar-track   { background: var(--card);  border-radius: 999px; }
.playlist::-webkit-scrollbar-thumb   { background: var(--brand); border-radius: 999px; }
.playlist                            { scrollbar-width: thin; scrollbar-color: var(--brand) var(--card); }

/* ──────────────────────────────────────────────────────
   PLAYLIST ITEM
────────────────────────────────────────────────────── */
.playlist-item {
  border: var(--bw) solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  padding: 10px;
  text-align: left;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: var(--sh-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.playlist-item:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}

.playlist-item:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.playlist-item.active {
  background: var(--brand-lt);
  border-color: var(--brand);
  box-shadow: 3px 3px 0 var(--brand);
}

.playlist-thumb-wrap {
  width: 92px;
  aspect-ratio: 16 / 9;
  border-radius: 7px;
  overflow: hidden;
  background: var(--card);
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
}

.playlist-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.playlist-thumb-placeholder {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace;
}

.playlist-item-content {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.playlist-item-name {
  font-size: 0.86rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
}

.playlist-item-sub {
  font-size: 0.7rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playlist-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

/* ──────────────────────────────────────────────────────
   PLAYLIST INLINE ACTION BUTTONS
────────────────────────────────────────────────────── */
.playlist-delete-btn {
  border: 1.5px solid var(--coral);
  border-radius: 6px;
  background: var(--coral-lt);
  color: var(--coral);
  font-size: 0.66rem;
  font-weight: 800;
  font-family: 'Nunito', sans-serif;
  padding: 2px 7px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.12s, color 0.12s;
}

.playlist-delete-btn:hover { background: var(--coral); color: #fff; }

.playlist-fix-btn {
  border: 1.5px solid var(--sky);
  border-radius: 6px;
  background: var(--sky-lt);
  color: var(--sky);
  font-size: 0.66rem;
  font-weight: 800;
  font-family: 'Nunito', sans-serif;
  padding: 2px 7px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.12s, color 0.12s;
}

.playlist-fix-btn:hover   { background: var(--sky); color: #fff; }
.playlist-fix-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.playlist-normalize-pill {
  border: 1.5px solid var(--sun);
  border-radius: 999px;
  background: var(--sun-lt);
  color: var(--sun);
  font-size: 0.6rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  padding: 1px 7px;
  flex: 0 0 auto;
  animation: pulse 1.5s ease-in-out infinite;
}

.playlist-normalize-pill.done {
  border-color: var(--lime);
  background: var(--lime-lt);
  color: var(--lime);
  animation: none;
}

.playlist-normalize-pill.failed {
  border-color: var(--coral);
  background: var(--coral-lt);
  color: var(--coral);
  animation: none;
}

.fix-all-btn {
  border: var(--bw) solid var(--sky);
  border-radius: var(--r);
  background: var(--sky-lt);
  color: var(--sky);
  font-size: 0.78rem;
  font-weight: 800;
  font-family: 'Nunito', sans-serif;
  padding: 9px 12px;
  cursor: pointer;
  width: 100%;
  box-shadow: var(--sh-sm);
  display: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.fix-all-btn:hover   { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--sky); }
.fix-all-btn.visible { display: block; }

/* ──────────────────────────────────────────────────────
   ERROR MESSAGE
────────────────────────────────────────────────────── */
.error-msg {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  text-align: center;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  z-index: 5;
  padding: 18px;
  font-size: 0.9rem;
  font-weight: 700;
}

.error-msg.visible { display: grid; }

.hidden-input { display: none; }

/* ──────────────────────────────────────────────────────
   ANIMATIONS
────────────────────────────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* ──────────────────────────────────────────────────────
   RESPONSIVE  (≤ 980px)
────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .app-shell {
    height: auto;
    max-height: none;
    min-height: calc(100vh - 32px);
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .player-panel { overflow: visible; }

  .sidebar { max-height: 42vh; }

  .playlist-item {
    grid-template-columns: 80px minmax(0, 1fr);
    gap: 8px;
  }

  .playlist-thumb-wrap { width: 80px; }

  .ctrl-btn    { width: 52px; height: 52px; }

  .speed-btn {
    min-height: 52px;
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .time-display { font-size: 0.9rem; }

  .play-btn-big { width: 92px; height: 92px; }
}
