:root {
  --bg: #e6e0d3;
  --ink: #2b2926;
  --ink-soft: #4a453d;
  --muted: #6b655c;
  --muted-2: #7a7263;
  --faint: #9b917f;
  --overline: #a1957d;

  --surface: #f5f2ea;
  --surface-2: #fbf9f3;
  --card: #fffdf8;

  --header: #2f2b28;
  --header-ink: #f0ebe0;
  --header-kicker: #b7a888;

  --gold: #8a6d3b;
  --gold-hi: #6e5528;
  --gold-bright: #c9a24b;

  --trusted: #3f6b4f;
  --trusted-accent: #4f7a5a;
  --trusted-bg: #e6efe4;
  --avoid: #8a3a34;
  --avoid-accent: #a34a44;
  --avoid-bg: #f3e2df;

  --star: #b98a2e;
  --star-empty: #e2d8c2;

  --line: #ddd4c2;
  --line-soft: #e6ddca;
  --line-card: #e7dece;
  --field-border: #d9cfb8;
  --footer-line: #e0d7c4;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  font-family: 'Karla', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-hi); }

/* ---------- Password gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, #2f2b28 0%, #211d1b 100%);
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.7);
  padding: 40px 40px 36px;
  text-align: center;
}
.gate-card .crest { margin-bottom: 14px; }
.gate-word {
  font-family: 'Libre Caslon Text', serif;
  font-size: 28px;
  letter-spacing: 0.02em;
  color: var(--ink);
  line-height: 1;
}
.gate-kicker {
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--overline);
  margin-top: 7px;
}
.gate-lede {
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
  margin: 22px 0 24px;
  text-wrap: pretty;
}
.gate-form { display: flex; flex-direction: column; gap: 12px; }
.gate-form input {
  background: #fff;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  padding: 12px 14px;
  font: 15px 'Karla', sans-serif;
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.08em;
}
.gate-form input::placeholder { color: #a49b8a; letter-spacing: normal; }
.gate-form input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(138, 109, 59, 0.12);
}
.gate-form .btn-primary { width: 100%; }
.gate-error {
  margin: 16px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--avoid);
}
.gate.shake .gate-card { animation: gate-shake 0.4s ease; }
@keyframes gate-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
@media (prefers-reduced-motion: reduce) {
  .gate.shake .gate-card { animation: none; }
}
/* Protected content stays hidden until the gate is cleared. */
.page { display: none; }
body.unlocked .gate { display: none; }
body.unlocked .page { display: flex; }
/* Returning resident (password already stored): never paint the gate. */
html.resuming .gate { display: none; }

.page {
  min-height: 100vh;
  padding: 56px 24px 96px;
  background: radial-gradient(circle at 50% 0%, #ece7db 0%, #e2dccd 100%);
  justify-content: center;
}

.shell {
  width: 100%;
  max-width: 1040px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 24px 60px -30px rgba(43, 41, 38, 0.5);
  overflow: hidden;
}

/* ---------- Masthead ---------- */
.masthead {
  background: var(--header);
  color: var(--header-ink);
  padding: 22px 44px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.crest { flex-shrink: 0; }
.masthead-title { flex: 1; min-width: 0; }
.wordmark {
  font-family: 'Libre Caslon Text', serif;
  font-size: 27px;
  letter-spacing: 0.02em;
  line-height: 1;
}
.kicker {
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--header-kicker);
  margin-top: 6px;
}
.mainnav {
  display: flex;
  align-items: center;
  gap: 30px;
  font-size: 14.5px;
  letter-spacing: 0.02em;
}
.navlink {
  color: #b0a48c;
  padding-bottom: 3px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease;
}
.navlink:hover { color: var(--header-ink); }
.navlink.is-active {
  color: var(--header-ink);
  border-bottom-color: var(--gold-bright);
}

/* ---------- Views ---------- */
.view { display: block; }

/* ---------- Hero ---------- */
.hero {
  padding: 38px 44px 30px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.hero-title {
  margin: 0;
  font-family: 'Libre Caslon Text', serif;
  font-weight: 400;
  font-size: 34px;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.hero-lede {
  margin: 10px 0 24px;
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 620px;
  text-wrap: pretty;
}
.hero-controls {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}
.searchbox {
  flex: 1;
  min-width: 260px;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  padding: 11px 15px;
}
.searchbox:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(138, 109, 59, 0.12);
}
.searchbox svg { flex-shrink: 0; }
.searchbox input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font: 15px 'Karla', sans-serif;
  color: var(--ink);
}
.searchbox input::placeholder { color: #a49b8a; }
.tally { font-size: 13px; color: #8a8375; white-space: nowrap; }
.tally .n-trusted { color: var(--trusted); }
.tally .n-avoid { color: var(--avoid); }

/* ---------- Category chips ---------- */
.chips {
  padding: 20px 44px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line-soft);
}
.chip {
  font: 13.5px 'Karla', sans-serif;
  color: var(--ink-soft);
  background: #efe9dc;
  border: 1px solid var(--footer-line);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.chip:hover { background: #e7e0d0; }
.chip.is-on {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--surface);
  background: var(--header);
  border-color: var(--header);
}

/* ---------- Provider grid ---------- */
.grid {
  padding: 32px 44px 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line-card);
  border-left: 3px solid var(--trusted-accent);
  border-radius: 5px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.is-avoid { border-left-color: var(--avoid-accent); }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.card-overline {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--overline);
  margin-bottom: 5px;
}
.card-name {
  font-family: 'Libre Caslon Text', serif;
  font-size: 20px;
  line-height: 1.15;
  color: var(--ink);
}
.card-trade { font-size: 13.5px; color: var(--muted-2); margin-top: 3px; }

.badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 600 12.5px 'Karla', sans-serif;
  letter-spacing: 0.02em;
  padding: 5px 11px;
  border-radius: 20px;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.trusted { color: var(--trusted); background: var(--trusted-bg); }
.badge.avoid { color: var(--avoid); background: var(--avoid-bg); }

.rating { display: flex; align-items: center; gap: 9px; }
.stars {
  position: relative;
  display: inline-block;
  font-size: 16px;
  letter-spacing: 2px;
  line-height: 1;
}
.stars .stars-empty { color: var(--star-empty); }
.stars .stars-fill {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  white-space: nowrap;
  color: var(--star);
}
.rating-label { font-size: 13.5px; font-weight: 600; color: var(--ink-soft); }

.card-quote {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
  font-style: italic;
  text-wrap: pretty;
}
.card-by {
  font-size: 12.5px;
  color: var(--faint);
  padding-top: 2px;
  border-top: 1px solid #eee6d6;
}
.card-contact {
  display: flex;
  gap: 14px;
  font-size: 12.5px;
  color: var(--muted-2);
}
.card-contact a { font-weight: 600; }

.empty {
  padding: 0 44px 48px;
  margin: -12px 0 0;
  font-size: 15px;
  color: var(--muted);
  font-style: italic;
}

/* ---------- About section ---------- */
.about-section {
  padding: 34px 44px 40px;
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
  scroll-margin-top: 16px;
}
.about-heading {
  margin: 0 0 12px;
  font-family: 'Libre Caslon Text', serif;
  font-weight: 400;
  font-size: 24px;
  color: var(--ink);
}
.about-section .about-body { max-width: 640px; }

/* ---------- Directory footer ---------- */
.dir-footer {
  padding: 22px 44px;
  background: #f0ebdf;
  border-top: 1px solid var(--footer-line);
  font-size: 12.5px;
  color: #8a8375;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.admin-toggle {
  border: none;
  background: none;
  cursor: pointer;
  font: 600 12.5px 'Karla', sans-serif;
  letter-spacing: 0.02em;
  color: #8a8375;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}
.admin-toggle:hover { color: var(--ink); background: #e7e0d0; }
body.admin .admin-toggle { color: var(--gold); background: #efe4d0; }

/* ---------- Admin controls on cards ---------- */
.card-admin {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  margin-top: 2px;
  border-top: 1px solid #eee6d6;
}
.card-btn {
  font: 600 12px 'Karla', sans-serif;
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid var(--field-border);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.card-btn:hover { background: #f3eee2; }
.card-btn.danger { color: var(--avoid); border-color: #e3c9c4; }
.card-btn.danger:hover { background: var(--avoid-bg); }
.card-confirm {
  font-size: 12.5px;
  color: var(--muted);
  margin-right: auto;
  font-style: italic;
}

/* ---------- Add-provider dialog ---------- */
.dialog {
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  max-width: 620px;
  width: calc(100% - 32px);
  box-shadow: 0 40px 90px -30px rgba(43, 41, 38, 0.6);
}
.dialog::backdrop {
  background: rgba(38, 34, 31, 0.55);
  backdrop-filter: blur(2px);
}
/* Entrance — respects reduced-motion */
.dialog[open] { animation: dialog-in 0.18s ease-out; }
.dialog[open]::backdrop { animation: backdrop-in 0.18s ease-out; }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .dialog[open], .dialog[open]::backdrop { animation: none; }
}
.dialog-panel { padding: 30px 36px 36px; }
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.dialog-close {
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 30px;
  line-height: 1;
  color: var(--faint);
  padding: 0 4px;
  margin-top: -2px;
  transition: color 0.15s ease;
}
.dialog-close:hover { color: var(--ink); }
.dialog .form-title { margin: 0; }
.dialog .form-lede { margin: 8px 0 26px; }

/* ---------- Add-provider form ---------- */
.form-wrap, .about-wrap { padding: 36px 44px 48px; max-width: 640px; }
.form-title {
  margin: 0;
  font-family: 'Libre Caslon Text', serif;
  font-weight: 400;
  font-size: 29px;
  color: var(--ink);
}
.form-lede, .about-body {
  margin: 9px 0 30px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--muted);
  text-wrap: pretty;
}
.about-body { margin: 0 0 18px; font-size: 15.5px; }

#add-form { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; }
.field-row { display: flex; gap: 16px; }
.field-row > .field { flex: 1; }
.field-narrow { flex: 0 0 150px !important; }

.field label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  margin-bottom: 7px;
}
.field label .opt { font-weight: 400; color: #a49b8a; }

.field input,
.field select,
.field textarea {
  background: #fff;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  padding: 12px 14px;
  font: 15px 'Karla', sans-serif;
  color: var(--ink);
  width: 100%;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
.field input::placeholder,
.field textarea::placeholder { color: #a49b8a; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(138, 109, 59, 0.12);
}
.field input.invalid,
.field textarea.invalid,
.field select.invalid {
  border-color: var(--avoid-accent);
  box-shadow: 0 0 0 3px rgba(163, 74, 68, 0.10);
}

/* Verdict toggle */
.verdict { display: flex; gap: 12px; }
.verdict-opt {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  padding: 12px;
  font: 14.5px 'Karla', sans-serif;
  color: #8a8375;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.verdict-opt .dot { width: 8px; height: 8px; border-radius: 50%; background: #c9b79a; }
.verdict-opt[data-verdict="trusted"].is-on {
  background: var(--trusted-bg);
  border: 1.5px solid var(--trusted);
  font-weight: 600;
  color: var(--trusted);
}
.verdict-opt[data-verdict="trusted"].is-on .dot { background: var(--trusted); }
.verdict-opt[data-verdict="avoid"].is-on {
  background: var(--avoid-bg);
  border: 1.5px solid var(--avoid);
  font-weight: 600;
  color: var(--avoid);
}
.verdict-opt[data-verdict="avoid"].is-on .dot { background: var(--avoid); }

/* Star rating input */
.rating-input { display: flex; gap: 5px; }
.rating-input .star {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
  color: var(--star-empty);
  transition: color 0.1s ease;
}
.rating-input .star.on { color: var(--star); }

.form-actions { display: flex; align-items: center; gap: 16px; margin-top: 6px; flex-wrap: wrap; }
.btn-primary {
  background: var(--gold);
  color: #fff;
  border: none;
  font: 600 15px 'Karla', sans-serif;
  letter-spacing: 0.02em;
  padding: 13px 30px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--gold-hi); }
.form-note { font-size: 13px; color: var(--faint); }
.form-note.error { color: var(--avoid); font-weight: 600; }
.form-note.success { color: var(--trusted); font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .page { padding: 24px 12px 60px; }
  .masthead { padding: 18px 22px; flex-wrap: wrap; gap: 14px; }
  .mainnav { width: 100%; gap: 22px; }
  .hero, .chips, .grid, .dir-footer { padding-left: 22px; padding-right: 22px; }
  .form-wrap, .about-wrap { padding: 28px 22px 40px; }
  .grid { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; gap: 22px; }
  .field-narrow { flex-basis: auto !important; }
  .empty { padding-left: 22px; padding-right: 22px; }
}
