:root {
  --font-serif: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", Palatino, Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --ink: #1a1d23;
  --ink-muted: #5c6069;
  --paper: #f7f5f0;
  --surface: #fffefb;
  --border: #e4e0d6;
  --border-strong: #d3cdbe;

  --accent: #1c3a5e;
  --accent-soft: rgba(28, 58, 94, 0.08);
  --accent-ring: rgba(28, 58, 94, 0.14);
  --danger: #99342a;

  --btn-bg: var(--accent);
  --btn-text: var(--paper);
  --btn-bg-hover: #244a76;

  --radius: 8px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --ink: #e9e5da;
  --ink-muted: #9b9488;
  --paper: #14161a;
  --surface: #1b1e24;
  --border: #2a2d33;
  --border-strong: #3b3e46;

  --accent: #c9a646;
  --accent-soft: rgba(201, 166, 70, 0.1);
  --accent-ring: rgba(201, 166, 70, 0.18);
  --danger: #d18072;

  --btn-bg: var(--accent);
  --btn-text: #14161a;
  --btn-bg-hover: #d9b65a;
}

* { box-sizing: border-box; }

html { color-scheme: light dark; font-size: 106.25%; }
[data-theme="dark"] { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom, 0);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app-header {
  padding: 1.75rem 1rem 1.25rem;
  padding-top: calc(1.75rem + env(safe-area-inset-top, 0));
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.brand-mark {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
}

.app-header h1 {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.tagline {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.header-controls {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover { border-color: var(--border-strong); color: var(--ink); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle svg { width: 17px; height: 17px; }

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.text-size-control {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.text-size-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.text-size-btn:first-child { border-right: 1px solid var(--border); }
.text-size-btn:hover:not(:disabled) { color: var(--ink); background: var(--accent-soft); }
.text-size-btn:active:not(:disabled) { transform: translateY(1px); }
.text-size-btn:disabled { opacity: 0.35; cursor: default; }

.text-size-btn .a-small { font-size: 0.7rem; font-weight: 700; }
.text-size-btn .a-large { font-size: 1.05rem; font-weight: 700; }

.intro {
  margin-top: 1rem;
  padding: 1.15rem 1.3rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.intro-text {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--ink);
}

.intro-text strong { font-family: var(--font-serif); font-weight: 600; }

.tabs {
  display: flex;
  max-width: 680px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}

.tab {
  flex: 1;
  padding: 0.9rem 0.35rem;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.5rem 1rem 0.75rem;
}

.panel { display: none; }
.panel.active { display: block; }

.search-form { display: flex; flex-direction: column; gap: 0.65rem; }

input[type="search"], textarea, select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="search"]::placeholder, textarea::placeholder { color: var(--ink-muted); opacity: 0.8; }

input[type="search"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

textarea { resize: vertical; font-family: inherit; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235c6069' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 15px;
  padding-right: 2.25rem;
}

[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239b9488' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
}

.filter-row.two-up {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 480px) {
  .filter-row { grid-template-columns: 1fr; }
  .filter-row.two-up { grid-template-columns: 1fr; }
}

button[type="submit"] {
  padding: 0.7rem 1.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-text);
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

button[type="submit"]:hover { background: var(--btn-bg-hover); }
button[type="submit"]:active { transform: translateY(1px); }
button[type="submit"]:disabled { opacity: 0.5; cursor: default; transform: none; }

.status { min-height: 1.4rem; margin: 0.85rem 0 0.25rem; font-size: 0.95rem; color: var(--ink-muted); }
.status:empty { min-height: 0; margin: 0; }
.status.error { color: var(--danger); font-weight: 600; }

.results { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.results:empty { margin: 0; }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.15rem;
  transition: border-color 0.15s ease, background-color 0.2s ease;
}

.result-card:hover { border-color: var(--border-strong); }

.result-card h3 { margin: 0 0 0.45rem; font-family: var(--font-serif); font-size: 1.2rem; font-weight: 600; }
.result-card h3 a { color: var(--ink); text-decoration: none; }
.result-card h3 a:hover { color: var(--accent); text-decoration: underline; }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  row-gap: 0.3rem;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
}

.tag {
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag:not(:last-child)::after {
  content: "\00b7";
  margin: 0 0.5rem;
  color: var(--border-strong);
  font-weight: 400;
}

.tag.state { color: var(--accent); }

.result-card p { margin: 0; font-size: 1rem; color: var(--ink-muted); line-height: 1.55; }

.result-card.reference h3::before {
  content: "Reference";
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-right: 0.55rem;
  vertical-align: middle;
}

.news-also-covered {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-muted);
}

.answer {
  margin-top: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
}

.answer-text { line-height: 1.65; font-size: 1.05rem; }
.answer-text p { margin: 0 0 0.85rem; }
.answer-text p:last-child { margin-bottom: 0; }
.answer-text strong { color: var(--accent); font-weight: 700; }
.answer-text ul, .answer-text ol { margin: 0 0 0.85rem; padding-left: 1.3rem; }
.answer-text li { margin-bottom: 0.4rem; }
.answer-text li:last-child { margin-bottom: 0; }

.answer details { margin-top: 0.7rem; font-size: 0.95rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.answer summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.answer ul#ask-sources-list { margin: 0.5rem 0 0; padding-left: 1.1rem; color: var(--ink-muted); }
.answer ul#ask-sources-list li { margin-bottom: 0.4rem; }

.news-section {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.25rem 1rem 0;
  border-top: 1px solid var(--border);
}

.news-section-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--ink);
}

.app-footer {
  max-width: 680px;
  margin: 1.5rem auto 2rem;
  padding: 1rem 1rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--ink-muted);
  text-align: center;
}
