:root {
  color-scheme: light;
  --ink: #262a36;
  --muted: #686f80;
  --paper: #fffaf0;
  --card: #ffffff;
  --line: #e8decf;
  --accent: #f85f52;
  --accent-deep: #d6423d;
  --sun: #ffc857;
  --mint: #65c6a3;
  --shadow: 0 10px 28px rgba(68, 48, 39, 0.1);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 12% 0%, #fff2cf 0, transparent 26rem), var(--paper); }
button, input, select, textarea { font: inherit; }
button, label.button { touch-action: manipulation; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid rgba(232, 222, 207, 0.9);
  background: rgba(255, 250, 240, 0.94);
  backdrop-filter: blur(14px);
}
.title-lockup { display: flex; align-items: center; gap: 0.8rem; }
.face { display: grid; place-items: center; width: 3rem; height: 3rem; border: 3px solid var(--ink); border-radius: 14px; background: var(--sun); font-weight: 900; transform: rotate(-3deg); }
h1 { margin: 0; font-size: clamp(1.35rem, 3vw, 2rem); line-height: 1; letter-spacing: -0.04em; }
.title-lockup p { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.9rem; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.sync-banner { display: flex; align-items: center; justify-content: center; gap: 0.7rem; min-height: 2.3rem; padding: 0.4rem 1rem; border-bottom: 1px solid var(--line); background: #fff7e6; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.sync-banner[data-state="ok"] { background: #e8f7f1; color: #24634f; }
.sync-banner[data-state="error"] { background: #fff0e7; color: #a53a32; }
.text-button { padding: 0; border: 0; border-bottom: 1px solid currentColor; background: transparent; color: inherit; cursor: pointer; font-weight: 900; }
.button-primary.unlocked { border-color: #247257; background: #2c8b6a; }

main { width: min(1500px, 100%); margin: 0 auto; padding: 1rem clamp(1rem, 4vw, 3rem) 4rem; }
.controls { display: grid; grid-template-columns: minmax(240px, 1.25fr) auto auto auto; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.search-wrap { display: flex; align-items: center; gap: 0.55rem; min-height: 2.75rem; padding: 0 0.85rem; border: 1px solid var(--line); border-radius: 13px; background: var(--card); box-shadow: 0 3px 10px rgba(68, 48, 39, 0.04); }
.search-wrap span { color: var(--accent-deep); font-size: 1.35rem; }
.search-wrap input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 1rem; }
.segmented { display: flex; padding: 0.25rem; border: 1px solid var(--line); border-radius: 13px; background: #fff; overflow-x: auto; }
.segmented button { padding: 0.55rem 0.75rem; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; white-space: nowrap; }
.segmented button.active { color: #fff; background: var(--ink); }
.select-wrap { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.9rem; }
.select-wrap select { min-height: 2.75rem; padding: 0 2rem 0 0.7rem; border: 1px solid var(--line); border-radius: 13px; background: var(--card); color: var(--ink); }
.summary { color: var(--muted); font-size: 0.9rem; font-weight: 700; text-align: right; white-space: nowrap; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; align-items: start; }
.card { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 19px; background: var(--card); box-shadow: var(--shadow); transition: transform 160ms ease, box-shadow 160ms ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(68, 48, 39, 0.15); }
.card.complete { border-color: #8ed8bd; }
.card.has-ordered { border-color: #e1b448; }
.image-button { position: relative; display: block; width: 100%; padding: 0; border: 0; background: #f3eee6; cursor: zoom-in; aspect-ratio: 4 / 3; overflow: hidden; }
.image-button img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 220ms ease; }
.image-button:hover img { transform: scale(1.025); }
.status-badge { position: absolute; top: 0.7rem; left: 0.7rem; padding: 0.35rem 0.6rem; border-radius: 999px; background: rgba(38, 42, 54, 0.88); color: white; font-size: 0.76rem; font-weight: 800; backdrop-filter: blur(6px); }
.card.complete .status-badge { background: rgba(34, 133, 97, 0.92); }
.card.has-ordered .status-badge { background: rgba(166, 112, 18, 0.94); }
.card.unspecified .status-badge { background: rgba(122, 109, 86, 0.92); }
.card-body { padding: 0.9rem; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.6rem; }
.card h2 { margin: 0; font-size: 1.05rem; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.section-label { margin: 0.3rem 0 0.8rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.icon-button { flex: 0 0 auto; min-width: 2.35rem; min-height: 2.35rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted); cursor: pointer; }
.icon-button:hover { color: var(--accent-deep); border-color: #f2aaa3; }
.targets { display: grid; gap: 0.45rem; }
.target { display: grid; grid-template-columns: 1.3rem minmax(0, 1fr) auto; align-items: start; gap: 0.55rem; min-height: 2.5rem; padding: 0.55rem 0.65rem; border-radius: 11px; background: #fff7e6; cursor: pointer; line-height: 1.35; }
.target:hover { background: #fff0ce; }
.target input { width: 1.15rem; height: 1.15rem; margin: 0.08rem 0 0; accent-color: var(--accent); }
.target.have { background: #e8f7f1; }
.target.have > span:not(.item-state) { color: #24634f; font-weight: 700; }
.target.ordered { border: 1px solid #e8c46d; background: #fff2cf; }
.target.ordered > span:not(.item-state) { color: #755016; font-weight: 700; }
.target.unknown { border: 1px dashed #cfc1aa; background: #faf7f1; color: var(--muted); }
.item-state { align-self: center; color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; }
.target.have .item-state { color: #247257; }
.target.ordered .item-state { color: #9a6512; }
.unspecified-note { margin: 0; padding: 0.7rem; border: 1px dashed #cfc1aa; border-radius: 11px; color: var(--muted); line-height: 1.4; }
.raw-note { margin: 0.75rem 0 0; padding-top: 0.65rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.research-details { margin-top: 0.8rem; padding-top: 0.7rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.83rem; line-height: 1.45; }
.research-details summary { color: var(--accent-deep); font-weight: 800; cursor: pointer; }
.research-details[open] summary { margin-bottom: 0.6rem; }
.fact-row, .description, .caveat { margin: 0.35rem 0; }
.fact-row strong { color: var(--ink); }
.caveat { padding: 0.55rem; border-radius: 8px; background: #fff2cf; color: #685124; }
.sources { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.sources a { color: var(--accent-deep); font-weight: 800; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.65rem; padding: 0 0.85rem; border-radius: 11px; cursor: pointer; font-weight: 800; text-decoration: none; }
.button-secondary { border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.button-primary { border: 1px solid var(--accent-deep); background: var(--accent); color: white; }
.empty { padding: 5rem 1rem; text-align: center; color: var(--muted); }
.empty div { font-size: 2rem; color: var(--ink); }

dialog { border: 0; border-radius: 18px; box-shadow: 0 24px 80px rgba(24, 20, 18, 0.32); }
dialog::backdrop { background: rgba(22, 20, 24, 0.74); backdrop-filter: blur(4px); }
.image-dialog { width: min(92vw, 1050px); max-height: 92vh; padding: 0.8rem; background: #17171d; color: white; }
.image-dialog img { display: block; max-width: 100%; max-height: 78vh; margin: auto; border-radius: 10px; object-fit: contain; }
.image-dialog p { margin: 0.65rem 3rem 0.1rem; text-align: center; }
.dialog-close { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; padding: 0; border: 0; border-radius: 50%; background: rgba(255,255,255,0.12); color: inherit; font-size: 1.7rem; cursor: pointer; }
.image-dialog > .dialog-close { position: absolute; top: 0.8rem; right: 0.8rem; z-index: 2; }
.edit-dialog { width: min(92vw, 540px); padding: 1.2rem; color: var(--ink); background: var(--paper); }
.dialog-heading { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.dialog-heading h2, .eyebrow { margin: 0; }
.eyebrow { color: var(--accent-deep); font-size: 0.78rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; }
.edit-dialog label { display: grid; gap: 0.35rem; margin-top: 0.9rem; font-weight: 800; }
.edit-dialog input, .edit-dialog textarea { width: 100%; padding: 0.75rem; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--ink); font-size: 1rem; }
.form-help { color: var(--muted); font-size: 0.85rem; }
.form-error { margin: 0.7rem 0 0; color: #b12f28; font-size: 0.85rem; font-weight: 800; }
.legacy-migration { margin-top: 1rem; padding: 0.8rem; border: 1px solid #e8c46d; border-radius: 11px; background: #fff2cf; }
.legacy-migration p { margin: 0 0 0.6rem; color: #685124; font-size: 0.88rem; font-weight: 700; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }
.toast { position: fixed; z-index: 50; right: 1rem; bottom: 1rem; max-width: min(360px, calc(100vw - 2rem)); padding: 0.8rem 1rem; border-radius: 12px; background: var(--ink); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (max-width: 980px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .search-wrap, .segmented { grid-column: 1 / -1; }
  .summary { text-align: right; }
}
@media (max-width: 640px) {
  .topbar { position: static; align-items: flex-start; }
  .title-lockup p { display: none; }
  .header-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .topbar { flex-direction: column; }
  .controls { grid-template-columns: 1fr; }
  .search-wrap, .segmented { grid-column: auto; }
  .select-wrap { justify-content: space-between; }
  .select-wrap select { flex: 1; }
  .summary { text-align: left; }
  .segmented button { flex: 1; }
  .card-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
