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

:root {
  --bg:        #0D0F14;
  --surface:   #1A1E2E;
  --surface2:  #242840;
  --border:    #2E3352;
  --accent:    #E8A020;
  --accent2:   #F5C24C;
  --text:      #E8EAF0;
  --muted:     #8890B0;
  --sidebar-w: 280px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .25s ease, min-width .25s ease;
}
#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border: none;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -1px;
  cursor: pointer;
}
.logo span {
  color: var(--accent);
}

#folder-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
#folder-tree::-webkit-scrollbar {
  width: 4px;
}
#folder-tree::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.tree-loading {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
}
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.folder-node {
  margin: 1px 0;
}
.folder-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}
.folder-row:hover {
  background: var(--surface2);
}
.folder-row.active {
  background: var(--surface2);
  color: var(--accent);
}
.chevron {
  font-size: 10px;
  color: var(--muted);
  transition: transform .15s;
  width: 12px;
  flex-shrink: 0;
}
.folder-row.open .chevron {
  transform: rotate(90deg);
}
.folder-icon {
  font-size: 15px;
}
.folder-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-count {
  font-size: 11px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}
.folder-children {
  padding-left: 18px;
  display: none;
}
.folder-children.open {
  display: block;
}

.video-leaf {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s;
}
.video-leaf:hover {
  background: var(--surface2);
}
.video-leaf.playing {
  background: rgba(232,160,32,.12);
  color: var(--accent);
}
.video-leaf .vicon {
  font-size: 12px;
  color: var(--muted);
}
.video-leaf .vname {
  flex: 1;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main Panel ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ── */
#topbar {
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#breadcrumb {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#breadcrumb .crumb {
  cursor: pointer;
  transition: color .12s;
}
#breadcrumb .crumb:hover {
  color: var(--accent);
}
#breadcrumb .sep {
  margin: 0 5px;
}
#breadcrumb .crumb.last {
  color: var(--text);
  cursor: default;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all .12s;
  font-family: inherit;
  white-space: nowrap;
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.icon-btn.active {
  border-color: #4CAF7A;
  color: #4CAF7A;
}
#cast-status {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
#cast-status.connected {
  color: #4CAF7A;
}

/* ── Content Viewports ── */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Welcome State ── */
#welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  color: var(--muted);
  text-align: center;
  padding: 32px;
}
#welcome .big-icon {
  font-size: 60px;
}
#welcome h2 {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
}
#welcome p {
  font-size: 14px;
  line-height: 1.6;
  max-width: 340px;
}

/* ── Video Player ── */
#player-section {
  background: #000;
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
#player-section.hidden {
  display: none;
}

/* Normal (non-fullscreen) video size */
#video-player {
  width: 100%;
  height: 52vh;
  max-height: 52vh;
  display: block;
  background: #000;
  object-fit: contain;
  cursor: pointer;
  flex-shrink: 0;
}

@keyframes filmstrip {
  0%   { background-position: 0 0; }
  100% { background-position: 60px 0; }
}
#player-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(90deg,
    #0D0F14 0px,#0D0F14 8px,#1A1E2E 8px,#1A1E2E 9px,
    #0D0F14 9px,#0D0F14 51px,#1A1E2E 51px,#1A1E2E 52px,
    #0D0F14 52px,#0D0F14 60px);
  animation: filmstrip .4s linear infinite;
  pointer-events: none;
}
#player-overlay.show {
  display: flex;
}
#player-overlay .loading-text {
  color: var(--accent);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  text-shadow: 0 0 20px rgba(232,160,32,.8);
}

#cast-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: #000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
}
#cast-overlay.show {
  display: flex;
}
.cast-icon-big {
  font-size: 52px;
}
.cast-device-name {
  font-size: 14px;
  color: var(--accent);
  font-family: 'DM Mono', monospace;
}

/* ── Fullscreen ── */
#player-section:fullscreen,
#player-section:-webkit-full-screen,
#player-section:-moz-full-screen {
  display: flex !important;
  flex-direction: column !important;
  width: 100vw !important;
  height: 100vh !important;
  background: #000 !important;
}

#player-section:fullscreen #video-player,
#player-section:-webkit-full-screen #video-player,
#player-section:-moz-full-screen #video-player {
  flex: 1 !important;
  width: 100% !important;
  height: 0 !important;
  max-height: none !important;
  min-height: 0 !important;
  object-fit: contain !important;
}

#player-section:fullscreen #controls,
#player-section:-webkit-full-screen #controls,
#player-section:-moz-full-screen #controls {
  flex-shrink: 0 !important;
  background: var(--surface) !important;
}

#player-section:fullscreen #native-cast-huge-btn,
#player-section:-webkit-full-screen #native-cast-huge-btn,
#player-section:-moz-full-screen #native-cast-huge-btn {
  display: none !important;
}

#player-section:fullscreen #player-overlay,
#player-section:-webkit-full-screen #player-overlay,
#player-section:-moz-full-screen #player-overlay {
  flex: 1;
  height: auto;
}

/* ── Player Controls ── */
#controls {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}
.progress-wrap {
  position: relative;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
  margin-bottom: 10px;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0;
  pointer-events: none;
}
.progress-thumb {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.progress-wrap:hover .progress-thumb {
  opacity: 1;
}
.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ctrl-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: 6px;
  transition: color .12s;
  line-height: 1;
}
.ctrl-btn:hover {
  color: var(--text);
}
.ctrl-btn.accent {
  color: var(--accent);
}
#time-display {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  min-width: 90px;
}
#now-playing-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.volume-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
#volume-slider {
  width: 70px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Content Presentation Grids ── */
#grid-section {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
#grid-section::-webkit-scrollbar {
  width: 6px;
}
#grid-section::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
}
.section-count {
  font-size: 12px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}

/* Subfolders Grid */
.subfolder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px,1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.subfolder-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  flex-direction: column;
}
.subfolder-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.sf-cover-container {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface2);
  overflow: hidden;
  position: relative;
}
.sf-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sf-icon {
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--surface2);
}
.sf-info-block {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sf-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sf-meta {
  font-size: 11px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}

/* Videos Feed Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px,1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all .15s;
}
.video-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.video-card.playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(232,160,32,.2);
}
.video-thumb {
  width: 100%;
  padding-top: 56.25%;
  position: relative;
  background: var(--surface2);
}
.thumb-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.play-icon {
  font-size: 28px;
  opacity: .5;
  position: absolute;
  z-index: 2;
  pointer-events: none;
}
.playing-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  background: var(--accent);
  color: #0D0F14;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'DM Mono', monospace;
}
.video-info {
  padding: 10px;
}
.video-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.video-meta {
  font-size: 11px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  display: flex;
  gap: 8px;
}

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}
.empty-state .icon {
  font-size: 40px;
  margin-bottom: 10px;
}

/* ── Modals & Dialogs ── */
#share-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.7);
  align-items: center;
  justify-content: center;
}
#share-modal.show {
  display: flex;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  min-width: 300px;
  max-width: 420px;
  width: 90%;
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}
.share-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.share-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: all .15s;
}
.share-opt:hover {
  border-color: var(--accent);
}
.opt-icon {
  font-size: 22px;
}
.opt-title {
  font-size: 14px;
  font-weight: 500;
}
.opt-sub {
  font-size: 12px;
  color: var(--muted);
}
#url-wrap {
  margin-top: 12px;
  display: none;
}
#url-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 12px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  outline: none;
}

/* ── Live Banner Notifications ── */
#notif-area {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.notif {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 13px;
  min-width: 200px;
  animation: slideIn .2s ease;
}
.notif.success {
  border-color: #4CAF7A;
}
.notif.info {
  border-color: var(--accent);
}
@keyframes slideIn {
  from { opacity:0; transform:translateX(20px); }
  to   { opacity:1; transform:translateX(0); }
}

/* ── Cast Button ── */
#native-cast-huge-btn {
  display: block;
  width: calc(100% - 24px);
  margin: 12px auto;
  padding: 16px;
  background: var(--surface2);
  border: 2px solid var(--accent);
  color: var(--text);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  font-family: inherit;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}
#native-cast-huge-btn:hover {
  background: var(--accent);
  color: #0D0F14;
  transform: translateY(-1px);
}
#native-cast-huge-btn:active {
  transform: translateY(1px);
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
  html, body {
    overflow-y: auto !important;
    height: auto !important;
  }

  #app {
    flex-direction: column;
    overflow-y: auto;
    height: auto !important;
    min-height: 100vh;
  }

  #sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #sidebar.collapsed {
    height: 0 !important;
    max-height: 0 !important;
  }

  #main {
    flex: 1;
    height: auto;
  }

  #content {
    overflow: visible;
  }

  #grid-section {
    overflow-y: visible;
  }

  #video-player {
    height: 35vh;
  }

  #cast-status, #share-btn {
    display: none;
  }
}

@media (max-width: 600px) {
  :root { --sidebar-w: 240px; }
  #cast-status, #share-btn { display: none; }
}