/* ============================================================
   MyTube — refined UI (dark-first, elegant)
   Champagne-gold accent · glass topbar · soft depth
   ============================================================ */

/* ---- Design tokens ---- */
:root {
  --bg:        #0b0b0e;
  --bg-2:      #101015;
  --bg-3:      #191921;
  --glass:     rgba(13,13,17,0.72);
  --text:      #f4f4f6;
  --text-2:    #a2a2ad;
  --text-3:    #6b6b77;
  --border:    rgba(255,255,255,0.07);
  --border-2:  rgba(255,255,255,0.13);
  --gold:      #e4ba76;
  --gold-2:    #f2d3a0;
  --gold-soft: rgba(228,186,118,0.12);
  --radius:    16px;
  --pill:      999px;
  --shadow:    0 10px 34px rgba(0,0,0,0.45);
  --shadow-sm: 0 4px 14px rgba(0,0,0,0.30);
  --topbar-h:  64px;
  --sidebar-w: 244px;
  --ease:      cubic-bezier(.22,.61,.36,1);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:#f7f6f3; --bg-2:#ffffff; --bg-3:#eeece7;
  --glass:rgba(255,255,255,0.78);
  --text:#17161b; --text-2:#605e69; --text-3:#98959f;
  --border:rgba(0,0,0,0.08); --border-2:rgba(0,0,0,0.14);
  --gold:#b07d2b; --gold-2:#916317; --gold-soft:rgba(176,125,43,0.12);
  --shadow:0 10px 34px rgba(0,0,0,0.10); --shadow-sm:0 4px 14px rgba(0,0,0,0.07);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:#f7f6f3; --bg-2:#ffffff; --bg-3:#eeece7;
    --glass:rgba(255,255,255,0.78);
    --text:#17161b; --text-2:#605e69; --text-3:#98959f;
    --border:rgba(0,0,0,0.08); --border-2:rgba(0,0,0,0.14);
    --gold:#b07d2b; --gold-2:#916317; --gold-soft:rgba(176,125,43,0.12);
    --shadow:0 10px 34px rgba(0,0,0,0.10); --shadow-sm:0 4px 14px rgba(0,0,0,0.07);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
/* ambient depth glow */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 520px at 82% -10%, rgba(228,186,118,0.07), transparent 60%),
    radial-gradient(760px 480px at -5% 4%, rgba(120,110,255,0.05), transparent 55%);
}
:root[data-theme="light"] body::before { opacity: .55; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
::selection { background: var(--gold-soft); color: var(--text); }

* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }

/* ---- Top bar ---- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px; padding: 0 22px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--border); z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.icon-btn {
  background: transparent; border: none; color: var(--text-2);
  width: 42px; height: 42px; border-radius: var(--pill);
  display: grid; place-items: center;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

.logo { display: flex; align-items: center; gap: 11px; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--gold-2), var(--gold));
  color: #1a1408; box-shadow: 0 4px 14px rgba(228,186,118,0.35); flex-shrink: 0;
}
.logo-mark svg { width: 17px; height: 17px; }
.logo-text {
  font-size: 20px; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap;
  background: linear-gradient(180deg, var(--text), var(--text-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.topbar-search { flex: 1; display: flex; max-width: 560px; margin: 0 auto; position: relative; }
.topbar-search input {
  flex: 1; height: 44px; padding: 0 48px 0 20px; min-width: 0;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--pill);
  color: var(--text); font: inherit; font-size: 14.5px;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.topbar-search input::placeholder { color: var(--text-3); }
.topbar-search input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); background: var(--bg); }
.topbar-search button {
  position: absolute; right: 5px; top: 5px; width: 34px; height: 34px;
  background: transparent; border: none; border-radius: var(--pill);
  color: var(--text-2); display: grid; place-items: center;
  transition: color .18s, background .18s;
}
.topbar-search button:hover { color: var(--gold); background: var(--gold-soft); }
.topbar-search button svg { width: 19px; height: 19px; }
.topbar-right { flex-shrink: 0; display: flex; align-items: center; gap: 6px; }

/* ---- Layout / sidebar ---- */
.layout { display: flex; padding-top: var(--topbar-h); min-height: 100vh; position: relative; z-index: 1; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0;
  background: var(--bg); border-right: 1px solid var(--border);
  padding: 16px 12px; overflow-y: auto; z-index: 90;
  transition: transform .28s var(--ease);
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.side-link {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 11px 14px; border-radius: 12px;
  font-size: 14.5px; font-weight: 500; color: var(--text-2);
  transition: background .18s, color .18s;
}
.side-link svg { width: 21px; height: 21px; flex-shrink: 0; }
.side-link:hover { background: var(--bg-3); color: var(--text); }
.side-link.active { background: var(--gold-soft); color: var(--text); font-weight: 600; }
.side-link.active::before { content: ""; position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 3px; background: var(--gold); }
.side-note {
  margin: 20px 6px 6px; padding: 14px; font-size: 12px; line-height: 1.7;
  color: var(--text-2); background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
}
.side-note code { background: var(--bg-3); color: var(--gold); padding: 1px 6px; border-radius: 6px; font-size: 11.5px; }

.overlay { display: none; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,0.55); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); z-index: 80; }
.content { margin-left: var(--sidebar-w); padding: 30px 34px 64px; width: calc(100% - var(--sidebar-w)); max-width: 1620px; }

/* ---- Section title ---- */
.section-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 20px; }

/* ---- Video grid ---- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 30px 20px; }
.video-card { display: block; transition: transform .22s var(--ease); }
.video-card:hover { transform: translateY(-4px); }
.thumb-wrap {
  position: relative; width: 100%; aspect-ratio: 16/9; overflow: hidden;
  border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); transition: box-shadow .22s, border-color .22s;
}
.video-card:hover .thumb-wrap { box-shadow: var(--shadow); border-color: var(--border-2); }
.thumb { width: 100%; height: 100%; object-fit: cover; transition: transform .35s var(--ease); }
.video-card:hover .thumb { transform: scale(1.05); }
.thumb-placeholder { display: grid; place-items: center; height: 100%; background: radial-gradient(120% 120% at 30% 20%, #23232c, #0e0e12); color: var(--gold); font-size: 30px; }
.duration-badge {
  position: absolute; right: 9px; bottom: 9px; letter-spacing: .02em;
  background: rgba(0,0,0,0.72); color: #fff; font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 7px; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.video-info { display: flex; flex-direction: column; gap: 5px; padding: 13px 4px 0; }
.video-title { font-size: 14.5px; font-weight: 600; line-height: 1.4; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.video-meta { font-size: 12.5px; color: var(--text-2); }

/* ---- Empty state ---- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 74px 24px; margin: 16px auto 0; max-width: 520px; }
.empty-icon {
  width: 94px; height: 94px; border-radius: 26px; margin-bottom: 26px; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--gold-soft), transparent), var(--bg-2);
  border: 1px solid var(--border-2); color: var(--gold); box-shadow: var(--shadow);
}
.empty-icon svg { width: 44px; height: 44px; }
.empty-state p { margin: 0; }
.empty-state > p:first-of-type { font-size: 19px; font-weight: 700; color: var(--text); }
.empty-hint { margin-top: 12px !important; font-size: 13.5px; line-height: 1.9; color: var(--text-2); }
.empty-hint code { background: var(--bg-3); color: var(--gold); padding: 2px 8px; border-radius: 7px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 22px;
  padding: 11px 22px; font-weight: 700; font-size: 14px;
  background: linear-gradient(140deg, var(--gold-2), var(--gold)); color: #1a1408;
  border: none; border-radius: var(--pill); box-shadow: 0 6px 18px rgba(228,186,118,0.30);
  transition: transform .18s, box-shadow .18s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(228,186,118,0.40); }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 44px; flex-wrap: wrap; }
.page-link { min-width: 40px; height: 40px; padding: 0 8px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--border); font-size: 14px; font-weight: 600; color: var(--text-2); transition: all .16s; }
.page-link:hover { background: var(--bg-3); color: var(--text); border-color: var(--border-2); }
.page-link.active { background: linear-gradient(140deg, var(--gold-2), var(--gold)); color: #1a1408; border-color: transparent; box-shadow: 0 4px 14px rgba(228,186,118,0.30); }

/* ---- Watch page ---- */
.watch-layout { display: flex; gap: 30px; align-items: flex-start; flex-wrap: wrap; }
.watch-main { flex: 1 1 640px; min-width: 0; }
.watch-related { flex: 0 1 380px; min-width: 280px; }
.player-wrap { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); }
#player { width: 100%; height: 100%; display: block; background: #000; }
/* Plyr theming — gold accent, fill the 16:9 wrap */
:root { --plyr-color-main: #e4ba76; --plyr-video-background: #000; --plyr-range-thumb-background: #e4ba76; --plyr-menu-background: rgba(18,18,24,0.96); --plyr-menu-color: #e8e8ec; --plyr-font-family: inherit; }
.player-wrap .plyr { width: 100%; height: 100%; }
.player-wrap .plyr__video-wrapper { height: 100%; }
.player-wrap .plyr video { width: 100%; height: 100%; object-fit: contain; }
.buffer-indicator { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.30); pointer-events: none; }
.buffer-indicator[hidden] { display: none; }   /* สำคัญ: ให้ attribute hidden ซ่อนได้จริง (ไม่งั้น display:grid ทับ) */
.spinner { width: 46px; height: 46px; border: 3px solid rgba(255,255,255,0.25); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.watch-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.35; margin: 20px 0 8px; }
.watch-meta { font-size: 13.5px; color: var(--text-2); padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.related-card { display: flex; gap: 12px; margin-bottom: 12px; padding: 6px; border-radius: 12px; transition: background .16s; }
.related-card:hover { background: var(--bg-2); }
.related-thumb-wrap { width: 170px; flex-shrink: 0; }
.related-card .video-info { padding: 2px 0 0; flex: 1; min-width: 0; }
.related-card .video-title { font-size: 13.5px; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,0.5); }
  .overlay.show { display: block; }
  .content { margin-left: 0; width: 100%; }
  .watch-related { flex-basis: 100%; }
}
@media (max-width: 600px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .logo-text { display: none; }
  .content { padding: 18px 14px 44px; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px 12px; }
  .related-thumb-wrap { width: 130px; }
  .section-title { font-size: 16px; }
  .playlist-thumb { width: 84px; }
}

/* ---- Series card (folder = playlist) ---- */
.series-card { position: relative; }
.series-card .thumb-wrap { position: relative; z-index: 1; }
.series-card::before, .series-card::after {
  content: ""; position: absolute; left: 8px; right: 8px; top: -6px; height: 28px;
  border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--border);
  z-index: 0; transition: transform .22s var(--ease);
}
.series-card::after { top: -11px; left: 16px; right: 16px; opacity: .5; }
.series-badge {
  position: absolute; right: 9px; bottom: 9px; display: inline-flex; align-items: center; gap: 5px;
  background: rgba(0,0,0,0.78); color: #fff; font-size: 12px; font-weight: 700;
  padding: 4px 9px 4px 7px; border-radius: 8px; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.series-badge svg { width: 14px; height: 14px; color: var(--gold-2); }

/* ---- Watch: series label above title ---- */
.watch-series { display: inline-flex; align-items: center; gap: 7px; margin: 18px 0 0; font-size: 13px; font-weight: 600; color: var(--gold); }
.watch-series svg { width: 17px; height: 17px; }
.watch-series + .watch-title { margin-top: 4px; }

/* ---- Playlist (watch sidebar) ---- */
.playlist { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-2); overflow: hidden; }
.playlist-header { padding: 14px 16px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, var(--gold-soft), transparent); }
.playlist-title { font-size: 15px; font-weight: 700; color: var(--text); line-height: 1.3; }
.playlist-sub { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }
.playlist-items { max-height: 68vh; overflow-y: auto; padding: 6px; }
.playlist-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; transition: background .15s; }
.playlist-item:hover { background: var(--bg-3); }
.playlist-item.active { background: var(--gold-soft); }
.playlist-index { width: 22px; flex-shrink: 0; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; color: var(--text-3); }
.playlist-item.active .playlist-index { color: var(--gold); }
.playlist-index svg { width: 13px; height: 13px; }
.playlist-thumb { position: relative; width: 104px; flex-shrink: 0; aspect-ratio: 16/9; border-radius: 9px; overflow: hidden; background: var(--bg-3); border: 1px solid var(--border); }
.playlist-thumb img { width: 100%; height: 100%; object-fit: cover; }
.playlist-thumb-ph { display: grid; place-items: center; height: 100%; color: var(--gold); font-size: 15px; }
.playlist-dur { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,0.8); color: #fff; font-size: 10.5px; font-weight: 600; padding: 1px 4px; border-radius: 5px; }
.playlist-info { flex: 1; min-width: 0; }
.playlist-ep-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.playlist-item.active .playlist-ep-title { color: var(--gold-2); }
.playlist-ep-meta { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
