:root {
  color-scheme: light dark;
  --bg: #fafaf9;
  --panel: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --tile: #f0efed;
  --ink: #1c1917;
  --ink-text: #fafaf9;
  --focus: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --panel: #1c1a19;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --line: #2e2b29;
    --tile: #23211f;
    --ink: #f5f5f4;
    --ink-text: #1c1917;
    --focus: #60a5fa;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* z-index scale: header 10, dialog uses the top layer. */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(12px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { color: inherit; text-decoration: none; font-weight: 650; font-size: 17px; white-space: nowrap; }
.search { flex: 1; max-width: 560px; margin-left: auto; }
.search input {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.list, .item {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px max(20px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 28px 18px; }
.card { color: inherit; text-decoration: none; display: grid; gap: 10px; }
.card .photo { aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; background: var(--tile); }
.card img { width: 100%; height: 100%; object-fit: cover; }
.card .title { font-size: 14px; font-weight: 550; line-height: 1.35; text-wrap: pretty; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .size { font-size: 13px; color: var(--muted); margin-top: -6px; }
.card:hover .title { text-decoration: underline; text-underline-offset: 3px; }

.empty { display: grid; justify-items: center; gap: 12px; padding: 80px 0; color: var(--muted); text-align: center; }
.empty p { margin: 0; text-wrap: pretty; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-weight: 550;
  cursor: pointer;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--ink); border-color: var(--ink); color: var(--ink-text); }
.button.primary:hover { opacity: 0.9; }
.button.large { height: 48px; padding: 0 22px; font-size: 16px; width: 100%; }

.back { display: inline-block; margin-bottom: 16px; color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.item-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 32px; align-items: start; }
.item-layout > * { min-width: 0; }
.stage { position: relative; display: grid; place-items: center; background: var(--tile); border-radius: 12px; overflow: hidden; min-height: 320px; }
.stage img { width: 100%; height: min(72dvh, 860px); object-fit: contain; }
.stage .nav {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
  font-size: 20px;
  cursor: pointer;
}
.stage .prev { left: 12px; }
.stage .next { right: 12px; }
.stage .position { position: absolute; bottom: 10px; right: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel); font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; }
.thumbs button { flex: 0 0 auto; width: 72px; height: 72px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--tile); cursor: pointer; }
.thumbs button[aria-current="true"] { border-color: var(--ink); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.info { position: sticky; top: 88px; display: grid; gap: 16px; }
.info h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 650; text-wrap: balance; }
.info .size { margin: -8px 0 0; color: var(--muted); }
.info .notes { margin: 0; white-space: pre-line; text-wrap: pretty; color: var(--muted); }

.description { max-width: 790px; margin: 48px auto 0; padding-top: 24px; border-top: 1px solid var(--line); }
.description h2 { margin: 0 0 16px; font-size: 18px; font-weight: 650; text-wrap: balance; }
.description img { width: 100%; height: auto; }

.card .photo { position: relative; }
.sold { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--ink); color: var(--ink-text); font-size: 12px; font-weight: 600; }
.sold-note { margin: 0; padding: 12px 0; text-align: center; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; }

.dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); }
.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog form { display: grid; gap: 14px; padding: 20px; }
.dialog h2 { margin: 0; font-size: 18px; text-wrap: balance; }
.handle-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.handle { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.mention { margin: 0; color: var(--muted); text-wrap: pretty; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .item-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .info { position: static; }
  .stage img { height: min(62dvh, 640px); }
}
@media (max-width: 520px) {
  .top { gap: 12px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 12px; }
  .stage .nav { display: none; }
  .thumbs button { width: 60px; height: 60px; }
}
