:root {
  color-scheme: dark;
  --bg: #000;
  --panel: #141820;
  --panel-hover: #1f2633;
  --border: rgba(255, 255, 255, 0.12);
  --text: #f4f7fb;
  --muted: #9aa6bd;
  --accent: #e8b86d;
  --accent-soft: rgba(232, 184, 109, 0.2);
  --accent-rose: #e8a0a8;
  --accent-teal: #7ec8c8;
  --era-1990: #c4a882;
  --era-2000: #e8b86d;
  --era-2020: #8eb4e8;
  --overlay: linear-gradient(180deg, rgba(0, 0, 0, 0.72) 0%, transparent 28%, transparent 72%, rgba(0, 0, 0, 0.82) 100%);
  --touch-min: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: -apple-system, "SF Pro Text", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  user-select: none;
}

button {
  font: inherit;
  cursor: pointer;
  color: inherit;
}

.touch-target {
  min-width: var(--touch-min);
  min-height: var(--touch-min);
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  background: #000;
  overflow: hidden;
}

.player-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}

.vhs-effect {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.45) 2px,
    rgba(0, 0, 0, 0.45) 4px
  );
  mix-blend-mode: overlay;
}

.video-fade {
  transition: opacity 0.35s ease;
}

.video-fade.is-changing {
  opacity: 0.15;
}

.scene-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.badge {
  font-size: 0.68rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
}

.badge-era { background: rgba(232, 184, 109, 0.25); border-color: rgba(232, 184, 109, 0.45); }
.badge-person { background: rgba(232, 160, 168, 0.25); border-color: rgba(232, 160, 168, 0.45); }
.badge-place { background: rgba(126, 200, 200, 0.25); border-color: rgba(126, 200, 200, 0.45); }

.explore {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.explore-tile {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  border: 1px solid rgba(232, 184, 109, 0.35);
  background: rgba(232, 184, 109, 0.12);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.65rem;
  font-weight: 600;
}

.explore-tile-icon {
  font-size: 1.2rem;
}

.explore-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  font-size: 0.78rem;
  min-height: 2rem;
}

.chip.active {
  background: var(--accent-soft);
  border-color: rgba(232, 184, 109, 0.5);
  color: #fff;
}

.chip-person { border-color: rgba(232, 160, 168, 0.35); }
.chip-place { border-color: rgba(126, 200, 200, 0.35); }
.chip-era { border-color: rgba(232, 184, 109, 0.35); }
.chip-event { border-color: rgba(180, 160, 220, 0.35); }

.playlist-group {
  margin-bottom: 0.5rem;
}

.playlist-group-title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 0.45rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.playlist-group-title.era-1990 { color: var(--era-1990); }
.playlist-group-title.era-2000 { color: var(--era-2000); }
.playlist-group-title.era-2020 { color: var(--era-2020); }

.browse-intro {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.browse-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

.browse-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  min-height: 5.5rem;
  background: rgba(255, 255, 255, 0.04);
}

.browse-card strong {
  font-size: 0.95rem;
}

.browse-card span {
  font-size: 0.78rem;
  color: var(--muted);
}

.browse-card-wedding { background: rgba(232, 160, 168, 0.12); border-color: rgba(232, 160, 168, 0.3); }
.browse-card-place { background: rgba(126, 200, 200, 0.12); border-color: rgba(126, 200, 200, 0.3); }
.browse-card-person { background: rgba(232, 184, 109, 0.12); border-color: rgba(232, 184, 109, 0.3); }
.browse-card-random { background: rgba(180, 160, 220, 0.15); border-color: rgba(180, 160, 220, 0.35); grid-column: 1 / -1; }

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.stage:fullscreen,
.stage:-webkit-full-screen {
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--overlay);
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.overlay > * {
  pointer-events: auto;
}

.overlay.hidden {
  opacity: 0;
}

.overlay.hidden .top-bar,
.overlay.hidden .bottom-bar,
.overlay.hidden .tap-zones {
  pointer-events: none;
}

.top-bar,
.bottom-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding:
    calc(0.65rem + var(--safe-top))
    calc(0.85rem + var(--safe-right))
    0.65rem
    calc(0.85rem + var(--safe-left));
}

.bottom-bar {
  justify-content: center;
  gap: 1.25rem;
  padding:
    0.65rem
    calc(1rem + var(--safe-right))
    calc(0.85rem + var(--safe-bottom))
    calc(1rem + var(--safe-left));
}

.top-meta {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.top-meta strong,
.top-meta span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-meta strong {
  font-size: 0.95rem;
}

.top-meta span {
  font-size: 0.8rem;
}

.top-actions {
  display: flex;
  gap: 0.35rem;
}

.muted {
  color: var(--muted);
}

.icon-button {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.scene-btn {
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
  border-radius: 50%;
  width: 3.4rem;
  height: 3.4rem;
  font-size: 1.35rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.scene-btn-play {
  width: 4rem;
  height: 4rem;
  font-size: 1.5rem;
}

.tap-zones {
  position: absolute;
  inset: 4.5rem 0 5.5rem;
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  pointer-events: none;
}

.tap-zone {
  border: none;
  background: transparent;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(360px, 88vw);
  z-index: 30;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transform: translateX(-105%);
  transition: transform 0.28s ease;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
}

.sidebar-header {
  position: relative;
  flex-shrink: 0;
  padding: 1rem 3rem 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.05rem;
}

.sidebar-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

.playlist-group .playlist {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.5rem 0.5rem;
}

#playlist {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.playlist li {
  margin-bottom: 0.35rem;
}

.playlist button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 0.9rem 0.95rem;
  min-height: var(--touch-min);
}

.playlist button.active {
  background: var(--accent-soft);
  border-color: rgba(232, 184, 109, 0.45);
}

.playlist .scene-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.playlist .scene-sub {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.text-button {
  border: none;
  background: none;
  color: var(--accent);
  padding: 0;
  margin-top: 0.35rem;
}

.text-button.hidden {
  display: none;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  width: min(520px, calc(100vw - 2rem - var(--safe-left) - var(--safe-right)));
  max-height: calc(100dvh - 2rem - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
  margin: auto;
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

dialog form {
  padding: 1.1rem 1.15rem calc(1.15rem + var(--safe-bottom));
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.info-fields {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 0.65rem 1rem;
  margin: 0 0 1.25rem;
}

.info-fields dt {
  color: var(--muted);
}

.info-fields dd {
  margin: 0;
}

.filter-actions h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.filter-buttons button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  min-height: var(--touch-min);
}

/* Desktop / mouse — secondary layout with persistent sidebar */
@media (min-width: 1100px) and (hover: hover) and (pointer: fine) {
  .app {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    position: relative;
    transform: none;
    width: auto;
    height: 100%;
    max-height: 100dvh;
    z-index: 1;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar-close,
  .sidebar-backdrop,
  #playlist-btn {
    display: none;
  }

  .player-pane {
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  .stage {
    border-radius: 0;
    height: 100%;
  }

  .tap-zones {
    display: none;
  }

  .overlay {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, transparent 22%, transparent 78%, rgba(0, 0, 0, 0.65) 100%);
  }
}

/* Compact phones — secondary */
@media (max-width: 480px) {
  .top-meta strong {
    font-size: 0.85rem;
  }

  .scene-btn {
    width: 3rem;
    height: 3rem;
  }

  .scene-btn-play {
    width: 3.5rem;
    height: 3.5rem;
  }
}
