@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Space+Grotesk:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --bg: #f4f0e7;
  --bg-deep: #e7eee5;
  --ink: #13273a;
  --muted: #596b7b;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-solid: #fffdf8;
  --line: rgba(19, 39, 58, 0.13);
  --gold: #c49a4d;
  --gold-soft: rgba(196, 154, 77, 0.16);
  --berry: #a8323b;
  --berry-soft: rgba(168, 50, 59, 0.1);
  --navy: #0b2136;
  --green: #326c51;
  --shadow: 0 24px 65px rgba(13, 34, 54, 0.12);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 15px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071525;
  --bg-deep: #04101d;
  --ink: #edf4fb;
  --muted: #9db0c3;
  --panel: rgba(10, 27, 45, 0.82);
  --panel-solid: #0c2034;
  --line: rgba(170, 197, 222, 0.16);
  --gold: #dfbd77;
  --gold-soft: rgba(223, 189, 119, 0.13);
  --berry: #e7868d;
  --berry-soft: rgba(231, 134, 141, 0.12);
  --navy: #071525;
  --green: #7ec59b;
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(168, 50, 59, 0.13), transparent 31rem),
    radial-gradient(circle at 91% 12%, rgba(196, 154, 77, 0.15), transparent 27rem),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: linear-gradient(180deg, black, transparent 80%);
}

a { color: inherit; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .8rem 1rem; border-radius: 999px; color: white; background: var(--berry); text-decoration: none; }
.skip-link:focus { top: 1rem; }

.site-header { position: sticky; top: 0; z-index: 50; padding: .75rem 1rem 0; }
.nav-shell {
  width: min(1180px, 100%);
  min-height: 74px;
  margin: 0 auto;
  padding: .75rem .8rem .75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--navy) 88%, transparent);
  color: #eef4fa;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand { display: inline-flex; align-items: center; gap: .75rem; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(223,189,119,.38); border-radius: 50%; background: rgba(223,189,119,.1); color: #f1d39a; font-family: "Fraunces", Georgia, serif; font-size: .9rem; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: "Fraunces", Georgia, serif; font-size: 1.05rem; white-space: nowrap; }
.brand small { margin-top: .08rem; color: #a8b8c8; font-size: .72rem; }
.nav-actions { display: flex; align-items: center; gap: .35rem; }
.nav-actions a, .theme-toggle { min-height: 42px; padding: .7rem .9rem; border: 1px solid transparent; border-radius: 999px; background: transparent; color: inherit; text-decoration: none; cursor: pointer; }
.nav-actions a:hover, .nav-actions a:focus-visible, .theme-toggle:hover, .theme-toggle:focus-visible { border-color: rgba(255,255,255,.14); background: rgba(255,255,255,.06); outline: none; }
.nav-count { display: inline-grid; place-items: center; min-width: 1.45rem; height: 1.45rem; margin-left: .3rem; border-radius: 999px; background: rgba(223,189,119,.17); color: #f1d39a; font-size: .72rem; }

main, .site-footer { width: min(1180px, calc(100% - 2rem)); margin-inline: auto; }
.hero { min-height: 640px; padding: clamp(4.2rem, 10vw, 8.8rem) 0 clamp(3.8rem, 7vw, 6.5rem); display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr); align-items: center; gap: clamp(2rem, 7vw, 6rem); }
.eyebrow { display: inline-flex; align-items: center; gap: .55rem; color: var(--berry); font-size: .78rem; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
.eyebrow::before { content: ""; width: 2.2rem; height: 1px; background: currentColor; }
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; }
h1 { max-width: 790px; margin: .85rem 0 1.15rem; font-size: clamp(3.7rem, 8.8vw, 7.6rem); line-height: .89; letter-spacing: -.055em; }
.hero-copy > p { max-width: 650px; margin: 0; color: var(--muted); font-size: clamp(1rem, 1.8vw, 1.18rem); line-height: 1.75; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.8rem; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: .8rem 1.1rem; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--panel); font-weight: 700; text-decoration: none; cursor: pointer; transition: transform 160ms ease, border-color 160ms ease, background 160ms ease; }
.button:hover:not(:disabled), .button:focus-visible:not(:disabled) { transform: translateY(-2px); border-color: color-mix(in srgb, var(--gold) 55%, var(--line)); outline: none; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { border-color: rgba(223,189,119,.28); background: var(--navy); color: #f4f7fb; box-shadow: 0 16px 35px rgba(7,21,37,.16); }
.button-secondary { background: var(--panel); }
.hero-card { position: relative; min-height: 445px; padding: 1.35rem; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: var(--radius-xl); background: radial-gradient(circle at 52% 36%, var(--gold-soft), transparent 44%), var(--panel); box-shadow: var(--shadow); }
.hero-orbit { position: relative; width: min(340px, 100%); aspect-ratio: 1; margin: 0 auto; border: 1px solid var(--line); border-radius: 50%; }
.hero-orbit::before, .hero-orbit::after { content: ""; position: absolute; inset: 18%; border: 1px solid var(--line); border-radius: 50%; }
.hero-orbit::after { inset: 37%; background: var(--navy); box-shadow: 0 0 0 12px var(--gold-soft); }
.hero-orbit span { position: absolute; z-index: 2; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-solid); color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.hero-orbit span:nth-child(1) { top: 5%; left: 50%; transform: translateX(-50%); }
.hero-orbit span:nth-child(2) { right: -1%; top: 55%; }
.hero-orbit span:nth-child(3) { left: 0; top: 55%; }
.hero-orbit i { position: absolute; z-index: 3; left: 50%; top: 50%; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 22px 9px var(--gold-soft); transform: translate(-50%, -50%); }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 1rem 0 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--line); }
.hero-stats div { padding: .85rem; background: var(--panel-solid); }
.hero-stats dt { font-family: "Fraunces", Georgia, serif; font-size: 1.45rem; font-weight: 700; }
.hero-stats dd { margin: .2rem 0 0; color: var(--muted); font-size: .7rem; line-height: 1.35; }

.principles, .library, .saved-section { padding: clamp(4.5rem, 8vw, 7rem) 0; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.section-heading.compact { display: block; }
.section-heading h2 { max-width: 780px; margin: .65rem 0 0; font-size: clamp(2.2rem, 5vw, 4.4rem); line-height: .98; letter-spacing: -.035em; }
.section-heading > p { max-width: 440px; margin: 0; color: var(--muted); line-height: 1.65; }
.principle-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-top: 2rem; }
.principle-grid article { min-height: 230px; padding: 1.2rem; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: 0 14px 35px rgba(13,34,54,.06); }
.principle-grid article > span { color: var(--gold); font-size: .75rem; font-weight: 700; }
.principle-grid h3 { margin: 3.1rem 0 .55rem; font-size: 1.35rem; }
.principle-grid p { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.6; }

.filter-panel { display: grid; grid-template-columns: minmax(260px, 1.4fr) minmax(180px, .75fr) minmax(210px, 1fr) auto; gap: .75rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: var(--shadow); }
.filter-panel label { display: grid; gap: .4rem; }
.filter-panel label > span { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.filter-panel input, .filter-panel select { width: 100%; min-height: 48px; padding: .75rem .85rem; border: 1px solid var(--line); border-radius: 12px; outline: none; color: var(--ink); background: var(--panel-solid); }
.filter-panel input:focus, .filter-panel select:focus { border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); box-shadow: 0 0 0 4px var(--gold-soft); }
.filter-actions { align-self: end; display: flex; align-items: center; gap: .45rem; }
.filter-actions .button { min-height: 48px; white-space: nowrap; }
.filter-actions .button[aria-pressed="true"] { border-color: var(--berry); background: var(--berry-soft); color: var(--berry); }
.text-button { min-height: 44px; padding: .65rem .45rem; border: 0; color: var(--muted); background: transparent; cursor: pointer; text-decoration: underline; text-underline-offset: .18em; }
.text-button:disabled { opacity: .45; cursor: not-allowed; }
.results-toolbar { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .88rem; }
.results-toolbar p { margin: 0; }
.live-indicator { display: inline-flex; align-items: center; gap: .45rem; }
.live-indicator i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 14%, transparent); }
.habit-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.habit-card { min-height: 270px; padding: 1.15rem; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: 0 16px 38px rgba(13,34,54,.07); transition: transform 180ms ease, border-color 180ms ease; }
.habit-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--gold) 48%, var(--line)); }
.habit-card.is-highlighted { animation: highlight-card 1.3s ease; }
@keyframes highlight-card { 0%,100% { box-shadow: 0 16px 38px rgba(13,34,54,.07); } 35% { box-shadow: 0 0 0 5px var(--gold-soft), 0 20px 42px rgba(13,34,54,.15); } }
.card-meta { display: flex; flex-wrap: wrap; gap: .4rem; }
.habit-tag, .strategy-tag { display: inline-flex; padding: .38rem .55rem; border-radius: 999px; font-size: .66rem; font-weight: 700; line-height: 1.15; }
.habit-tag { border: 1px solid color-mix(in srgb, var(--berry) 28%, transparent); background: var(--berry-soft); color: var(--berry); }
.strategy-tag { border: 1px solid var(--line); color: var(--muted); }
.habit-example { margin: 1.25rem 0 1.4rem; white-space: pre-line; line-height: 1.66; }
.save-button { display: inline-flex; align-items: center; gap: .42rem; align-self: flex-start; margin-top: auto; padding: .55rem .72rem; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; }
.save-button:hover, .save-button:focus-visible { border-color: var(--gold); color: var(--ink); outline: none; }
.save-button[aria-pressed="true"] { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); background: color-mix(in srgb, var(--green) 11%, transparent); color: var(--green); }
.loading-card, .saved-empty, .load-error, .empty-state { padding: 1.3rem; border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--panel); color: var(--muted); }
.loading-card, .saved-empty { display: flex; align-items: center; gap: 1rem; }
.loading-card strong, .saved-empty strong, .load-error strong { color: var(--ink); }
.loading-card p, .saved-empty p, .load-error p { margin: .25rem 0 0; }
.loading-mark { width: 32px; height: 32px; flex: 0 0 auto; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { padding: 3.2rem 1.2rem; text-align: center; }
.empty-state > span { display: block; color: var(--gold); font-size: 2rem; }
.empty-state h3 { margin: .7rem 0 .35rem; color: var(--ink); font-size: 1.5rem; }
.empty-state p { margin: 0 0 1rem; }
.load-error { text-align: center; }
.load-error .button { margin-top: .5rem; }
.pagination { margin-top: 1.25rem; display: flex; justify-content: center; align-items: center; gap: .8rem; }
.pagination span { min-width: 8rem; color: var(--muted); font-size: .85rem; text-align: center; }

.saved-section { min-height: 400px; }
.saved-empty > span { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; color: var(--gold); font-size: 1.35rem; }
.saved-list { display: grid; gap: .65rem; }
.saved-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); }
.saved-item p { margin: 0; line-height: 1.55; }
.saved-item small { display: block; margin-top: .45rem; color: var(--muted); }
.saved-item button { align-self: start; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: .16em; }
.site-footer { margin-top: 2rem; padding: 2rem 0 3rem; display: flex; justify-content: space-between; gap: 2rem; border-top: 1px solid var(--line); color: var(--muted); }
.site-footer strong { color: var(--ink); font-family: "Fraunces", Georgia, serif; }
.site-footer p { max-width: 650px; margin: .35rem 0 0; line-height: 1.55; }
.footer-links { display: flex; align-items: flex-start; flex-wrap: wrap; gap: .8rem; }
.footer-links a { text-underline-offset: .2em; }

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .hero-card { width: min(560px, 100%); }
  .principle-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-actions { align-self: end; }
  .habit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .site-header { padding: .45rem .45rem 0; }
  .nav-shell { min-height: 64px; padding: .55rem .6rem; border-radius: 22px; }
  .brand small, .nav-actions > a:first-child, .theme-toggle #themeLabel { display: none; }
  .nav-actions a, .theme-toggle { min-height: 40px; padding: .55rem .65rem; }
  main, .site-footer { width: min(100% - 1rem, 1180px); }
  .hero { padding-top: 4.8rem; }
  h1 { font-size: clamp(3.45rem, 18vw, 5.6rem); }
  .section-heading { align-items: flex-start; flex-direction: column; gap: .8rem; }
  .principle-grid, .habit-grid, .filter-panel { grid-template-columns: 1fr; }
  .principle-grid article { min-height: 190px; }
  .principle-grid h3 { margin-top: 2rem; }
  .filter-actions { justify-content: space-between; }
  .results-toolbar { align-items: flex-start; flex-direction: column; padding: 1rem 0; }
  .habit-card { min-height: 0; }
  .site-footer { flex-direction: column; }
}

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