:root {
  color-scheme: dark;
  --bg: #070B14;
  --bg-elevated: #0D1526;
  --bg-hover: #131E33;
  --border: #1E2D4A;
  --border-focus: #3E8EF7;
  --accent: #3E8EF7;
  --accent-hover: #63A4FF;
  --accent-2: #22D3EE;
  --accent-glow: rgba(62, 142, 247, .35);
  --text: #E6EDF7;
  --text-muted: #8B9BB4;
  --text-faint: #5A6A85;
  --success: #2DD4A7;
  --warning: #F5B84D;
  --danger: #F0526A;
  --gradient-hero: linear-gradient(135deg, #0D1526 0%, #0A1A38 60%, #10264F 100%);
  --radius: 12px;
  --radius-lg: 16px;
  --transition: 180ms ease;
  --transition-slow: 400ms cubic-bezier(.2, .8, .2, 1);
  /* UX FIX: 'Sora'/'Inter'/'JetBrains Mono' were declared here but never
     actually loaded anywhere (no @font-face, no <link>, and the CSP's
     font-src 'self' would block a Google Fonts CDN anyway) — every page has
     silently been rendering in the browser's default font this whole time.
     Rather than add an external font dependency, these are now real,
     carefully-ordered *system* font stacks: zero network cost, crisp
     native rendering on every OS, and no CSP change needed. */
  --font-display: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win. Several elements we toggle with
   [hidden] (the header logout button in particular) also carry a class like
   .btn that sets `display`, which ties [hidden]'s specificity in the
   browser's UA stylesheet — and author CSS beats UA CSS on a tie, so the
   element stayed visible. This makes [hidden] non-negotiable. */
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-display: swap;
  font-size: 15px;
  line-height: 1.55;
}

/* Sticky footer: everything header.php/footer.php emit is a direct flex
   child of body, so the page's own <main> grows to fill leftover space and
   the footer always sits at the bottom of the viewport on short pages
   instead of floating mid-screen — without resorting to position:fixed,
   which would overlap content on long pages. */
body > main { flex: 1 0 auto; width: 100%; }
body { padding-bottom: 64px; }

img, video { max-width: 100%; height: auto; }

a { color: inherit; text-decoration: none; }

h1, h2, h3 { font-family: var(--font-display); font-display: swap; line-height: 1.25; font-weight: 700; }
h1 { font-size: clamp(22px, 4vw, 30px); margin: 0 0 4px; }
h2 { font-size: clamp(18px, 3vw, 22px); margin: 0 0 16px; }
p { margin: 0 0 12px; color: var(--text-muted); }

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Every <form> gets sane vertical rhythm by default — this is the fix for
   pages like /upload where individual form controls (label, input, select,
   button) have no wrapper element and no gap between them, so they render
   crammed together using each control's own inline/inline-block default
   display instead of stacking with breathing room. */
form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

form label input, form label select, form label textarea { width: 100%; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
}

fieldset legend {
  padding: 0 6px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
}

.form-hint { font-size: 13px; color: var(--text-faint); margin: -6px 0 0; }
.form-error { color: var(--danger); background: rgba(240,82,106,.1); border: 1px solid rgba(240,82,106,.3); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 0; }
.form-success { color: var(--success); background: rgba(45,212,167,.1); border: 1px solid rgba(45,212,167,.3); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 0; }

/* Checkboxes/inputs keep native appearance intentionally — global
   appearance:none has broken admin checkboxes before. Style per-component. */
input, select, textarea, button {
  font-family: inherit;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.admin-checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; }
.admin-checkbox input { width: auto; }

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
}

.btn:hover { background: var(--bg-hover); transform: translateY(-1px); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #04070D;
  font-weight: 600;
}

.btn-accent:hover { background: var(--accent-hover); box-shadow: 0 0 24px var(--accent-glow); }

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(7, 11, 20, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  flex-shrink: 0;
}

.search-form { flex: 1; display: none; margin: 0; }
.search-form input { width: 100%; }

/* Language toggle lives here (not the footer) so it's reachable from every
   viewport size without hunting to the bottom of the page. */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.lang-select {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  width: auto;
}

.nav-links { display: none; align-items: center; gap: 4px; }
.nav-links a:not(.btn) {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
}
.nav-links a:not(.btn):hover { color: var(--text); background: var(--bg-hover); }
.nav-links a[aria-current="page"] { color: var(--text); background: var(--bg-hover); }
.nav-links .btn { margin-left: 8px; }

/* Bottom nav for mobile */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 6px 4px env(safe-area-inset-bottom);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  font-size: 11px;
  color: var(--text-muted);
  border-radius: 10px;
  transition: color var(--transition), background var(--transition), transform var(--transition);
}

.bottom-nav-icon { font-size: 18px; line-height: 1; }

.bottom-nav a:hover, .bottom-nav a:active { color: var(--text); background: var(--bg-hover); }
/* Active tab: accent color + a subtle lift, so the current section is
   unmistakable at a glance while scrolling one-handed. */
.bottom-nav a[aria-current="page"] { color: var(--accent); transform: translateY(-2px); }
.bottom-nav-accent { color: var(--accent) !important; font-weight: 700; }

/* Media grid & cards */
.media-section { margin: 40px 0; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-icon { font-size: 1.1em; line-height: 1; filter: saturate(1.3); }

.media-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

/* Trending rail: swipeable on mobile (scroll-snap, no JS), a normal wrapping
   grid from the md breakpoint up — see the media queries below. This is
   what makes the homepage's top section read as a "for you" feed instead of
   just another static tile wall, which is the single highest-impact change
   for making the mobile homepage feel alive. */
.media-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 62%;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 4px;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
  scrollbar-width: none;
}
.media-rail::-webkit-scrollbar { display: none; }
.media-rail .media-card { scroll-snap-align: start; }

.media-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  display: block;
}

/* Card itself lifts + gets an accent-tinted glow (not flat black shadow —
   ties into the "sensual premium" palette); the thumbnail image zooms
   independently inside its own overflow:hidden box, which reads as a much
   smoother, more deliberate motion than scaling the whole tile. */
.media-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 12px 32px rgba(0,0,0,.45), 0 0 0 1px var(--accent-glow);
}
.media-card:hover .media-card-thumb img { transform: scale(1.08); }
.media-card:hover .media-card-play { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.media-card-thumb {
  position: relative;
  aspect-ratio: 16/9;
  background: var(--bg-hover);
  overflow: hidden;
}

.media-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-slow);
}

/* Gradient scrim anchored to the bottom of every thumbnail so badges (and,
   on album covers, nothing else needed) stay legible over busy images
   without needing a solid-color bar. */
.media-card-scrim {
  position: absolute;
  inset: auto 0 0 0;
  height: 55%;
  background: linear-gradient(to top, rgba(4,6,12,.85), transparent);
  pointer-events: none;
}

.media-card-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.8);
  opacity: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7,11,20,.6);
  color: var(--text);
  backdrop-filter: blur(4px);
  transition: opacity var(--transition), transform var(--transition);
  pointer-events: none;
}
.media-card-play svg { margin-left: 2px; } /* optically center the triangle */

.badge {
  position: absolute;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(7,11,20,.75);
  color: var(--text);
  z-index: 1;
}

.badge-duration { bottom: 8px; right: 8px; }
.badge-trending { top: 8px; left: 8px; background: rgba(240,82,106,.85); }
.badge-album { bottom: 8px; left: 8px; background: rgba(62,142,247,.85); }

.media-card-body { padding: 12px 14px; }

.media-card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color var(--transition);
}

.media-card-meta { font-size: 12px; color: var(--text-muted); margin: 0; }

.empty-state {
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}

/* Skeleton loaders */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.4s ease infinite;
  border-radius: var(--radius);
}

@keyframes skeleton-shine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Watch page */
.watch-player { border-radius: var(--radius); overflow: hidden; background: #000; margin: 16px 0; }
.watch-title { margin: 0 0 8px; }
.watch-meta { color: var(--text-muted); font-size: 14px; }
.watch-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.share-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.share-buttons button { min-height: 44px; }

.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.tag-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--accent-2);
}

.category-chip {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.comments-section { margin: 32px 0; }
.comments-section form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.comments-section textarea { min-height: 80px; resize: vertical; }
.comment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }

/* Album viewer */
.album-viewer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  scroll-snap-type: x mandatory;
}

.album-item {
  position: relative;
  margin: 0;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow: hidden;
  scroll-snap-align: start;
  touch-action: pan-y;
}

.album-item img, .album-item video { width: 100%; display: block; }
.album-item figcaption { padding: 8px 12px; font-size: 13px; color: var(--text-muted); }

.drag-handle {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 44px;
  min-width: 44px;
  cursor: grab;
}

.reorder-hint { color: var(--text-muted); font-size: 13px; }
.album-item.dragging { opacity: .5; }

.upload-page, .auth-page { max-width: 520px; }
.auth-switch { text-align: center; font-size: 13px; }
.auth-switch a { color: var(--accent-2); }
.auth-switch a:hover { text-decoration: underline; }

.dropzone {
  display: flex !important;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 120px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.dropzone:hover { border-color: var(--accent); color: var(--text); background: var(--bg-hover); }

.upload-progress-list { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.upload-row-ok { color: var(--success); }
.upload-row-error { color: var(--danger); }

.new-album-section { margin: 16px 0; }

.manage-delete-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* Forms */
.browse-filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.browse-filters input { flex: 1; min-width: 160px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 24px 0 48px;
  color: var(--text-muted);
}

.pagination a { min-height: 44px; min-width: 44px; display: flex; align-items: center; justify-content: center; }

/* Footer: slim, single-purpose (legal links + copyright) — the language
   toggle now lives in the header, not here, so this never needs to grow. */
.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 16px 0;
  background: var(--bg-elevated);
}
.footer-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  font-size: 12px;
}
.footer-copy { color: var(--text-faint); }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; color: var(--text-muted); }
.footer-links a:hover { color: var(--text); }

/* Age gate: blocks the entire page until dismissed. Rendered first inside
   <body> (see head.php) specifically so it paints before header/content do
   — avoids a flash of the real page behind it while JS checks localStorage. */
.age-gate {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 6, 12, .96);
  backdrop-filter: blur(6px);
}

.age-gate-box {
  max-width: 440px;
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

.age-gate-box h1 { font-size: 22px; margin: 0 0 12px; }
.age-gate-box p { margin: 0 0 24px; }
.age-gate-actions { display: flex; flex-direction: column; gap: 10px; }
.age-gate-actions .btn { width: 100%; }

/* Admin */
.admin-panel { font-family: var(--font-mono); }
.admin-form { max-width: 640px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; }

@media (min-width: 640px) {
  .media-grid { grid-template-columns: repeat(3, 1fr); }
  .album-viewer { grid-template-columns: repeat(2, 1fr); }
  .media-rail { grid-auto-columns: 38%; }
}

@media (min-width: 900px) {
  .search-form { display: block; }
  .nav-links { display: flex; }
  .bottom-nav { display: none; }
  body { padding-bottom: 0; }
  .media-grid { grid-template-columns: repeat(4, 1fr); }
  .album-viewer { grid-template-columns: repeat(3, 1fr); }
  .footer-row { flex-direction: row; justify-content: space-between; text-align: left; }
  .media-card:hover .media-card-title { color: var(--accent-2); }
  /* Enough room to just show the whole Trending row as a grid like every
     other section — the swipeable rail is a mobile-specific affordance. */
  .media-rail {
    display: grid;
    grid-auto-flow: row;
    grid-template-columns: repeat(4, 1fr);
    overflow-x: visible;
    margin: 0;
    padding: 0;
  }
}

@media (min-width: 1200px) {
  .media-grid { grid-template-columns: repeat(6, 1fr); }
  .media-rail { grid-template-columns: repeat(6, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
