:root {
  --bg: #f6f3ee;
  --bg-elevated: #ffffff;
  --bg-subtle: #efe9df;
  --ink: #1c2340;
  --ink-soft: #3a4468;
  --ink-muted: #6b7394;
  --border: #ded5c4;
  --border-strong: #c4b9a3;
  --accent: #5a4e86;
  --accent-soft: #e8dff5;
  --accent-ink: #2d2455;
  --awake: #f5d9b3;
  --awake-ink: #7a4f11;
  --sleep: #4a5a8a;
  --sleep-ink: #ffffff;
  --focus: #5a4e86;
  --danger: #8a3f3f;
  --danger-bg: #f5e6e6;
  --shadow-sm: 0 1px 2px rgba(20, 25, 50, 0.04);
  --shadow: 0 4px 16px rgba(20, 25, 50, 0.06);
  --shadow-lg: 0 10px 30px rgba(20, 25, 50, 0.08);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --font-serif: "Cormorant Garamond", "Playfair Display", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  --maxw: 72rem;
  --readw: 40rem;
}

[data-theme="dark"] {
  --bg: #0f1326;
  --bg-elevated: #171c36;
  --bg-subtle: #1d2344;
  --ink: #ece9f5;
  --ink-soft: #c2c0d9;
  --ink-muted: #8d8fb0;
  --border: #2a3056;
  --border-strong: #3a4278;
  --accent: #b4a9e6;
  --accent-soft: #2a2355;
  --accent-ink: #ece9f5;
  --awake: #3a3317;
  --awake-ink: #ebc88b;
  --sleep: #8f99c8;
  --sleep-ink: #0f1326;
  --focus: #b4a9e6;
  --danger: #e2a3a3;
  --danger-bg: #3a1d1d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.65;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.22em;
}
a:hover { color: var(--accent-ink); }
a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 0.6em;
}
h1 { font-size: clamp(2rem, 4vw + 1rem, 3rem); }
h2 { font-size: clamp(1.6rem, 2vw + 1rem, 2.1rem); margin-top: 2.4em; }
h3 { font-size: clamp(1.25rem, 1vw + 1rem, 1.5rem); margin-top: 1.8em; }
h4 { font-size: 1.1rem; margin-top: 1.4em; }

p, ul, ol { margin: 0 0 1.1em; }
p { max-width: var(--readw); }
article p, article ul, article ol { max-width: none; }
ul, ol { padding-left: 1.3em; }
li { margin-bottom: 0.4em; }

img, svg { max-width: 100%; height: auto; display: block; }

button, .button {
  font: inherit;
  font-family: var(--font-sans);
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  min-height: 52px;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
  background: var(--accent);
  color: #fff;
}
button:hover, .button:hover { background: var(--accent-ink); }
button:focus-visible, .button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button:active, .button:active { transform: translateY(1px); }
button.secondary, .button.secondary {
  background: var(--bg-elevated);
  color: var(--ink);
  border-color: var(--border-strong);
}
button.secondary:hover, .button.secondary:hover {
  background: var(--bg-subtle);
}

input, select, textarea {
  font: inherit;
  font-family: var(--font-sans);
  padding: 0.85rem 1rem;
  min-height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0.5rem;
  background: var(--ink);
  color: var(--bg);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { top: 0.5rem; }

/* Header */
.site-header {
  padding: 1.2rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(1.4) blur(8px);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.brand svg { color: var(--accent); }

.nav {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  font-size: 0.95rem;
}
.nav a { color: var(--ink-soft); text-decoration: none; }
.nav a:hover { color: var(--ink); }
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--ink-soft);
  padding: 0.5rem 0.8rem;
  min-height: 44px;
  border-radius: 999px;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.theme-toggle:hover { background: var(--bg-subtle); color: var(--ink); }

@media (max-width: 640px) {
  .nav .nav-link-desktop { display: none; }
}

/* Hero */
.hero {
  padding: 3rem 0 1rem;
  text-align: center;
}
.hero p.tagline {
  max-width: 34rem;
  margin: 0 auto 1.5rem;
  color: var(--ink-soft);
  font-size: 1.1rem;
}

/* Disclaimer */
.disclaimer {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin: 1.5rem auto;
  max-width: 50rem;
}
.disclaimer strong { color: var(--ink); }

/* Calculator */
.calculator {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin: 2rem auto;
  max-width: 48rem;
  box-shadow: var(--shadow);
}
.calculator h2 {
  margin-top: 0;
  font-size: 1.5rem;
}
.field {
  margin-bottom: 1.2rem;
}
.field label {
  display: block;
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 0.45rem;
  color: var(--ink-soft);
}
.field .hint {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-top: 0.35rem;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 540px) {
  .field-row { grid-template-columns: 1fr; }
}
.calculator button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
}

/* Result */
.result {
  margin: 2rem auto;
  max-width: 54rem;
}
.result.hidden { display: none; }

.summary-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.summary-card h2 {
  margin-top: 0;
  margin-bottom: 1rem;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.stat {
  background: var(--bg-subtle);
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid var(--border);
}
.stat-label {
  font-size: 0.82rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.stat-value {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 0.25rem;
  line-height: 1.2;
}

/* Schedule list */
.schedule {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.schedule ol {
  list-style: none;
  padding: 0;
  margin: 0;
}
.schedule-item {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px dashed var(--border);
  align-items: baseline;
}
.schedule-item:last-child { border-bottom: 0; }
.schedule-time {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--accent);
  font-size: 1.05rem;
}
.schedule-activity { color: var(--ink); font-weight: 500; }
.schedule-note { display: block; color: var(--ink-muted); font-size: 0.9rem; margin-top: 0.15rem; }

/* Timeline */
.timeline-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.timeline {
  display: flex;
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-top: 0.8rem;
}
.timeline-block {
  min-width: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  overflow: hidden;
}
.timeline-block.awake { background: var(--awake); color: var(--awake-ink); }
.timeline-block.sleep { background: var(--sleep); color: var(--sleep-ink); }
.timeline-legend {
  display: flex;
  gap: 1.2rem;
  margin-top: 0.8rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 0.4rem;
  vertical-align: middle;
}
.legend-awake { background: var(--awake); }
.legend-sleep { background: var(--sleep); }
.timeline-hours {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--ink-muted);
  margin-top: 0.4rem;
}

/* Age grid */
.age-grid-section {
  padding: 3rem 0;
}
.age-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.9rem;
  margin-top: 1.5rem;
}
.age-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.age-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.age-card strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  margin-bottom: 0.2rem;
}
.age-card span {
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* Page sections */
.page-section {
  margin: 2.5rem 0;
}

.quick-ref {
  background: var(--accent-soft);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin: 1.5rem 0 2.5rem;
}
.quick-ref h2 {
  margin-top: 0;
  color: var(--accent-ink);
}
.quick-ref .stats .stat {
  background: var(--bg-elevated);
}

.pill {
  display: inline-block;
  font-size: 0.82rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--ink-soft);
  margin-right: 0.4rem;
}

.article {
  max-width: var(--readw);
  margin: 0 auto;
  padding: 2rem 0 4rem;
}
.article header { margin-bottom: 2rem; }
.article .eyebrow {
  color: var(--ink-muted);
  text-transform: uppercase;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}
.article p, .article li { font-size: 1.05rem; }
.article blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.3rem 0 0.3rem 1.2rem;
  color: var(--ink-soft);
  font-style: italic;
}

.schedule-page {
  max-width: var(--readw);
  margin: 0 auto;
  padding: 2rem 0 4rem;
}
.schedule-page > * { max-width: 100%; }
.schedule-page .quick-ref,
.schedule-page .timeline-wrap,
.schedule-page .schedule {
  max-width: var(--readw);
  margin-left: auto;
  margin-right: auto;
}
.schedule-page h1 {
  text-align: center;
  margin-bottom: 0.4rem;
}
.schedule-page .sub {
  text-align: center;
  color: var(--ink-muted);
  margin-bottom: 2rem;
}

.prev-next {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 3rem 0 1rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.prev-next a {
  display: block;
  padding: 1rem 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
}
.prev-next a:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.prev-next a small {
  display: block;
  color: var(--ink-muted);
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}
.prev-next .next { text-align: right; }
.prev-next .empty { visibility: hidden; }

.callout {
  background: var(--bg-subtle);
  border-left: 4px solid var(--accent);
  padding: 1.1rem 1.3rem;
  margin: 1.2rem 0;
  border-radius: var(--radius);
}
.callout.warn {
  background: var(--danger-bg);
  border-left-color: var(--danger);
}
.callout.warn strong { color: var(--danger); }
.callout h3, .callout h4 { margin-top: 0; }

.faq details {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin-bottom: 0.75rem;
}
.faq details[open] { border-color: var(--accent); }
.faq summary {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  padding-right: 1.5rem;
  position: relative;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  position: absolute;
  right: 0;
  top: 0;
  font-size: 1.4rem;
  color: var(--accent);
  font-weight: 400;
}
.faq details[open] summary::after { content: "–"; }

.challenge-list { list-style: none; padding: 0; }
.challenge-list li {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 0.75rem;
}
.challenge-list strong {
  display: block;
  font-family: var(--font-serif);
  color: var(--accent);
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.red-flags {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
}
.red-flags h3 {
  margin-top: 0;
  color: var(--danger);
}
[data-theme="dark"] .red-flags h3 { color: var(--danger); }

/* Footer */
.site-footer {
  margin-top: auto;
  padding: 2.5rem 0 2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.site-footer .container {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 2rem;
}
@media (max-width: 700px) {
  .site-footer .container { grid-template-columns: 1fr; }
}
.site-footer h4 {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
  margin-top: 0;
  margin-bottom: 0.8rem;
}
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: 0.4rem; }
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--ink); }
.footer-bottom {
  max-width: var(--maxw);
  margin: 2rem auto 0;
  padding: 1.2rem 1.25rem 0;
  border-top: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Blog index cards */
.post-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  text-decoration: none;
  color: var(--ink);
  display: block;
}
.post-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); color: var(--ink); }
.post-card h3 { margin: 0 0 0.5rem; font-size: 1.35rem; }
.post-card p { color: var(--ink-soft); margin: 0; font-size: 0.95rem; }

.related-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  padding: 0;
  list-style: none;
}
.related-list a {
  display: block;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  background: var(--bg-elevated);
}
.related-list a:hover { border-color: var(--accent); }

/* Error page */
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: clamp(3rem, 8vw, 5rem); color: var(--accent); }

/* Print */
@media print {
  .site-header, .site-footer, .theme-toggle, .calculator { display: none; }
  body { background: white; color: black; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---- Affiliate card ---- */
.aff-card-wrap { max-width: var(--readw); margin: 2rem auto; padding: 0 1.25rem; }
.schedule-page .aff-card-wrap,
.article .aff-card-wrap { max-width: 100%; padding: 0; }

.aff-card {
  position: relative;
  display: block;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.6rem 1.5rem 1.25rem;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
[data-theme="dark"] .aff-card { background: var(--bg-elevated); }
.aff-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  color: var(--ink);
}
.aff-card:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.aff-sponsored {
  position: absolute;
  top: 0.75rem;
  right: 0.95rem;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  opacity: 0.5;
  font-weight: 500;
}
.aff-moon {
  position: absolute;
  top: 0.9rem;
  left: 1rem;
  color: var(--accent);
  opacity: 0.65;
}

.aff-micro {
  margin: 0 0 0.6rem;
  padding-left: 2rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
  max-width: none;
}
.aff-headline {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.5rem;
  line-height: 1.3;
}
.aff-body {
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0 0 0.9rem;
  max-width: none;
  line-height: 1.55;
}
.aff-values {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.aff-values li {
  padding-left: 1.35rem;
  position: relative;
  margin-bottom: 0.3rem;
}
.aff-values li::before {
  content: "\2713";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-weight: 600;
}
.aff-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.005em;
  transition: background 0.15s ease;
}
.aff-card:hover .aff-cta { background: var(--accent-ink); }
[data-theme="dark"] .aff-cta { color: var(--bg); }
.aff-reassure {
  margin: 0.6rem 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-muted);
  max-width: none;
}

@media (max-width: 480px) {
  .aff-card { padding: 1.35rem 1.15rem 1rem; }
  .aff-headline { font-size: 1.05rem; }
}
