/* Mobile first: big touch targets, high contrast for daylight at outdoor fairs.
   Owned = green + ✓, wanted = amber + ★ — never colour alone. */
:root {
  color-scheme: light dark;
  --bg: #f6f3ee;
  --fg: #1c1a17;
  --muted: #6b645a;
  --card: #fffdf9;
  --border: #e3dbcf;
  --accent: #c8551d;
  --owned: #1d7a3a;
  --owned-soft: #e2f3e6;
  --wanted: #a45f00;
  --wanted-soft: #fdf0d9;
  --chip: #efe9e0;
  --shadow: 0 1px 2px rgba(28, 26, 23, 0.05), 0 8px 24px -16px rgba(28, 26, 23, 0.35);
  --radius: 14px;
}
/* Sombre : soit parce que le système le demande (et que rien n'est forcé en clair),
   soit parce que le bouton de la barre du haut l'a choisi. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #151311;
    --fg: #f1ece4;
    --muted: #a59d91;
    --card: #1f1c19;
    --border: #36312a;
    --accent: #e6834a;
    --owned: #5fcf7e;
    --owned-soft: rgba(95, 207, 126, 0.13);
    --wanted: #f2b04b;
    --wanted-soft: rgba(242, 176, 75, 0.14);
    --chip: #2c2824;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -18px rgba(0, 0, 0, 0.8);
  }
}
:root[data-theme='dark'] {
    --bg: #151311;
    --fg: #f1ece4;
    --muted: #a59d91;
    --card: #1f1c19;
    --border: #36312a;
    --accent: #e6834a;
    --owned: #5fcf7e;
    --owned-soft: rgba(95, 207, 126, 0.13);
    --wanted: #f2b04b;
    --wanted-soft: rgba(242, 176, 75, 0.14);
    --chip: #2c2824;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -18px rgba(0, 0, 0, 0.8);
  }
:root[data-theme='dark'] { color-scheme: dark; }
:root[data-theme='light'] { color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: #c0392b; }

/* --- Top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.4rem 0.75rem; flex-wrap: wrap;
  /* env(safe-area-inset-top) vaut 0 en navigateur, et la hauteur de la barre d'état
     (heure, réseau, batterie) quand l'app est lancée depuis l'écran d'accueil. */
  padding: calc(0.5rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.5rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: 0.5rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; min-width: 0;
}
.brand-dot {
  width: 1.1rem; height: 1.1rem; border-radius: 50%; display: inline-block;
  background: radial-gradient(circle, var(--accent) 0 30%, #1c1a17 32% 100%);
}
.nav { display: flex; gap: 0.25rem; flex: 0 0 auto; }
.nav a { text-decoration: none; padding: 0.45rem 0.8rem; border-radius: 999px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.nav a.active { background: var(--fg); color: var(--bg); }
.refresh {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: 1.25rem; line-height: 1; padding: 0.35rem 0.6rem; border-radius: 999px;
}
.refresh:active { background: var(--chip); }
.theme-toggle { font-size: 1.05rem; }
.lang-toggle { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.03em; }
@media (max-width: 560px) {
  .nav { order: 3; flex: 1 0 100%; gap: 0.3rem; }
  .nav a { flex: 1; text-align: center; padding: 0.5rem 0.25rem; }
  .brand { font-size: 0.98rem; }
}
.update-btn { white-space: nowrap; }

.view { max-width: 860px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-left)); }

/* --- Search --- */
.search-box { position: sticky; top: var(--topbar-h, 3.4rem); z-index: 5; background: var(--bg); padding: 0.25rem 0 0.75rem; }
.artist-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.1rem 0 0.4rem; }
.artist-chip {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.7rem; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border); text-decoration: none; box-shadow: var(--shadow);
}
.section-title { font-size: 0.95rem; margin: 1rem 0.25rem 0.5rem; }
.section-title.owned { color: var(--owned); }
.section-title.wanted { color: var(--wanted); }
.search-input {
  width: 100%; font-size: 1.15rem; padding: 0.8rem 1rem; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--card); outline: none; -webkit-appearance: none; appearance: none;
}
.search-input:focus { border-color: var(--accent); }
.hint { color: var(--muted); padding: 1rem 0.25rem; }
.result-note { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0.25rem; }

.list { display: flex; flex-direction: column; gap: 0.5rem; }

.artist-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.85rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; box-shadow: var(--shadow);
}
.artist-name { font-weight: 600; }

.badges { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; }
.badge { font-size: 0.78rem; font-weight: 700; padding: 0.18rem 0.55rem; border-radius: 999px; white-space: nowrap; letter-spacing: 0.01em; }
.badge.owned { background: var(--owned-soft); color: var(--owned); }
.badge.wanted { background: var(--wanted-soft); color: var(--wanted); }
.badge.note { background: var(--chip); color: var(--muted); font-weight: 600; }

/* --- Work cards --- */
.work { background: var(--card); border: 1px solid var(--border); border-left: 5px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.work.is-wanted { border-left-color: var(--wanted); }
.work.is-owned { border-left-color: var(--owned); }
.work-head {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 0.75rem; align-items: center;
  width: 100%; text-align: left; background: none; border: 0; padding: 0.6rem 0.75rem; cursor: pointer;
}
.cover { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--chip); display: block; }
.work-main { min-width: 0; display: flex; flex-direction: column; }
.work-title { font-weight: 700; overflow-wrap: anywhere; }
.work-artist { font-size: 0.92rem; overflow-wrap: anywhere; }
.work-meta { font-size: 0.82rem; color: var(--muted); }
.work-status { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.work-foot {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.45rem 0.75rem;
  border-top: 1px dashed var(--border); font-size: 0.82rem;
}
.foot-text { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.open-discogs { font-weight: 700; padding: 0.2rem 0; }

.versions { border-top: 1px solid var(--border); padding: 0.25rem 0.75rem 0.75rem; }
.version { padding: 0.6rem 0; border-bottom: 1px dashed var(--border); }
.version:last-of-type { border-bottom: 0; }
.v-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 0.6rem; }
.chip { background: var(--chip); border-radius: 6px; padding: 0.05rem 0.45rem; font-size: 0.8rem; font-weight: 700; }
.v-label { font-size: 0.92rem; }
.v-title { font-size: 0.9rem; font-style: italic; }
.v-detail { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.v-status { margin-top: 0.35rem; padding: 0.35rem 0.55rem; border-radius: 8px; font-size: 0.88rem; font-weight: 600; }
.v-status.owned { background: var(--owned-soft); color: var(--owned); }
.v-status.wanted { background: var(--wanted-soft); color: var(--wanted); }
.fields { display: flex; flex-wrap: wrap; gap: 0.2rem 0.8rem; margin-top: 0.2rem; font-weight: 400; color: var(--fg); font-size: 0.82rem; }
.ext { font-size: 0.85rem; font-weight: 600; color: var(--accent); text-decoration: none; margin-left: auto; white-space: nowrap; }
.versions > .ext { display: inline-block; margin-top: 0.5rem; }

/* --- Artist page --- */
.page-head { margin: 0.25rem 0 0.75rem; }
.page-head h1 { margin: 0.2rem 0; font-size: 1.6rem; line-height: 1.2; }
.back { color: var(--muted); text-decoration: none; font-weight: 600; background: none; border: 0; padding: 0; cursor: pointer; }
.filters { display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 0.5rem; margin-bottom: 0.25rem; }
.filters button {
  border: 1px solid var(--border); background: var(--card); border-radius: 999px; padding: 0.4rem 0.8rem; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.filters button.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.stats-tabs {
  position: sticky; top: var(--topbar-h, 3.4rem); z-index: 5;
  background: var(--bg); padding-top: 0.5rem; margin-bottom: 0.5rem;
  scrollbar-width: none;
}
.stats-tabs::-webkit-scrollbar { display: none; }

/* --- Buttons --- */
.btn { border: 1px solid var(--border); background: var(--card); border-radius: 999px; padding: 0.55rem 1rem; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.6; cursor: default; }
.live-search { margin: 1rem 0; }

/* --- Stats --- */
.stats { display: grid; gap: 0.9rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.card h3 { margin: 1rem 0 0.4rem; font-size: 0.92rem; color: var(--muted); }
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.75rem; }
.figure .num { font-size: 1.7rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.figure .lbl { font-size: 0.82rem; color: var(--muted); }
.grid-2 { display: grid; gap: 0.9rem; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.bars { display: flex; flex-direction: column; gap: 0.3rem; }
.bar-row { display: grid; grid-template-columns: minmax(6rem, 38%) 1fr auto; gap: 0.5rem; align-items: center; font-size: 0.88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label a { text-decoration: none; }
.bar-label a:hover { text-decoration: underline; }
.bar-track { height: 0.7rem; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 2px; }
.bar-fill.outlined { box-shadow: inset 0 0 0 1px var(--border); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; min-width: 3ch; }

.facts { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.fact { background: var(--chip); border-radius: 10px; padding: 0.7rem 0.8rem; }
.fact .big { font-size: 1.35rem; font-weight: 800; display: block; line-height: 1.2; }
.fact small { color: var(--muted); display: block; margin-top: 0.15rem; }
.release-list { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; }
.release-list li { margin: 0.15rem 0; }
.release-list a { text-decoration: none; }
.release-list a:hover { text-decoration: underline; }
.words { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.words span { background: var(--chip); border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.88rem; }
.mosaic { display: grid; grid-template-columns: repeat(auto-fill, minmax(22px, 1fr)); gap: 3px; margin-top: 0.75rem; }
.swatch { aspect-ratio: 1; border-radius: 4px; display: block; }

/* --- Sync bar --- */
.syncbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.5rem max(1rem, env(safe-area-inset-left)) calc(0.5rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); font-size: 0.82rem; color: var(--muted);
}
.syncbar .btn { padding: 0.35rem 0.8rem; font-size: 0.82rem; }

/* --- Login --- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 0.6rem; }
.login h1 { font-size: 1.25rem; display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.5rem; }
.login input { padding: 0.75rem; border-radius: 10px; border: 2px solid var(--border); background: var(--bg); font-size: 1.05rem; }
.login input:focus { border-color: var(--accent); outline: none; }

.loading { color: var(--muted); padding: 1.5rem 0.25rem; }

/* --- Wantlist browsing --- */
.browse-controls { display: flex; gap: 0.5rem; align-items: stretch; }
.browse-controls .search-input { flex: 1; min-width: 0; }
select.sort {
  border: 2px solid var(--border); background: var(--card); border-radius: var(--radius);
  padding: 0.5rem; font-weight: 600; max-width: 42%;
}
