/* Palette taken from blue-and-white porcelain: glaze-white ground, cobalt, celadon. */
:root {
  --ground: #f2f4f3;
  --paper: #ffffff;
  --ink: #18202e;
  --muted: #566070;
  --line: #d3d9df;
  --cobalt: #22418f;
  --cobalt-ink: #ffffff;
  --cobalt-soft: #e5ebf7;
  --celadon: #3f7a5e;
  --celadon-soft: #e1eee6;
  --warn: #9a3b1f;
  --radius-lg: 14px;
  --radius-sm: 8px;
  --tap: 56px;
  --font-ui: "Atkinson Hyperlegible", "Verdana", system-ui, sans-serif;
  --font-title: "Literata", "Georgia", serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #121720; --paper: #1a2130; --ink: #e9edf3; --muted: #a4aebd;
    --line: #2d3749; --cobalt: #8ea8ec; --cobalt-ink: #0f1830; --cobalt-soft: #223055;
    --celadon: #8cc4a6; --celadon-soft: #1f3a2e; --warn: #f0a080;
  }
}
:root[data-theme="dark"] {
  --ground: #121720; --paper: #1a2130; --ink: #e9edf3; --muted: #a4aebd;
  --line: #2d3749; --cobalt: #8ea8ec; --cobalt-ink: #0f1830; --cobalt-soft: #223055;
  --celadon: #8cc4a6; --celadon-soft: #1f3a2e; --warn: #f0a080;
}

*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 19px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; }
img { max-width: 100%; display: block; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.views { display: flex; gap: 6px; overflow-x: auto; }
.view {
  min-height: 48px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 999px;
  background: none; white-space: nowrap;
}
.view[aria-pressed="true"] { background: var(--cobalt-soft); border-color: var(--cobalt); font-weight: 700; }
.count { color: var(--muted); font-weight: 400; }
.sort { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.sort select {
  min-height: 48px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper);
}

/* ---------- listing layout ---------- */
main { outline: none; }
.listing {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, 1fr);
  gap: 28px;
  max-width: 1400px; margin: 0 auto; padding: 24px 20px 120px;
}
.photos { position: sticky; top: 92px; align-self: start; }
.photos, .details { min-width: 0; }   /* let the thumbnail strip scroll instead of widening the page */
.photo-main {
  display: block; width: 100%; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--paper); overflow: hidden;
}
.photo-main img { width: 100%; aspect-ratio: 1 / 1; max-height: calc(100vh - 290px); object-fit: contain; }
.thumbs { display: flex; gap: 10px; margin-top: 12px; overflow-x: auto; padding-bottom: 4px; }
.thumb {
  flex: 0 0 auto; width: 84px; height: 84px; padding: 0;
  border: 2px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--paper);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb[aria-current="true"] { border-color: var(--cobalt); border-width: 3px; }
.photo-hint { margin: 8px 0 0; color: var(--muted); font-size: 16px; }

.details { min-width: 0; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); }
.stepper button {
  min-height: 48px; min-width: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper);
}
.stepper button:disabled { opacity: .4; cursor: default; }

.title {
  font-family: var(--font-title); font-weight: 600;
  font-size: clamp(26px, 2.6vw, 34px); line-height: 1.2;
  margin: 14px 0 18px; max-width: 26ch;
}

.money { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 18px; margin-bottom: 6px; }
.price { font-size: 40px; font-weight: 700; line-height: 1.1; }
.price-kind { color: var(--muted); }
.ends { font-weight: 700; margin: 0 0 18px; }
.ends.soon { color: var(--warn); }

.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 18px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.open-link {
  margin-bottom: 22px;
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 20px;
  border: 2px solid var(--cobalt); border-radius: var(--radius-sm);
  color: var(--cobalt); font-weight: 700; text-decoration: none;
}
.open-link:hover { background: var(--cobalt-soft); }

.description { margin: 8px 0 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.description summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; font-weight: 700; }
.description .body { white-space: pre-line; max-width: 65ch; padding-bottom: 16px; }
.attrs { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; margin: 0 0 16px; font-size: 17px; }
.attrs dt { color: var(--muted); }
.attrs dd { margin: 0; }

/* ---------- valuation ---------- */
.valuation { border: 0; padding: 0; margin: 0 0 18px; }
.valuation legend { font-family: var(--font-title); font-size: 24px; font-weight: 600; margin-bottom: 10px; padding: 0; }
.bands { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.band {
  min-height: 64px; padding: 6px 10px;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper);
  font-size: 20px; font-weight: 700; white-space: nowrap;
}
.band:hover { border-color: var(--cobalt); }
.band[aria-pressed="true"] { background: var(--cobalt); border-color: var(--cobalt); color: var(--cobalt-ink); }
.key { display: none; }
@media (hover: hover) and (pointer: fine) {
  .key { display: inline; font-weight: 400; opacity: .6; font-size: 15px; margin-left: 6px; }
}

.field { display: block; margin: 0 0 16px; }
.field > span { display: block; font-weight: 700; margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper);
}
.field input { max-width: 240px; min-height: var(--tap); }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.45; }

/* ---------- action bar ---------- */
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center; gap: 12px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--paper); border-top: 1px solid var(--line);
}
.actions button {
  flex: 1 1 0; max-width: 260px; min-height: 60px; padding: 0 16px;
  border-radius: var(--radius-sm); font-size: 20px; font-weight: 700;
}
.btn-pass { border: 2px solid var(--line); background: var(--paper); }
.btn-save { border: 2px solid var(--cobalt); background: var(--cobalt); color: var(--cobalt-ink); }
.btn-save:disabled { opacity: .45; cursor: default; }

.status-note { margin: 0 0 14px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--celadon-soft); }

/* ---------- empty state ---------- */
/* ---------- sign in ---------- */
.signin { max-width: 30rem; margin: 10vh auto; padding: 0 24px 40px; }
.signin h1 { font-family: var(--font-title); font-weight: 600; font-size: 34px; margin: 0 0 6px; }
.signin-note { color: var(--muted); margin: 0 0 22px; }
.signin .field input { width: 100%; max-width: none; min-height: var(--tap); font-size: 20px; }
.signin-error { margin: 4px 0 16px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(200, 40, 20, .12); color: inherit; border: 1px solid rgba(200, 40, 20, .45); }
.signin-button { width: 100%; min-height: 60px; margin-top: 8px; border-radius: var(--radius-sm); font-size: 20px; font-weight: 700; }
.signout { margin-left: auto; min-height: 44px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--paper); color: var(--muted); font-size: 16px; }
.topbar[hidden] { display: none; }

.empty { max-width: 34rem; margin: 12vh auto; padding: 0 24px; text-align: center; }
.empty h1 { font-family: var(--font-title); font-weight: 600; font-size: 30px; margin: 0 0 8px; }
.empty p { color: var(--muted); margin: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom, 0px)); z-index: 7;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 10px 10px 20px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
}
.toast[hidden] { display: none; }
.toast button {
  min-height: 48px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--paper); color: var(--ink); font-weight: 700;
}

/* ---------- loupe ---------- */
.photo-main.loupe-on { touch-action: none; }   /* touch moves the glass, not the page */
.loupe { position: fixed; z-index: 11; pointer-events: none; }
.loupe[hidden] { display: none; }
.loupe-glass {
  position: absolute; left: calc(var(--reach) - var(--r)); top: calc(var(--reach) - var(--r));
  width: calc(2 * var(--r)); height: calc(2 * var(--r));
  border-radius: 50%; background-color: var(--paper); background-repeat: no-repeat;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .45);
}
.loupe-frame { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#loupe-rim { fill: none; stroke: #2b2f36; }
#loupe-handle { stroke: #3a2a1c; stroke-linecap: round; }
.photo-tools { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; }
.photo-tools .thumbs { flex: 1 1 auto; margin-top: 0; min-width: 0; }
.loupe-btn {
  flex: 0 0 auto; margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  min-height: 84px; min-width: 110px; padding: 0 16px;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink);
  font-size: 22px; font-weight: 700;
}
.loupe-btn svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.loupe-btn[aria-pressed="true"] { background: var(--cobalt); border-color: var(--cobalt); color: var(--cobalt-ink); }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  body { font-size: 18px; }
  .topbar { position: static; padding: 8px 10px; gap: 8px; }
  .views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 100%; }
  .view { padding: 0 4px; font-size: 16px; }
  .view .count { display: block; line-height: 1; font-size: 14px; }
  .view { min-height: 54px; border-radius: var(--radius-sm); }
  .sort { width: 100%; }
  .sort span { display: none; }
  .sort select { width: 100%; }
  .wide-only { display: none; }
  .bands { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .band:last-child:nth-child(odd) { grid-column: 1 / -1; }   /* 7 bands: last one full width */
  .photo-main img { max-height: 55vh; }
  .listing { grid-template-columns: 1fr; gap: 16px; padding: 12px 12px 120px; }
  .photos { position: static; }
  .photo-main img { aspect-ratio: 4 / 3; }
  .photo-hint { display: none; }
  .title { margin-top: 8px; }
  .price { font-size: 34px; }
  .actions { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .actions button { font-size: 18px; }
  .loupe-btn { min-height: 72px; }
}
@media (prefers-reduced-motion: no-preference) {
  .band, .view, .thumb { transition: background-color .12s, border-color .12s; }
}
