:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f8f5fb);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #261e2f);
  --muted: var(--tg-theme-hint-color, #756d7f);
  --accent: var(--tg-theme-button-color, #8067a9);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 14%, transparent);
  --lavender: #eee7f7;
  --lavender-ink: #513d72;
  --gold: #f8edcf;
  --gold-ink: #705522;
  --sage: #e7f1e9;
  --sage-ink: #345a42;
  --danger: #a43e51;
  --shadow: 0 14px 40px rgba(54, 36, 72, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 90% 0%, color-mix(in srgb, var(--lavender) 72%, transparent), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, white);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.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;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
}

.skip-link:focus { transform: translateY(0); }

.session-gate {
  width: min(100% - 32px, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(72px, 15vh) 12px 80px;
  text-align: center;
}

.session-gate h1 { margin: 10px 0; font-size: clamp(1.75rem, 7vw, 2.5rem); line-height: 1.15; }
.session-gate .button { margin-top: 20px; }

.gate-orbit {
  display: grid;
  width: 84px;
  height: 84px;
  margin: 0 auto 22px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-size: 2rem;
  animation: breathe 2.4s ease-in-out infinite;
}

.app-shell { width: min(100%, 760px); min-height: 100vh; margin: 0 auto; padding-bottom: calc(92px + var(--safe-bottom)); }

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 12px max(18px, env(safe-area-inset-left)) 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(18px);
}

.brand { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; font-weight: 700; letter-spacing: 0.02em; }
.brand-subtitle { margin: -2px 0 0; color: var(--muted); font-size: 0.76rem; }
.icon-button { min-width: 46px; min-height: 44px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 700; }

main { padding: 18px clamp(14px, 4vw, 28px) 30px; }
.view { display: grid; gap: 14px; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.9rem, 8vw, 2.8rem); line-height: 1.08; }
h2 { margin: 0 0 4px; font-size: 1.08rem; line-height: 1.3; }
p { margin: 0; }
.muted, .section-intro, .path-copy p, .stars-card p { color: var(--muted); }
.small { margin-top: 6px; font-size: 0.82rem; }
.eyebrow { color: var(--accent); font-size: 0.74rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }

.hero-card,
.luma-season,
.path-card,
.privacy-card,
.stars-card,
.article-card,
.journal-form,
.journal-entry,
.article-reader {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-card { display: grid; gap: 9px; padding: clamp(20px, 6vw, 32px); background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--lavender) 72%, var(--surface))); }
.hero-copy { max-width: 35rem; color: var(--muted); }
.progress { display: grid; gap: 7px; margin-top: 8px; font-size: 0.82rem; font-weight: 700; }
.progress-track { width: 100%; height: 7px; overflow: hidden; border-radius: 99px; background: color-mix(in srgb, var(--text) 10%, transparent); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 220ms ease; }
.progress[data-completed="1"] .progress-track span { width: 33%; }
.progress[data-completed="2"] .progress-track span { width: 67%; }
.progress[data-completed="3"] .progress-track span { width: 100%; }

.sync-row { display: flex; min-height: 24px; align-items: center; justify-content: space-between; gap: 10px; }
.sync-status { color: var(--muted); font-size: 0.78rem; }
.sync-retry { min-height: 38px; padding: 4px 8px; border: 0; background: transparent; color: var(--accent); font-size: 0.8rem; font-weight: 750; cursor: pointer; }

.luma-season { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; padding: 18px; background: linear-gradient(145deg, color-mix(in srgb, var(--lavender) 80%, var(--surface)), var(--surface)); }
.luma-orbit { display: grid; width: 52px; height: 52px; place-items: center; border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent); border-radius: 50%; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); font-size: 1.45rem; }
.luma-season-copy { display: grid; gap: 7px; min-width: 0; }
.reward-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
.reward-row > span { padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.reward-row > span[data-unlocked="true"] { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--surface); color: var(--lavender-ink); }
.luma-season[data-verified="false"] .reward-row { opacity: 0.45; }

.path-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; padding: 18px; }
.path-copy { display: grid; gap: 10px; }
.path-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 14px; font-size: 1.25rem; }
.tone-gold { background: var(--gold); color: var(--gold-ink); }
.tone-lavender { background: var(--lavender); color: var(--lavender-ink); }
.tone-sage { background: var(--sage); color: var(--sage-ink); }

.button { min-height: 44px; padding: 10px 16px; border: 1px solid transparent; border-radius: 14px; font-weight: 750; cursor: pointer; }
.button-primary { background: var(--accent); color: var(--accent-text); }
.button-secondary { border-color: var(--line); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); color: var(--text); }
.button-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.button:disabled { cursor: default; opacity: 0.62; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.choice-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.choice-grid button { min-height: 44px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; }
.choice-grid button[aria-pressed="true"] { border-color: var(--accent); background: var(--lavender); color: var(--lavender-ink); }
.field-error { color: var(--danger); font-size: 0.86rem; }

.privacy-card { display: flex; gap: 11px; padding: 14px 16px; background: color-mix(in srgb, var(--sage) 76%, var(--surface)); color: var(--sage-ink); box-shadow: none; }
.stars-card { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 18px; background: linear-gradient(140deg, var(--surface), var(--gold)); }
.stars-card > div { display: grid; gap: 4px; }

.search-field { display: flex; align-items: center; gap: 9px; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.search-field input { width: 100%; min-width: 0; padding: 12px 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.article-list, .journal-list { display: grid; gap: 10px; }
.article-card { display: grid; gap: 8px; padding: 18px; }
.article-card .meta, .article-meta { color: var(--muted); font-size: 0.8rem; }
.article-card .button { justify-self: start; }
.article-reader { display: grid; gap: 14px; padding: clamp(20px, 6vw, 34px); }
.article-reader h1 { font-size: clamp(1.8rem, 7vw, 2.55rem); }
.article-body { display: grid; gap: 15px; font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; line-height: 1.72; }
.back-button { justify-self: start; min-height: 44px; padding: 6px 0; border: 0; background: transparent; color: var(--accent); font-weight: 750; cursor: pointer; }
.journal-privacy { margin-bottom: 4px; }
.journal-form { display: grid; gap: 8px; padding: 18px; }
.journal-form label { margin-top: 4px; font-weight: 750; }
.journal-form input, .journal-form textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--bg); color: var(--text); resize: vertical; }
.status-line { min-height: 1.5rem; color: var(--sage-ink); font-size: 0.88rem; }
.journal-entry { display: grid; gap: 8px; padding: 16px; }
.journal-entry h2 { font-family: Georgia, "Times New Roman", serif; }
.journal-entry .entry-body { display: -webkit-box; overflow: hidden; color: var(--muted); -webkit-box-orient: vertical; -webkit-line-clamp: 3; white-space: pre-wrap; }
.journal-entry .entry-date { color: var(--muted); font-size: 0.78rem; }
.journal-actions { display: flex; gap: 8px; }
.journal-actions button, .danger-link { min-height: 44px; padding: 6px 4px; border: 0; background: transparent; color: var(--accent); font-weight: 750; cursor: pointer; }
.journal-actions .remove-entry, .danger-link { color: var(--danger); }
.danger-link { justify-self: start; }
.privacy-footnote, .empty-state { padding: 18px 8px; color: var(--muted); text-align: center; font-size: 0.88rem; }

.tabbar {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 760px);
  min-height: calc(70px + var(--safe-bottom));
  margin: 0 auto;
  padding: 7px 10px calc(7px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(18px);
}

.tabbar button { display: grid; min-height: 54px; place-items: center; align-content: center; gap: 1px; border: 0; border-radius: 14px; background: transparent; color: var(--muted); font-size: 0.76rem; cursor: pointer; }
.tabbar button > span:first-child { font-size: 1.1rem; }
.tabbar button[aria-current="page"] { background: var(--lavender); color: var(--lavender-ink); font-weight: 750; }

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@media (min-width: 620px) {
  main { padding-top: 26px; }
  .path-card { grid-template-columns: 52px minmax(0, 1fr); padding: 22px; }
  .path-icon { width: 48px; height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --lavender: #342b43;
    --lavender-ink: #eadffa;
    --gold: #3d3524;
    --gold-ink: #f7e5b8;
    --sage: #25372b;
    --sage-ink: #d7efdc;
    --shadow: 0 14px 42px rgba(0, 0, 0, 0.2);
  }
}
