
@font-face {
  font-family: 'JetBrains Mono';
  src: url(JetBrainsMono-VariableFont_wght.ttf);
}

:root {
  --bg:       #0e0f12;
  --bg-2:     #15171c;
  --bg-3:     #1c1f26;
  --line:     #262a33;
  --line-2:   #323642;
  --ink:      #eceef3;
  --ink-2:    #a8acb8;
  --ink-3:    #6b7080;
  --accent:   #2372D4;
  --danger:   #e06464;
  --ok:       #7cc48b;

  --band-green:  #3b8d5b;
  --band-yellow: #c9a227;
  --band-blue:   #3a6ea5;
  --band-red:    #c04848;
  --band-gray:   #2c303a;

  --radius: 4px;
  --radius-lg: 8px;

  --f-display: 'JetBrains Mono', Georgia, serif;
  --f-body:    'JetBrains Mono','IBM Plex Sans', system-ui, sans-serif;
  --f-mono:    'JetBrains Mono','IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Kill the iOS gray tap flash; we render our own :active styles. */
  -webkit-tap-highlight-color: transparent;
  /* Block iOS double-tap-to-zoom on UI; keep native zoom on actual content
     (the .video-frame has its own touch-action exception). */
  touch-action: manipulation;
  /* Prevent over-scroll bounce on iOS that exposes the viewport behind the app. */
  overscroll-behavior: none;
}
/* iOS Safari zooms when an input has font-size <16px. Force at least 16px
   for inputs/textarea so this doesn't happen. */
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; }
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #fff; }

/* --------- buttons --------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font: inherit; font-weight: 500;
  color: var(--ink);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); background: var(--bg-2); }
.btn-danger { background: #2a1a1d; border-color: #5b2a2e; color: #f3bcbc; }
.btn-danger:hover { background: #351d21; border-color: var(--danger); }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 7px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 64px; }

/* --------- top bar (home + admin) --------- */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  position: sticky; top: 0; z-index: 10;
}
.brand {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.me {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink-3);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.search { min-width: 220px; }
.sort   { min-width: 160px; }

/* --------- flashes --------- */
.flash {
  padding: 10px 14px; margin: 12px 22px;
  background: #1a1d22; border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-size: 13px;
}
.flash-err { border-left-color: var(--danger); color: #f3bcbc; }

/* =================== AUTH PAGE =================== */
.page-auth {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(232,217,168,0.05), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(58,110,165,0.07), transparent 50%),
    var(--bg);
}
.auth-card {
  width: min(420px, 92vw);
  padding: 36px 32px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
}
.auth-title {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 32px;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}
.auth-sub { margin: 0 0 22px; color: var(--ink-3); }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.auth-form button { width: 100%; padding: 11px; background: var(--accent); color: #1a1a1a; border: none; font-weight: 600; }
.auth-form button:hover { background: #fff; }

/* =================== HOME =================== */
.page-home { min-height: 100vh; }
.grid-wrap { padding: 24px 22px 60px; }
.empty {
  margin: 60px auto; text-align: center; color: var(--ink-3);
  font-family: var(--f-display); font-size: 18px;
}
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.tile-link { display: block; color: inherit; }
.tile-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.tile-link:hover .tile-thumb { border-color: var(--accent); transform: translateY(-2px); }
.tile-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.tile-thumb-empty {
  width: 100%; height: 100%;
  background: repeating-linear-gradient(45deg, var(--bg-3) 0 10px, var(--bg-2) 10px 20px);
}
.tile-short {
  position: absolute; left: 8px; top: 8px;
  font-family: var(--f-mono);
  font-size: 11px;
  padding: 2px 8px;
  background: rgba(14,15,18,0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  backdrop-filter: blur(6px);
}
.tile-caption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* =================== ADMIN =================== */
.page-admin { min-height: 100vh; }
.admin-wrap { padding: 22px; display: grid; gap: 22px; max-width: 1200px; margin: 0 auto; }
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
}
.panel h2 {
  font-family: var(--f-display); font-weight: 600;
  margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em;
}
.muted { color: var(--ink-3); font-size: 12px; margin: 0 0 14px; }
.tiny { font-size: 11px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: middle;
}
.tbl th {
  font-weight: 500; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-3);
}
.tbl tbody tr:hover { background: var(--bg-3); }
.cell-visibility { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.chk-inline { font-size: 12px; color: var(--ink-2); display: inline-flex; gap: 4px; align-items: center; }
.cell-actions { white-space: nowrap; }
.cell-actions .btn { margin-right: 6px; }

.add-form summary { cursor: pointer; margin-top: 12px; color: var(--accent); font-size: 13px; }
.inline-form {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px;
}
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; color: var(--ink-2); }

/* --- "no password" pill (admin users table) --- */
.pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-family: var(--f-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* --- auth-page divider + guest button --- */
.auth-divider {
  display: flex; align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: var(--ink-3);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
}
.auth-divider::before,
.auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}
.auth-guest-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--line-2);
  color: var(--ink-2);
  padding: 10px;
}
.auth-guest-btn:hover { color: var(--ink); border-color: var(--accent); }

/* --- shared form helpers --- */
.field { display: grid; gap: 6px; }
.field-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-3);
}

/* --- preset waypoint editor (shown in the player's Waypoints tab) --- */
.preset-config {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.preset-config > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  list-style: none;
  display: flex; align-items: center; gap: 6px;
}
.preset-config > summary::before {
  content: '›';
  display: inline-block;
  transition: transform .15s;
  font-size: 16px;
  color: var(--ink-3);
}
.preset-config[open] > summary::before { transform: rotate(90deg); }
.preset-form { display: grid; gap: 10px; margin-top: 10px; }
.preset-rows { display: grid; gap: 6px; }
.preset-row {
  display: grid;
  grid-template-columns: 24px 40px 86px 1fr;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.preset-num {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-3);
}
.preset-offset {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-2);
}
.preset-ts {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--accent);
  padding: 2px 4px;
  background: rgba(232,217,168,0.07);
  border: 1px solid rgba(232,217,168,0.2);
  border-radius: 4px;
  text-align: center;
}
.preset-row input[type="text"] {
  padding: 4px 8px;
  font-size: 12px;
  min-width: 0;   /* lets grid track shrink */
}
.preset-actions { display: flex; justify-content: flex-end; }

/* mobile tweaks */
@media (max-width: 640px) {
  .top-bar { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .top-actions { gap: 6px; }
  .search { min-width: 0; flex: 1 1 140px; }
  .sort { flex: 1 1 120px; }
  .tbl { display: block; overflow-x: auto; }
  .preset-row {
    grid-template-columns: 22px 36px 76px 1fr;
    font-size: 12px;
  }
}

/* ============================================================
   Folder browsing & admin (home page)
   ============================================================ */
.section-title {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 24px 0 12px;
  padding-left: 2px;
}
.section-title:first-of-type { margin-top: 4px; }

.back-link {
  color: var(--ink-2);
  text-decoration: none;
  font-family: var(--f-body);
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0;
}
.back-link:hover { color: var(--ink); }
.brand-sep { color: var(--ink-3); margin: 0 4px; }

/* Folder tiles */
.tile-folder .tile-thumb-folder {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--bg-3), var(--bg-2));
  position: relative;
}
.tile-folder .tile-thumb-folder svg {
  width: 56px; height: 56px;
  color: var(--accent);
  opacity: 0.55;
}
.tile-folder .folder-icon {
  font-size: 56px;
  color: var(--accent);
  opacity: 0.55;
  line-height: 1;
}
.tile-folder .folder-count {
  position: absolute;
  right: 10px; bottom: 10px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-2);
  padding: 2px 8px;
  background: rgba(14,15,18,0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

/* =================== FOLDERS (home page) =================== */

.crumbs {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px;
  padding: 12px 22px 0;
  font-size: 13px;
  color: var(--ink-2);
}
.crumb {
  color: var(--ink-2);
  padding: 4px 8px;
  border-radius: 4px;
  transition: background .12s;
}
.crumb:hover { background: var(--bg-3); color: var(--ink); }
.crumb-sep { color: var(--ink-3); }
.crumb-spacer { flex: 1; }

.tile { position: relative; }   /* anchor for the folder delete X */
.tile-folder .tile-thumb {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1a1d24, #20242c);
  color: var(--accent);
}
.folder-thumb { gap: 8px; flex-direction: column; }
.folder-thumb svg { color: var(--accent); }
.folder-label {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(0,0,0,0.5);
  position: absolute;
  bottom: 8px; left: 8px; right: 8px;
  text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-action {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  background: rgba(14,15,18,0.78);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity .15s;
  z-index: 2;
}
.tile-folder:hover .tile-action,
.tile-folder:focus-within .tile-action { opacity: 1; }
.tile-action:hover { color: var(--danger); border-color: var(--danger); }

/* =================== MOBILE / TOUCH POLISH =================== */

/* Kill the gray flash on iOS taps. */
* { -webkit-tap-highlight-color: transparent; }

/* iOS Safari zooms the page when an input < 16px is focused. Bump
   inputs to 16px on small screens so this never happens. */
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; }
}

/* Disable text-selection on touch UI controls (pure UX preference). */
.btn, .icon-btn, .seg-btn, .tile, .crumb, .menu-tab, .ts-chip {
  -webkit-user-select: none; user-select: none;
}

/* Side menu shouldn't bounce-scroll the page on iOS. */
.menu, .list, .modal-body { overscroll-behavior: contain; }

/* Use dynamic viewport height where supported so the player fills
   the screen even when the iOS URL bar is showing. */
@supports (height: 100dvh) {
  .stage { height: 100dvh; }
  .menu  { height: 100dvh; }
}

/* Larger tap targets for delete buttons in lists on phones. */
@media (max-width: 640px) {
  .list-item .btn-sm { padding: 6px 12px; min-height: 32px; }
  .crumbs { padding: 10px 14px 0; }
}
