:root {
  --paper: #f4efe6;
  --paper-deep: #ece5d8;
  --card: #fdfbf6;
  --ink: #201b15;
  --ink-soft: #6b6154;
  --line: #d8cfbf;
  --rust: #b5432a;
  --rust-soft: #f3ded7;
  --moss: #2e6b4f;
  --moss-soft: #dfeae2;
  --gold: #a07d2e;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Karla", -apple-system, sans-serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(32, 27, 21, 0.06), 0 8px 24px -12px rgba(32, 27, 21, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background: var(--paper);
  background-image: radial-gradient(rgba(32, 27, 21, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  max-width: 640px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(48px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ---------- masthead ---------- */
.masthead { padding: 10px 2px 14px; }
.masthead-row { display: flex; align-items: baseline; justify-content: space-between; }
.wordmark {
  font-family: var(--serif);
  font-weight: 600;
  font-style: italic;
  font-size: 44px;
  letter-spacing: -0.02em;
  line-height: 1;
}
.wordmark-dot { color: var(--rust); }
.masthead-sub {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 15px;
  margin-top: 6px;
}
.refresh-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.2s;
}
.refresh-btn:active { transform: rotate(90deg); }
.refresh-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- add bar ---------- */
.add-bar {
  display: flex; gap: 8px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: 3px 3px 0 var(--ink);
}
.add-bar input {
  flex: 1;
  border: 0; background: transparent; outline: none;
  font-family: var(--sans); font-size: 16px;
  padding: 8px 10px;
  color: var(--ink);
  min-width: 0;
}
.add-bar input::placeholder { color: var(--ink-soft); font-style: italic; }
.add-bar button {
  font-family: var(--sans); font-weight: 700; font-size: 14px;
  letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--ink); color: var(--paper);
  border: 0; border-radius: 9px;
  padding: 10px 18px;
  cursor: pointer;
}
.add-bar button:disabled { opacity: 0.5; }
#pasteBtn {
  background: var(--paper-deep); color: var(--ink);
  border: 0; border-radius: 9px;
  width: 42px; flex: none;
  display: grid; place-items: center;
  cursor: pointer;
}
#pasteBtn:active { background: var(--line); }
.add-error { color: var(--rust); font-size: 13px; margin: 8px 4px 0; }

.clip-banner {
  display: block; width: 100%; text-align: left;
  margin-top: 10px; padding: 12px 14px;
  background: var(--moss-soft); color: var(--moss);
  border: 1px solid var(--moss); border-radius: var(--radius);
  font-family: var(--sans); font-size: 14px; font-weight: 700;
  cursor: pointer;
  animation: rise 0.25s ease;
}
.clip-banner small { display: block; font-weight: 400; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: 14px; font-weight: 700;
  padding: 12px 20px; border-radius: 99px;
  box-shadow: var(--shadow);
  z-index: 60; white-space: nowrap;
  animation: rise 0.25s ease;
}

/* ---------- view tabs ---------- */
.views { display: flex; gap: 4px; margin: 20px 0 4px; border-bottom: 1px solid var(--line); }
.view-tab {
  font-family: var(--serif); font-size: 17px; font-weight: 500;
  background: none; border: 0; cursor: pointer;
  color: var(--ink-soft);
  padding: 8px 12px 10px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.view-tab.is-active { color: var(--ink); border-bottom-color: var(--rust); font-style: italic; }
.drop-count {
  background: var(--moss); color: #fff;
  font-family: var(--sans); font-size: 11px; font-weight: 700;
  border-radius: 99px; padding: 1px 7px; vertical-align: 2px;
}

/* ---------- compare controls ---------- */
.compare-controls { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  font-size: 13px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line); border-radius: 99px;
  background: var(--card); color: var(--ink-soft);
  padding: 6px 12px; cursor: pointer;
}
.chip.is-active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
#sortSelect {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink);
  padding: 6px 8px;
}

/* ---------- shop groups ---------- */
.shop-group { margin-top: 26px; }
.shop-head { display: flex; align-items: baseline; gap: 10px; padding: 0 2px 10px; flex-wrap: wrap; }
.shop-name {
  font-family: var(--serif); font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em; cursor: pointer;
}
.shop-meta { font-size: 13px; color: var(--ink-soft); }
.shop-subtotal { margin-left: auto; font-family: var(--serif); font-size: 16px; font-weight: 600; }
.promo-chip {
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  background: var(--gold); color: #fff;
  border: 0; border-radius: 6px; padding: 3px 8px; cursor: pointer;
}
.promo-chip.bare { background: transparent; color: var(--ink-soft); border: 1px dashed var(--line); font-weight: 600; }
.promo-note-line { flex-basis: 100%; font-size: 12.5px; font-style: italic; color: var(--gold); }
.promo-detected-line { flex-basis: 100%; font-size: 12.5px; font-weight: 700; color: var(--rust); }
.promo-detected-line em { font-weight: 400; font-style: italic; color: var(--ink-soft); }

/* ---------- item grid & cards ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease backwards;
  position: relative;
}
.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.08s; }
.card:nth-child(4) { animation-delay: 0.12s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.card-img {
  aspect-ratio: 3 / 4;
  background: var(--paper-deep);
  width: 100%;
  object-fit: cover;
  display: block;
}
.card-img.placeholder { display: grid; place-items: center; font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 13px; }
.card.sold .card-img { filter: grayscale(1) opacity(0.55); }

.card-body { padding: 9px 11px 11px; }
.card-title {
  font-size: 13px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.6em;
}
.card-shop { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.card-price-row { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; }
.card-price { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.card-price.drop { color: var(--moss); }
.card-compare { font-size: 12px; color: var(--ink-soft); text-decoration: line-through; }

.badges { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.badge {
  font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 5px;
}
.badge.sale { background: var(--rust); color: #fff; }
.badge.drop { background: var(--moss); color: #fff; }
.badge.sold { background: var(--ink); color: var(--paper); }
.badge.err { background: var(--paper-deep); color: var(--ink-soft); border: 1px solid var(--line); }

/* ---------- empty state ---------- */
.empty {
  text-align: center; padding: 70px 20px;
}
.empty h2 { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 24px; }
.empty p { color: var(--ink-soft); font-size: 14px; margin-top: 10px; line-height: 1.6; }

.footer-note { text-align: center; font-size: 12px; color: var(--ink-soft); margin-top: 40px; font-style: italic; }
.account-line { margin-top: 8px; }
.linkish { background: none; border: 0; color: var(--ink-soft); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

/* ---------- bulk match ---------- */
#shotBtn {
  background: var(--paper-deep); color: var(--ink);
  border: 0; border-radius: 9px;
  width: 42px; flex: none;
  display: grid; place-items: center;
  cursor: pointer;
}
#shotBtn:active { background: var(--line); }

.match-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.match-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--moss); flex: none; }
.match-thumb { width: 44px; height: 56px; object-fit: cover; border-radius: 7px; background: var(--paper-deep); flex: none; }
.match-info { flex: 1; min-width: 0; }
.match-name { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-found { font-size: 12.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-found.none { color: var(--rust); font-style: italic; }
.match-price { font-family: var(--serif); font-weight: 600; font-size: 14px; flex: none; }

/* ---------- auth screen ---------- */
.auth-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--paper);
  background-image: radial-gradient(rgba(32, 27, 21, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 18vh 28px 40px;
  overflow-y: auto;
}
.auth-screen > * { max-width: 384px; margin-left: auto; margin-right: auto; }
.auth-screen form { margin-top: 32px; }
.auth-submit { width: 100%; padding: 13px; font-size: 15px; margin-top: 4px; }
.auth-toggle {
  display: block; margin: 18px auto 0;
  background: none; border: 0; cursor: pointer;
  font-family: var(--serif); font-style: italic; font-size: 14px;
  color: var(--ink-soft); text-decoration: underline;
}

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(32, 27, 21, 0.45);
  backdrop-filter: blur(2px); z-index: 40;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 640px; margin: 0 auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--line); border-bottom: 0;
  box-shadow: 0 -12px 40px rgba(32, 27, 21, 0.25);
  animation: slideUp 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
  max-height: 88vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 10px auto 0; }
.sheet-body { padding: 18px 20px calc(24px + env(safe-area-inset-bottom)); }
.sheet-title { font-family: var(--serif); font-size: 22px; font-weight: 600; }
.sheet-sub { color: var(--ink-soft); font-size: 13.5px; margin: 6px 0 16px; line-height: 1.5; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 5px; }
.field input {
  width: 100%; font-family: var(--sans); font-size: 16px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper); color: var(--ink);
  padding: 10px 12px; outline: none;
}
.field input:focus { border-color: var(--ink); }

.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.btn {
  font-family: var(--sans); font-weight: 700; font-size: 14px;
  border-radius: 10px; padding: 11px 18px; cursor: pointer; border: 0;
}
.btn.solid { background: var(--ink); color: var(--paper); }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--rust); border: 1px solid var(--rust-soft); }

/* item sheet detail */
.detail-top { display: flex; gap: 14px; }
.detail-img { width: 110px; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; background: var(--paper-deep); }
.detail-info { flex: 1; min-width: 0; }
.detail-title { font-size: 16px; font-weight: 700; line-height: 1.35; }
.detail-shop { font-size: 13px; color: var(--ink-soft); margin-top: 3px; }
.detail-material {
  display: inline-block;
  font-size: 12px; font-weight: 600;
  color: var(--moss); background: var(--moss-soft);
  border-radius: 6px; padding: 2px 8px; margin-top: 6px;
}
.detail-price { font-family: var(--serif); font-size: 26px; font-weight: 600; margin-top: 8px; }
.detail-price .was { font-size: 15px; color: var(--ink-soft); text-decoration: line-through; font-weight: 400; margin-left: 6px; }
.detail-status { font-size: 12.5px; margin-top: 4px; color: var(--ink-soft); }
.detail-status.sold { color: var(--rust); font-weight: 700; }

.spark-wrap { margin: 18px 0 4px; }
.spark-label { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }
.spark { width: 100%; height: 56px; }
.spark polyline { fill: none; stroke: var(--moss); stroke-width: 2; }
.spark .area { fill: var(--moss-soft); stroke: none; opacity: 0.6; }

.open-shop-btn {
  display: block; text-align: center; text-decoration: none;
  font-weight: 700; font-size: 15px;
  background: var(--ink); color: var(--paper);
  border-radius: 10px; padding: 13px; margin-top: 16px;
}
