:root {
  color-scheme: dark;
  --bg: #111827;
  --panel-border: #2f3a4f;
  --text: #f9fafb;
  --muted: #94a3b8;
  --accent: #22c55e;
  --app-height: 100dvh;
  --top-bar-height: 68px;
  --main-top-gap: 80px;
  --main-bottom-gap: calc(max(12px, env(safe-area-inset-bottom)) + 16px);
}

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

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

[hidden] {
  display: none !important;
}

html {
  background-color: var(--bg);
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  min-height: var(--app-height);
  display: flex;
  flex-direction: column;
  align-items: center;
}

main {
  width: 100%;
  max-width: 680px;
  padding: 80px 24px calc(40px + env(safe-area-inset-bottom));
  box-sizing: border-box;
  flex: 1;
}

h1,
h2,
p {
  margin-top: 0;
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: max(12px, env(safe-area-inset-top)) 0 12px;
  background: linear-gradient(to top, rgba(17, 24, 39, 0) 0%, rgba(17, 24, 39, 0.55) 60%, rgba(17, 24, 39, 0.7) 100%);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  z-index: 10;
  pointer-events: none;
}

.top-bar>* {
  pointer-events: auto;
}

.top-bar-scroll {
  display: flex;
  justify-content: center;
  gap: 28px;
  align-items: center;
  pointer-events: auto;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 24px;
  box-sizing: border-box;
}

.top-bar .tiny-link {
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.top-bar .tiny-link:hover {
  opacity: 1;
}

.top-bar .tiny-link:focus-visible {
  opacity: 1;
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.top-bar .active-nav {
  opacity: 1;
  text-decoration: none;
  position: relative;
}

.top-bar .active-nav::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: -6px;
  width: 60%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.6;
}

.menu {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(12px, calc((100vw - 680px) / 2 + 24px));
  z-index: 11;
}

body:has(.menu[open]) main {
  pointer-events: none;
}

.menu summary {
  list-style: none;
  cursor: pointer;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  user-select: none;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu summary:hover {
  color: var(--text);
}

.menu>div {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 10px 0;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.menu [role="menuitem"] {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: unset;
  padding: 10px 22px;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: normal;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu [role="menuitem"]:hover {
  background: rgba(255, 255, 255, 0.08);
}

.menu [role="menuitem"][hidden] {
  display: none;
}

.menu p {
  margin: 0 0 8px;
  padding: 0 22px 10px;
  border-bottom: 1px solid #374151;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: left;
}

.menu p a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.35);
}

.menu p a:hover {
  text-decoration-color: currentColor;
}

label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #4b5563;
  background: #0f172a;
  color: var(--text);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #052e16;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

button.secondary {
  background: #374151;
  color: var(--text);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tiny-link {
  display: inline;
  min-height: unset;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

.toast {
  position: fixed;
  top: auto;
  bottom: 24px;
  left: 16px;
  right: 16px;
  width: auto;
  height: auto;
  max-width: 480px;
  margin: 0 auto;
  background: #1e2d3d;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.875rem;
  color: var(--text);
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.toast:not(:popover-open) { display: none; }

.range-tabs {
  display: flex;
  gap: 4px;
}

.range-tab {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  border-radius: 6px;
  min-height: unset;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.range-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 600;
}

@media (pointer: coarse) and (orientation: landscape) {
  .view-hint {
    display: none;
  }

  .top-bar {
    position: absolute;
  }

  html {
    scroll-snap-type: y mandatory;
  }

  .media-section {
    scroll-snap-align: start;
    scroll-snap-stop: always;
    min-height: calc(100dvh - var(--main-top-gap, 80px));
  }
}

@media (max-width: 680px) {
  :root {
    --main-top-gap: max(var(--top-bar-height), calc(52px + env(safe-area-inset-top)));
  }

  .top-bar {
    padding:
      max(10px, env(safe-area-inset-top)) 0 10px;
    background: linear-gradient(to bottom, rgba(17, 24, 39, 0.96), rgba(17, 24, 39, 0.72) 72%, transparent);
  }

  .top-bar-scroll {
    width: 100%;
    gap: 20px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    touch-action: pan-x;
  }

  .top-bar.logged-out .top-bar-scroll {
    justify-content: center;
  }

  .top-bar-scroll::-webkit-scrollbar {
    display: none;
  }

  .top-bar .tiny-link {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: rgba(148, 163, 184, 0.35);
    text-underline-offset: 0.16em;
    justify-content: center;
    transition: color 0.15s, text-decoration-color 0.15s, opacity 0.15s;
  }

  .top-bar .active-nav {
    color: var(--text);
    text-decoration-color: rgba(249, 250, 251, 0.7);
  }

  body {
    height: var(--app-height);
    min-height: 0;
    overflow: hidden;
  }

  main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-top: var(--main-top-gap);
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  main>[role="region"] {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.logged-in #nextContent,
  body.logged-in #trendingContent,
  body.logged-in #similarContent,
  body.logged-in #aiContent {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .view-teaser {
    flex: 1;
    min-height: 0;
  }

}

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

@media (max-width: 768px) {
  main {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: var(--main-top-gap) 12px calc(8px + env(safe-area-inset-bottom));
  }

  .top-bar-scroll {
    padding: 0 12px;
  }

  .poster-title {
    font-size: 1.08rem;
  }
}

body.logged-in .view-teaser {
  display: none;
}

body:not(.logged-in) .view-content {
  display: none;
}

.view-teaser {
  position: relative;
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

.view-teaser>*:not(.teaser-bg) {
  position: relative;
  z-index: 1;
}

.teaser-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.32;
  filter: blur(2px);
  mask-image: radial-gradient(circle at center, black 45%, transparent 95%);
  -webkit-mask-image: radial-gradient(circle at center, black 45%, transparent 95%);
  pointer-events: none;
  z-index: 0;
}

.view-teaser-cta {
  position: relative;
}

.view-teaser-cta::before {
  content: "";
  position: absolute;
  inset: -24px -40px;
  background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.55) 0%, rgba(15, 23, 42, 0.25) 55%, transparent 85%);
  z-index: -1;
  pointer-events: none;
}

.view-teaser {
  flex-direction: column;
  gap: 32px;
}

.teaser-eyebrow {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  opacity: 0.85;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.teaser-eyebrow:hover {
  color: var(--text);
  opacity: 1;
}

.view-teaser-cta {
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
}

.view-teaser-cta p {
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.4;
  margin: 0 0 24px;
  opacity: 0.85;
}

@media (max-width: 600px) {
  .view-teaser-cta p {
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
  }
}

.view-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 24px;
  padding: 0 8px 0 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.9rem;
  color: var(--muted);
  opacity: 0.85;
}

.view-hint-dismiss {
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 1.1em;
  line-height: 1;
  margin-left: 6px;
  padding: 0 4px;
  opacity: 0.6;
}

.view-hint-dismiss:hover {
  opacity: 1;
}
