:root {
  color-scheme: light dark;
  --fg: #262220;
  --bg: #faf7f1;
  --muted: #726b62;
  --card-bg: #ffffff;
  --card-bg-alt: #f2ede3;
  --accent: #7a3b2e;
  --accent-soft: #c9a15e;
  --border: #e4dccb;
  --shadow: 0 1px 2px rgba(38, 34, 32, 0.04), 0 8px 24px -12px rgba(38, 34, 32, 0.12);
  --serif: "Fraunces", "Source Serif 4", Georgia, serif;
  --serif-text: "Source Serif 4", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #ece6dc;
    --bg: #16140f;
    --muted: #a99e8f;
    --card-bg: #1f1c16;
    --card-bg-alt: #201d17;
    --accent: #e0a37b;
    --accent-soft: #cfa15e;
    --border: #332e24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px -14px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--fg);
  background:
    radial-gradient(ellipse 60rem 30rem at 50% -10%, color-mix(in srgb, var(--accent-soft) 10%, transparent), transparent),
    var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: var(--accent);
}

/* Header */

.site-header {
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-title {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.site-title-mark {
  color: var(--accent);
  font-size: 1rem;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
  font-size: 0.9rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 0.15rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.site-nav a:hover {
  color: var(--accent);
  border-color: var(--accent-soft);
}

.auth-controls {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
}

.auth-sign-in,
.auth-sign-out {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 2rem;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.auth-sign-in:hover,
.auth-sign-out:hover {
  background: var(--accent);
  color: var(--card-bg);
}

.auth-signed-in {
  display: none;
  align-items: center;
  gap: 0.65rem;
}

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

.auth-controls.is-signed-in .auth-sign-in {
  display: none;
}

.auth-controls.is-signed-in .auth-signed-in {
  display: flex;
}

/* Main / shared layout */

main {
  flex: 1;
  max-width: 42rem;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.section-heading {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 500;
  margin: 0 0 1.1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

/* Home: hero */

.hero {
  padding: 1rem 0 2.75rem;
  text-align: left;
}

.hero-eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2.1rem, 6vw, 2.9rem);
  font-weight: 600;
  margin: 0 0 0.75rem;
  line-height: 1.15;
}

.hero-description {
  margin: 0;
  max-width: 34rem;
  color: var(--muted);
  font-family: var(--serif-text);
  font-size: 1.05rem;
}

/* Home: latest card */

.latest {
  margin-bottom: 3rem;
}

.latest-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-start;
  text-decoration: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.latest-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-soft);
}

.latest-date {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.latest-title {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--fg);
}

.latest-topic {
  font-size: 0.85rem;
  color: var(--accent);
}

.latest-cta {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}

/* Home: discover (random old entry) card */

.discover {
  margin-bottom: 3rem;
}

.discover-card {
  border-color: var(--accent-soft);
  border-style: dashed;
}

.discover-eyebrow {
  margin: 0;
  color: var(--accent-soft);
}

/* Home: archive list */

.archive {
  margin-bottom: 3rem;
}

.archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.archive-item {
  border-bottom: 1px solid var(--border);
}

.archive-item a {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.85rem 0.25rem;
  text-decoration: none;
  color: var(--fg);
  transition: color 0.15s ease, padding-left 0.15s ease;
}

.archive-item a:hover {
  color: var(--accent);
  padding-left: 0.5rem;
}

.archive-date {
  flex: none;
  width: 6.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.archive-title {
  font-family: var(--serif-text);
}

/* Home: gamification stats widget */

.hero-with-stats {
  padding-bottom: 1.25rem;
}

.stats {
  margin-bottom: 3rem;
}

.stats-panel {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.9rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem 1.1rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

/* On desktop the top row's children merge straight into .stats-panel's own
   flex row, so the whole widget reads as one line; the mobile breakpoint
   below turns this back into a real box and stacks it under the top row. */
.stats-top-row {
  display: contents;
}

.stats-collected-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex: none;
}

.stats-check {
  display: flex;
  align-items: center;
  flex: none;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.stats-check-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.95rem;
  flex: none;
}

.stats-check.is-done .stats-check-icon {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--card-bg);
}

.stats-check.is-done .stats-check-label {
  color: var(--fg);
}

.stats-row {
  display: flex;
  flex: none;
  gap: 1.25rem;
}

.stats-figure {
  display: flex;
  flex-direction: column;
  flex: none;
}

.stats-figure-value {
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.1;
  white-space: nowrap;
}

.stats-figure-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
}

.stats-trend {
  display: flex;
  align-items: flex-end;
  flex: none;
  gap: 0.2rem;
  height: 2rem;
  margin-left: auto;
}

.stats-bar {
  display: inline-block;
  width: 0.4rem;
  height: max(10%, var(--pct));
  border-radius: 0.2rem;
  background: var(--accent-soft);
}

/* Home: quiz teaser */

.quiz-copy {
  color: var(--muted);
  font-family: var(--serif-text);
  max-width: 34rem;
}

/* Daily page */

.back-link {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 1.5rem;
}

.back-link:hover {
  color: var(--accent);
}

.back-link-bottom {
  margin-top: 2.5rem;
  margin-bottom: 0;
}

.daily-header {
  margin-bottom: 2.25rem;
}

.daily-date {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.daily-header h1 {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  font-weight: 600;
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

.daily-topic {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.fact-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.fact-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow);
}

.fact-number {
  color: var(--accent);
  font-weight: 600;
}

.fact-question {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0 0 0.85rem;
  font-size: 1.15rem;
  line-height: 1.4;
}

.fact-answer {
  margin: 0 0 0.85rem;
  font-weight: 600;
  font-family: var(--serif-text);
}

.fact-answer-label {
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  margin-right: 0.5rem;
}

.fact-explanation {
  margin: 0 0 1.25rem;
  color: var(--fg);
  font-family: var(--serif-text);
}

.add-to-collection {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.add-to-collection:hover {
  background: var(--accent);
  color: var(--card-bg);
}

.add-to-collection:disabled {
  cursor: default;
}

.add-to-collection.is-saving {
  opacity: 0.7;
}

.add-to-collection.is-added {
  background: var(--accent);
  color: var(--card-bg);
  opacity: 1;
}

.add-to-collection.is-error {
  border-color: #b3382c;
  color: #b3382c;
}

/* Quiz page */

.quiz-header {
  margin-bottom: 2.25rem;
}

.quiz-header h1 {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  font-weight: 600;
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

.quiz-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.quiz-status {
  color: var(--muted);
  font-family: var(--serif-text);
}

.quiz-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.quiz-progress {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.quiz-topic {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.quiz-question {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0 0 1.25rem;
  font-size: 1.3rem;
  line-height: 1.4;
}

.quiz-reveal {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: 2rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--card-bg);
  cursor: pointer;
}

.quiz-answer-block {
  margin-top: 1rem;
}

.quiz-answer {
  margin: 0 0 0.85rem;
  font-weight: 600;
  font-family: var(--serif-text);
  font-size: 1.05rem;
}

.quiz-explanation-link {
  display: inline-block;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
}

.quiz-grade-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.quiz-grade {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 2rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.quiz-grade-correct:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.quiz-grade-missed:hover {
  border-color: #b3382c;
  color: #b3382c;
}

.quiz-summary {
  text-align: center;
}

.quiz-score {
  font-family: var(--serif);
  font-size: 2.5rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--accent);
}

/* My Facts (manage collected facts) */

.manage-topic-group {
  margin-bottom: 2.25rem;
}

.manage-topic-heading {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 500;
  text-transform: capitalize;
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.manage-fact-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.manage-fact-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  transition: opacity 0.15s ease;
}

.manage-fact-card.is-removed {
  opacity: 0.55;
}

.manage-fact-card .fact-question {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}

.manage-fact-card .fact-answer {
  margin-bottom: 0;
}

.manage-fact-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.manage-removed-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: auto;
}

.manage-forget {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.manage-forget:hover {
  border-color: #b3382c;
  color: #b3382c;
}

.manage-forget.is-removed {
  border-color: var(--accent);
  color: var(--accent);
}

.manage-forget.is-removed:hover {
  background: var(--accent);
  color: var(--card-bg);
}

.manage-forget:disabled {
  cursor: default;
  opacity: 0.6;
}

/* Getting started */

.guide-steps {
  margin-bottom: 3rem;
}

.guide-step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.guide-step {
  display: flex;
  gap: 1.1rem;
  align-items: flex-start;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}

.guide-step-num {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--card-bg-alt);
  color: var(--accent);
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.95rem;
}

.guide-step-body h3 {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 500;
  margin: 0 0 0.4rem;
}

.guide-step-body p {
  margin: 0;
  color: var(--muted);
  font-family: var(--serif-text);
  font-size: 0.95rem;
}

.guide-faq {
  margin-bottom: 3rem;
}

.guide-faq-list {
  margin: 0;
  border-top: 1px solid var(--border);
}

.guide-faq-item {
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--border);
}

.guide-faq-item dt {
  font-family: var(--serif);
  font-weight: 500;
  margin-bottom: 0.35rem;
}

.guide-faq-item dd {
  margin: 0;
  color: var(--muted);
  font-family: var(--serif-text);
  font-size: 0.95rem;
}

/* Footer */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 1.25rem 2rem;
  text-align: center;
}

.site-footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--serif-text);
  font-style: italic;
}

/* Small screens */

@media (max-width: 30rem) {
  .site-header-inner {
    padding: 1.25rem 1rem;
  }

  main {
    padding: 2rem 1rem 3rem;
  }

  .fact-card,
  .latest-card {
    padding: 1.25rem 1.25rem;
  }

  .stats-panel {
    flex-direction: column;
    align-items: stretch;
    overflow-x: visible;
    padding: 1rem;
    gap: 0.75rem;
  }

  .stats-top-row {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 1.5rem;
    overflow-x: auto;
  }

  .stats-collected-row {
    justify-content: center;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
  }

  .stats-check-icon {
    width: 1.3rem;
    height: 1.3rem;
    font-size: 0.8rem;
  }

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

  .stats-row {
    gap: 1rem;
  }

  .stats-figure-value {
    font-size: 1.2rem;
  }

  .stats-figure-label {
    font-size: 0.62rem;
  }

  .stats-trend {
    gap: 0.2rem;
    height: 1.5rem;
    margin-left: 0;
  }

  .stats-bar {
    width: 0.3rem;
  }

  .archive-item a {
    gap: 0.6rem;
  }

  .archive-date {
    width: 4.4rem;
    font-size: 0.72rem;
  }
}

/* Install banner (iOS "Add to Home Screen" prompt) */

.install-banner {
  display: none;
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 100;
  align-items: center;
  gap: 0.85rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.install-banner.is-visible {
  display: flex;
}

.install-banner-icon {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.6rem;
}

.install-banner-body {
  flex: 1;
  min-width: 0;
}

.install-banner-title {
  margin: 0 0 0.15rem;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 0.95rem;
}

.install-banner-copy {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.install-banner-action {
  flex: none;
  font: inherit;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 2rem;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.install-banner-action[hidden] {
  display: none;
}

.install-banner-dismiss {
  flex: none;
  font: inherit;
  font-family: var(--sans);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
