:root {
  --bg: #fff7ec;
  --surface: #ffffff;
  --ink: #2a2140;
  --muted: #7a7090;
  --line: #eadfce;
  --accent: #ff6b4a;
  --accent-ink: #ffffff;
  --accent-2: #5b5bd6;
  --good: #1fae6b;
  --bad: #e5484d;
  --shadow: 0 6px 18px rgba(60, 40, 20, .10), 0 1px 3px rgba(60, 40, 20, .08);
  --p1: #ffd2c7; --p2: #ffe7a6; --p3: #c6f0d8; --p4: #c9e4ff; --p5: #e2d6ff; --p6: #ffd3ea; --p0: #fff1d6;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17151f; --surface: #221f2d; --ink: #f3eefc; --muted: #a49cb8; --line: #332e42;
    --accent: #ff7a5c; --accent-2: #8b8bff;
    --shadow: 0 6px 18px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .3);
    --p1: #5a3029; --p2: #564719; --p3: #1f4a35; --p4: #213e5c; --p5: #3b3163; --p6: #57294a; --p0: #3a3322;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17151f; --surface: #221f2d; --ink: #f3eefc; --muted: #a49cb8; --line: #332e42;
  --accent: #ff7a5c; --accent-2: #8b8bff;
  --shadow: 0 6px 18px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .3);
  --p1: #5a3029; --p2: #564719; --p3: #1f4a35; --p4: #213e5c; --p5: #3b3163; --p6: #57294a; --p0: #3a3322;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

.screen {
  display: none;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 20px);
  max-width: 520px;
  margin: 0 auto;
  flex-direction: column;
}
.screen.active { display: flex; }

/* Accueil */
.home-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; }
.home-head h1 { font-size: 30px; letter-spacing: -.5px; margin: 0; flex: 1; }
.logo { position: relative; width: 44px; height: 44px; flex: none; }
.logo span {
  position: absolute; width: 18px; height: 18px; border-radius: 50%;
  left: 13px; top: 13px;
}
.logo span:nth-child(1) { background: var(--p1); transform: rotate(0deg) translateY(-14px); }
.logo span:nth-child(2) { background: var(--p2); transform: rotate(60deg) translateY(-14px); }
.logo span:nth-child(3) { background: var(--p3); transform: rotate(120deg) translateY(-14px); }
.logo span:nth-child(4) { background: var(--p4); transform: rotate(180deg) translateY(-14px); }
.logo span:nth-child(5) { background: var(--p5); transform: rotate(240deg) translateY(-14px); }
.logo span:nth-child(6) { background: var(--p6); transform: rotate(300deg) translateY(-14px); }
.logo b {
  position: absolute; inset: 11px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 17px; line-height: 1;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 45%;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-weight: 600; font-size: 15px; box-shadow: var(--shadow);
}
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--line); border-radius: 14px;
}
.seg button {
  border: 0; background: transparent; padding: 10px; border-radius: 11px;
  font-weight: 700; font-size: 16px; color: var(--muted);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.rule { color: var(--muted); font-size: 15px; line-height: 1.4; margin: 14px 2px; }
.rule b { color: var(--ink); }

.settings {
  background: var(--surface); border-radius: 20px; padding: 6px 16px 12px; box-shadow: var(--shadow);
}
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.setting-label { font-weight: 700; font-size: 16px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--bg);
  font-size: 24px; font-weight: 800; line-height: 1; color: var(--accent);
}
.stepper button:disabled { color: var(--muted); opacity: .35; }
.stepper button:active:not(:disabled) { transform: scale(.92); }
.stepper output {
  min-width: 48px; text-align: center; font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums;
}
.best-line { margin: 12px 0 0; font-size: 14px; color: var(--muted); text-align: center; }
.best-line b { color: var(--ink); }

.modes { display: grid; gap: 10px; margin-top: 18px; }
.btn {
  border: 0; border-radius: 18px; padding: 14px 18px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-weight: 800; font-size: 19px; width: 100%;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn small { font-weight: 600; font-size: 13px; opacity: .85; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 70%, #000); }
.btn.secondary { background: var(--accent-2); color: #fff; box-shadow: 0 6px 0 color-mix(in srgb, var(--accent-2) 70%, #000); }
.btn.ghost { background: var(--surface); box-shadow: var(--shadow); }
.btn.small { width: auto; font-size: 15px; padding: 10px 14px; background: var(--accent); color: #fff; border-radius: 12px; }
.btn:disabled { opacity: .4; }
.link { background: none; border: 0; color: var(--muted); font-size: 15px; padding: 14px; margin: 8px auto 0; }

/* Jeu */
.bar { display: flex; align-items: center; gap: 12px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface);
  box-shadow: var(--shadow); font-size: 17px; flex: none;
}
.progress { flex: 1; height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width .3s ease; }
.score { font-weight: 900; font-size: 18px; color: var(--good); font-variant-numeric: tabular-nums; min-width: 44px; }
.timer.hurry { color: var(--bad); animation: pulse 1s ease infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; min-width: 56px; text-align: right; }
.hint { text-align: center; color: var(--muted); font-size: 16px; margin: 18px 0 0; min-height: 22px; }
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.feedback { text-align: center; font-size: 26px; font-weight: 800; min-height: 36px; margin: 0; font-variant-numeric: tabular-nums; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); font-size: 18px; }

/* Fleur */
.flower { position: relative; flex: none; }
.num {
  position: absolute; border-radius: 50%; border: 0;
  display: grid; place-items: center; font-weight: 800; font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow), inset 0 -4px 0 rgba(0, 0, 0, .07);
  transform: translate(-50%, -50%);
  transition: background-color .2s, color .2s, transform .12s ease, opacity .2s;
  animation: pop .32s cubic-bezier(.3, 1.6, .5, 1) both;
}
.num:active { transform: translate(-50%, -50%) scale(.92); }
.num.wrong { background: var(--bad) !important; color: #fff; opacity: .45; animation: shake .35s ease; }
.num.pair { box-shadow: 0 0 0 4px var(--good), var(--shadow); }
.num.answer { background: var(--good) !important; color: #fff; transform: translate(-50%, -50%) scale(1.12); }
.flower.done .num:not(.answer):not(.pair) { opacity: .35; }
.flower.locked { pointer-events: none; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.3); opacity: 0; } }
@keyframes shake {
  20% { transform: translate(-58%, -50%); } 40% { transform: translate(-42%, -50%); }
  60% { transform: translate(-56%, -50%); } 80% { transform: translate(-45%, -50%); }
}

/* Composé */
.minis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; justify-items: center; }
.mini {
  position: relative; display: flex; justify-content: center; width: 100%;
  background: var(--surface); border-radius: 20px; padding: 6px; box-shadow: var(--shadow);
  transition: opacity .3s;
}
.mini.solved { opacity: .75; }
.mini-tag {
  position: absolute; top: 8px; left: 11px; font-size: 13px; font-weight: 800; color: var(--muted); z-index: 1;
}
.mini .num { box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .07); }
.mini .num.pair { box-shadow: 0 0 0 3px var(--good); }
.final-wrap { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.final-label { font-size: 14px; color: var(--muted); font-weight: 700; }
.slots { display: flex; gap: 10px; justify-content: center; }
.slot {
  width: 58px; height: 58px; border-radius: 50%; border: 2px dashed var(--line);
  display: grid; place-items: center; font-weight: 800; font-size: 20px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.slot.filled { border-style: solid; border-color: transparent; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); animation: pop .3s ease both; }
.slot small { font-size: 12px; }

/* Résultat */
#result { justify-content: center; }
.result-card {
  background: var(--surface); border-radius: 28px; padding: 28px 20px 22px; text-align: center;
  box-shadow: var(--shadow);
}
.stars { font-size: 42px; letter-spacing: 6px; min-height: 52px; }
.stars span { display: inline-block; animation: pop .4s cubic-bezier(.3, 1.6, .5, 1) both; }
.stars span.off { filter: grayscale(1); opacity: .25; }
.result-card h2 { margin: 6px 0 4px; font-size: 28px; }
.result-time { font-size: 52px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.result-detail { color: var(--muted); margin: 4px 0; font-size: 16px; }
.result-best { font-weight: 700; color: var(--accent-2); min-height: 22px; margin: 8px 0 18px; }
.last { margin: -6px 0 18px; display: flex; flex-direction: column; align-items: center; }
.last[hidden] { display: none; }
.last-title { margin: 0 0 4px; font-size: 14px; font-weight: 800; color: var(--muted); }
.last-eq { margin: 6px 0 0; font-size: 22px; font-weight: 900; color: var(--good); font-variant-numeric: tabular-nums; }
.last .num, .last .num.wrong { animation: none; }
.result-actions { display: grid; gap: 10px; }

/* Joueurs */
dialog {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: min(420px, calc(100vw - 32px)); max-width: none;
}
dialog::backdrop { background: rgba(20, 14, 30, .45); }
.sheet { background: var(--surface); border-radius: 24px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet h3 { margin: 0; font-size: 21px; }
.player-list { display: grid; gap: 8px; }
.player {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-radius: 14px; background: var(--bg); border: 2px solid transparent;
  font-weight: 700; font-size: 17px; width: 100%; text-align: left;
}
.player.on { border-color: var(--accent); }
.player .del { border: 0; background: none; color: var(--muted); font-size: 15px; padding: 2px 6px; }
.add-player { display: flex; gap: 8px; }
.add-player input {
  flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  -webkit-user-select: text; user-select: text;
}
