/* ---------------------------------------------------------------------------
   Game Score — design system
   Mobile-first, light/dark automatic, one accent gradient per game
--------------------------------------------------------------------------- */

:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #eceef4;
  --text: #16181d;
  --muted: #69707d;
  --border: rgba(20, 24, 40, 0.09);
  --shadow: 0 1px 2px rgba(16, 20, 34, 0.05), 0 8px 24px rgba(16, 20, 34, 0.07);
  --danger: #dc2626;
  --ok: #16a34a;
  --accent: #6366f1;
  --accent-2: #a855f7;
  --on-accent: #ffffff;
  --radius: 18px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e12;
    --surface: #191b22;
    --surface-2: #23252e;
    --text: #f1f2f6;
    --muted: #9aa1ad;
    --border: rgba(235, 238, 255, 0.09);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
    --danger: #f87171;
    --ok: #4ade80;
  }
}

/* --- thèmes par jeu : accent, halos de fond, couleurs signature ------------
   Par défaut, les halos dérivent de l'accent du jeu (posé en CSS ou en inline
   par jeu.js) ; certains jeux les surchargent avec leurs couleurs signature. */

body {
  --glow-a: color-mix(in srgb, var(--accent) 12%, transparent);
  --glow-b: color-mix(in srgb, var(--accent-2) 11%, transparent);
  --glow-c: transparent;
}

body[data-game='uno'] {
  --accent: #e11d48;
  --accent-2: #f59e0b;
  --uno-red: #e3342f;
  --uno-yellow: #f6c500;
  --uno-green: #2bb673;
  --uno-blue: #0096d6;
  --glow-a: rgba(227, 52, 47, 0.12);
  --glow-b: rgba(0, 150, 214, 0.11);
  --glow-c: rgba(246, 197, 0, 0.10);
}

body[data-game='flip7'] {
  --accent: #0891b2;
  --accent-2: #8b5cf6;
  --glow-a: rgba(8, 145, 178, 0.14);
  --glow-b: rgba(139, 92, 246, 0.14);
  --glow-c: rgba(236, 72, 153, 0.09);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 60rem at 85% -5%, var(--glow-a, transparent), transparent 55%),
    radial-gradient(50rem 50rem at -15% 35%, var(--glow-b, transparent), transparent 55%),
    radial-gradient(45rem 45rem at 70% 105%, var(--glow-c, transparent), transparent 55%);
  background-repeat: no-repeat;
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

input {
  font: inherit;
  color: inherit;
}

a { color: inherit; text-decoration: none; }

.wrap {
  max-width: 34rem;
  margin: 0 auto;
  padding: 0 1rem calc(6.5rem + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ app bar */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.app-bar-inner {
  max-width: 34rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.55rem 0.6rem;
  min-height: 3.25rem;
}

.app-bar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar .h1-text {
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* liseré signature sous la barre : accent du jeu par défaut */
body:not([data-game='home']) .app-bar::after {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* UNO : les 4 couleurs */
body[data-game='uno'] .app-bar::after {
  background: linear-gradient(90deg,
    var(--uno-red) 0 25%, var(--uno-yellow) 25% 50%,
    var(--uno-green) 50% 75%, var(--uno-blue) 75% 100%);
}

/* Flip 7 : dégradé néon */
body[data-game='flip7'] .app-bar::after {
  background: linear-gradient(90deg, #06b6d4, #8b5cf6 55%, #ec4899);
}

.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 1.25rem;
  transition: background 0.15s;
}

.icon-btn:active { background: var(--surface-2); }

/* ------------------------------------------------------------------ buttons */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.25rem;
  padding: 0 1.25rem;
  border-radius: 16px;
  font-weight: 650;
  font-size: 1rem;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}

.btn-soft {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.btn-ghost { color: var(--muted); min-height: 2.75rem; }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }

/* -------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.5rem 0 0.6rem 0.25rem;
}

/* --------------------------------------------------------------------- home */

.hero {
  text-align: center;
  padding: 2.25rem 1rem 0.75rem;
}

.hero .logo {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 24px;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 40%, transparent);
}

.hero h1 {
  margin: 0 0 0.35rem;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero p { margin: 0; color: var(--muted); font-size: 0.98rem; }

.search-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.4rem;
  padding: 0 1rem;
  min-height: 3.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.search-box:focus-within { border-color: var(--accent); }
.search-box span { color: var(--muted); font-size: 1.05rem; }

.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  font-size: 1rem;
  padding: 0.6rem 0;
}

.game-list { display: grid; gap: 0.8rem; margin-top: 0.5rem; }
.game-list .section-title { grid-column: 1 / -1; margin: 1rem 0 0; }
.game-list .empty-state { grid-column: 1 / -1; }

@media (min-width: 44rem) {
  .wrap.home { max-width: 46rem; }
  .game-list { grid-template-columns: 1fr 1fr; }
}

.game-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem;
  transition: transform 0.12s;
}

a.game-card:active { transform: scale(0.98); }

.game-card .tile {
  width: 3.4rem;
  height: 3.4rem;
  flex: none;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 1.7rem;
  color: #fff;
  background: linear-gradient(135deg, var(--tile-a, var(--accent)), var(--tile-b, var(--accent-2)));
}

.game-card .info { flex: 1; min-width: 0; }
.game-card .info b { display: block; font-size: 1.08rem; }
.game-card .info span { color: var(--muted); font-size: 0.86rem; }

.game-card .chevron { color: var(--muted); font-size: 1.2rem; }

.game-card.disabled { opacity: 0.55; }

.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--ok);
}

.badge-live::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: 0.35; } }

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2.5rem;
}

/* -------------------------------------------------------------------- setup */

.player-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.45rem 0.45rem 0.9rem;
}

.player-row .dot {
  width: 0.65rem;
  height: 0.65rem;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.player-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font-size: 1rem;
  padding: 0.55rem 0;
  outline: none;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.chip {
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.92rem;
  font-weight: 550;
  transition: transform 0.1s, background 0.15s, color 0.15s, border-color 0.15s;
}

.chip:active { transform: scale(0.94); }

.chip.on {
  background: var(--chip-on, linear-gradient(135deg, var(--accent), var(--accent-2)));
  border-color: transparent;
  color: var(--on-accent);
}

/* Flip 7 : bonus dorés, ×2 rose */
body[data-game='flip7'] .mod-row .chip.on { --chip-on: linear-gradient(135deg, #f59e0b, #f97316); }
body[data-game='flip7'] .mod-row .chip:last-child.on { --chip-on: linear-gradient(135deg, #ec4899, #8b5cf6); }

.pdot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-right: 0.45rem;
  vertical-align: 0.02em;
  background: var(--accent);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
}

.field-row label { font-weight: 600; }
.field-row .hint { display: block; font-weight: 400; font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }

.num-input {
  width: 6rem;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 0.55rem 0.4rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  outline: none;
}

.num-input:focus { border-color: var(--accent); }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0.25rem;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 0.25rem;
}

.seg button {
  padding: 0.6rem 0.5rem;
  border-radius: 11px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.seg button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.option-help { color: var(--muted); font-size: 0.85rem; margin: 0.6rem 0.25rem 0; line-height: 1.45; }

.divider { border: 0; border-top: 1px solid var(--border); margin: 0; }

/* --------------------------------------------------------------- scoreboard */

.winner-banner {
  text-align: center;
  padding: 1.4rem 1rem;
  border-radius: var(--radius);
  margin-top: 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 40%, transparent);
}

.winner-banner .trophy { font-size: 2.3rem; display: block; margin-bottom: 0.3rem; }
.winner-banner b { font-size: 1.25rem; }
.winner-banner p { margin: 0.25rem 0 0; opacity: 0.9; font-size: 0.9rem; }

.standings { display: grid; gap: 0.55rem; margin-top: 1rem; }

.standing {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.75rem 1rem;
}

.standing.leader { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

.standing .rank {
  width: 1.9rem;
  height: 1.9rem;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.standing.leader .rank {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
}

.standing .who { flex: 1; min-width: 0; }

.standing .who .name {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress {
  height: 0.32rem;
  border-radius: 99px;
  background: var(--surface-2);
  margin-top: 0.45rem;
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.standing .pts { text-align: right; }

.standing .pts .total {
  font-size: 1.45rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.standing .pts .delta {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.standing .pts .delta.gain { color: var(--ok); }

/* ------------------------------------------------------------------ history */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table.history {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

table.history th, table.history td {
  padding: 0.65rem 0.85rem;
  text-align: right;
  white-space: nowrap;
}

table.history th:first-child, table.history td:first-child {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  left: 0;
  background: var(--surface);
}

table.history thead th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  max-width: 6.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.history tbody tr { transition: background 0.15s; }
table.history tbody tr:active { background: var(--surface-2); }
table.history tbody tr + tr td { border-top: 1px solid var(--border); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------- bottom bar */

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
  pointer-events: none;
}

.bottom-bar-inner {
  max-width: 34rem;
  margin: 0 auto;
  display: flex;
  gap: 0.6rem;
  pointer-events: auto;
}

.bottom-bar .btn { flex: 1; }
.bottom-bar .btn-square { flex: none; width: 3.25rem; padding: 0; font-size: 1.25rem; }

/* ------------------------------------------------------------------- sheets */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(8, 10, 18, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

.sheet-backdrop.closing { animation: fade-out 0.18s ease forwards; }

.sheet {
  width: 100%;
  max-width: 34rem;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 0.6rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
  animation: slide-up 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet-backdrop.closing .sheet { animation: slide-down 0.18s ease forwards; }

.sheet .grip {
  width: 2.4rem;
  height: 0.3rem;
  border-radius: 99px;
  background: var(--border);
  margin: 0.35rem auto 0.8rem;
}

.sheet h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  text-align: center;
  font-weight: 750;
}

.sheet .hint-text {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  margin: 0.8rem 0 0;
  line-height: 1.5;
}

@media (min-width: 40rem) {
  .sheet-backdrop { align-items: center; padding: 1.5rem; }
  .sheet { border-radius: 24px; }
  .sheet .grip { display: none; }
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(35%); opacity: 0.4; } }
@keyframes slide-down { to { transform: translateY(30%); opacity: 0; } }

/* ------------------------------------------------------------- round sheet */

.score-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.9rem;
}

.score-row .name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-row .calc-btn {
  width: 2.6rem;
  height: 2.6rem;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 1.15rem;
}

.sheet .actions { display: grid; gap: 0.5rem; margin-top: 1.1rem; }

/* -------------------------------------------------------- flip7 calculator */

.calc-score {
  text-align: center;
  margin: 0.2rem 0 1rem;
}

.calc-score .value {
  font-size: 2.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.calc-score .detail { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; min-height: 1.2em; }

.calc-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.45rem;
}

.calc-grid .chip, .mod-row .chip {
  padding: 0;
  height: 2.7rem;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.98rem;
}

.mod-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.bust-btn {
  margin-top: 0.7rem;
  width: 100%;
  min-height: 2.9rem;
  border-radius: 14px;
  border: 1.5px dashed var(--border);
  font-weight: 650;
  color: var(--muted);
  transition: all 0.15s;
}

.bust-btn.on {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border-color: var(--danger);
  color: var(--danger);
}

.flash-bonus {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 750;
  color: var(--accent);
  animation: pop 0.3s ease;
}

@keyframes pop { from { transform: scale(0.6); } }

/* ----------------------------------------------------------------- confetti */

.confetti-box {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  overflow: hidden;
}

.confetti-box i {
  position: absolute;
  top: -3vh;
  width: 0.55rem;
  height: 0.85rem;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.7; }
}

/* -------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(6.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s cubic-bezier(0.22, 1, 0.36, 1), fade-out 0.3s ease 2.2s forwards;
  white-space: nowrap;
}

@keyframes toast-in { from { transform: translate(-50%, 1rem); opacity: 0; } }

/* --------------------------------------------------------------- menu sheet */

.menu-list { display: grid; gap: 0.25rem; }

.menu-list button {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.9rem 0.9rem;
  border-radius: 14px;
  font-weight: 600;
  font-size: 0.98rem;
  text-align: left;
  transition: background 0.15s;
}

.menu-list button:active { background: var(--surface-2); }
.menu-list button .ico { font-size: 1.2rem; width: 1.6rem; text-align: center; }
