/* Brand tokens — mirrors KnowBite/Design/Theme.swift 1:1 so the web
   version reads as the same product, not a reskin. */
:root {
  --midnight-navy: #0F172A;
  --vibrant-orange: #F97316;
  --warm-amber: #FBBF24;
  --near-black: #0A0A0B;

  --background: var(--midnight-navy);
  --surface: rgba(255, 255, 255, 0.06);
  --surface-stroke: rgba(255, 255, 255, 0.10);
  --text-primary: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.68);
  --text-tertiary: rgba(255, 255, 255, 0.45);

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  --radius-card: 24px;
  --radius-chip: 20px;
  --radius-button: 16px;

  /* Matches iOS's `.tint(.red)` on the destructive Settings buttons. */
  --danger: #EF4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--near-black);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior-y: none;
}

/* On phones the feed is full-bleed, matching the native app. On wider
   viewports it's a centered phone-width column — the same pattern TikTok's
   own desktop site uses for this kind of vertical card content, rather
   than stretching cards edge-to-edge across a wide window.
   The centering lives on #app (not .feed) because .topbar is positioned
   absolute relative to #app — centering only .feed left the wordmark
   pinned to the true page corner, orphaned from the card column. */
#app {
  position: relative;
  height: 100dvh;
}

@media (min-width: 640px) {
  #app {
    max-width: 430px;
    margin: 0 auto;
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
  }
}

.feed {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  background: var(--background);
  -webkit-overflow-scrolling: touch;
}

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top), var(--space-md)) var(--space-lg) var(--space-sm);
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(10, 10, 11, 0.55), transparent);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.2px;
  color: inherit;
  text-decoration: none;
  pointer-events: auto;
}
.wordmark-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: block;
}
.wordmark .accent { color: var(--vibrant-orange); }

.topnav {
  pointer-events: auto;
  font-size: 13px;
  font-weight: 600;
}
.topnav a {
  color: var(--text-secondary);
  text-decoration: none;
}
.topnav a:hover { color: var(--text-primary); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.interests-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--surface-stroke);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

/* Account / sign-out — only shown once signed in (see app.js renderAccount).
   `.topbar` disables pointer-events so it never blocks swipes on the feed
   below it; this re-enables them just for the interactive account control. */
.account-area {
  position: relative;
  pointer-events: auto;
}

.account-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--vibrant-orange);
  color: var(--near-black);
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.account-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: var(--near-black);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-button);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}
/* `[hidden]` needs higher specificity than `.account-menu` to actually win —
   a class selector beats the UA `[hidden]{display:none}` rule on its own,
   which is exactly why this was rendering open by default. */
.account-menu[hidden] {
  display: none;
}

.account-email {
  padding: var(--space-xs) var(--space-sm);
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-all;
}

.account-signout {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-button);
  padding: 10px var(--space-sm);
  cursor: pointer;
}
.account-signout:hover { background: rgba(239, 68, 68, 0.25); }

.loading {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--surface-stroke);
  border-top-color: var(--text-primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Card --- */

.card {
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  background: var(--background);
  overflow: hidden;
}

/* height (not max-height) is deliberate: .card has an explicit height, so
   this percentage resolves cleanly. Mixing max-height with a
   aspect-ratio'd, flex-centered child here previously created a circular
   sizing dependency — the box collapsed and its icon rendered huge and
   mispositioned over the topbar instead of filling this box. */
.card-visual {
  position: relative;
  width: 100%;
  height: 46%;
  flex-shrink: 0;
  background: var(--background);
  overflow: hidden;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top;
  display: block;
}

.card-visual::after {
  /* Fades the image's lower edge into the background, same seam-softening
     trick as the iOS card. */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 48px;
  background: linear-gradient(to bottom, transparent, var(--background));
  pointer-events: none;
}

.card-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.35), var(--midnight-navy));
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.25);
}
/* Same fix as .account-menu above: an unconditional `display` on a class
   beats the UA `[hidden]{display:none}` rule, so without this override
   the placeholder rendered behind every successfully-loaded image too. */
.card-visual[hidden],
.story-visual[hidden] {
  display: none;
}

.card.no-visual .card-visual {
  display: none;
}

.card.no-visual .card-body {
  padding-top: var(--space-lg);
}

.card-body {
  padding: var(--space-md) var(--space-lg) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
  overflow: hidden;
}

.meta-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-xs);
}

.category-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 5px var(--space-sm);
  border-radius: var(--radius-chip);
  background: var(--chip-tint, rgba(249, 115, 22, 0.35));
  border: 1px solid var(--chip-stroke, rgba(249, 115, 22, 0.6));
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
}

.meta-line {
  font-size: 13px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.card-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-title-link {
  color: inherit;
  text-decoration: none;
}

.card-summary {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.why-block {
  padding: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-card);
}
.why-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--warm-amber);
  margin-bottom: var(--space-xs);
}
.why-text {
  margin: 0;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.92);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.action-row {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg) max(env(safe-area-inset-bottom), var(--space-md));
  margin-top: auto;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px var(--space-md);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-button);
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s ease;
}
.action-btn:hover { background: rgba(255, 255, 255, 0.1); }
.read-btn { flex: 1; }
.save-btn.saved {
  background: var(--warm-amber);
  border-color: transparent;
  color: var(--near-black);
}

.signin-prompt {
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
}
.signin-prompt-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  text-align: center;
  color: var(--text-secondary);
  max-width: 320px;
}
.signin-prompt-body svg { color: var(--warm-amber); }
.signin-prompt-body h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}
.signin-prompt-body p { margin: 0; font-size: 15px; }
.signin-fineprint {
  font-size: 13px;
  color: var(--text-tertiary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(env(safe-area-inset-bottom), 24px);
  transform: translateX(-50%);
  background: var(--near-black);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  border: 1px solid var(--surface-stroke);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.toast.visible { opacity: 1; }

/* --- Your Interests modal --- */

.interests-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
/* Same specificity fix as .account-menu/.card-placeholder above — an
   unconditional `display` on the class beats the UA `[hidden]` rule. */
.interests-modal[hidden] {
  display: none;
}

@media (min-width: 640px) {
  .interests-modal { align-items: center; }
}

.interests-panel {
  width: 100%;
  max-width: 430px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--midnight-navy);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: var(--space-lg);
}
@media (min-width: 640px) {
  .interests-panel {
    border-radius: var(--radius-card);
    margin: 0 var(--space-md);
  }
}

.interests-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-xs);
}
.interests-panel-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.interests-close {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.interests-hint {
  margin: 0 0 var(--space-md);
  font-size: 13px;
  color: var(--text-tertiary);
}

.interests-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding-bottom: env(safe-area-inset-bottom);
}

.interest-chip {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-chip);
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--surface-stroke);
  color: var(--text-secondary);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.interest-chip.selected {
  color: var(--text-primary);
}

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

#app.page-app {
  height: auto;
  min-height: 100dvh;
  background: var(--background);
}
#app.page-app .topbar {
  position: sticky;
  pointer-events: auto;
  background: var(--background);
}

.page-main {
  padding: 72px var(--space-lg) var(--space-xl);
}
.page-intro h1,
.story-page h1 {
  margin: 0 0 var(--space-sm);
  font-size: 28px;
  line-height: 1.2;
}
.page-intro p,
.story-summary {
  margin: 0 0 var(--space-md);
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.5;
}
.story-page .why-text {
  -webkit-line-clamp: unset;
}
.story-visual {
  margin: 0 calc(var(--space-lg) * -1) var(--space-lg);
}
.story-visual img {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  display: block;
}
.story-article .meta-row {
  margin-bottom: var(--space-md);
}

.category-index {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin: 0 0 var(--space-lg);
}
.category-index a {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px var(--space-sm);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-chip);
}
.category-index a[aria-current="page"],
.category-index a:hover {
  color: var(--text-primary);
  border-color: var(--vibrant-orange);
}

.teaser-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}
.teaser-title {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 1.25;
  margin-bottom: var(--space-xs);
}
.teaser-title:hover { color: var(--warm-amber); }
.teaser p { margin: 0 0 var(--space-xs); }

.source-group { margin-bottom: var(--space-xl); }
.source-group h2 {
  margin: 0 0 var(--space-sm);
  font-size: 18px;
}
.source-group h2 a {
  color: inherit;
  text-decoration: none;
}
.source-list {
  margin: 0;
  padding-left: 1.2em;
  color: var(--text-secondary);
}
.source-list a { color: var(--text-secondary); }

.related { margin-top: var(--space-xl); }
.related h2 { font-size: 16px; margin: 0 0 var(--space-sm); }
.related ul { margin: 0; padding-left: 1.2em; }
.related a { color: var(--text-primary); }
.related span { color: var(--text-tertiary); font-size: 13px; margin-left: 0.4em; }

.site-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--surface-stroke);
  color: var(--text-tertiary);
  font-size: 13px;
}
.site-footer nav {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}
.site-footer a { color: var(--text-secondary); text-decoration: none; }
.site-footer p { margin: 0; }
