:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1d1b17;
  --muted: #6d675c;
  --border: #e2ddd2;
  --brand: #ffcf00;
  --brand-ink: #1d1b17;
  --accent: #d01012;
  --accent-ink: #ffffff;
  --pos: #1f7a3d;
  --neg: #c0392b;
  --owned: #1f6fd1;
  --wishlist: #8a5cd1;
  --sold: #6d675c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
/* Dark: automatic (follows the device) unless the user chose light; or forced with data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15140f;
    --surface: #1f1d18;
    --surface-2: #2a2721;
    --text: #f2efe8;
    --muted: #a39d90;
    --border: #36322b;
    --pos: #4cc47a;
    --neg: #ff6b5e;
    --owned: #5b9dff;
    --wishlist: #b48cff;
    --sold: #a39d90;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15140f;
  --surface: #1f1d18;
  --surface-2: #2a2721;
  --text: #f2efe8;
  --muted: #a39d90;
  --border: #36322b;
  --pos: #4cc47a;
  --neg: #ff6b5e;
  --owned: #5b9dff;
  --wishlist: #b48cff;
  --sold: #a39d90;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 96px;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.topbar .btn.ghost { color: var(--brand-ink); border-color: rgba(0,0,0,.2); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.lang-switch { display: inline-flex; background: rgba(0,0,0,.1); border-radius: 10px; padding: 3px; }
.lang-switch button { border: 0; background: none; color: var(--brand-ink); font-weight: 700; font-size: 13px; padding: 6px 10px; border-radius: 8px; cursor: pointer; min-height: 32px; }
.lang-switch button.active { background: var(--brand-ink); color: var(--brand); }
@media (max-width: 420px) {
  .brand h1 { font-size: 16px; }
}

/* Account menu */
.user-menu { position: relative; }
.user-btn {
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--brand-ink); background: transparent; color: var(--brand-ink);
  font-weight: 800; font-size: 16px;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 220px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column;
}
.menu[hidden] { display: none; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-head small { color: var(--muted); }
.menu button { border: 0; background: none; text-align: left; padding: 10px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.menu button:hover { background: var(--surface-2); }
.menu button[hidden] { display: none; }

main { max-width: 1500px; margin: 0 auto; padding: 16px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Toolbar */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.toolbar-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.toolbar-selects { display: flex; gap: 10px; }
#sort, #ownerFilter { width: auto; }
@media (max-width: 600px) {
  .toolbar-selects { width: 100%; }
  #sort, #ownerFilter { flex: 1; min-width: 0; }
}
.owner-tag { font-size: 12px; font-weight: 700; color: var(--muted); }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; max-width: 100%; }
.segmented button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card {
  display: flex; gap: 12px; padding: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.card:hover { transform: translateY(-1px); }
.card:focus-visible { outline: 2px solid var(--brand); }
.thumb { flex: 0 0 88px; height: 88px; border-radius: 10px; background: #fff; display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb span { font-size: 34px; }
.card-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.card-top { display: flex; align-items: center; gap: 6px; }
.setnum { font-weight: 700; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.qty { font-size: 12px; font-weight: 700; background: var(--surface-2); border-radius: 6px; padding: 0 6px; }
.badge { margin-left: auto; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; color: #fff; text-transform: uppercase; letter-spacing: .03em; }
.badge.owned { background: var(--owned); }
.badge.wishlist { background: var(--wishlist); }
.badge.for_sale { background: #d9822b; }
.badge.sold { background: var(--sold); }
.card h3 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { margin: 0; color: var(--muted); font-size: 13px; }
.prices { margin: auto 0 0; display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn[hidden] { display: none; }
a.btn.ghost, a.btn.secondary { color: var(--text); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: transparent; color: var(--neg); border-color: var(--neg); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.icon-btn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 15px; }
.link { border: 0; background: none; color: inherit; text-decoration: underline; font-weight: 700; cursor: pointer; padding: 0; }

.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; gap: 10px;
}
.fab .btn { min-height: 52px; padding: 0 20px; border-radius: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

/* Dialogs */
dialog {
  border: 0; padding: 0; background: transparent; color: var(--text);
  width: min(720px, 100%); max-width: 100%; max-height: 100%;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
/* While a window is open the page behind it stays put; the window itself scrolls without dragging the page along */
html:has(dialog[open]) { overflow: hidden; }
dialog .sheet { overscroll-behavior: contain; }
.sheet {
  background: var(--surface); border-radius: 18px; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100dvh - 32px); overflow-y: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-head h2 { font-size: 18px; }
.sheet-actions {
  position: sticky; bottom: -16px; margin: 0 -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center;
}
.spacer { flex: 1; }

.editor-body { display: flex; flex-direction: column; gap: 14px; }

/* Set editor on a wide screen: wider and in two columns (set details left, copies right), so there is less scrolling.
   The grid sits in .editor-body, so Save / Cancel stay stuck to the bottom of the sheet. */
@media (min-width: 1000px) {
  dialog { width: min(880px, calc(100vw - 48px)); }
  #editor { width: min(1280px, calc(100vw - 48px)); }
  #editor .editor-body {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 18px;
    grid-template-areas: "banner banner" "hero copies" "info copies" "photos copies" "mocs copies"
                         "market copies" "notes copies" "rest copies";
    grid-template-rows: repeat(7, auto) 1fr;
    align-items: start;
  }
  #editor #dupBanner { grid-area: banner; }
  #editor .hero { grid-area: hero; }
  #editor .ed-info { grid-area: info; }
  #editor .ed-photos { grid-area: photos; }
  #editor .ed-mocs { grid-area: mocs; }
  #editor #copiesBox { grid-area: copies; }
  #editor .ed-market { grid-area: market; }
  #editor .ed-notes { grid-area: notes; }
}

@media (max-width: 600px) {
  dialog { margin: auto 0 0; width: 100%; }
  .sheet { border-radius: 18px 18px 0 0; max-height: 92dvh; }
  .fab { left: 16px; }
  .fab .btn { flex: 1; padding: 0 10px; }
  /* minmax(0, …): long set names must not make the column wider than the screen */
  .grid { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  /* All five status filters on one row */
  /* Longer words (French, German) wrap onto a second row instead of falling off the screen */
  #statusFilter { display: flex; flex-wrap: wrap; width: 100%; }
  #statusFilter button { flex: 1 1 auto; padding: 8px 6px; font-size: 14px; }
  .stat-value { font-size: 17px; }
}

/* Form */
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
fieldset[hidden] { display: none; }
legend { font-weight: 700; padding: 0 6px; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
label input, label select { color: var(--text); font-weight: 400; font-size: 15px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.lookup-status { font-weight: 500; min-height: 1.2em; }
.values-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#valuesStatus.lookup-status:not(.warn):not(.busy) { color: var(--muted); }
.values-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.segmented.small button { padding: 6px 12px; font-size: 14px; }
.no-key { color: var(--neg); }
label[hidden] { display: none; }
.name-view { font-size: 18px; margin: 0; }
.name-view:empty { display: none; }
.info-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; margin: 0; }
.info-view:empty, .info-view[hidden] { display: none; }
.info-view div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.info-view dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.info-view dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.info-empty { margin: 0; }
#instructionsBox[hidden] { display: none; }
#sellDescription { font-size: 14px; line-height: 1.45; resize: vertical; }
.sell-photo { display: flex; gap: 12px; align-items: center; }
.sell-photo img { width: 110px; height: 110px; object-fit: contain; background: #fff; border-radius: 12px; border: 1px solid var(--border); }
.sell-photo-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
#sellPhotoField[hidden] { display: none; }
a.btn.primary { color: var(--accent-ink); }
.instr-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.instr-links:empty { display: none; }
.info-empty[hidden] { display: none; }
#infoEdit { display: flex; flex-direction: column; gap: 10px; }
#infoEdit[hidden], #priceEdit[hidden] { display: none; }
#priceView dd { font-size: 17px; font-variant-numeric: tabular-nums; }
.avail { font-weight: 600; }
.avail.retired { color: var(--accent); }
.forecast { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; border-top: 1px dashed var(--border); }
.forecast[hidden] { display: none; }
.forecast-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.forecast-grid:empty { display: none; }
.fc { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; }
.fc.calc { background: transparent; border: 1px dashed var(--border); }
.fc-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.fc-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.fc-growth { font-size: 12px; font-weight: 700; }
@media (max-width: 600px) { .forecast-grid { grid-template-columns: repeat(2, 1fr); } }
.lookup-status.busy { color: var(--muted); }
.lookup-status.ok { color: var(--pos); }
.lookup-status.warn { color: var(--neg); }
.checks { display: flex; gap: 20px; flex-wrap: wrap; }
.check { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; color: var(--text); font-weight: 400; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.hero { display: flex; gap: 12px; align-items: flex-start; }
.hero img { width: 110px; height: 110px; object-fit: contain; background: #fff; border-radius: 12px; border: 1px solid var(--border); }
.hero-fields { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.banner { background: #fff4c2; color: #4d3d00; border-radius: 10px; padding: 10px 12px; font-size: 14px; }

/* Scanner */
#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; min-height: 220px; }
#reader[hidden] { display: none; }
#reader video { border-radius: 12px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.manual { display: flex; gap: 8px; }
.status-msg { margin: 0; font-weight: 600; min-height: 1.4em; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px); transition: opacity .2s, transform .2s; font-weight: 600;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Settings */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer; padding: 0; overflow: hidden;
  border: 2px solid var(--border); display: grid; grid-template-rows: 1fr 1fr;
}
.swatch span { display: block; }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
input[type="color"] { padding: 4px; height: 44px; cursor: pointer; }
.owner-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.owner-list li {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px;
  background: var(--surface-2); border-radius: 99px; font-weight: 600;
}
.owner-list li.empty { background: none; padding: 0; color: var(--muted); font-weight: 400; }
.owner-list button { border: 0; background: none; cursor: pointer; width: 28px; height: 28px; border-radius: 50%; color: var(--muted); }
.owner-list button:hover { background: var(--border); color: var(--text); }

/* Users (admin) */
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); flex-wrap: wrap;
}
/* Grey out the person, not the buttons: those are exactly what the admin needs here */
.user-row.inactive .user-avatar, .user-row.inactive .user-info { opacity: .6; }
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--brand); color: var(--brand-ink); font-weight: 800;
}
.user-info { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 2px; }
.user-info small { color: var(--muted); }
.user-info .badge { margin-left: 6px; vertical-align: middle; display: inline-block; white-space: nowrap; }
.badge.admin { background: var(--accent); color: var(--accent-ink); }
.badge.off { background: var(--sold); }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Login page */
body.auth-page { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow);
}
.auth-card .brand { justify-content: center; }
.auth-card .brand h1 { font-size: 22px; }
.auth-card .segmented { display: flex; }
.auth-card .segmented[hidden] { display: none; }
.auth-card .segmented button { flex: 1; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label[hidden] { display: none; }
.auth-error { color: var(--neg); font-weight: 600; margin: 0; min-height: 1.2em; }
.auth-error:empty { min-height: 0; }
.auth-info {
  margin: 0; padding: 10px 12px; border-radius: 10px; font-weight: 600;
  background: color-mix(in srgb, var(--pos) 14%, var(--surface)); color: var(--pos);
}
.auth-info[hidden], .auth-card .btn[hidden] { display: none; }
.badge.pending { background: #c77700; }
.auth-lang { align-self: center; background: var(--surface-2); }
.auth-lang button { color: var(--text); }
.auth-lang button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Legal: footer, menu links, terms dialog, danger zone */
.app-footer { max-width: 1500px; margin: 8px auto 0; padding: 8px 16px 24px; text-align: center; color: var(--muted); font-size: 12px; }
.app-footer a, .menu-foot a, .auth-foot a { color: inherit; }
.app-footer p { margin: 4px 0 0; }
.menu-foot { display: flex; gap: 12px; padding: 8px 10px 4px; margin-top: 4px; border-top: 1px solid var(--border); font-size: 12px; }
.menu-foot a { color: var(--muted); }
.danger-zone { border-top: 1px dashed var(--border); padding-top: 8px; }
.danger-zone summary { cursor: pointer; color: var(--neg); font-weight: 600; }
.danger-zone[open] { display: flex; flex-direction: column; gap: 8px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin: 0; }
.auth-check { flex-direction: row; align-items: flex-start; gap: 8px; font-size: 14px; color: var(--text); font-weight: 400; }
.auth-check input { width: 20px; height: 20px; min-height: 0; margin-top: 1px; flex: none; accent-color: var(--accent); }
.auth-card .link { align-self: center; color: var(--muted); font-weight: 600; font-size: 14px; }
.auth-card label.auth-check[hidden], .auth-card .link[hidden] { display: none; }

/* Privacy policy / terms of use pages */
body.legal-page { padding-bottom: 0; }
.legal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
}
.legal-head .brand { color: inherit; text-decoration: none; font-size: 18px; }
.legal-page section { max-width: 760px; margin: 0 auto; padding: 24px 16px; line-height: 1.6; }
.legal-page section[hidden] { display: none; }
.legal-page h1 { font-size: 26px; margin-bottom: 4px; }
.legal-page h2 { font-size: 18px; margin: 24px 0 6px; }
.legal-page ul { padding-left: 20px; }
.legal-page li { margin-bottom: 6px; }
.legal-page a { color: var(--owned); }

/* Help page */
.legal-page .lead { font-size: 17px; }
.legal-page h3 { font-size: 16px; margin: 16px 0 4px; }
.toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.toc ol { margin: 6px 0 0; padding-left: 20px; columns: 2; column-gap: 24px; }
@media (max-width: 600px) { .toc ol { columns: 1; } }
.legal-page .tip { background: color-mix(in srgb, var(--brand) 18%, var(--surface)); border-radius: 10px; padding: 10px 12px; }
.help-list dt { font-weight: 700; margin-top: 12px; }
.help-list dd { margin: 2px 0 0; }
.legal-page h2[id] { scroll-margin-top: 12px; }

/* Own photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo-grid:empty { display: none; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 2px solid transparent; }
.photo-thumb.main { border-color: var(--accent); }
.photo-thumb a, .photo-thumb img { display: block; width: 100%; height: 100%; }
.photo-thumb img { object-fit: cover; }
.photo-thumb button {
  position: absolute; top: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,.55); color: #fff; font-size: 15px; line-height: 30px; padding: 0;
}
.photo-thumb .ph-main { left: 4px; }
.photo-thumb.main .ph-main { background: var(--accent); color: var(--accent-ink); }
.photo-thumb .ph-del { right: 4px; }
#photoAddBtn { cursor: pointer; }

/* Language dropdown in the top bar */
.lang-select {
  width: auto; min-height: 34px; padding: 4px 26px 4px 10px; border-radius: 10px; font-weight: 700; font-size: 13px;
  background-color: rgba(0,0,0,.1); color: var(--brand-ink); border: 0; cursor: pointer;
}
.lang-select option { color: #1d1b17; background: #fff; }
#settingsLang { flex-wrap: wrap; }

/* Language menu with flags (top bar) */
.lang-menu { position: relative; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 4px 9px; cursor: pointer;
  border: 0; border-radius: 10px; background: rgba(0,0,0,.1); color: var(--brand-ink); font-weight: 700; font-size: 13px;
}
.caret { font-size: 10px; opacity: .8; }
.flag { width: 22px; height: 15px; object-fit: cover; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.18); flex: none; }
.lang-list { min-width: 180px; }
.lang-list button { display: flex; align-items: center; gap: 10px; }
.lang-list button.active { background: var(--surface-2); }
.lang-list button.active::after { content: '✓'; margin-left: auto; color: var(--accent); }
.auth-lang button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; }

/* First name + last name side by side */
.name-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.name-row[hidden] { display: none; }
.name-row label { min-width: 0; }

/* LEGO's own "coming soon" / "retiring soon" lists: two tiles under the totals */
.lego-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.lego-tile {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--pos);
  border-radius: var(--radius); box-shadow: var(--shadow); transition: transform .12s ease;
}
.lego-tile.retiring { border-left-color: #d9822b; }
.lego-tile.mocs { border-left-color: #7b4bd1; font: inherit; text-align: left; cursor: pointer; }
.lego-tile:hover { transform: translateY(-1px); }
.lego-tile-icon { font-size: 26px; line-height: 1; flex: none; }
.lego-tile-text { display: flex; flex-direction: column; min-width: 0; }
.lego-tile-text strong { font-size: 16px; }
.lego-tile-text small { color: var(--muted); font-weight: 600; font-size: 13px; }
@media (max-width: 600px) {
  .lego-tile { padding: 10px 12px; gap: 8px; }
  .lego-tile-icon { font-size: 22px; }
  .lego-tile-text strong { font-size: 14px; }
}
@media (max-width: 600px) {
  /* Narrow tiles: icon above the text, so the text gets the whole width */
  .lego-tile { flex-direction: column; align-items: flex-start; gap: 4px; }
  .lego-tile-text small { white-space: nowrap; }
}

/* Side panel with LEGO facts: right column on wide screens, below the collection on phones */
.page-layout { max-width: 1840px; margin: 0 auto; }
.fun-panel { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.side-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.side-card h2 { font-size: 16px; display: flex; gap: 6px; align-items: center; }
.side-card > small { font-size: 12px; }
.fact-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fact-list li { background: color-mix(in srgb, var(--brand) 16%, var(--surface)); border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.45; }
.side-card .btn { align-self: flex-start; }
@media (min-width: 1100px) {
  .page-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .page-layout > main { margin: 0; justify-self: end; width: 100%; }
  .fun-panel { position: sticky; top: 70px; padding: 16px 16px 16px 0; max-height: calc(100vh - 80px); overflow-y: auto; }
}
@media (min-width: 1100px) {
  /* Keep the bottom of the panel free for the Scan / Add buttons */
  .fun-panel { max-height: calc(100vh - 160px); }
}

/* Top bar links to the pages: Sets / Minifigs */
.topbar { flex-wrap: wrap; }
.main-nav { display: flex; gap: 4px; background: rgba(0,0,0,.1); border-radius: 12px; padding: 3px; margin-right: auto; margin-left: 12px; }
.main-nav a {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; min-height: 36px; border-radius: 9px;
  color: var(--brand-ink); text-decoration: none; font-weight: 700; font-size: 15px;
}
.main-nav a:hover { background: rgba(0,0,0,.08); }
.main-nav a.active { background: var(--brand-ink); color: var(--brand); }
.main-nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.main-nav circle { fill: currentColor; }
@media (max-width: 600px) {
  /* Phones: the page links get their own row under the logo */
  .main-nav { order: 3; width: 100%; margin: 0; }
  .main-nav a { flex: 1; justify-content: center; }
}
.fab[hidden], #setsView[hidden], #figsView[hidden] { display: none; }

/* Minifig cards: tall pictures */
.card.fig .thumb img { padding: 4px; }
.card.fig h3 { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 15px; }
.from-set { font-size: 12px; font-weight: 700; color: var(--muted); }

/* "From a set": minifigs to tick */
.fig-pick { display: flex; flex-direction: column; gap: 6px; }
.fig-pick label {
  display: flex; flex-direction: row; align-items: center; color: var(--text); font-size: 14px; gap: 10px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; background: var(--surface);
}
.fig-pick input[type=checkbox] { width: 20px; height: 20px; min-height: 0; flex: none; }
.fig-pick img { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 8px; flex: none; }
.fig-pick .pick-text { display: flex; flex-direction: column; min-width: 0; }
.fig-pick .pick-text small { color: var(--muted); }
.fig-pick .pick-text strong { font-size: 14px; }
.fig-pick .have { color: var(--pos); font-weight: 700; }

.cols[hidden] { display: none; }
.hero-fields small a { color: inherit; font-weight: 700; }
#figSetForm .btn { white-space: nowrap; }
@media (max-width: 600px) {
  /* Longer French / German label: buttons share the width by their text, on one line */
  #figsFab .btn { flex: 1 1 auto; white-space: nowrap; padding: 0 14px; }
}

/* Minifig that appears in only one set (or none) */
.badge.exclusive { background: linear-gradient(135deg, #e0a800, #b8860b); color: #fff; white-space: nowrap; }
.info-view .badge.exclusive { margin-left: 4px; vertical-align: 1px; }
/* Number, owner and badge: keep each in one piece; the badge moves to its own line when there is no room */
.card.fig .card-top { flex-wrap: wrap; row-gap: 2px; }
.card.fig .owner-tag, .card.fig .setnum { white-space: nowrap; }

/* Minifig statistics panel */
#figStatsCard[hidden] { display: none; }
.stats-sub { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.stats-empty { margin: 0; font-size: 14px; }
.theme-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; }
.bar-label span:last-child { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.stats-facts { margin: 4px 0 0; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; }
.stats-facts div { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.stats-facts dt { color: var(--muted); font-weight: 600; flex: none; }
.stats-facts dd { margin: 0; text-align: right; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.of-all { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.stats-source { font-size: 11px; }

/* BrickHeadz page */
#bhView[hidden], .main-nav a[hidden] { display: none; }
.card.bh { cursor: default; }
.card.bh:hover { transform: none; }
.card.bh.have { border-color: var(--pos); box-shadow: inset 4px 0 0 var(--pos), var(--shadow); }
.card.bh h3 { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 15px; }
.bh-have { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; margin-top: 2px; }
.bh-have input { width: 20px; height: 20px; min-height: 0; margin: 0; }
/* New and used counters under each other, the buttons aligned whatever the length of the word */
.bh-steps { display: grid; grid-template-columns: max-content repeat(3, auto); justify-content: start; align-items: center; gap: 6px 8px; font-size: 13px; }
.bh-step { display: contents; }
.bh-step-label { color: var(--muted); font-weight: 600; }
.bh-step button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: 17px; font-weight: 700; line-height: 1; cursor: pointer; color: var(--text);
}
.bh-step-n { min-width: 18px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.bh-source { font-size: 12px; text-align: center; margin: 16px 0 0; }
@media (max-width: 600px) {
  /* Three page links: a bit smaller */
  .main-nav a { padding: 6px 8px; font-size: 14px; gap: 4px; }
  .main-nav svg { width: 18px; height: 18px; }
}

/* ---------- Set editor: list of copies ---------- */
.copy-count { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.copy-count input { width: 110px; }
.copy-count .muted { padding-bottom: 10px; }
#copiesBox { min-width: 0; }
.copy-list { display: flex; flex-direction: column; gap: 8px; }
.copy { border: 1px solid var(--border); border-left: 4px solid var(--owned); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.copy.for_sale { border-left-color: #d9822b; }
.copy.sold { border-left-color: var(--sold); }
.copy-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.copy-head .badge { margin-left: auto; flex: none; }
.copy-head .icon-btn { flex: none; width: 32px; height: 32px; font-size: 13px; }
.copy-toggle { flex: 1 1 auto; overflow: hidden; display: flex; align-items: baseline; gap: 8px; min-width: 0; border: 0; background: none; padding: 4px 0; cursor: pointer; color: var(--text); font: inherit; text-align: left; }
.copy-toggle strong { white-space: nowrap; }
.copy-chev { color: var(--muted); width: 12px; flex: none; }
.copy-facts { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.copy-quick:empty { display: none; }
.copy-body { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; border-top: 1px dashed var(--border); }
.copy-body[hidden] { display: none; }
.copy-sub { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
#copyAddBtn { align-self: flex-start; margin-top: 8px; }
#copyFields[hidden], #wishFields[hidden] { display: none; }

/* Value check: the values themselves stand out */
.vc-values dd { font-size: 20px; font-weight: 700; }
.vc-result:not([hidden]) { display: flex; flex-direction: column; gap: 14px; }
.sheet-actions[hidden] { display: none; }
.vc-form input { flex: 1; min-width: 0; }

/* Scanning needs the camera of a phone or tablet: on a computer with a mouse the Scan buttons are left out */
@media (hover: hover) and (pointer: fine) {
  .mobile-only { display: none !important; }
}

/* Plans */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.plan-card.current { border: 2px solid var(--accent); }
.plan-head { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.plan-price { font-size: 24px; font-weight: 800; }
.plan-price small { font-size: 13px; font-weight: 600; color: var(--muted); }
.plan-features { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.plan-features li.off { color: var(--muted); }
.plan-summary { display: flex; flex-direction: column; gap: 8px; }
.user-plan { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.user-plan select, .user-plan input { min-height: 34px; padding: 4px 8px; font-size: 13px; }
.linkish { border: 0; background: none; padding: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.user-plan select { width: auto; }
.user-plan label { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
#planSeeBtn { align-self: flex-start; }
@media (min-width: 1000px) {
  #planDialog { width: min(720px, calc(100vw - 48px)); }
}

/* Plan in the top bar: "Free · Upgrade" or "★ Premium" */
.plan-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 3px 4px 3px 12px;
  border: 0; border-radius: 99px; background: rgba(0,0,0,.1); color: var(--brand-ink);
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.plan-chip[hidden] { display: none; }
.plan-chip:hover { background: rgba(0,0,0,.16); }
.plan-chip-up { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 5px 10px; }
.plan-chip-up::before { content: '⬆ '; }
.plan-chip.premium { padding-right: 12px; }
.plan-chip.premium .plan-chip-name::before { content: '★ '; }
/* Phone: only a round ⬆ Upgrade button (or the star), so the top bar stays one row */
@media (max-width: 600px) {
  .plan-chip:not(.premium) { padding: 0; background: none; }
  .plan-chip:not(.premium) .plan-chip-name { display: none; }
  .plan-chip-up { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; font-size: 0; }
  .plan-chip-up::before { content: '⬆'; font-size: 17px; }
  .plan-chip.premium { padding: 3px 10px; }
  .plan-chip.premium .plan-chip-name { font-size: 0; }
  .plan-chip.premium .plan-chip-name::before { font-size: 15px; content: '★'; }
}
.plan-pay { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.plan-pay .check { font-size: 13px; align-items: flex-start; }
.plan-pay .check a { color: inherit; font-weight: 700; }
.pay-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.pay-list li { display: flex; gap: 12px; flex-wrap: wrap; }
.pay-st { margin-left: auto; font-weight: 700; }
.pay-st.paid { color: var(--owned); }
.pay-st.failed, .pay-st.refunded { color: var(--sold); }

/* MOC ideas: on phones the third tile gets its own row */
@media (max-width: 600px) {
  .lego-links { grid-template-columns: 1fr 1fr; }
  .lego-tile.mocs { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 10px; }
}
.moc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.moc-grid.big { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.moc-card { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); text-decoration: none; min-width: 0; }
.moc-card:hover { border-color: var(--accent); }
.moc-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #fff; border-radius: 6px; }
.moc-name { font-weight: 700; font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.moc-card small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.moc-card .moc-from { color: var(--text); }
.moc-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.moc-tools input { flex: 1 1 200px; min-width: 0; }
.moc-tools select { flex: 0 1 auto; width: auto; min-width: 0; max-width: 100%; }
@media (max-width: 600px) { .moc-tools select { flex: 1 1 140px; } }
#mocMoreBtn { align-self: center; }
@media (min-width: 1000px) {
  #mocDialog { width: min(1280px, calc(100vw - 48px)); }
}

/* Minifig mixer: the parts from head to toe, the pictures stacked in one column like a figure */
.btn-emoji { font-size: 18px; line-height: 1; }
.mix-name { text-align: center; font-size: 22px; font-weight: 800; min-height: 1.3em; }
.mix-figure { display: flex; flex-direction: column; gap: 4px; }
.mix-slot { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto auto; align-items: center; gap: 10px;
  padding: 4px 8px; border-radius: 10px; }
.mix-slot.locked { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.mix-slot img { width: 110px; height: 80px; object-fit: contain; background: #fff; border-radius: 8px; }
.mix-slot.slot-torso img, .mix-slot.slot-legs img { height: 96px; }
.mix-slot.accessory { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 10px; }
.mix-info { display: flex; flex-direction: column; min-width: 0; }
.mix-info span.mix-kind { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.mix-info strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-info small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-slot .icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.mix-empty { width: 110px; height: 80px; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); border-radius: 8px; }
@media (max-width: 600px) {
  .mix-slot { grid-template-columns: 84px minmax(0, 1fr) auto auto; gap: 8px; }
  .mix-slot img, .mix-empty { width: 84px; height: 64px; }
  .mix-slot.slot-torso img, .mix-slot.slot-legs img { height: 76px; }
}
