:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #f0ece3;
  --text: #1d1b16;
  --muted: #6b665c;
  --line: #e2ddd1;
  --red: #e3000b;
  --red-ink: #b00009;
  --yellow: #ffcf00;
  --blue: #006cb7;
  --green: #00852b;
  --green-bg: #e3f4e8;
  --amber-bg: #fff4cc;
  --amber-ink: #7a5a00;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 14px rgba(40, 30, 10, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15140f;
    --surface: #1f1d17;
    --surface-2: #29261e;
    --text: #f3efe4;
    --muted: #a8a191;
    --line: #37332a;
    --red: #ff3b44;
    --red-ink: #ff6b72;
    --blue: #4ea8ff;
    --green: #3ccf6a;
    --green-bg: #173323;
    --amber-bg: #3a300f;
    --amber-ink: #ffd95a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
img { display: block; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* En-tête */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 4px solid var(--yellow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.status { color: var(--muted); font-size: 13px; }

/* Mise en page */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px;
  max-width: 1500px; width: 100%; margin: 0 auto;
}
.panel h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.pill { background: var(--red); color: #fff; font-size: 12px; border-radius: 99px; padding: 1px 8px; }
.pill:empty { display: none; }

/* Mes boîtes */
.mine {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; align-self: start; position: sticky; top: 16px;
  max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.search { position: relative; }
.search input {
  width: 100%; padding: 10px 12px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--surface-2); outline: none;
}
.search input:focus { border-color: var(--blue); }
.suggest {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  list-style: none; margin: 0; padding: 4px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 360px; overflow: auto;
}
.suggest li {
  display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer;
}
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--surface-2); }
.suggest img, .mine-list img { width: 52px; height: 40px; object-fit: contain; background: #fff; border-radius: 6px; flex: none; }
.suggest .t, .mine-list .t { font-weight: 600; font-size: 14px; line-height: 1.25; }
.suggest .m, .mine-list .m { color: var(--muted); font-size: 12px; }
.suggest .none { color: var(--muted); padding: 10px; cursor: default; }

.mine-list { list-style: none; margin: 12px 0 0; padding: 0; overflow: auto; }
.mine-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.mine-list li:first-child { border-top: 0; }
.mine-list .info { flex: 1; min-width: 0; }
.qty { display: flex; align-items: center; gap: 2px; }
.qty button {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; line-height: 1;
}
.qty span { min-width: 22px; text-align: center; font-weight: 600; font-size: 13px; }
.qty .rm { color: var(--red-ink); }
.mine-empty { color: var(--muted); font-size: 14px; }
.mine-empty[hidden] { display: none; }
.mine-total { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.mine-total:empty { display: none; }

.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600;
  background: var(--red); color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn:hover { filter: brightness(1.05); }

/* Barre d'outils */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.seg { display: inline-flex; background: var(--surface); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--text); color: var(--bg); }
.toggle {
  border: 0; border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px;
  background: var(--surface); color: var(--muted); box-shadow: var(--shadow);
}
.toggle[aria-pressed="true"] { background: var(--blue); color: #fff; }
.badge3d {
  position: absolute; right: 8px; top: 8px; font-size: 11px; font-weight: 800;
  padding: 3px 7px; border-radius: 6px; background: var(--blue); color: #fff;
}
.toolbar select {
  background: var(--surface); border: 0; border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 14px;
}

.view-seg { margin-bottom: 12px; }
.view-seg button { font-size: 15px; padding: 8px 14px; }
.toolbar[hidden] { display: none; }
.moc-box {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; margin-top: 8px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 14px;
}
.moc-box img { width: 64px; height: 48px; object-fit: contain; background: #fff; border-radius: 8px; }
.moc-box span { display: block; color: var(--muted); font-size: 13px; }
.moc-more { grid-column: 1 / -1; margin: 0 0 8px; }
.moc-note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }
a.card { color: inherit; text-decoration: none; }
.moc-link { color: var(--blue); }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); min-width: 150px; }
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.full b { color: var(--green); }

/* Galerie */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card {
  text-align: left; border: 0; padding: 0; cursor: pointer; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; transition: transform .12s ease;
}
.card:hover { transform: translateY(-2px); }
.card:focus-visible { outline: 3px solid var(--blue); }
.card .pic { position: relative; background: #fff; aspect-ratio: 4 / 3; }
.card .pic img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.badge {
  position: absolute; left: 8px; top: 8px; font-size: 12px; font-weight: 700;
  padding: 3px 8px; border-radius: 99px; background: var(--amber-bg); color: var(--amber-ink);
}
.badge.full { background: var(--green); color: #fff; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .t { font-weight: 650; line-height: 1.25; }
.card .m { color: var(--muted); font-size: 12px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: auto; }
.bar i { display: block; height: 100%; background: var(--yellow); border-radius: 99px; }
.bar.full i { background: var(--green); }
.pct { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.pct b { color: var(--text); }

.empty {
  grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 20px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.more { text-align: center; margin: 18px 0 8px; }

/* Détail */
dialog {
  width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 0; border-radius: 18px; padding: 0; background: var(--bg); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(20, 15, 5, .55); }
.d-head { display: grid; grid-template-columns: 260px 1fr; gap: 20px; padding: 20px; background: var(--surface); }
.d-head .pic { background: #fff; border-radius: 12px; }
.d-head .pic img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; padding: 8px; }
.d-head h3 { margin: 0 0 4px; font-size: 22px; line-height: 1.2; }
.d-head .m { color: var(--muted); font-size: 14px; }
.d-head .bar { height: 12px; margin: 14px 0 6px; }
.close {
  position: absolute; right: 14px; top: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--surface-2); cursor: pointer; font-size: 20px; line-height: 1;
}
.contrib { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 4px 10px 4px 4px; font-size: 13px; }
.chip img { width: 40px; height: 30px; object-fit: contain; background: #fff; border-radius: 6px; }
.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.idea-link { color: var(--blue); font-weight: 600; font-size: 14px; }
.btn.donate { background: var(--yellow); color: #1d1b16; }
.btn.buy { background: var(--green); }
.buy-panel {
  margin: 0 20px 4px; padding: 16px 18px; border-radius: 12px; background: var(--surface);
  border: 2px solid var(--green); display: flex; flex-direction: column; gap: 10px;
}
.buy-panel[hidden] { display: none; }
.buy-panel h4 { margin: 0; font-size: 17px; }
.buy-panel p { margin: 0; }
.buy-steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.buy-steps li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.buy-steps span { color: var(--muted); font-size: 13px; flex: 1 1 220px; }
.buy-unmatched { font-size: 13px; color: var(--muted); }
.buy-unmatched ul { margin: 6px 0 0; padding-left: 18px; }
.buy-alt { font-size: 13px; color: var(--muted); }
.buy-error { color: var(--red-ink); }
.buy-wait { color: var(--muted); }
.link-btn { border: 0; background: none; padding: 0; color: var(--blue); cursor: pointer; font: inherit; text-decoration: underline; }
.no3d { flex-basis: 100%; margin: 0 0 2px; font-size: 13px; color: var(--muted); }
.no3d b { background: var(--blue); color: #fff; border-radius: 5px; padding: 0 5px; font-size: 11px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs { display: flex; gap: 6px; padding: 14px 20px 0; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px 8px 0 0; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--surface); color: var(--text); }
.parts {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
  padding: 14px 20px 20px; background: var(--surface); margin: 0 20px 20px; border-radius: 0 12px 12px 12px;
}
.part { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.part.miss { border-color: var(--red); }
.part img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 6px; }
.part .n { font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.part .c { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .2); flex: none; }
.part .q { font-weight: 700; }
.part.miss .q { color: var(--red-ink); }
.part .from { color: var(--muted); }
.part .variant { color: var(--blue); font-size: 11px; }
.part .figtag { color: var(--amber-ink); background: var(--amber-bg); border-radius: 5px; padding: 0 5px; font-size: 11px; align-self: flex-start; }
.parts .none { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 30px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px 24px 24px; }

@media (max-width: 860px) {
  .top { padding: 12px 16px; }
  .brand p { display: none; }
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .mine { position: static; max-height: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { min-width: 0; padding: 8px 10px; }
  .stat b { font-size: 20px; }
  .stat span { font-size: 12px; }
  .d-head { grid-template-columns: 1fr; padding: 16px; }
  .d-head .pic { max-width: 280px; }
  .parts { margin: 0 12px 12px; padding: 12px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .tabs { padding: 12px 12px 0; }
}
