:root {
  color-scheme: light;
  --bg: #f2f4f1;
  --surface: #ffffff;
  --ink: #17201b;
  --muted: #5e6a62;
  --line: #d5dcd6;
  --pine: #1f3b2f;
  --needle: #3f6a52;
  --resin: #a86f17;
  --resin-ink: #ffffff;
  --warn-bg: #fbf3e2;
  --warn-line: #e3c98f;
  --err: #a3342a;
  --ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --read: "Literata", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111813;
    --surface: #18211c;
    --ink: #e4eae5;
    --muted: #9aa69e;
    --line: #2c3a32;
    --pine: #16291f;
    --needle: #7fb093;
    --resin: #d9a043;
    --resin-ink: #1a1206;
    --warn-bg: #2a2416;
    --warn-line: #5c4a22;
    --err: #ef8a7e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111813; --surface: #18211c; --ink: #e4eae5; --muted: #9aa69e; --line: #2c3a32;
  --pine: #16291f; --needle: #7fb093; --resin: #d9a043; --resin-ink: #1a1206;
  --warn-bg: #2a2416; --warn-line: #5c4a22; --err: #ef8a7e;
}

* { box-sizing: border-box; }
:root {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--ui);
}
a { color: var(--needle); text-underline-offset: 0.15em; }
:focus-visible { outline: 3px solid var(--resin); outline-offset: 2px; }
h1, h2 { font-family: var(--read); font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.75rem; margin: 0.25rem 0 0.5rem; }
h2 { font-size: 1.25rem; margin: 2.25rem 0 0.75rem; }
code { font-size: 0.9em; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.err { color: var(--err); }

.bar {
  background: var(--pine);
  color: #eef3ef;
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem;
  align-items: center; justify-content: space-between;
  padding: 0.85rem clamp(1rem, 4vw, 2.5rem);
}
.bar a { color: inherit; text-decoration: none; }
.brand { font-family: var(--read); font-size: 1.15rem; font-weight: 600; }
.bar nav { display: flex; gap: 1.25rem; align-items: center; }
.bar nav a:hover, .bar .link:hover { text-decoration: underline; }
.bar .link { color: #eef3ef; }

main { max-width: 52rem; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 4rem; }
main.wide { max-width: 82rem; }
main.narrow { max-width: 26rem; }

button {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 0.55rem 1.1rem;
  border: 1px solid transparent; min-height: 2.75rem;
}
button.primary { background: var(--resin); color: var(--resin-ink); font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.secondary:hover { border-color: var(--needle); }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--needle); text-decoration: underline; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.55rem 0.7rem; width: 100%;
}
textarea { line-height: 1.45; resize: vertical; }
#description { font-family: var(--read); font-size: 0.95rem; }
label { font-weight: 700; display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.stack { display: grid; gap: 0.5rem; }
.stack label:not(:first-child) { margin-top: 0.75rem; }
.count { font-weight: 400; color: var(--muted); font-size: 0.875rem; }
.count.over { color: var(--err); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1rem; }
.actions.spaced { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
form.inline { display: inline-flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0.75rem 0 0; }
form.inline input[type=file] { width: auto; }

.flash {
  background: var(--surface); border-left: 4px solid var(--needle);
  padding: 0.75rem 1rem; margin: 0 0 1.5rem; border-radius: 0 6px 6px 0;
}
.status p { margin: 0 0 0.35rem; }

.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rows li { border-bottom: 1px solid var(--line); }
.rows a {
  display: grid; grid-template-columns: 7.5rem 1fr auto; gap: 0.25rem 1rem;
  align-items: baseline; padding: 0.85rem 0.25rem; color: var(--ink); text-decoration: none;
}
.rows a:hover strong { text-decoration: underline; }
.when { color: var(--muted); font-variant-numeric: tabular-nums; }
.what { display: grid; gap: 0.15rem; min-width: 0; }
.what small { color: var(--muted); }
.kind { font-size: 0.85rem; padding: 0.1rem 0.55rem; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.kind-sunday { border-color: var(--needle); color: var(--needle); }
.kind-wotd { border-color: var(--resin); color: var(--resin); }
.empty { color: var(--muted); }
@media (max-width: 34rem) {
  .rows a { grid-template-columns: 1fr auto; }
  .when { grid-column: 1 / -1; font-size: 0.875rem; }
}

.addform { display: grid; grid-template-columns: 1fr 14rem auto; gap: 0.4rem 0.75rem; align-items: end; }
.addform label { grid-row: 1; }
.addform input, .addform select, .addform button { grid-row: 2; }
@media (max-width: 40rem) {
  .addform { grid-template-columns: 1fr; }
  .addform label, .addform input, .addform select, .addform button { grid-row: auto; }
}

.notes { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; padding: 0.25rem 1.25rem 0.75rem; margin: 1.25rem 0; }
.notes h2 { margin-top: 0.75rem; font-size: 1.05rem; }
.notes ul { margin: 0; padding-left: 1.1rem; }
.notes li { margin: 0.3rem 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.25rem 1.25rem 1.25rem; }
.crumbs { margin: 0; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2.5rem; align-items: start; margin-top: 1.5rem; }
.preview {
  position: sticky; top: 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.25rem 1.5rem 1rem; max-height: calc(100vh - 2rem); overflow: auto;
}
.preview h2 { font-family: var(--ui); font-size: 0.95rem; color: var(--muted); font-weight: 700; margin: 1rem 0 0.75rem; }
.pv-title { font-family: var(--ui); font-weight: 700; font-size: 1.15rem; margin: 0 0 0.75rem; }
.pv-body { font-family: var(--read); font-size: 0.95rem; line-height: 1.6; overflow-wrap: anywhere; max-width: 68ch; }
.pv-body a { color: var(--needle); }
.hashtag { color: var(--needle); }
@media (max-width: 62rem) {
  .editor { grid-template-columns: 1fr; }
  .preview { position: static; max-height: none; }
}

.plist { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.plist th, .plist td { text-align: left; padding: 0.6rem 0.75rem 0.6rem 0; border-bottom: 1px solid var(--line); }
.plist th { color: var(--muted); font-weight: 700; }

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