/* Reset some defaults for consistent layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Theme defaults */
:root {
  --theme-card: rgba(118, 170, 158, 0.75);
  --theme-card-hover: rgba(118, 170, 158, 0.9);
  --theme-card-active: rgba(132, 190, 176, 0.95);
  --theme-card-border: rgba(255, 255, 255, 0.12);
  --theme-button-bg: rgba(255, 255, 255, 0.08);
  --theme-button-border: rgba(255, 255, 255, 0.45);
  --bottom-nav-space: 80px;
  --bottom-nav-height: 72px;
  --bottom-nav-offset: 18px;
  --cta-nav-gap: 12px;
}

@supports (-webkit-touch-callout: none) {
  :root {
    --cta-nav-gap: -20px;
  }
}

/* Base body styles */
html,
body {
  height: 100%;
  background: #0f0f0f;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100lvh;
  color: #f5f2ee;
  font-family: "Georgia", "Times New Roman", serif;
  font-weight: 300;
}

/* Prevent background scroll when overlay is open */
body.no-scroll {
  overflow: hidden;
}

/* Blur the background when the overlay is open */
body.overlay-open .page {
  filter: blur(6px) saturate(0.9);
  transform: scale(1.01);
}

/* Full page wrapper */
.page {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100lvh;
  height: 100vh;
  height: 100svh;
  height: 100lvh;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  padding: calc(32px + env(safe-area-inset-top))
    calc(24px + env(safe-area-inset-right))
    calc(var(--bottom-nav-space) + env(safe-area-inset-bottom))
    calc(24px + env(safe-area-inset-left));
  overflow: hidden;
  transition: filter 0.25s ease, transform 0.25s ease;
}

/* Soft watercolor-style background */
.page::before {
  content: "";
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(80% 60% at 10% 90%, rgba(34, 105, 102, 0.65), transparent 60%),
    radial-gradient(60% 50% at 85% 85%, rgba(160, 132, 98, 0.55), transparent 65%),
    radial-gradient(70% 60% at 50% 30%, rgba(214, 205, 190, 0.7), transparent 60%),
    radial-gradient(50% 40% at 20% 20%, rgba(190, 170, 160, 0.45), transparent 55%),
    /* Paper-like grain using subtle repeating gradients */
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.03),
      rgba(255, 255, 255, 0.03) 1px,
      rgba(0, 0, 0, 0.02) 2px,
      rgba(0, 0, 0, 0.02) 3px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.02),
      rgba(255, 255, 255, 0.02) 1px,
      rgba(0, 0, 0, 0.015) 2px,
      rgba(0, 0, 0, 0.015) 3px
    ),
    linear-gradient(180deg, rgba(32, 32, 32, 0.75), rgba(32, 32, 32, 0.35) 35%, rgba(32, 32, 32, 0.2) 100%);
  filter: blur(0.5px);
  z-index: 0;
}

/* Photo background layer (updated by JS) */
.page.has-photo::before {
  background:
    /* Photo goes first so gradients can sit on top */
    var(--photo, none),
    radial-gradient(80% 60% at 10% 90%, rgba(34, 105, 102, 0.45), transparent 60%),
    radial-gradient(60% 50% at 85% 85%, rgba(160, 132, 98, 0.35), transparent 65%),
    radial-gradient(70% 60% at 50% 30%, rgba(214, 205, 190, 0.45), transparent 60%),
    radial-gradient(50% 40% at 20% 20%, rgba(190, 170, 160, 0.3), transparent 55%),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.03),
      rgba(255, 255, 255, 0.03) 1px,
      rgba(0, 0, 0, 0.02) 2px,
      rgba(0, 0, 0, 0.02) 3px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.02),
      rgba(255, 255, 255, 0.02) 1px,
      rgba(0, 0, 0, 0.015) 2px,
      rgba(0, 0, 0, 0.015) 3px
    ),
    linear-gradient(180deg, rgba(32, 32, 32, 0.7), rgba(32, 32, 32, 0.35) 35%, rgba(32, 32, 32, 0.2) 100%);
  background-size: cover;
  background-position: center;
  animation: breathe 18s ease-in-out infinite;
}

/* More vivid motion when using gradient-based background */
.page.has-photo.has-gradient::before {
  background-size:
    220% 220%,
    cover,
    cover,
    cover,
    cover,
    auto,
    auto,
    auto;
  background-position:
    0% 50%,
    center,
    center,
    center,
    center,
    center,
    center,
    center;
  animation: gradient-drift var(--grad-drift, 26s) ease-in-out infinite,
    gradient-hue var(--grad-hue, 36s) linear infinite;
}

/* Extra ripple/grain layer for vivid gradient motion */
.page.has-photo.has-gradient::after {
  content: "";
  position: absolute;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.34;
  filter: blur(6px);
  background-image:
    radial-gradient(
      circle at var(--grad-center-x, 35%) var(--grad-center-y, 25%),
      rgba(255, 255, 255, calc(var(--grad-ripple-alpha, 0.32) * 0.45)) 0%,
      rgba(255, 255, 255, 0.02) 28%,
      transparent 55%
    ),
    radial-gradient(
      circle at calc(100% - var(--grad-center-x, 35%)) calc(100% - var(--grad-center-y, 25%)),
      rgba(0, 0, 0, calc(var(--grad-ripple-alpha, 0.32) * 0.45)) 0%,
      rgba(0, 0, 0, 0.03) 30%,
      transparent 60%
    ),
    repeating-radial-gradient(
      circle at var(--grad-center-x, 50%) var(--grad-center-y, 50%),
      rgba(255, 255, 255, calc(var(--grad-ripple-alpha, 0.32) * 0.2)) 0px,
      rgba(255, 255, 255, calc(var(--grad-ripple-alpha, 0.32) * 0.2)) 1px,
      transparent 3px,
      transparent calc(var(--grad-grain, 22px) * 1.2)
    ),
    radial-gradient(
      circle at calc(var(--grad-center-x, 50%) + 12%) calc(var(--grad-center-y, 50%) - 8%),
      rgba(255, 255, 255, calc(var(--grad-ripple-alpha, 0.32) * 0.25)) 0%,
      transparent calc(var(--grad-particle, 18px) * 1.3)
    );
  mix-blend-mode: soft-light;
  animation: ripple-flow var(--grad-ripple, 22s) ease-in-out infinite alternate,
    ripple-orbit calc(var(--grad-ripple, 22s) * 1.4) ease-in-out infinite alternate;
}

/* Loading state: soften text until image is ready */
.page.is-loading .content,
.page.is-loading .top,
.page.is-loading .bottom-nav {
  opacity: 0.85;
}

/* Slow breathing scale for background */
@keyframes breathe {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes gradient-drift {
  0% {
    background-position:
      0% calc(50% - (var(--grad-shift, 40%) / 4)),
      center,
      center,
      center,
      center,
      center,
      center,
      center;
  }
  50% {
    background-position:
      100% calc(50% + (var(--grad-shift, 40%) / 4)),
      center,
      center,
      center,
      center,
      center,
      center,
      center;
  }
  100% {
    background-position:
      0% calc(50% - (var(--grad-shift, 40%) / 4)),
      center,
      center,
      center,
      center,
      center,
      center,
      center;
  }
}

@keyframes gradient-hue {
  0% {
    filter: hue-rotate(0deg) saturate(1);
  }
  50% {
    filter: hue-rotate(12deg) saturate(1.05);
  }
  100% {
    filter: hue-rotate(0deg) saturate(1);
  }
}

@keyframes ripple-flow {
  0% {
    transform: translate3d(
        calc(-2% * var(--grad-dir-x, 1)),
        calc(-1% * var(--grad-dir-y, 1)),
        0
      )
      scale(1);
  }
  45% {
    transform: translate3d(
        calc(2% * var(--grad-dir-x, 1)),
        calc(1% * var(--grad-dir-y, 1)),
        0
      )
      scale(1.03);
  }
  100% {
    transform: translate3d(
        calc(-2% * var(--grad-dir-x, 1)),
        calc(-1% * var(--grad-dir-y, 1)),
        0
      )
      scale(1);
  }
}

@keyframes ripple-orbit {
  0% {
    transform: translate3d(
        calc(-3% * var(--grad-dir-y, 1)),
        calc(2% * var(--grad-dir-x, 1)),
        0
      )
      scale(1.01);
  }
  100% {
    transform: translate3d(
        calc(3% * var(--grad-dir-y, 1)),
        calc(-2% * var(--grad-dir-x, 1)),
        0
      )
      scale(1.04);
  }
}

/* Slight vignette for depth */
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 35%, transparent 40%, rgba(0, 0, 0, 0.45) 85%);
  z-index: 1;
}

/* Keep content above background layers */
.page > * {
  position: relative;
  z-index: 2;
}

/* Top header area */
.top {
  display: flex;
  justify-content: center;
  min-height: 24px;
  padding-top: 20px;
  position: relative;
  z-index: 2;
  width: 100%;
}

.top::before {
  content: "";
  position: absolute;
  top: calc(-32px - env(safe-area-inset-top));
  left: 50%;
  width: 100vw;
  transform: translateX(-50%);
  height: calc(120px + env(safe-area-inset-top));
  background: linear-gradient(
    180deg,
    #0f0f0f,
    transparent
  );
  pointer-events: none;
  z-index: -1;
}

/* Logo text styling */
.logo {
  font-family: "Arial Black", "Arial", sans-serif;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 18px;
  opacity: 0.9;
  color: #f5f2ee;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* Main content area */
.content {
  text-align: center;
  padding: 40px 12px 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.quote-block {
  margin: auto 0;
  display: grid;
  gap: 6px;
}

/* Category label */
.label {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0.08em;
  opacity: 0.8;
  margin-bottom: 6px;
  font-weight: 300;
}

/* Quote text */
.quote {
  font-size: clamp(28px, 3.2vw, 44px);
  font-weight: 300;
  line-height: 1.25;
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* CTA block */
.cta {
  margin-top: auto;
  padding-bottom: calc(
    var(--bottom-nav-height) +
      var(--bottom-nav-offset) +
      var(--cta-nav-gap) +
      env(safe-area-inset-bottom)
  );
  display: grid;
  gap: 12px;
  justify-items: center;
}

/* People count text */
.count {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  opacity: 0.75;
  font-weight: 300;
}

.count.is-hidden {
  display: none;
}

.is-hidden {
  display: none;
}

/* Primary button */
.button {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: #f8f6f2;
  background: var(--theme-button-bg);
  border: 1px solid var(--theme-button-border);
  padding: 10px 26px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

/* Button hover */
.button:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* Disabled like button */
.button:disabled,
.button.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.04);
}

/* Bottom nav bar */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-nav-offset) + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-evenly;
  padding: 12px 24px;
  min-height: var(--bottom-nav-height);
  color: rgba(255, 255, 255, 0.9);
  z-index: 2;
}

.bottom-nav::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(-18px - env(safe-area-inset-bottom));
  height: calc(160px + env(safe-area-inset-bottom));
  background: linear-gradient(
    0deg,
    #0f0f0f,
    transparent
  );
  pointer-events: none;
  z-index: -1;
}

/* Nav item layout */
.nav-item {
  background: transparent;
  border: none;
  color: inherit;
  display: grid;
  gap: 6px;
  justify-items: center;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 12px;
  cursor: pointer;
}

/* Icon sizing */
.icon {
  width: 28px;
  height: 28px;
}

/* SVG to fill the icon box */
.icon svg {
  width: 100%;
  height: 100%;
}

/* Text under icon */
.nav-text {
  opacity: 0.85;
}

/* Share modal */
.share-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 6;
}

.share-modal.is-open {
  display: flex;
}

.share-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.share-panel {
  position: relative;
  width: min(560px, 90vw);
  background: rgba(20, 20, 20, 0.92);
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  color: #f5f2ee;
  text-align: center;
  transform: translateY(12px) scale(0.98);
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.share-modal.is-open .share-backdrop {
  opacity: 1;
}

.share-modal.is-open .share-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.share-preview {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  text-align: left;
}

.share-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(245, 242, 238, 0.7);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.share-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #f5f2ee;
  font-size: 13px;
}

.share-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.35);
}

.share-title {
  font-size: 20px;
  margin-bottom: 20px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.share-close {
  position: absolute;
  right: 18px;
  top: 16px;
  background: transparent;
  border: none;
  color: #f5f2ee;
  font-size: 26px;
  cursor: pointer;
}

.share-actions {
  display: grid;
  gap: 12px;
}

.share-action {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f5f2ee;
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  cursor: pointer;
}

.share-action:hover {
  background: rgba(255, 255, 255, 0.15);
}

.share-action.cancel {
  background: rgba(255, 255, 255, 0.04);
}

.share-toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.9);
  color: #f5f2ee;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 7;
}

.share-toast.is-visible {
  opacity: 1;
}

/* Topic overlay */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 24px;
  z-index: 5;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.is-open {
  display: flex;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.overlay-panel {
  position: relative;
  width: min(760px, 92vw);
  background: rgba(24, 24, 24, 0.92);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  color: #f5f2ee;
  max-height: calc(100vh - 140px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay-title {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 16px;
  opacity: 0.9;
}

.overlay-close {
  position: absolute;
  top: 18px;
  right: 20px;
  background: transparent;
  border: none;
  color: #f5f2ee;
  font-size: 16px;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.topic-card {
  position: relative;
  background: var(--theme-card);
  border: 1px solid var(--theme-card-border);
  color: #f5f2ee;
  padding: 16px;
  border-radius: 12px;
  text-align: left;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topic-card:hover {
  background: var(--theme-card-hover);
}

.topic-card.is-active {
  background: var(--theme-card-active);
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.topic-card.featured {
  grid-column: span 2;
  min-height: 120px;
  background: rgba(60, 60, 60, 0.7);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}

.topic-card.featured.has-link {
  cursor: pointer;
}

.pull-indicator {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, calc(-100% + var(--pull-distance, 0px)));
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #f5f2ee;
  font-size: 12px;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.pull-indicator.is-active {
  opacity: 1;
}

.topic-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.topic-card.is-active .topic-icon {
  opacity: 1;
}

.topic-icon svg {
  width: 100%;
  height: 100%;
}

.topic-label {
  flex: 1;
}

.topic-card.is-active .topic-icon svg path {
  fill: currentColor;
}

.topic-random {
  margin-top: 16px;
  width: 100%;
  background: var(--theme-button-bg);
  border: 1px solid var(--theme-card-border);
  color: #f5f2ee;
  padding: 12px;
  border-radius: 12px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.topic-random:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}

.topic-random:active {
  transform: translateY(0);
  box-shadow: none;
}

.topic-photo {
  position: absolute;
  inset: 0;
  background-image: var(
    --featured-photo,
    url("https://images.unsplash.com/photo-1482192596544-9eb780fc7f66?auto=format&fit=crop&w=1600&q=80")
  );
  background-size: cover;
  background-position: center;
  opacity: 0.9;
}

.topic-text {
  position: relative;
  z-index: 1;
  padding-bottom: 6px;
  text-shadow: 0 8px 18px rgba(0, 0, 0, 0.55);
}

/* Small screen tweaks */
@media (max-width: 600px) {
  .page {
    padding: 24px 16px 96px;
  }

  .bottom-nav {
    gap: 24px;
  }

  .share-panel {
    padding: 24px 18px 20px;
  }

  .overlay {
    padding: 48px 16px;
  }

  .topic-grid {
    grid-template-columns: 1fr;
  }

  .topic-grid.two-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topic-card.featured {
    grid-column: span 1;
  }

  .topic-grid.two-columns .topic-card.featured {
    grid-column: span 2;
  }
}
