/* Flip 7 Score — feuille de style. Cartes à bord épais, ombres décalées, gros chiffres. */
:root {
  /* Turquoise « boîte de jeu », crème, encre bleu nuit, accents pastel façon cartes. */
  --bg: #5BC2CE;
  --dot: rgba(255, 255, 255, .28);
  --text: #1E1C4F;
  --muted: #2A4870;
  --card: #FFFAF0;
  --field: #FFF1D6;
  --panel: #FFF1D6;
  --edge: #1E1C4F;
  --accent: #F4A48F;          /* corail pastel (boutons principaux) */
  --accent-text: #1E1C4F;
  --accent-strong: #B5462F;   /* corail foncé, pour du texte lisible */
  --sun: #F6DA86;             /* jaune pastel */
  --danger: #C81E3A;
  --radius: 18px;
  --shadow: 4px 4px 0 var(--edge);
  --font: 'Bricolage Grotesque', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E2730;
    --dot: rgba(91, 194, 206, .12);
    --text: #F6EFDC;
    --muted: #9EC4CC;
    --card: #163A45;
    --field: #0E2730;
    --panel: #12323C;
    --edge: #3E8392;
    --danger: #FF8A96;
    --accent-strong: #F4A48F;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.6px, transparent 1.7px);
  background-size: 22px 22px;
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
b, .num, .ptotal, .pval, td, .rwins, .rec b { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); font-size: .9rem; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
body.has-keypad .app { padding-bottom: calc(var(--kp-h, 330px) + 24px); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 10px 18px;
  border: 3px solid var(--edge); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
  font-weight: 750; font-size: 1.1rem; letter-spacing: -.01em;
  transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--edge); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-big { width: 100%; min-height: 66px; font-size: 1.3rem; font-weight: 800; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-blue { background: #5FB8C4; color: #1E1C4F; }
.btn-small { min-height: 44px; font-size: .95rem; padding: 8px 14px; border-radius: 14px; box-shadow: 3px 3px 0 var(--edge); }
.btn-danger { color: var(--danger); }
.btn .count { background: var(--text); color: var(--card); border-radius: 99px; padding: 1px 10px; font-size: .95rem; }
.link { background: none; border: 0; padding: 6px 2px; text-decoration: underline; text-underline-offset: 3px; color: var(--muted); font-weight: 600; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--edge);
  background: var(--card); font-weight: 800; font-size: 1.1rem; display: grid; place-items: center;
}
.stack { display: grid; gap: 14px; margin: 18px 0; }
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 8px; }

/* ---------- Indicateur de synchro ---------- */
.sync {
  position: fixed; z-index: 30;
  top: calc(10px + env(safe-area-inset-top)); right: max(12px, calc(50vw - 308px));
  border: 2px solid var(--edge); border-radius: 99px; padding: 4px 11px;
  background: var(--card); font-size: .8rem; font-weight: 700;
}
.sync[data-state="ok"] { background: #A6DCC0; color: #1E1C4F; }
.sync[data-state="auth"] { background: var(--sun); color: #1E1C4F; }
.sync[data-state="error"], .sync[data-state="offline"] { background: var(--card); color: var(--muted); }
.banner {
  display: block; width: 100%; text-align: left; margin: 10px 0;
  border: 3px dashed var(--edge); border-radius: 14px; padding: 12px 14px;
  background: var(--sun); color: #1E1C4F; font-weight: 700;
}

/* ---------- Accueil ---------- */
.hero { text-align: center; padding: 34px 0 6px; }
.fan { position: relative; height: 136px; margin-bottom: 10px; }
/* Carte à chiffre : fond crème, double cadre, chiffre en couleur cerné d'encre, nom en toutes lettres. */
.pcard {
  position: absolute; left: 50%; top: 8px;
  width: 80px; height: 112px; margin-left: -40px;
  display: grid; place-items: center; align-content: center; gap: 2px;
  border: 2.5px solid var(--edge); border-radius: 10px;
  background: #FBF3DE;
  box-shadow: inset 0 0 0 4px #FBF3DE, inset 0 0 0 6px var(--c), 4px 4px 0 var(--edge);
  transform: translateX(var(--x)) rotate(var(--r));
  animation: deal .6s cubic-bezier(.2, 1.4, .4, 1) both;
}
.pcard b {
  font-size: 3rem; line-height: .95; font-weight: 800; letter-spacing: -.05em;
  color: var(--c); -webkit-text-stroke: 2px #1E1C4F; paint-order: stroke fill;
}
.pcard i {
  font-style: normal; font-size: .5rem; font-weight: 800; letter-spacing: .12em; color: #1E1C4F;
  background: #FFFDF6; border: 1.5px solid #1E1C4F; border-radius: 3px; padding: 1px 5px;
}
.pcard::before, .pcard::after {  /* petits losanges d'angle */
  content: ''; position: absolute; width: 8px; height: 8px; background: var(--c);
  border: 1.5px solid #1E1C4F; transform: rotate(45deg);
}
.pcard::before { top: 11px; left: 11px; }
.pcard::after { bottom: 11px; right: 11px; }
.pcard:nth-child(2) { z-index: 1; top: 0; animation-delay: .08s; }
.pcard:nth-child(3) { animation-delay: .16s; }
@keyframes deal { from { transform: translate(0, 40px) rotate(0); opacity: 0; } }
.logo { font-size: clamp(2.6rem, 12.5vw, 4.4rem); white-space: nowrap; line-height: .9; margin: 6px 0 10px; font-weight: 800; letter-spacing: -.055em; }
.logo span {
  display: inline-block; transform: rotate(8deg); margin: 0 .04em;
  color: var(--sun); -webkit-text-stroke: 3px #1E1C4F; paint-order: stroke fill;
}
.tagline { margin: 0 auto; max-width: 30ch; color: var(--muted); font-size: 1.02rem; }
.tagline b { color: var(--text); }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; margin: 0 0 4px; color: var(--muted); font-weight: 800; }
.foot { text-align: center; margin-top: 26px; }

.live {
  display: grid; gap: 10px; width: 100%; text-align: left;
  border: 3px solid var(--edge); border-radius: var(--radius); background: var(--card);
  box-shadow: 5px 5px 0 var(--accent); padding: 14px;
}
.live-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.live-names { display: flex; flex-wrap: wrap; gap: 6px; }
.live-cta { font-weight: 800; }
.badge, .round-badge {
  display: inline-block; border: 2px solid var(--edge); border-radius: 99px; padding: 2px 10px;
  background: var(--sun); color: #1E1C4F; font-weight: 800; font-size: .85rem;
}
.mini { border-radius: 8px; padding: 2px 8px; background: var(--pc); color: var(--pf); font-size: .9rem; font-weight: 600; border: 2px solid var(--edge); }

/* ---------- Barre de titre ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; padding-right: 96px; min-height: 48px; }
.topbar h1 { margin: 0; font-size: 1.55rem; letter-spacing: -.03em; font-weight: 800; }
.back {
  flex: none; width: 48px; height: 48px; border-radius: 14px; border: 3px solid var(--edge);
  background: var(--card); box-shadow: 3px 3px 0 var(--edge); font-size: 1.4rem; font-weight: 800;
}
.back:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--edge); }

/* ---------- Nouvelle partie ---------- */
.panel { background: var(--card); border: 3px solid var(--edge); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 16px; }
.panel p { margin: 6px 0 12px; }
.add-form { display: flex; gap: 10px; }
.add-form input {
  flex: 1; min-width: 0; min-height: 52px; padding: 8px 14px;
  border: 3px solid var(--edge); border-radius: 14px; background: var(--field); font-size: 1.15rem; font-weight: 600;
}
.add-form input:focus { outline: 3px solid var(--accent); outline-offset: 2px; }
.hint { color: var(--muted); font-size: .9rem; margin: 14px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--edge); border-radius: 99px; background: var(--field); padding: 9px 14px; font-weight: 700; min-height: 44px; }
.chip:active { background: var(--sun); color: #1E1C4F; }
.draft { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.draft li {
  display: grid; grid-template-columns: 44px 1fr 44px 44px; align-items: center; gap: 10px;
  background: var(--card); border: 3px solid var(--edge); border-radius: 16px; padding: 8px 10px; box-shadow: 3px 3px 0 var(--edge);
}
.dname { font-weight: 750; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.sticky-bottom { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); margin-top: 18px; }

.avatar {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 3px solid var(--edge);
  background: var(--pc); color: var(--pf);
  display: inline-grid; place-items: center; font-weight: 800; font-size: 1.3rem;
  transform: rotate(-5deg);
}

/* ---------- Partie en cours ---------- */
.round-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.round-head .round-badge { font-size: 1.05rem; padding: 4px 14px; }
.round-head .muted { margin-left: auto; }
.tb { background: var(--accent); color: var(--accent-text); border: 2px solid var(--edge); border-radius: 99px; padding: 2px 10px; font-weight: 800; font-size: .85rem; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.prow {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto 78px; align-items: center; gap: 10px;
  background: var(--card); border: 3px solid var(--edge); border-radius: 16px;
  padding: 8px 8px 8px 10px; box-shadow: 3px 3px 0 var(--edge); cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  scroll-margin-top: 70px; scroll-margin-bottom: calc(var(--kp-h, 330px) + 14px);
}
.prow.is-active { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--pc), 6px 6px 0 3px var(--edge); }
.prow.is-out { opacity: .45; cursor: default; }
.pinfo { display: grid; gap: 6px; min-width: 0; }
.pname { font-weight: 750; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crown { color: #C99A1E; }
.bar { position: relative; height: 10px; border: 2px solid var(--edge); border-radius: 99px; background: var(--field); overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--pc); opacity: .45; border-radius: 99px; transition: width .25s; }
.bar i.base { opacity: 1; }
.ptotal { display: grid; justify-items: end; line-height: 1; }
.ptotal b { font-size: 1.75rem; font-weight: 800; letter-spacing: -.03em; }
.ptotal small { font-size: .78rem; color: var(--muted); font-weight: 700; margin-top: 3px; }
.pval {
  height: 62px; border: 3px solid var(--edge); border-radius: 12px; background: var(--field);
  display: grid; place-items: center; align-content: center; line-height: 1;
}
.pval b { font-size: 2rem; font-weight: 800; letter-spacing: -.04em; }
.pval b.ph { color: var(--muted); opacity: .5; }
.pval small { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.pval.is-out { color: var(--muted); }
.pval.bust { background: var(--edge); color: #FFF3DF; }
.pval.f7 small { color: inherit; }
.is-active .pval { background: var(--pc); color: var(--pf); transform: rotate(-3deg); }
.is-active .pval.bust { background: var(--edge); color: #fff; }

/* Clavier */
.keypad {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--panel); border-top: 3px solid var(--edge);
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}
.kp-inner { max-width: 640px; margin: 0 auto; }
.kp-who { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 2px 10px; min-height: 36px; }
.kp-who > span:first-child { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; min-width: 0; }
.kp-who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-who .avatar { width: 34px; height: 34px; font-size: 1rem; border-width: 2px; border-radius: 9px; }
.kp-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.key {
  min-height: 58px; border: 3px solid var(--edge); border-radius: 14px; background: var(--card);
  box-shadow: 3px 3px 0 var(--edge);
  font-size: 1.8rem; font-weight: 800; line-height: 1;
  display: grid; place-items: center; align-content: center; user-select: none; -webkit-user-select: none;
}
.key:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--edge); }
.key small { font-size: .72rem; font-weight: 700; opacity: .8; margin-top: 2px; }
.key-fn { font-size: 1.5rem; }
.key-bust { background: #1E1C4F; color: #FFF3DF; font-size: 1.1rem; }
.key-f7 { background: var(--sun); color: #1E1C4F; font-size: 1.1rem; }
.key[aria-pressed="true"] { outline: 4px solid var(--accent); outline-offset: -9px; }
.key-zero { grid-column: span 2; }
.key-next { grid-column: span 2; background: var(--card); font-size: 1.15rem; }
.key-next.is-ready { background: var(--accent); color: var(--accent-text); animation: pulse 1.4s infinite; }
@media (prefers-color-scheme: dark) {
  .key-bust, .pval.bust, .is-active .pval.bust { background: #071A20; color: #FFF3DF; }
  .btn .count { background: #FFF3DF; color: #0E2730; }
}
@media (max-height: 700px) {
  .key { min-height: 50px; }
  .kp-who { margin-bottom: 6px; }
}

/* Tableau des manches */
.rounds { margin-top: 20px; background: var(--card); border: 3px solid var(--edge); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.rounds summary { padding: 14px; font-weight: 750; cursor: pointer; }
.rounds summary::marker { color: var(--accent-strong); }
.table-wrap { overflow-x: auto; border-top: 3px solid var(--edge); }
table { border-collapse: collapse; width: 100%; font-size: 1rem; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid color-mix(in srgb, var(--edge) 18%, transparent); white-space: nowrap; }
thead th { font-size: .85rem; font-weight: 800; position: sticky; top: 0; background: var(--card); }
th:first-child { text-align: center; color: var(--muted); width: 1%; }
.th-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--pc); border: 1.5px solid var(--edge); margin-right: 5px; }
tfoot td, tfoot th { font-weight: 800; font-size: 1.1rem; border-top: 3px solid var(--edge); border-bottom: 0; }
td.win { color: var(--accent-strong); }
td sup { font-size: .62rem; font-weight: 800; color: #2E8F68; margin-left: 2px; }
.t-bust { text-decoration: line-through; color: var(--muted); }
tr.clickable { cursor: pointer; }
tr.clickable:active, tr.is-editing { background: #F6DA8666; }

/* ---------- Fin de partie ---------- */
.winner {
  position: relative; overflow: hidden; text-align: center;
  background: var(--pc); color: var(--pf);
  border: 3px solid var(--edge); border-radius: 26px; box-shadow: 6px 6px 0 var(--edge);
  padding: 26px 16px 22px; margin-bottom: 18px;
}
.winner > * { position: relative; }
.star {
  position: absolute; width: 360px; height: 360px; left: 50%; top: 50%; margin: -180px 0 0 -180px;
  background: currentColor; opacity: .14;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  animation: spin 24s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.kicker { margin: 0; text-transform: uppercase; letter-spacing: .2em; font-weight: 800; font-size: .9rem; }
.winner h2 { margin: 4px 0; font-size: clamp(2.4rem, 12vw, 3.6rem); line-height: 1; letter-spacing: -.045em; font-weight: 800; overflow-wrap: anywhere; }
.wscore { margin: 8px 0 2px; font-weight: 700; }
.wscore b { font-size: 3rem; letter-spacing: -.04em; }
.wmeta { margin: 0; opacity: .85; font-size: .95rem; }
.final { list-style: none; padding: 0; margin: 0 0 6px; display: grid; gap: 8px; }
.final li, .rank {
  display: grid; grid-template-columns: 28px 44px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  background: var(--card); border: 3px solid var(--edge); border-radius: 16px; padding: 8px 14px 8px 10px; box-shadow: 3px 3px 0 var(--edge);
}
.final li b { font-size: 1.5rem; font-weight: 800; }
.pos { font-weight: 800; color: var(--muted); text-align: center; font-size: 1.1rem; }
.final li:first-child .pos { color: var(--accent-strong); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; border: 1.5px solid #1E1C4F;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translate(var(--drift), 110vh) rotate(var(--rot)); } }

/* ---------- Classement ---------- */
.records { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.rec {
  background: var(--c); color: var(--t, #1E1C4F); border: 3px solid var(--edge); border-radius: 16px; box-shadow: 3px 3px 0 var(--edge);
  padding: 10px 12px; display: grid; line-height: 1.1;
}
.rec small { font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; opacity: .9; }
.rec b { font-size: 2.1rem; font-weight: 800; letter-spacing: -.04em; margin: 4px 0 2px; }
.rec span { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.rank { grid-template-columns: 28px 44px minmax(0, 1fr) auto; row-gap: 10px; }
.rname { display: grid; min-width: 0; }
.rname b { font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rname small { color: var(--muted); font-size: .85rem; }
.rwins { display: grid; justify-items: center; line-height: 1; }
.rwins b { font-size: 2rem; font-weight: 800; }
.rwins small { font-size: .72rem; font-weight: 700; color: var(--muted); }
.rstats {
  grid-column: 1 / -1; margin: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  border-top: 2px dashed color-mix(in srgb, var(--edge) 30%, transparent); padding-top: 10px;
}
.rstats div { text-align: center; }
.rstats dt { font-size: .68rem; color: var(--muted); font-weight: 700; line-height: 1.1; }
.rstats dd { margin: 3px 0 0; font-weight: 800; font-size: 1.15rem; }
.podium.p1 { box-shadow: 5px 5px 0 var(--sun), 5px 5px 0 3px var(--edge); }
.podium.p1 .pos { color: #C99A1E; font-size: 1.4rem; }
.podium.p2 .pos, .podium.p3 .pos { color: var(--text); }
@media (max-width: 340px) {
  .rstats { grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
}
@media (max-width: 380px) {
  .rstats dt { font-size: .62rem; }
  .prow { grid-template-columns: 38px minmax(0, 1fr) auto 68px; gap: 8px; }
  .prow .avatar { width: 38px; height: 38px; font-size: 1.1rem; }
}

/* ---------- Historique ---------- */
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.hist {
  width: 100%; text-align: left; display: grid; gap: 8px;
  background: var(--card); border: 3px solid var(--edge); border-radius: 16px; padding: 12px 14px; box-shadow: 3px 3px 0 var(--edge);
}
.hist:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--edge); }
.hwin { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; }
.hwin .num { margin-left: auto; font-weight: 800; font-size: 1.5rem; }
.hothers { color: var(--muted); font-size: .92rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 40; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--edge); color: #FFF3DF; border-radius: 14px; padding: 12px 18px; font-weight: 700;
  max-width: calc(100vw - 32px); text-align: center; transition: opacity .2s, transform .2s;
}
@media (prefers-color-scheme: dark) { .toast { background: #FFF3DF; color: #1E1C4F; } }
body.has-keypad .toast { bottom: calc(var(--kp-h, 330px) + 14px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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