@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/source-sans-3-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/source-serif-4-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --bg: #f4efe6;
  --glow: rgba(141, 46, 42, 0.09);
  --ink: #1c1915;
  --muted: #5a5148;
  --card: #fffdf8;
  --line: #e4d9c8;
  --accent: #8d2e2a;
  --accent-hover: #6e221f;
  --accent-ink: #fffdf8;
  --focus: #1c1915;
  --c1: #8d2e2a;
  --c1bg: #f8e4e0;
  --c2: #7a4510;
  --c2bg: #f8edd9;
  --c3: #1d4d28;
  --c3bg: #e3f0e4;
  --rail1: #b42318;
  --rail2: #b54708;
  --rail3: #2f6b38;
  --why: #f6efe4;
  --sheen: rgba(255, 255, 255, 0.55);
  --shadow: 0 1px 2px rgba(28, 25, 21, 0.04), 0 12px 32px rgba(28, 25, 21, 0.06);
  --serif: "Source Serif 4", Georgia, "Iowan Old Style", Palatino, serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12110f;
    --glow: rgba(240, 168, 162, 0.1);
    --ink: #f3eee6;
    --muted: #c8beb2;
    --card: #1c1a17;
    --line: #3a342c;
    --accent: #f0a8a2;
    --accent-hover: #ffd4ce;
    --accent-ink: #2a1210;
    --focus: #f3eee6;
    --c1: #ffb4ac;
    --c1bg: #4a2824;
    --c2: #f0c27a;
    --c2bg: #3d2e16;
    --c3: #b7d7b4;
    --c3bg: #1c2c1e;
    --rail1: #ffb4ac;
    --rail2: #f0c27a;
    --rail3: #9dca9a;
    --why: #2a241c;
    --sheen: rgba(255, 255, 255, 0.07);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html { touch-action: manipulation; }

@media (pointer: fine) {
  html { overscroll-behavior: none; }
}

body {
  margin: 0;
  min-height: 100vh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background:
    radial-gradient(ellipse 90% 46% at 8% -12%, var(--glow), transparent 58%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

body::before {
  content: "";
  position: fixed;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--rail1), var(--rail2) 55%, var(--rail3));
  pointer-events: none;
}

::selection { background: var(--c1bg); color: var(--ink); }

.wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "intro"
    "results"
    "footer";
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 0 max(48px, env(safe-area-inset-bottom));
}

.intro { grid-area: intro; min-width: 0; }
footer { grid-area: footer; }

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

.skip:focus-visible { top: 12px; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }

button, a, input { -webkit-tap-highlight-color: transparent; }

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

h1, h2, #results { scroll-margin-top: 24px; }

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

.mark {
  width: 42px;
  height: 42px;
  color: var(--ink);
  flex: none;
}

.kicker {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 12px 0 0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 8vw, 3.4rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 0.98;
  text-wrap: balance;
  text-rendering: optimizeLegibility;
}

.lede {
  margin: 12px 0 0;
  max-width: 32em;
  color: var(--muted);
  font-size: 1.05rem;
  text-wrap: pretty;
}

form { margin-top: 24px; }

label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 650;
}

.row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.field {
  position: relative;
  flex: 1;
  min-width: 0;
}

input[type="text"] {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  padding: 0 18px;
  font: inherit;
}

input::placeholder { color: var(--muted); opacity: 1; }

input.pad-clear { padding-right: 76px; }

.field:focus-within input[type="text"] {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

button {
  font: inherit;
  cursor: pointer;
}

.primary, #clear {
  border: 0;
  border-radius: 999px;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: none;
  min-width: 6.75rem;
  height: 52px;
  padding: 0 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  transition: background-color 0.15s ease;
}

.primary:hover { background: var(--accent-hover); }

form .primary.is-busy::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--accent-ink);
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#clear {
  position: absolute;
  top: 6px;
  right: 6px;
  height: 40px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

#clear:hover { color: var(--ink); background: var(--why); }

[hidden] { display: none !important; }

.recent {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  min-height: 32px;
  padding: 4px 12px;
  font: inherit;
  font-size: 0.85rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.chip:hover { border-color: var(--ink); background: var(--bg); }

.status {
  min-height: 1.5em;
  margin: 16px 0 0;
  font-weight: 650;
  letter-spacing: -0.011em;
  text-wrap: pretty;
  font-variant-numeric: tabular-nums;
}

.status.is-error { color: var(--c1); }

.results {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
  min-width: 0;
}

.card, .note {
  background: var(--card);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 16px;
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  animation: rise 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.card { border-left-color: var(--rail, var(--line)); }
.card.c1 { --rail: var(--rail1); }
.card.c2 { --rail: var(--rail2); }
.card.c3 { --rail: var(--rail3); }

.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.08s; }
.card:nth-child(4) { animation-delay: 0.12s; }
.card:nth-child(5) { animation-delay: 0.16s; }
.card:nth-child(6) { animation-delay: 0.2s; }
.card:nth-child(n + 7) { animation-delay: 0.24s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card-top, .byline, .meta, .fact, .card h2, .note-title, .note p { margin: 0; }

.card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.byline {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.badge {
  display: inline-block;
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.badge.c1 { color: var(--c1); background: var(--c1bg); }
.badge.c2 { color: var(--c2); background: var(--c2bg); }
.badge.c3 { color: var(--c3); background: var(--c3bg); }

.when {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.card h2, .note-title {
  font-family: var(--serif);
  text-rendering: optimizeLegibility;
  text-wrap: pretty;
}

.card h2 {
  margin-top: 10px;
  font-size: 1.28rem;
  font-weight: 560;
  line-height: 1.3;
  overflow-wrap: break-word;
}

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

.clamp.open {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

.more {
  margin-top: 4px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.more:hover { color: var(--accent-hover); }

.fact { margin-top: 12px; overflow-wrap: break-word; }

.fact > span:first-child {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fact-body {
  display: block;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.45;
  text-transform: none;
}

.fact-body.clamp { display: -webkit-box; }
.fact-body.clamp.open { display: block; }

.why {
  margin-top: 14px;
  background: var(--why);
  border-radius: 12px;
  padding: 12px 14px;
}

.meta {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.note { border-left-color: var(--muted); padding: 22px 20px 18px; }

.note-title {
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-wrap: balance;
}

.note p { margin-top: 8px; max-width: 62ch; color: var(--muted); text-wrap: pretty; }
.note .primary { margin-top: 16px; }

.skeleton {
  position: relative;
  overflow: hidden;
  height: 156px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 16px;
  background-color: var(--card);
  background-image:
    linear-gradient(var(--line), var(--line)),
    linear-gradient(var(--line), var(--line)),
    linear-gradient(var(--line), var(--line)),
    linear-gradient(var(--why), var(--why));
  background-repeat: no-repeat;
  background-size: 108px 16px, 76% 16px, 92% 12px, calc(100% - 36px) 42px;
  background-position: 16px 18px, 16px 48px, 16px 76px, 16px 100px;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--sheen), transparent);
  transform: translateX(-100%);
  animation: sheen 1.3s ease-in-out infinite;
}

@keyframes sheen { to { transform: translateX(100%); } }

footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

footer p { margin: 0 0 8px; text-wrap: pretty; }
#updated { font-variant-numeric: tabular-nums; }

@media (pointer: coarse) {
  .chip { min-height: 44px; padding: 10px 14px; }
  #clear { height: 44px; top: 4px; }
  .more { min-height: 44px; }
}

@media (max-width: 959px) {
  .note .primary { width: 100%; }
}

@media (min-width: 960px) {
  .wrap {
    width: min(1120px, calc(100% - 64px));
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    column-gap: 56px;
    grid-template-areas:
      "intro results"
      "footer footer";
    align-items: start;
  }

  .results { margin-top: 0; }
  footer { margin-top: 40px; }
  .note .primary { width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
