/* Wellnestia — dark-first, mobile-first.
   Theme tokens: :root is the dark (night) theme; [data-theme="light"] overrides.
   The no-JS fallback follows the OS preference via prefers-color-scheme.
   The header backdrop is pure CSS (aurora glows + star field) — no image. */
:root {
  --bg: #070b19;
  --surface: #10162b;
  --surface-2: #1a2138;
  --card: rgba(18, 24, 44, .66);
  --line: rgba(148, 163, 214, .16);
  --line-strong: rgba(148, 163, 214, .3);
  --text: #ece9e2;
  --muted: #a3a1b5;
  --accent: #f2b263;
  --accent-2: #f68d6f;
  --accent-ink: #2a1c05;
  --danger: #f0a4a4;
  --shadow: 0 12px 40px rgba(2, 4, 12, .5);
  --glow-a: rgba(242, 178, 99, .16);
  --glow-b: rgba(124, 110, 245, .2);
  --sky-top: #0a1026;
  --star: rgba(236, 233, 226, .85);
  --star-opacity: .5;
  --card-highlight: rgba(255, 255, 255, .05);
  --hero-image: url("hero-dark.jpg");
  --hero-veil: linear-gradient(180deg, rgba(7, 11, 25, .5) 0%, rgba(7, 11, 25, .12) 34%, rgba(7, 11, 25, .6) 72%, var(--bg) 99%);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #faf7f1;
  --surface: #ffffff;
  --surface-2: #f1ede2;
  --card: rgba(255, 255, 255, .72);
  --line: rgba(90, 70, 30, .14);
  --line-strong: rgba(90, 70, 30, .28);
  --text: #221f2a;
  --muted: #5b5865;
  --accent: #9d5a10;
  --accent-2: #bf4e2a;
  --accent-ink: #ffffff;
  --danger: #a13c3c;
  --shadow: 0 12px 36px rgba(90, 70, 30, .14);
  --glow-a: rgba(242, 178, 99, .35);
  --glow-b: rgba(168, 190, 245, .4);
  --sky-top: #f3ecdd;
  --star: transparent;
  --star-opacity: 0;
  --card-highlight: rgba(255, 255, 255, .65);
  --hero-image: url("hero-light.jpg");
  --hero-veil: linear-gradient(180deg, rgba(250, 247, 241, .42) 0%, rgba(250, 247, 241, .26) 34%, rgba(250, 247, 241, .78) 74%, var(--bg) 99%);
  color-scheme: light;
}
/* No-JS visitors still get the right theme via the OS preference. */
@media (prefers-color-scheme: light) {
  html:not([data-theme]) {
    --bg: #faf7f1; --surface: #ffffff; --surface-2: #f1ede2; --card: rgba(255, 255, 255, .72);
    --line: rgba(90, 70, 30, .14); --line-strong: rgba(90, 70, 30, .28);
    --text: #221f2a; --muted: #5b5865; --accent: #9d5a10; --accent-2: #bf4e2a; --accent-ink: #ffffff;
    --danger: #a13c3c; --shadow: 0 12px 36px rgba(90, 70, 30, .14);
    --glow-a: rgba(242, 178, 99, .35); --glow-b: rgba(168, 190, 245, .4);
    --sky-top: #f3ecdd; --star: transparent; --star-opacity: 0;
    --card-highlight: rgba(255, 255, 255, .65); color-scheme: light;
    --hero-image: url("hero-light.jpg");
    --hero-veil: linear-gradient(180deg, rgba(250, 247, 241, .42) 0%, rgba(250, 247, 241, .26) 34%, rgba(250, 247, 241, .78) 74%, var(--bg) 99%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.06rem;
  line-height: 1.65;
}
h1:focus { outline: none; } /* FocusOnNavigate target */
.wrap { max-width: 46rem; margin: 0 auto; padding: 0 1.5rem; position: relative; z-index: 1; }

/* Photographic night-sky / dawn backdrop behind the header and title. A calm
   Pexels photo per theme (starry night for dark, misty dawn mountains for
   light), under a soft veil that keeps the title legible and dissolves the
   image into the page. Absolutely positioned, so it adds no height. */
.banner {
  position: absolute; top: 0; left: 0; right: 0;
  height: clamp(20rem, 46vw, 27rem);
  overflow: hidden; z-index: 0; pointer-events: none;
  background:
    var(--hero-veil),
    var(--hero-image) center 30% / cover no-repeat;
}

.skip {
  position: absolute; left: -999px; top: 0; z-index: 10;
  background: var(--accent); color: var(--accent-ink);
  padding: .5rem 1rem; border-radius: 0 0 .5rem .5rem; font-weight: 600;
}
.skip:focus { left: 1rem; }

/* Header */
header.site {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 0 0;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; letter-spacing: .02em; font-size: 1.05rem; color: inherit; text-decoration: none; }
.brand:hover { color: var(--accent); }
.brand svg { display: block; filter: drop-shadow(0 0 6px var(--glow-a)); }
.header-controls { display: flex; gap: .5rem; }
.icon-btn {
  background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--text);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: .7rem;
  min-height: 2.25rem; min-width: 2.75rem; padding: .3rem .6rem;
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  transition: border-color .18s, background-color .18s;
}
.icon-btn:hover { border-color: var(--line-strong); }

/* Hero */
h1 {
  font-size: clamp(2.3rem, 7vw, 3.4rem); line-height: 1.08; letter-spacing: -.025em;
  margin: 2.4rem 0 .6rem;
  background: linear-gradient(92deg, var(--text) 55%, color-mix(in srgb, var(--accent) 72%, var(--text)));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--text); /* fallback if clip unsupported */
}
.lede {
  color: var(--muted); margin: 0 0 1.5rem;
  font-size: clamp(1.06rem, 3vw, 1.28rem); line-height: 1.5; max-width: 34rem;
  /* The lede sits over the hero photo; a faint halo keeps it legible on the
     brighter light-theme image (all but invisible over the dark starry one). */
  text-shadow: 0 1px 16px rgba(7, 11, 25, .55);
}
[data-theme="light"] .lede { text-shadow: 0 1px 2px rgba(255, 255, 255, .9), 0 0 14px rgba(250, 247, 241, .85); }
@media (prefers-color-scheme: light) {
  html:not([data-theme]) .lede { text-shadow: 0 1px 2px rgba(255, 255, 255, .9), 0 0 14px rgba(250, 247, 241, .85); }
}

/* Tool card — glassy: translucent, blurred, lit from the top edge. */
.tool {
  background: var(--card);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 1.25rem; padding: 1rem;
  box-shadow: var(--shadow), inset 0 1px 0 var(--card-highlight);
}
.tool fieldset { border: 0; margin: 0; padding: 0; }
#calc { display: none; }
html.js #calc { display: block; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.segs {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .3rem;
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  border: 1px solid var(--line);
  border-radius: .85rem; padding: .3rem;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .18);
}
[data-theme="light"] .segs { box-shadow: inset 0 1px 3px rgba(90, 70, 30, .1); }
/* Segments are navigation now: the current technique is a highlighted, non-link
   tab (.is-active); the other two are links to their dedicated pages. */
.seg { display: block; text-decoration: none; }
.seg > span {
  display: block; text-align: center; padding: .5rem .25rem;
  border-radius: .6rem; font-size: .85rem; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: background-color .18s, color .18s, box-shadow .18s;
}
a.seg:hover > span { color: var(--text); }
/* Buttons reuse the segment look for in-place toggles (the sleep sounds player). */
button.seg { border: 0; background: none; font: inherit; width: 100%; cursor: pointer; }
button.seg:hover > span { color: var(--text); }
.seg.is-active { cursor: default; }
.seg.is-active > span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); cursor: default;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent);
}
.seg:focus-visible { outline: none; }
.seg:focus-visible > span { outline: 2px solid var(--accent); outline-offset: 2px; }

.row { display: flex; align-items: end; gap: .6rem; margin-top: .7rem; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field > label, .field > .label { font-size: .78rem; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
input[type="time"], select {
  background: color-mix(in srgb, var(--surface-2) 85%, transparent); color: var(--text);
  border: 1px solid var(--line); border-radius: .7rem;
  padding: .45rem .7rem; font: inherit; font-size: 1.1rem; min-height: 2.7rem;
  transition: border-color .18s;
}
input[type="time"]:hover, select:hover { border-color: var(--line-strong); }
input[type="time"] { font-variant-numeric: tabular-nums; min-width: 9rem; }
select { font-size: 1rem; }
.btn {
  background: color-mix(in srgb, var(--surface-2) 85%, transparent); color: var(--text);
  border: 1px solid var(--line); border-radius: .7rem;
  padding: .55rem .9rem; font: inherit; font-weight: 600; cursor: pointer; min-height: 2.9rem;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 4px 18px color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-accent:hover { box-shadow: 0 6px 24px color-mix(in srgb, var(--accent) 42%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .btn, .btn:hover { transform: none; }
}

details.tune { margin-top: .7rem; border-top: 1px solid var(--line); padding-top: .5rem; }
details.tune summary {
  cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--muted);
  list-style: none; display: flex; align-items: center; gap: .4rem;
  transition: color .18s;
}
details.tune summary:hover { color: var(--text); }
details.tune summary::-webkit-details-marker { display: none; }
details.tune summary::before { content: "▸"; transition: transform .15s; }
details.tune[open] summary::before { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { details.tune summary::before { transition: none; } }
.tune-grid { display: grid; gap: .8rem; margin-top: .8rem; }
.tune-row label { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; }
.tune-row output { color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 1.6rem; }
.tune-note { font-size: .8rem; color: var(--muted); margin: 0; }

/* Results */
.results-block { margin-top: .8rem; }
/* min-heights reserve the JS-rendered content's space so the first paint
   doesn't shift when results populate (CLS). */
.results-heading { font-size: .92rem; font-weight: 650; margin: 0 0 .05rem; min-height: 1.47rem; }
.results-sub { font-size: .76rem; color: var(--muted); margin: 0 0 .45rem; min-height: 2.43rem; }
ol.results { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; min-height: 14.3rem; align-content: start; }
@media (min-width: 30rem) {
  .results-sub { min-height: 1.2rem; }
}
.opt {
  display: flex; align-items: center; gap: .85rem;
  background: color-mix(in srgb, var(--surface-2) 75%, transparent);
  border: 1px solid var(--line);
  border-radius: .85rem; padding: .45rem .85rem;
  transition: border-color .18s, transform .18s;
}
.opt:hover { border-color: var(--line-strong); transform: translateX(2px); }
@media (prefers-reduced-motion: reduce) { .opt:hover { transform: none; } }
.opt-time { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; min-width: 6rem; line-height: 1.25; }
.opt-body { display: flex; flex-direction: column; gap: .05rem; min-width: 0; line-height: 1.3; }
.opt-meta { font-size: .83rem; color: var(--muted); }
.opt-flag { font-size: .75rem; color: var(--muted); }
.opt.is-rec {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
  box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 14%, transparent);
}
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .03em;
  border-radius: .4rem; padding: .1rem .45rem; width: fit-content;
}
.badge-rec { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.opt-flag.is-min { color: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.results.animate .opt { animation: rise .35s ease both; }
.results.animate .opt:nth-child(2) { animation-delay: .05s; }
.results.animate .opt:nth-child(3) { animation-delay: .1s; }
.results.animate .opt:nth-child(4) { animation-delay: .15s; }
@media (prefers-reduced-motion: reduce) { .results.animate .opt { animation: none; } }

.share-row { display: flex; align-items: center; gap: .7rem; margin-top: .5rem; }
.share-row .btn { font-size: .8rem; min-height: 2rem; padding: .25rem .75rem; }
#copy-status { font-size: .82rem; color: var(--accent); }

/* Breathing pacer */
#pacer-form { display: none; }
html.js #pacer-form { display: block; }
.pacer-stage { margin-top: .9rem; }
.pacer-ring {
  position: relative; width: min(16rem, 68vw); aspect-ratio: 1;
  margin: 0 auto; border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  box-shadow: 0 0 70px color-mix(in srgb, var(--accent) 12%, transparent), inset 0 1px 0 var(--card-highlight);
}
.pacer-disc {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--accent) 55%, var(--surface-2)), var(--accent) 78%, var(--accent-2));
  opacity: .34; transform: scale(.55); will-change: transform;
}
.pacer-center {
  position: absolute; inset: 0; z-index: 1;
  display: grid; place-content: center; text-align: center; gap: .1rem;
}
.pacer-phase { margin: 0; font-size: 1.02rem; font-weight: 650; }
.pacer-count { margin: 0; font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); min-height: 2.5rem; }
[data-theme="light"] .pacer-count { color: var(--text); }
.pacer-phrase { text-align: center; color: var(--muted); font-size: .95rem; margin: .8rem 0 0; min-height: 1.5em; }
.pacer-progress { text-align: center; color: var(--muted); font-size: .78rem; margin: .15rem 0 0; min-height: 1.2em; font-variant-numeric: tabular-nums; }
.pacer-controls { justify-content: center; align-items: end; margin-top: .8rem; }
.pacer-begin { min-width: 8rem; }

.noscript-note {
  background: color-mix(in srgb, var(--surface-2) 85%, transparent); border: 1px solid var(--line);
  border-radius: .85rem; padding: .8rem 1rem; font-size: .9rem;
}

/* Sleep sounds player */
.noise-stage { margin-top: 1rem; }
.noise-ring {
  position: relative; width: min(15rem, 64vw); aspect-ratio: 1; margin: 0 auto;
  border-radius: 50%; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  box-shadow: 0 0 70px color-mix(in srgb, var(--accent) 10%, transparent), inset 0 1px 0 var(--card-highlight);
  display: grid; place-items: center; padding: 0; cursor: pointer; color: var(--accent-ink);
  transition: border-color .18s;
}
.noise-ring:hover { border-color: var(--line-strong); }
.noise-ring:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.noise-disc {
  width: 46%; aspect-ratio: 1; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 32%, transparent);
  display: grid; place-items: center;
}
.noise-icon { display: none; line-height: 0; }
.noise-icon-play { display: block; margin-left: 5px; } /* nudge the triangle to optical centre */
#noise-tool.is-playing .noise-icon-play { display: none; }
#noise-tool.is-playing .noise-icon-pause { display: block; }
@keyframes noisePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 28%, transparent); }
  50% { transform: scale(1.05); box-shadow: 0 8px 46px color-mix(in srgb, var(--accent) 52%, transparent); }
}
#noise-tool.is-playing .noise-disc { animation: noisePulse 4.5s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { #noise-tool.is-playing .noise-disc { animation: none; } }
.noise-status { text-align: center; font-weight: 650; margin: .95rem 0 0; }
.noise-timer { text-align: center; color: var(--muted); font-size: .82rem; margin: .15rem 0 0; min-height: 1.2em; font-variant-numeric: tabular-nums; }
.noise-controls { justify-content: center; align-items: end; margin-top: 1rem; }
.noise-vol-field { flex: 1 1 12rem; }
.noise-vol-field input[type="range"] { min-width: 10rem; }

/* Content */
main section.prose { margin-top: 3.6rem; }
main.article section.prose { margin-top: 1.6rem; }
main.article h1 { margin-top: 2rem; }
main.article .lede { margin-bottom: 0; }
h2 { font-size: 1.55rem; letter-spacing: -.015em; margin: 0 0 .7rem; }
h3 { font-size: 1.15rem; margin: 1.5rem 0 .35rem; }
.prose p, .prose li { color: var(--text); font-size: 1.05rem; }
.prose p { margin: .7rem 0; }
.prose a { color: var(--accent); text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); transition: text-decoration-color .18s; }
.prose a:hover { text-decoration-color: var(--accent); }
.prose ul { padding-left: 1.2rem; margin: .6rem 0; }
.prose li { margin: .35rem 0; }
table { border-collapse: collapse; width: 100%; margin: .8rem 0; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr.hl td { color: var(--accent); font-weight: 600; }

.disclaimer { font-size: .82rem; color: var(--muted); border-left: 3px solid color-mix(in srgb, var(--accent) 40%, var(--line)); padding-left: .8rem; }

footer.site {
  margin-top: 3.2rem; padding: 1.4rem 0 2.2rem; border-top: 1px solid var(--line);
  font-size: .84rem; color: var(--muted);
}
footer.site p { margin: .35rem 0; }
footer.site a { color: var(--muted); text-underline-offset: 3px; transition: color .18s; }
footer.site a:hover { color: var(--accent); }

@media (min-width: 30rem) {
  .tool { padding: 1.75rem; }
  main section.prose { margin-top: 4.2rem; }
}
