/* Mobile first: phones are the primary target, desktop is the enhancement. */

:root {
  --bg: #0d1117;
  --bg-raised: #151b24;
  --bg-inset: #1c242f;
  --line: #263141;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --accent: #4dd4c0;
  --accent-dim: #2b8177;
  --danger: #ff7b72;
  --radius: 10px;
  --header-h: 52px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

.spacer { flex: 1; }

/* ------------------------------------------------------------- top bar -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--header-h);
  padding: 0 10px;
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), var(--accent-dim));
  color: #06231f;
  font-size: 12px;
}

.brand-text { white-space: nowrap; }

.ghost {
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-inset);
  cursor: pointer;
  white-space: nowrap;
}

.ghost:active { background: #253040; }

.folder-form {
  order: 10;
  flex: 1 0 100%;
  display: flex;
  gap: 8px;
  padding: 0 0 10px;
}

.folder-form[hidden] { display: none; }

.folder-form input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  font-size: 16px; /* iOS zooms in on anything smaller */
}

.folder-form input:focus { border-color: var(--accent-dim); }

.folder-form button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #06231f;
  font-weight: 600;
  cursor: pointer;
}

/* -------------------------------------------------------------- layout -- */

.layout { display: block; }

.stage {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  background: var(--bg);
  padding-bottom: 8px;
}

.player {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.player video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

/* An author-level `display` beats the browser's [hidden] rule, so every layer
   that sets one must opt back out explicitly. */
.placeholder[hidden], .spinner[hidden] { display: none; }

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 16px;
}

.placeholder-title { margin: 0; font-size: 16px; }
.placeholder-sub { margin: 0; color: var(--text-dim); font-size: 13px; }

.placeholder code {
  background: var(--bg-inset);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12.5px;
}

.spinner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.spinner span {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, .18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Shown when the browser refuses to autoplay — every phone, first tap. */
.tap-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(13, 17, 23, .72);
  color: var(--text);
  font-size: 26px;
  padding-left: 5px;
  cursor: pointer;
  backdrop-filter: blur(3px);
}

.tap-play[hidden] { display: none; }

.notice {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 12px 14px;
  background: rgba(16, 22, 30, .96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.notice p { margin: 0 0 8px; font-size: 13.5px; }
.notice p:only-child { margin: 0; }

.notice-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.notice-actions:empty { display: none; }

.notice-actions button, .notice-actions a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
}

/* ------------------------------------------------------------ controls -- */

.controls {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  padding: 4px 8px 6px;
}

.scrub {
  position: relative;
  height: 30px;
  display: flex;
  align-items: center;
}

.scrub-track {
  position: absolute;
  left: 6px;
  right: 6px;
  height: 4px;
  border-radius: 3px;
  background: var(--bg-inset);
  overflow: hidden;
}

.scrub-buffer, .scrub-played {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 3px;
}

.scrub-buffer { background: #33455a; }
.scrub-played { background: var(--accent); }

.scrub input[type=range] {
  position: relative;
  width: 100%;
  height: 30px;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.scrub input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
  box-shadow: 0 0 0 4px rgba(77, 212, 192, .18);
}

.scrub input[type=range]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.scrub input[type=range]:disabled { opacity: .45; cursor: default; }

.controls-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon {
  min-width: 44px;
  min-height: 44px;
  padding: 0 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  font-size: 14px;
}

.icon:active { background: var(--bg-inset); }
.icon.primary { font-size: 17px; }

.time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text-dim);
  padding: 0 4px;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text-dim);
  white-space: nowrap;
}

.volume { display: flex; align-items: center; gap: 2px; }

.volume input[type=range] {
  width: 80px;
  accent-color: var(--accent);
  cursor: pointer;
}

#rate {
  min-height: 40px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 4px;
  cursor: pointer;
  outline: none;
  font-size: 13px;
}

.now-playing { padding: 8px 12px 0; }

.now-playing h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.now-playing p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }

/* ------------------------------------------------------------- sidebar -- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.crumbs button {
  background: none;
  border: 0;
  padding: 6px 6px;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumbs button:last-child { color: var(--text); font-weight: 600; }
.crumbs .sep { opacity: .45; }

.filter-row { padding: 2px 10px 10px; }

.filter-row input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  font-size: 16px; /* keeps iOS from zooming the page on focus */
}

.filter-row input:focus { border-color: var(--accent-dim); }

.tree {
  margin: 0;
  padding: 0 8px 12px;
  list-style: none;
}

.tree li { margin-bottom: 2px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.row:active { background: var(--bg-inset); }
.row.active { background: #1d3b39; box-shadow: inset 3px 0 0 var(--accent); }
.row.active .row-name { color: var(--accent); }

.row-icon { flex: none; width: 20px; text-align: center; font-size: 15px; }
.row-body { min-width: 0; flex: 1; }

.row-name {
  display: block;
  font-size: 14.5px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.row-sub {
  display: block;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.row-progress {
  height: 3px;
  margin-top: 6px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.row-progress span { display: block; height: 100%; background: var(--accent-dim); }

.sidebar-note {
  margin: 0;
  padding: 8px 14px 16px;
  font-size: 12px;
  color: var(--text-dim);
}

.error-text { color: var(--danger); }

/* --------------------------------------------------------------- toast -- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 18px;
  background: #1f2836;
  border: 1px solid var(--line);
  border-radius: 22px;
  font-size: 13.5px;
  text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  z-index: 30;
}

/* ---------------------------------------------------------- fullscreen -- */

.stage:fullscreen { padding: 0; background: #000; }
.stage:fullscreen .player { height: 100dvh; aspect-ratio: auto; }
.stage:fullscreen .controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 17, 23, .92);
  border: 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.stage:fullscreen .now-playing { display: none; }

/* ---------------------------------------------------------- pointer/hi -- */

@media (pointer: coarse) {
  /* Phones have hardware volume keys; the slider only eats space. */
  .volume input[type=range] { display: none; }
}

@media (hover: hover) {
  .ghost:hover { border-color: var(--accent-dim); }
  .row:hover { background: var(--bg-inset); }
  .icon:hover { background: var(--bg-inset); border-color: var(--line); }
  .crumbs button:hover { color: var(--text); background: var(--bg-inset); }
  .notice-actions button:hover, .notice-actions a:hover { border-color: var(--accent-dim); }
}

/* Landscape phone: give the video as much height as we can spare. */
@media (orientation: landscape) and (max-height: 560px) {
  .player { aspect-ratio: auto; height: calc(100dvh - var(--header-h) - 100px); }
  .brand-text { display: none; }
}

/* ------------------------------------------------------------- desktop -- */

@media (min-width: 960px) {
  body { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }

  .topbar { flex-wrap: nowrap; padding: 0 16px; }
  .brand { margin-right: 8px; }

  .folder-form {
    order: 0;
    flex: 1;
    max-width: 620px;
    padding: 0;
  }

  .folder-form[hidden] { display: flex; } /* always visible where there is room */
  #folder-toggle { display: none; }

  .layout {
    flex: 1;
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    min-height: 0;
  }

  .sidebar {
    order: -1;
    border-top: 0;
    border-right: 1px solid var(--line);
    background: var(--bg-raised);
    min-height: 0;
    overflow: hidden;
  }

  .crumbs { border-bottom: 1px solid var(--line); min-height: 42px; }
  .crumbs button { max-width: 190px; }
  .tree { flex: 1; overflow-y: auto; }

  .stage {
    position: static;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px;
    gap: 12px;
  }

  .player {
    flex: 1;
    aspect-ratio: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    min-height: 0;
  }

  .controls {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px 14px 8px;
  }

  .icon { min-width: 36px; min-height: 36px; }
  .row { min-height: 0; padding: 8px 10px; }
  .now-playing { padding: 0; }
}
