:root {
  color-scheme: light;
  --bg: #f3eee4;
  --bg-raise: #e7dfd0;
  --ink: #211c16;
  --muted: #5c5348;
  --line: #ddd3c3;
  --card: #fffcf7;
  --brass: #8a4b0c;
  --brass-fill: #d4923a;
  --chip: #efe6d6;
  --bad: #8f2d12;
  --shadow: 0 1px 0 rgba(33, 28, 22, 0.04), 0 14px 34px rgba(70, 48, 16, 0.06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --note: #8a6a32;
  --link: #1f6f62;
  --quote: #8a4b0c;
  --spark: #9a3f24;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #100e0c;
  --bg-raise: #1a1612;
  --ink: #f6efe4;
  --muted: #cbbba6;
  --line: #3a322a;
  --card: #1c1814;
  --brass: #f0c27a;
  --brass-fill: #e4a04a;
  --chip: #2a241c;
  --bad: #ffb4a2;
  --shadow: 0 1px 0 rgba(255, 236, 210, 0.04), 0 18px 40px rgba(0, 0, 0, 0.35);
  --note: #e4c98a;
  --link: #8fd0c0;
  --quote: #f0c27a;
  --spark: #f0a36a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #100e0c;
    --bg-raise: #1a1612;
    --ink: #f6efe4;
    --muted: #cbbba6;
    --line: #3a322a;
    --card: #1c1814;
    --brass: #f0c27a;
    --brass-fill: #e4a04a;
    --chip: #2a241c;
    --bad: #ffb4a2;
    --shadow: 0 1px 0 rgba(255, 236, 210, 0.04), 0 18px 40px rgba(0, 0, 0, 0.35);
    --note: #e4c98a;
    --link: #8fd0c0;
    --quote: #f0c27a;
    --spark: #f0a36a;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, color-mix(in srgb, var(--brass-fill) 22%, transparent), transparent 55%),
    var(--bg);
}

body::before {
  content: "";
  display: block;
  height: 4px;
  background: linear-gradient(90deg, var(--brass-fill), color-mix(in srgb, var(--brass-fill) 15%, transparent));
}

.wrap {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--card);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}

.skip:focus { top: 12px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em; text-wrap: balance; }

h1 { font-size: 2rem; line-height: 1.05; margin: 0; }

h2 { font-size: 1.35rem; line-height: 1.2; margin: 0; }

h3 { font-size: 1.15rem; line-height: 1.25; margin: 0; }

p { margin: 0; }

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  font-weight: 700;
}

.top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px 28px;
  align-items: center;
}

.brand { display: flex; gap: 12px; align-items: center; }

.mark { width: 42px; height: 42px; flex: none; }

.lede { color: var(--muted); max-width: 42ch; }

.actions, .composer-actions, .card-actions, .filters, .tag-row, .type-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button, input, textarea { font: inherit; color: inherit; }

button, .btn { cursor: pointer; }

.btn, .chip, .tag, .text-btn {
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 8px 14px;
}

.btn.primary {
  background: var(--brass-fill);
  border-color: transparent;
  color: #1c1712;
  font-weight: 700;
}

.btn.primary:hover { filter: brightness(1.05); }

.chip[aria-pressed="true"], .tag[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: transparent;
}

.file { display: inline-flex; align-items: center; }

.file:focus-within, .type-pick label:focus-within {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.composer {
  display: grid;
  gap: 12px;
  margin-top: 22px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.composer[hidden], .empty[hidden], .tag-row[hidden] { display: none; }

.composer-head, .toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.ask form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.type-pick {
  border: 0;
  margin: 0;
  padding: 0;
}

.type-pick legend {
  width: 100%;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.type-pick label {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}

.type-pick input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.type-pick label:has(input:checked) {
  background: var(--ink);
  color: var(--bg);
  border-color: transparent;
}

.field { display: grid; gap: 6px; min-width: 0; }

.field span, .count, .hint, .meta, .card-link { color: var(--muted); font-size: 0.85rem; }

input, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
}

textarea { resize: vertical; min-height: 96px; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-error { color: var(--bad); font-size: 0.92rem; }

.form-error:empty { display: none; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
  margin-top: 22px;
}

.cabinet { min-width: 0; }

.toolbar { margin-bottom: 12px; }

.search { flex: 1; min-width: 0; }

.count { margin: 0; white-space: nowrap; }

.filters { margin-bottom: 10px; }

.tag-row { margin-bottom: 14px; }

.tag {
  background: var(--chip);
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--note);
  border-radius: 16px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card[data-type="link"] { border-left-color: var(--link); }
.card[data-type="quote"] { border-left-color: var(--quote); }
.card[data-type="spark"] { border-left-color: var(--spark); }

.card:hover {
  border-top-color: color-mix(in srgb, var(--brass) 55%, var(--line));
  border-right-color: color-mix(in srgb, var(--brass) 55%, var(--line));
  border-bottom-color: color-mix(in srgb, var(--brass) 55%, var(--line));
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
}

.card[data-type="note"] .kind { color: var(--note); }
.card[data-type="link"] .kind { color: var(--link); }
.card[data-type="quote"] .kind { color: var(--quote); }
.card[data-type="spark"] .kind { color: var(--spark); }

.card-body {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card[data-type="quote"] .card-body {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.08rem;
  line-height: 1.4;
}

.card-link {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.card-tags span {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--chip);
  border-radius: 999px;
  padding: 2px 8px;
}

.card-actions { margin-top: auto; }

.text-btn {
  background: transparent;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.text-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--brass-fill) 28%, var(--card));
  border-color: var(--brass);
}

.text-btn.confirm {
  background: #8f2d12;
  border-color: transparent;
  color: #fffdf8;
  font-weight: 700;
}

.empty {
  padding: 36px 8px 12px;
  color: var(--muted);
  display: grid;
  gap: 10px;
  justify-items: start;
  max-width: 42ch;
}

.ask {
  position: sticky;
  top: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}

.ask form { align-items: stretch; }

.ask form input { min-width: 0; }

.ask .hint { margin-bottom: 4px; }

.answer { display: grid; gap: 10px; margin-top: 8px; }

.answer ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.answer li {
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 4px;
}

.answer strong { font-family: var(--serif); font-size: 1.02rem; }

.ask-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kicker {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
  font-weight: 700;
}

mark {
  background: color-mix(in srgb, var(--brass-fill) 42%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 10px 16px;
  max-width: min(420px, calc(100% - 32px));
  box-shadow: var(--shadow);
  z-index: 6;
}

.toast:empty { display: none; }

.noscript {
  width: min(1120px, calc(100% - 32px));
  margin: 12px auto;
  color: var(--bad);
}

@media (max-width: 860px) {
  .top, .layout, .row { grid-template-columns: 1fr; }
  .ask { position: static; }
  .lede { max-width: none; }
}

@media (max-width: 420px) {
  .wrap { width: min(1120px, calc(100% - 24px)); }
  h1 { font-size: 1.7rem; }
  .toolbar { align-items: stretch; flex-direction: column; }
}

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