:root {
  color-scheme: light dark;
  --paper: #efe4d2;
  --paper-deep: #e3d3b4;
  --ink: #1c1612;
  --muted: #5c5148;
  --line: #dccdb4;
  --tag: #fffaf3;
  --glow: #fffaf3;
  --rust: #9d3424;
  --rust-ink: #f8e6df;
  --moss: #1d3b30;
  --moss-soft: #d7ebe1;
  --navy: #1e3a5c;
  --navy-soft: #d9e4f0;
  --shadow: #1c1612;
  --pass: #3f3832;
  --pass-soft: #e7e0d4;
  --serif: Fraunces, "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Source Sans 3", "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14110e;
    --paper-deep: #2c261e;
    --ink: #f3eadc;
    --muted: #cbbba6;
    --line: #4a4036;
    --tag: #221c17;
    --glow: #2a241c;
    --rust: #f0a090;
    --rust-ink: #3c241e;
    --moss: #c5e6d4;
    --moss-soft: #1a2c24;
    --navy: #d5e4f5;
    --navy-soft: #1a2836;
    --shadow: #000000;
    --pass: #ddd4c8;
    --pass-soft: #2a261f;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-padding-top: 1rem; }

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

html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background-color: var(--paper);
  background-image: radial-gradient(120% 26rem at 50% -12rem, var(--glow), transparent 68%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  accent-color: var(--rust);
}

::selection {
  background: #e7b2a4;
  color: #221b15;
}

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

.wrap {
  display: flex;
  flex-direction: column;
  width: min(72rem, calc(100% - 2.5rem));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(1.35rem, env(safe-area-inset-top)) 0 max(1.5rem, env(safe-area-inset-bottom));
}

main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  outline: none;
}

main:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 4px;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.45rem 0.75rem;
  z-index: 5;
}

.skip:focus { top: max(0.75rem, env(safe-area-inset-top)); }

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

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

button, .file-btn, .chip, a {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button, .file-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  min-height: 2.75rem;
  font-weight: 600;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.ghost, .chip, .danger, .file-btn {
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
}

.danger { border-color: var(--rust); color: var(--rust); }

.primary:hover { background: var(--rust); border-color: var(--rust); color: #fffaf6; }

.ghost:hover, .danger:hover, .file-btn:hover { background: var(--paper-deep); }

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

.mast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "kicker action"
    "title action"
    "lede lede";
  column-gap: 1.5rem;
  align-items: end;
  position: relative;
  padding: 0.2rem 0 1.25rem;
  margin-bottom: 0.35rem;
}

.mast::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7px;
  background:
    linear-gradient(var(--ink), var(--ink)) top / 100% 1px no-repeat,
    linear-gradient(var(--ink), var(--ink)) bottom / 100% 3px no-repeat;
}

.kicker { grid-area: kicker; }
h1 { grid-area: title; }
.lede { grid-area: lede; }
#add-find { grid-area: action; margin-bottom: 0.1rem; }

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

h1, h2, .title, .price, .stat b {
  font-family: var(--serif);
  font-optical-sizing: auto;
}

h1, h2, .title { text-wrap: balance; }

h1 {
  margin: 0.05rem 0 0;
  font-size: clamp(2.7rem, 6.2vw, 4.6rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 0.94;
  scroll-margin-top: 1rem;
}

.lede, .empty-copy p, .foot p { text-wrap: pretty; }

.lede {
  max-width: 38rem;
  margin: 0.8rem 0 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 1.15rem;
  background: var(--tag);
  border: 1px solid var(--line);
}

.stat {
  margin: 0;
  min-width: 0;
  padding: 0.85rem 1rem 0.8rem;
  border-right: 1px solid var(--line);
}

.stat:last-child { border-right: 0; }

.stat b {
  display: block;
  font-size: clamp(1.6rem, 3vw, 2rem);
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat.is-zero b { color: var(--muted); }

.stat.is-spent:not(.is-zero) b { color: var(--rust); }

.stat span {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0.9rem 0 0;
  padding: 0.75rem 0.9rem;
  background: var(--tag);
  border: 1px solid var(--ink);
}

.banner p { margin: 0; }

.banner[data-kind="error"] {
  background: var(--rust-ink);
  border-color: var(--rust);
}

.banner[data-kind="info"] {
  background: var(--navy-soft);
  border-color: var(--navy);
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin: 1.15rem 0 0;
  padding: 0.55rem;
  background: var(--tag);
  border: 1px solid var(--line);
}

.search {
  position: relative;
  flex: 1 1 16rem;
  min-width: min(100%, 14rem);
}

.search kbd {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  min-width: 1.4rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

.search input { padding-right: 2.3rem; }

.search input:focus + kbd,
.search input:not(:placeholder-shown) + kbd { visibility: hidden; }

.tools input,
.field input,
.field select,
.field textarea,
.tools select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background-color: var(--paper);
  color: var(--ink);
}

.tools select {
  width: auto;
  min-width: 11rem;
  max-width: 100%;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--ink);
  background: var(--paper);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.chip:last-child { border-right: 0; }

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.chip:hover:not([aria-pressed="true"]) { background: var(--paper-deep); }

[aria-invalid="true"] {
  border-color: var(--rust);
  box-shadow: inset 3px 0 0 var(--rust);
}

.count {
  margin: 0.7rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.empty {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 1.35rem 6px 1.6rem 0;
}

.empty-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.2rem 2rem;
  width: 100%;
  padding: 1.4rem 1.45rem 1.3rem;
  background: var(--tag);
  border: 1px solid var(--ink);
  border-top: 4px solid var(--rust);
  box-shadow: 6px 6px 0 var(--shadow);
}

.empty-copy { flex: 1 1 22rem; min-width: 0; max-width: 40rem; }

.empty-copy h2 {
  margin: 0.2rem 0 0.45rem;
  font-size: clamp(2rem, 4.5vw, 2.85rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.02;
  scroll-margin-top: 1rem;
}

.empty-copy p { margin: 0; color: var(--muted); max-width: 38rem; }

.row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

.nomatch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin: 0.9rem 0 1.2rem;
  padding: 1rem 1.1rem;
  background: var(--tag);
  border: 1px dashed var(--ink);
}

.nomatch p { margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1.15rem;
  padding: 0 4px 6px 0;
  scroll-margin-top: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  text-align: left;
  font-weight: 400;
  background: var(--tag);
  border: 1px solid var(--ink);
  box-shadow: 4px 4px 0 var(--shadow);
  cursor: pointer;
  /* ponytail: skip painting offscreen tags instead of virtualizing.
     Ceiling is 200 finds. Upgrade path: virtua if scroll jank shows up. */
  content-visibility: auto;
  contain-intrinsic-size: auto 23rem;
}

.frame {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--paper-deep);
}

.frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.frame-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 50% 46%, transparent 2.1rem, var(--line) 2.15rem, transparent 2.25rem),
    var(--paper-deep);
}

.frame-empty strong {
  font-family: var(--serif);
  font-size: 2.8rem;
  font-weight: 650;
  line-height: 1;
  color: var(--ink);
}

.frame-empty em {
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.pill, .photos-n {
  position: absolute;
  padding: 0.16rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.pill {
  top: 0.6rem;
  right: 0.6rem;
  border: 1px solid currentColor;
}

.photos-n {
  left: 0.6rem;
  bottom: 0.6rem;
  background: var(--ink);
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}

.status-bought { background: var(--moss-soft); color: var(--moss); }
.status-spotted { background: var(--navy-soft); color: var(--navy); }
.status-passed { background: var(--pass-soft); color: var(--pass); }

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 0;
  padding: 0.85rem 0.95rem 1rem;
}

.price {
  color: var(--rust);
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  font-size: 1.45rem;
  font-weight: 650;
  line-height: 1.15;
  overflow-wrap: break-word;
}

.meta {
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: break-word;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  align-items: center;
  margin-top: 0;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.foot p { margin: 0; max-width: 36rem; }

.file-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.has-stall .empty { display: none; }

dialog {
  width: min(42rem, calc(100vw - 2rem));
  max-height: min(92dvh, 52rem);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--ink);
  background: var(--tag);
  color: var(--ink);
  box-shadow: 8px 8px 0 var(--shadow);
  overscroll-behavior: contain;
}

dialog::backdrop { background: rgba(20, 16, 12, 0.62); }

dialog form {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  max-height: min(92dvh, 52rem);
  padding: 1.15rem 1.25rem 0;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-top: 4.5rem;
  scroll-padding-bottom: 5.5rem;
}

.dialog-head, .dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding-bottom: 0.75rem;
  background: var(--tag);
  border-bottom: 1px solid var(--line);
}

.dialog-actions {
  position: sticky;
  bottom: 0;
  margin-top: 0.15rem;
  padding: 0.8rem 0 0.9rem;
  background: var(--tag);
  border-top: 1px solid var(--line);
}

.dialog-actions .row { margin-left: auto; }

.dialog-head h2 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.15rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.form-error {
  margin: 0;
  padding: 0.6rem 0.75rem;
  background: var(--rust-ink);
  border: 1px solid var(--rust);
  scroll-margin-bottom: 5.5rem;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem 1rem;
}

.span-2 { grid-column: 1 / -1; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  min-width: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 1rem;
  font-weight: 400;
  scroll-margin-top: 4.5rem;
  scroll-margin-bottom: 5.5rem;
}

.field textarea { min-height: 6.5rem; resize: vertical; }

.hint { margin: 0; color: var(--muted); font-size: 0.92rem; font-weight: 400; letter-spacing: 0; text-transform: none; }

.photo-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.photo-block[aria-busy="true"] .file-btn { opacity: 0.55; pointer-events: none; }

.photo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.photo-list:empty { display: none; }

.photo-list li { width: 5.6rem; }

.photo-list img {
  display: block;
  width: 5.6rem;
  height: 4.2rem;
  object-fit: cover;
  border: 1px solid var(--ink);
}

.photo-list button {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.2rem;
  font-size: 0.78rem;
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
  .empty-card { animation: rise 380ms ease both; }
  dialog[open] { animation: fade 160ms ease; }
  dialog[open]::backdrop { animation: fade 160ms ease; }
}

@media (prefers-reduced-motion: no-preference) and (hover: hover) {
  .card { transition: transform 160ms ease; }
  .card:hover { transform: translateY(-3px); }
  .card:active { transform: translateY(0); }
}

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

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(1),
  .stat:nth-child(2) { border-bottom: 1px solid var(--line); }
  .stat:nth-child(odd) { border-right: 1px solid var(--line); }
  .stat:nth-child(even) { border-right: 0; }
}

@media (max-width: 640px) {
  .wrap { width: min(72rem, calc(100% - 1.5rem)); }
  .mast {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "kicker"
      "title"
      "lede"
      "action";
  }
  #add-find { width: 100%; margin-top: 0.95rem; }
  .search kbd { display: none; }
  .search input { padding-right: 0.7rem; }
  .tools select, .search { flex: 1 1 100%; }
  .tools select { width: 100%; }
  .chips { width: 100%; }
  .chip { flex: 1; padding-inline: 0.35rem; justify-content: center; }
  .empty { padding: 1.1rem 0 1.25rem; }
  .empty-card { align-items: stretch; padding: 1.2rem 1.05rem 1.1rem; }
  .empty-card > .row { flex-direction: column; align-items: stretch; width: 100%; }
  .empty-card > .row > * { width: 100%; justify-content: center; }
  .foot { flex-direction: column; align-items: stretch; }
  .foot .row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .foot .row > * { width: 100%; padding-inline: 0.35rem; justify-content: center; }
  .fields { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .dialog-actions { flex-direction: column; align-items: stretch; }
  .dialog-actions .row { width: 100%; margin-left: 0; }
  .dialog-actions .row button { flex: 1; justify-content: center; }
  #delete { width: 100%; }
  dialog {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    box-shadow: none;
  }
  dialog form {
    max-height: 100dvh;
    padding:
      max(1rem, env(safe-area-inset-top))
      max(1rem, env(safe-area-inset-right))
      0
      max(1rem, env(safe-area-inset-left));
  }
  .dialog-actions { padding-bottom: max(0.9rem, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .empty-card,
  .card,
  dialog,
  dialog::backdrop {
    animation: none;
    transition: none;
  }
}

@media (forced-colors: active) {
  .card, .primary, .ghost, .chip, .file-btn, .empty-card, .stats, dialog, .frame img {
    border: 1px solid CanvasText;
  }
  .primary, .chip[aria-pressed="true"] {
    background: CanvasText;
    color: Canvas;
  }
}
