:root {
  --bg: #ffffff;
  --bg-glass: rgba(255, 255, 255, .82);
  --ink: #0a0a0a;
  --ink-soft: #4d4d4d;
  --muted: #8a8a8a;
  --line: #e2e2e2;
  --rule: #0a0a0a;
  --good: #1f7a4c;
  --bad: #b23a2c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f;
    --bg-glass: rgba(15, 15, 15, .82);
    --ink: #f2f2f0;
    --ink-soft: #c4c2bc;
    --muted: #8f8d87;
    --line: #2a2a2a;
    --rule: #f2f2f0;
    --good: #7fd19c;
    --bad: #e2897a;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-glass: rgba(15, 15, 15, .82);
  --ink: #f2f2f0;
  --ink-soft: #c4c2bc;
  --muted: #8f8d87;
  --line: #2a2a2a;
  --rule: #f2f2f0;
  --good: #7fd19c;
  --bad: #e2897a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font-family: inherit; }
h1, h2, p { margin: 0; }

/* ---------------- topbar ---------------- */
.topbar {
  padding: 8px 16px 6px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-mark { display: block; color: var(--ink); flex-shrink: 0; }
.brand-line1 {
  font-weight: 800;
  font-size: clamp(22px, 7vw, 28px);
  letter-spacing: -.01em;
  line-height: 1;
  text-transform: uppercase;
}

/* ---------------- tabs ---------------- */
.tabs {
  display: flex;
  justify-content: center;
  border-bottom: 1px solid var(--line);
  padding: 0 18px;
  gap: 24px;
}
.tabs button {
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 9px 6px 7px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.tabs button:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

/* ---------------- layout ---------------- */
.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 20px;
}
.panel:not(.show) { display: none; }

/* ---------------- stats strip ---------------- */
.stats {
  display: flex;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin-bottom: 10px;
}
.stats[hidden] { display: none; }
.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 6px;
  text-align: center;
  border-right: 1px solid var(--line);
}
.stat:last-child { border-right: none; }
.stat-n {
  font-weight: 800;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.stat-l {
  font-weight: 600;
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------- quiz block ---------------- */
.quiz-block {
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.range-tag {
  text-align: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.swatch-frame {
  position: relative;
  width: 100%;
  margin: 0 0 14px;
}
.swatch {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 2px;
  background-size: 130%;
  background-position: center;
  background-repeat: no-repeat;
}

.hint-toggle {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.hint-toggle:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.hint-toggle svg { flex-shrink: 0; }
.hint-box {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  font-size: clamp(20px, 6vw, 28px);
  color: #fff;
  background: rgba(0, 0, 0, .4);
  border: none;
  border-radius: 2px;
  padding: 24px;
  margin: 0;
}
.hint-box[hidden] { display: none; }

.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.choice {
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  padding: 13px 6px;
  min-height: 48px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  .choice:hover:not(:disabled) { background: var(--ink); color: var(--bg); }
}
.choice:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.choice:disabled { cursor: default; }

.reveal-line {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  column-gap: 0.3em;
  min-height: 48px;
  padding: 4px 8px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .01em;
}
.reveal-line.is-good { color: var(--good); }
.reveal-line.is-bad { color: var(--bad); }
.reveal-name { color: var(--ink); }

.next {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 48px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
  background: var(--ink);
  color: var(--bg);
  border: none;
  cursor: pointer;
}
.next:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

.reset {
  display: block;
  margin: 12px auto 0;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .03em;
  color: var(--ink);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 6px;
}
@media (hover: hover) and (pointer: fine) {
  .reset:hover { color: var(--bad); }
}
.reset:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

/* ---------------- nuancier sheet ---------------- */
.sheet-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 10px 0;
  margin: 0 -16px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.switch-track {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s;
}
.switch input:checked ~ .switch-track .switch-thumb {
  background: var(--ink);
  transform: translateX(18px);
}
.switch input:focus-visible ~ .switch-track {
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}
.sheet-group { margin-bottom: 30px; }
.sheet-group h2 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.sheet-group h2 span {
  font-weight: 500;
  font-size: 11px;
  letter-spacing: .02em;
  text-transform: none;
  color: var(--muted);
}
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-flow: dense;
  gap: 16px 14px;
}
.tile {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.tile { grid-column: span 1; }
.tile.expanded { grid-column: 1 / -1; }
.tile-chip {
  display: block;
  aspect-ratio: 1/1;
  border: 1px solid var(--line);
  border-radius: 2px;
  background-size: 145%;
  background-position: center;
  background-color: var(--bg);
}
.tile.expanded .tile-chip { background-size: 115%; }
.tile-cap {
  display: block;
  padding: 8px 0 10px;
  border-bottom: 1px solid var(--line);
}
.tile.expanded .tile-cap { padding: 12px 0 16px; }
.tile-name { display: block; font-weight: 700; font-size: 12.5px; }
.tile.expanded .tile-name { font-size: 16px; }
.names-hidden .tile-name { display: none; }
.names-hidden .tile.expanded .tile-name { display: block; }
.tile-detail {
  display: block;
  margin-top: 4px;
  font-weight: 500;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.tile.expanded .tile-detail { font-size: 13px; margin-top: 6px; }

/* ---------------- ≥600px : tablette ---------------- */
@media (min-width: 600px) {
  .wrap { padding-top: 24px; }
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------------- ≥900px : desktop ---------------- */
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------------- retour en haut ---------------- */
.scroll-top {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border: none;
  background: var(--ink);
  color: var(--bg);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 50;
}
.scroll-top[hidden] { display: none; }
.scroll-top:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
