/* Life 101 — one stylesheet, no framework. */

:root {
  --bg:        #faf7f2;
  --bg-raised: #ffffff;
  --ink:       #1c1a17;
  --ink-soft:  #55504a;
  --ink-faint: #8b847b;
  --rule:      #e6ded1;
  --accent:    #b4451f;
  --accent-soft:#fdefe7;
  --mark:      #ffe9a8;
  --shadow:    0 1px 2px rgba(28,26,23,.05), 0 6px 18px -10px rgba(28,26,23,.18);
  --radius:    14px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html { color-scheme: light; }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg:        #14120f;
    --bg-raised: #1e1b17;
    --ink:       #f0ebe3;
    --ink-soft:  #b6ada1;
    --ink-faint: #857c70;
    --rule:      #322d26;
    --accent:    #ff9166;
    --accent-soft:#33231b;
    --mark:      #5d4a15;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 22px -12px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}

html[data-theme="dark"] {
  --bg:        #14120f;
  --bg-raised: #1e1b17;
  --ink:       #f0ebe3;
  --ink-soft:  #b6ada1;
  --ink-faint: #857c70;
  --rule:      #322d26;
  --accent:    #ff9166;
  --accent-soft:#33231b;
  --mark:      #5d4a15;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 22px -12px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

.wrap { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 50;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------- masthead ---------- */

.masthead {
  padding: clamp(3rem, 9vw, 6rem) 0 clamp(2rem, 5vw, 3rem);
  border-bottom: 1px solid var(--rule);
  position: relative;
}
.masthead .wrap { position: relative; }

.kicker {
  font-family: var(--sans);
  font-size: .78rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 1.1rem;
}

h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2.1rem, 6.2vw, 4rem);
  line-height: 1.05;
  letter-spacing: -.02em;
  margin: 0 0 1.4rem;
  max-width: 20ch;
}

.lede {
  font-size: clamp(1rem, 2.2vw, 1.18rem);
  color: var(--ink-soft);
  max-width: 56ch;
  margin: 0;
}
.lede em { color: var(--ink); font-style: italic; }

.count {
  display: inline-block;
  margin-left: .35rem;
  color: var(--ink-faint);
  font-size: .95em;
}

.theme {
  position: absolute; top: 0; right: 0;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  width: 38px; height: 38px;
  border-radius: 999px;
  display: grid; place-items: center;
  cursor: pointer;
}
.theme:hover { color: var(--accent); border-color: var(--accent); }
.theme .moon { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme .sun { display: none; }
  html:not([data-theme="light"]) .theme .moon { display: block; }
}
html[data-theme="dark"] .theme .sun { display: none; }
html[data-theme="dark"] .theme .moon { display: block; }
html[data-theme="light"] .theme .sun { display: block; }
html[data-theme="light"] .theme .moon { display: none; }

/* ---------- toolbar ---------- */

.toolbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--rule);
  padding: .8rem 0 .7rem;
}

.searchrow { display: flex; gap: .6rem; align-items: center; }

.searchbox {
  flex: 1;
  display: flex; align-items: center; gap: .55rem;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: .5rem .95rem;
  color: var(--ink-faint);
}
.searchbox:focus-within { border-color: var(--accent); color: var(--accent); }
.searchbox input {
  flex: 1; border: 0; background: none; outline: none;
  font: inherit; color: var(--ink); min-width: 0;
}
.searchbox input::-webkit-search-cancel-button { display: none; }
.clear {
  border: 0; background: none; color: var(--ink-faint);
  font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 .2rem;
}
.clear:hover { color: var(--accent); }

.dice {
  border: 1px solid var(--rule);
  background: var(--bg-raised);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: .5rem 1rem;
  font: inherit; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.dice:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 620px) { .dice span { display: none; } }

.chips {
  display: flex; gap: .4rem;
  margin-top: .7rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: .15rem;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: .3rem .8rem;
  font: inherit; font-size: .87rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip .n { color: var(--ink-faint); font-variant-numeric: tabular-nums; margin-left: .3rem; font-size: .92em; }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.chip[aria-pressed="true"] .n { color: color-mix(in srgb, var(--bg) 70%, transparent); }

/* ---------- list ---------- */

main { padding: 2rem 0 4rem; }

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
  scroll-margin-top: 8.5rem;
  position: relative;
  display: flex;
  flex-direction: column;
}

.card.hit {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}

.card .meta {
  display: flex; align-items: center; gap: .4rem;
  font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
  font-weight: 600; color: var(--ink-faint);
  margin-bottom: .55rem;
}
.card .meta .cat { cursor: pointer; background: none; border: 0; font: inherit; color: inherit; padding: 0; letter-spacing: inherit; }
.card .meta .cat:hover { color: var(--accent); }

.card h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.14rem;
  line-height: 1.28;
  letter-spacing: -.01em;
  margin: 0 0 .6rem;
}

.card p {
  margin: 0;
  color: var(--ink-soft);
  font-size: .935rem;
  line-height: 1.62;
}

.card .link {
  position: absolute; top: .85rem; right: .9rem;
  border: 0; background: none; cursor: pointer;
  color: var(--ink-faint); opacity: 0; transition: opacity .15s;
  font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 600;
  padding: .1rem .2rem;
}
.card:hover .link, .card:focus-within .link { opacity: 1; }
.card .link:hover { color: var(--accent); }

mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .1em; }

.empty { text-align: center; color: var(--ink-soft); padding: 4rem 0; }
.empty button {
  border: 0; background: none; color: var(--accent);
  font: inherit; text-decoration: underline; cursor: pointer;
}

/* ---------- footer ---------- */

.foot {
  border-top: 1px solid var(--rule);
  padding: 2.5rem 0 3.5rem;
  color: var(--ink-soft);
  font-size: .9rem;
}
.foot p { margin: 0 0 .7rem; max-width: 62ch; }
.foot .fine { color: var(--ink-faint); font-size: .82rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
