:root {
  --bg: #f5f0e7;
  --surface: #fffdf8;
  --surface-2: #ebe3d6;
  --text: #1f2822;
  --muted: #687069;
  --line: rgba(31, 40, 34, 0.12);
  --accent: #264f3a;
  --accent-soft: #dce7dd;
  --shadow: 0 20px 60px rgba(47, 42, 33, 0.08);
  --reader-width: 720px;
  --reader-size: 20px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  transition: background .25s ease, color .25s ease;
}
button, input, textarea { font: inherit; }
button { color: inherit; }

body.dark {
  --bg: #121713;
  --surface: #1a211c;
  --surface-2: #242d26;
  --text: #edf1ec;
  --muted: #a9b2aa;
  --line: rgba(255,255,255,.1);
  --accent: #a9c9af;
  --accent-soft: #283b2e;
  --shadow: 0 20px 60px rgba(0,0,0,.22);
}

.app-shell { min-height: 100vh; }
.topbar {
  height: 76px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}
.brand {
  border: 0;
  background: none;
  font-family: "Literata", serif;
  font-size: 27px;
  font-weight: 600;
  cursor: pointer;
}
.brand span { color: var(--accent); }
.desktop-nav { display: flex; gap: 28px; }
.nav-link, .text-button {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.nav-link.active, .nav-link:hover, .text-button:hover { color: var(--text); }
.icon-button {
  width: 42px; height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}
.view { display: none; }
.view.active { display: block; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.hero {
  min-height: 610px;
  padding: 115px clamp(22px, 8vw, 130px) 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(circle at 80% 25%, rgba(81,111,81,.15), transparent 28%),
    radial-gradient(circle at 15% 85%, rgba(181,142,93,.12), transparent 30%);
}
.eyebrow {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .16em;
}
.hero h1, .page-header h1, .article-header h1 {
  font-family: "Literata", serif;
  font-weight: 500;
  letter-spacing: -.04em;
}
.hero h1 {
  max-width: 990px;
  margin: 0;
  font-size: clamp(42px, 6vw, 82px);
  line-height: 1.07;
}
.hero h1 em { color: var(--accent); font-weight: 400; }
.hero-copy {
  max-width: 650px;
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}
.hero-actions { display: flex; gap: 12px; margin-top: 34px; }
.primary-button, .secondary-button {
  padding: 14px 22px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  cursor: pointer;
  font-weight: 700;
}
.primary-button { background: var(--accent); color: var(--bg); }
.secondary-button { background: transparent; color: var(--accent); }

.content-section { padding: 78px clamp(20px, 6vw, 92px); }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 28px;
}
h2 { font-family: "Literata", serif; font-weight: 500; }
.section-heading h2 { margin: 0; font-size: clamp(28px, 4vw, 44px); }
.story-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}
.story-card {
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease, box-shadow .25s ease;
}
.story-card:hover { transform: translateY(-6px); }
.story-card .story-index { color: var(--muted); font-size: 13px; }
.story-card .story-icon { font-size: 42px; margin: 45px 0 28px; }
.story-card h3 {
  font-family: "Literata", serif;
  font-size: 26px;
  line-height: 1.25;
  margin: 0 0 12px;
}
.story-card p { color: var(--muted); line-height: 1.6; margin: 0; }
.story-card footer { margin-top: auto; padding-top: 24px; display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.story-card:nth-child(3n+2) { background: var(--accent-soft); }

.continue-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  padding: 26px;
  text-align: left;
  cursor: pointer;
}
.continue-card strong { display: block; font-family: "Literata", serif; font-size: 24px; margin-bottom: 8px; }
.mini-progress { height: 5px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin-top: 18px; }
.mini-progress span { display: block; height: 100%; background: var(--accent); }
.hidden { display: none !important; }

.reflection-banner {
  margin: 30px clamp(20px, 6vw, 92px) 90px;
  padding: 52px;
  border-radius: 30px;
  background: var(--accent);
  color: #f6f3eb;
  display: flex;
  justify-content: space-between;
  gap: 30px;
  align-items: center;
}
.reflection-banner .eyebrow { color: #cddbcf; }
.reflection-banner h2 { max-width: 650px; font-size: clamp(28px, 4vw, 48px); margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chips button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 10px 15px;
  cursor: pointer;
}
.reflection-banner .chips button { border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: white; }

.page-header { padding: 90px clamp(20px, 8vw, 130px) 46px; }
.page-header h1 { max-width: 850px; font-size: clamp(40px, 6vw, 72px); line-height: 1.1; margin: 0; }
.search-wrap { max-width: 680px; margin-top: 34px; }
.search-wrap input {
  width: 100%;
  padding: 17px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.filter-chips { margin-top: 18px; }
#libraryGrid { padding: 10px clamp(20px, 6vw, 92px) 100px; }

.heart-list { max-width: 900px; padding: 0 clamp(20px, 8vw, 130px) 100px; }
.heart-item { border-top: 1px solid var(--line); padding: 30px 0; }
.heart-item blockquote { font-family: "Literata", serif; font-size: 25px; line-height: 1.55; margin: 0 0 14px; }
.heart-item small { color: var(--muted); }
.empty-state { padding: 38px; border: 1px dashed var(--line); border-radius: 20px; color: var(--muted); }

.reader-view { min-height: 100vh; background: var(--surface); }
.reader-topbar {
  position: sticky; top: 0; z-index: 25;
  display: grid; grid-template-columns: 50px 1fr 50px;
  align-items: center; gap: 18px;
  padding: 16px clamp(16px, 4vw, 50px);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(16px);
}
.reader-progress-track { height: 3px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.reader-progress { height: 100%; width: 0%; background: var(--accent); }
.settings-panel {
  position: fixed; right: 24px; top: 78px; z-index: 30;
  width: min(330px, calc(100vw - 48px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 12px 0; }
.setting-row button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.reader-article { max-width: var(--reader-width); margin: 0 auto; padding: 90px 24px 130px; }
.article-header { margin-bottom: 70px; }
.article-header h1 { font-size: clamp(42px, 7vw, 70px); line-height: 1.08; margin: 0 0 22px; }
.article-meta { color: var(--muted); }
.reader-body { font-family: "Literata", serif; font-size: var(--reader-size); line-height: 1.95; }
.reader-body p { margin: 0 0 1.6em; }
.reader-body .pullquote {
  margin: 2.5em 0;
  padding-left: 24px;
  border-left: 3px solid var(--accent);
  font-size: 1.35em;
  line-height: 1.55;
  color: var(--accent);
}
.reader-body .saveable { cursor: pointer; border-radius: 4px; transition: background .2s; }
.reader-body .saveable:hover { background: var(--accent-soft); }
.reader-body .saved { background: var(--accent-soft); }
.article-footer { margin-top: 90px; padding-top: 48px; border-top: 1px solid var(--line); }
.article-footer h2 { font-size: 32px; }
.article-footer textarea {
  width: 100%; min-height: 150px; resize: vertical;
  padding: 18px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--bg); color: var(--text); margin: 10px 0 16px;
}
.save-message { color: var(--accent); font-weight: 600; }
.reader-view.night { --surface: #151a16; --text: #e7ece7; --muted: #a8b0a9; --surface-2: #252d27; --accent: #acc8b1; --accent-soft: #26382b; }

.mobile-nav { display: none; }
@media (max-width: 850px) {
  body { padding-bottom: 72px; }
  .desktop-nav { display: none; }
  .hero { min-height: 560px; padding-top: 90px; }
  .story-grid { grid-template-columns: 1fr; }
  .story-card { min-height: 310px; }
  .reflection-banner { padding: 34px 24px; align-items: flex-start; flex-direction: column; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(3,1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    height: 68px; border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(18px);
  }
  .mobile-nav button { border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; }
  .mobile-nav button span { font-size: 20px; }
  .mobile-nav button.active { color: var(--accent); }
  .reader-view.active ~ .mobile-nav { display: none; }
  .reader-article { padding-top: 60px; }
  .article-header { margin-bottom: 48px; }
}
