*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111118;
  --surface: #1c1c28;
  --surface2: #26263a;
  --accent: #7c6af7;
  --accent-light: #9d8ffa;
  --text: #e4e4f0;
  --muted: #6e6e88;
  --danger: #e05572;
  --r: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── App shell (mobile-first: column) ─── */
#app {
  display: grid;
  height: 100dvh;
}

/* ── Home state (default on load) ─────── */
body.home #app {
  grid-template-rows: 52px 1fr;
  grid-template-areas: "nav" "main";
  grid-template-columns: 1fr;
}
body.home #sidebar  { display: none; }
body.home #main     { border-top: none; display: flex; flex-direction: column; }
body.home #home-grid { display: block; flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; }
body.home #player-area { display: none; }
body.home #section-grid { display: none; }

/* ── Section state (儿童区 / 大人区 / 音乐 full grid) ── */
body.section #app {
  grid-template-rows: 52px 1fr;
  grid-template-areas: "nav" "main";
  grid-template-columns: 1fr;
}
body.section #sidebar    { display: none; }
body.section #main       { border-top: none; display: flex; flex-direction: column; }
body.section #section-grid { display: block; flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; }
body.section #home-grid  { display: none; }
body.section #player-area { display: none; }

/* ── Browsing state ───────────────────── */
body.browsing #app {
  grid-template-rows: 52px 1fr auto;
  grid-template-areas: "nav" "sidebar" "main";
  grid-template-columns: 1fr;
}
body.browsing #sidebar   { display: block; }
body.browsing #home-grid { display: none; }
body.browsing #section-grid { display: none; }
body.browsing #player-area { display: flex; flex-direction: column; }
body.browsing #main { display: flex; flex-direction: column; }

/* ── Browsing + playing (mobile): player on top, file list below ── */
body.browsing.playing #app {
  grid-template-rows: 52px auto 1fr;
  grid-template-areas: "nav" "main" "sidebar";
}
body.browsing.playing #main {
  border-top: none;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
body.browsing.playing #sidebar {
  border-top: none;
  min-height: 0;
}

/* ── Nav ─────────────────────────────── */
#nav {
  grid-area: nav;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

#logo-btn {
  flex-shrink: 0;
  text-align: left;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
#logo-btn:hover { color: var(--accent-light); }

/* Scrollable nav items — flex: 1 so it takes remaining nav width */
.nav-items {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  white-space: nowrap;
}
.nav-items::-webkit-scrollbar { display: none; }

.nav-item {
  flex-shrink: 0;
  padding: 0 14px;
  height: 52px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--text); }
.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.nav-item:hover:not(.active) { color: var(--text); }

/* ── Sidebar ─────────────────────────── */
#sidebar {
  grid-area: sidebar;
  overflow: hidden;
  position: relative;
}

.panel {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}
.panel.active { display: block; }

/* Breadcrumb */
#breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding-bottom: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.crumb { cursor: pointer; }
.crumb:not(.current):hover { color: var(--text); }
.crumb.current { color: var(--text); font-weight: 500; }
.crumb-sep { opacity: 0.4; }

/* Folder actions */
.folder-action {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.btn-folder-pl, .btn-play-folder {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--r);
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-folder-pl:hover, .btn-play-folder:hover,
.btn-folder-pl:active, .btn-play-folder:active {
  background: var(--accent);
  border-color: var(--accent);
}

/* File items */
.file-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--r);
  cursor: pointer;
  gap: 10px;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.file-item:hover, .file-item:active { background: var(--surface2); }
.file-item.playing { background: var(--surface2); }
.file-item.playing .file-name { color: var(--accent-light); }

.file-icon { font-size: 18px; width: 26px; text-align: center; flex-shrink: 0; }
.file-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-add {
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.file-item:hover .btn-add { opacity: 1; }

.btn-del-file {
  padding: 3px 6px;
  font-size: 13px;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.file-item:hover .btn-del-file { opacity: 1; }
.btn-del-file:hover { color: var(--danger); }
.btn-add:hover { border-color: var(--accent); color: var(--accent); }

.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 12px; }

/* Playlist list */
.btn-primary {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 12px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover { background: var(--accent-light); }

.pl-item {
  display: flex;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--r);
  margin-bottom: 8px;
  cursor: pointer;
  gap: 12px;
  border: 1px solid rgba(255,255,255,0.04);
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.pl-item:hover, .pl-item:active { background: var(--surface2); }
.pl-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-count { font-size: 12px; color: var(--muted); flex-shrink: 0; }

/* Playlist detail */
.pl-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.pl-detail-header h3 { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-back { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 4px 0; flex-shrink: 0; }
.btn-del { background: none; border: 1px solid var(--danger); color: var(--danger); padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; flex-shrink: 0; }

.track-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--r);
  gap: 10px;
  cursor: pointer;
  transition: background 0.12s;
  border-left: 3px solid transparent;
  -webkit-tap-highlight-color: transparent;
}
.track-item:hover, .track-item:active { background: var(--surface2); }
.track-item.playing { background: var(--surface2); border-left-color: var(--accent); }
.track-item.playing .track-name { color: var(--accent-light); }

.track-num { width: 22px; text-align: center; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.track-icon { font-size: 16px; flex-shrink: 0; }
.track-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-remove {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 2px 6px; opacity: 0; transition: opacity 0.15s;
}
.track-item:hover .btn-remove { opacity: 1; }
.btn-remove:hover { color: var(--danger); }

/* ── Player (mobile: bottom bar) ─────── */
#main {
  grid-area: main;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,0.06);
}

#player-area { display: flex; flex-direction: column; }

#player-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
  gap: 6px;
  color: var(--muted);
}
.ph-icon { font-size: 28px; opacity: 0.35; }
.ph-text { font-size: 12px; }

/* Audio cover art (shown when playing audio) */
#audio-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 8px;
}
#audio-cover.hidden { display: none; }
.ac-icon { font-size: 40px; }
#ac-title { font-size: 13px; color: var(--muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

#video-player { width: 100%; max-height: 38vh; background: #000; display: block; }
#video-player.hidden { display: none; }

#audio-player { width: 100%; padding: 8px 12px; }
#audio-player.hidden { display: none; }

#player-info {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  gap: 12px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
#player-info.hidden { display: none; }

#now-playing-title {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#queue-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#queue-pos { font-size: 11px; color: var(--muted); min-width: 38px; text-align: center; }

#btn-prev, #btn-next {
  background: none; border: none; color: var(--text);
  cursor: pointer; font-size: 16px; padding: 4px 6px;
  opacity: 0.7; transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#btn-prev:hover, #btn-next:hover { opacity: 1; color: var(--accent); }
#btn-prev:disabled, #btn-next:disabled { opacity: 0.2; cursor: default; }

/* ── Modal ───────────────────────────── */
#modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: flex-end;
  z-index: 200;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#modal.hidden { display: none; }

#modal-box {
  background: var(--surface);
  border-radius: var(--r) var(--r) 0 0;
  padding: 20px;
  width: 100%;
  max-height: 65vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#modal-box h3 { font-size: 15px; margin-bottom: 14px; }

.modal-pl-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px; border-radius: var(--r); cursor: pointer; font-size: 14px;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.modal-pl-item:hover, .modal-pl-item:active { background: var(--surface2); }

#modal-close {
  width: 100%; padding: 12px; margin-top: 12px;
  background: none; border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted); border-radius: var(--r); cursor: pointer; font-size: 14px;
}

/* ── Desktop (≥768px): sidebar + main side by side ── */
@media (min-width: 768px) {
  body.browsing #app {
    grid-template-rows: 52px 1fr;
    grid-template-columns: 300px 1fr;
    grid-template-areas:
      "nav nav"
      "sidebar main";
  }

  #sidebar {
    border-right: 1px solid rgba(255,255,255,0.06);
  }

  #main {
    border-top: none;
    display: flex;
    flex-direction: column;
  }

  #player-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  #video-player { max-height: none; flex: 1; min-height: 0; }

  #player-placeholder { flex: 1; }
  .ph-icon { font-size: 48px; }
  .ph-text { font-size: 14px; }

  #audio-cover { flex: 1; justify-content: center; }
  .ac-icon { font-size: 64px; }
  #ac-title { font-size: 15px; }

  #modal { align-items: center; }
  #modal-box { border-radius: var(--r); max-width: 380px; margin: 0 auto; }

  .btn-add { opacity: 1; }
}

/* ── Upload modal ────────────────────────── */
#upload-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: flex-end;
  z-index: 300;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#upload-modal.hidden { display: none; }

#upload-box {
  background: var(--surface);
  border-radius: var(--r) var(--r) 0 0;
  padding: 20px;
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.upload-header {
  display: flex; align-items: center; margin-bottom: 14px;
}
.upload-header h3 { flex: 1; font-size: 15px; }
#upload-close {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 18px; padding: 4px;
}

#upload-pick { cursor: pointer; margin-bottom: 12px; }

.upload-item {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.upload-item:last-child { border-bottom: none; }
.upload-item-name {
  font-size: 13px; margin-bottom: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-progress-wrap {
  height: 4px; background: var(--surface2);
  border-radius: 2px; overflow: hidden;
}
.upload-progress-bar {
  height: 100%; width: 0%;
  background: var(--accent); border-radius: 2px;
  transition: width 0.15s;
}
.upload-status { font-size: 11px; color: var(--muted); margin-top: 4px; }
.upload-status.done { color: #4ade80; }
.upload-status.error { color: var(--danger); }

#upload-cancel {
  width: 100%; padding: 12px; margin-top: 12px;
  background: none; border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted); border-radius: var(--r); cursor: pointer; font-size: 14px;
}

.btn-upload {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--r);
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-upload:hover, .btn-upload:active { background: var(--accent); border-color: var(--accent); }

@media (min-width: 768px) {
  #upload-modal { align-items: center; }
  #upload-box { border-radius: var(--r); max-width: 420px; margin: 0 auto; }
}

/* Safe area padding for iPhone notch/home bar */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #nav { padding-top: env(safe-area-inset-top); }
  #main { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Section header ───────────────────── */
.section-block { margin-bottom: 28px; }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}
.section-header-label {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.section-header-sub {
  font-size: 12px;
  color: var(--muted);
}

/* Card row — horizontal scroll (home page) */
.card-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.card-row::-webkit-scrollbar { display: none; }

/* Portrait card */
.portrait-card {
  flex-shrink: 0;
  width: 140px;
  height: 180px;
  border-radius: var(--r);
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  text-align: left;
}
.portrait-card:hover,
.portrait-card:active { border-color: var(--accent); }

.portrait-card .card-icon-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  line-height: 1;
}
.portrait-card .card-info {
  padding: 8px 24px 10px 10px;
  background: var(--surface);
}
.portrait-card .card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.portrait-card .card-desc {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.portrait-card .card-arrow {
  position: absolute;
  bottom: 10px;
  right: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Section grid — 2-col on mobile, 4-col on desktop */
.section-card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.section-card-grid .portrait-card {
  width: 100%;
}

@media (min-width: 768px) {
  .section-card-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Subcategory grid (video root subdirs) — keep small cards */
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 4px 0 16px;
}
.category-card {
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}
.category-card:hover,
.category-card:active { background: var(--surface); border-color: var(--accent); }
.cat-icon { font-size: 28px; line-height: 1; }
.cat-name { font-size: 13px; font-weight: 500; color: var(--text); }

/* ── YouTube Download modal ──────────────────── */
#dl-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: flex-end;
  z-index: 300;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#dl-modal.hidden { display: none; }

#dl-box {
  background: var(--surface);
  border-radius: var(--r) var(--r) 0 0;
  padding: 20px;
  width: 100%;
  max-height: 75vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dl-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

#dl-url {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--r);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#dl-url:focus { border-color: var(--accent); }
#dl-url::placeholder { color: var(--muted); }

#dl-quality {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--r);
  color: var(--text);
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

#dl-submit { margin-bottom: 0; }

.dl-item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.dl-item-footer .upload-status { margin-top: 0; }

.btn-dl-cancel {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  flex-shrink: 0;
  transition: color 0.15s;
}
.btn-dl-cancel:hover { color: var(--danger); }


@media (min-width: 768px) {
  #dl-modal { align-items: center; }
  #dl-box { border-radius: var(--r); max-width: 460px; margin: 0 auto; }
}
