/* ============================================================
   ScoreBot clone — Thème
   👉 TOUT le design se règle ici. Remplacez ces variables par
      vos couleurs / polices / arrondis et l'app entière suit.
   ============================================================ */
:root {
  /* Couleurs de base — fond bleu nuit (rappel du bleu royal de la raquette) */
  --bg:          #0a1020;
  --surface:     #111b30;
  --surface-2:   #18243d;
  --surface-3:   #233253;
  --border:      #2a3a5a;
  --text:        #eef3fb;
  --muted:       #93a3c0;
  --muted-2:     #5b6b8a;

  /* Accents = couleurs du logo PADEL MG */
  --team-a:      #b9e21a;  /* vert citron — la balle & le "MG" */
  --team-a-ink:  #0a1020;
  --team-b:      #1ba3e6;  /* bleu azur — le swoosh */
  --team-b-ink:  #061322;
  --royal:       #1f44c4;  /* bleu royal — la raquette */
  --accent:      var(--team-a);
  --accent-ink:  var(--team-a-ink);
  --danger:      #f0506e;
  --warn:        #ffb648;
  --ok:          #37c98a;

  /* Typo */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-score: "SF Pro Display", "Segoe UI", var(--font);

  /* Formes, profondeur & mouvement */
  --radius:      24px;
  --radius-sm:   14px;
  --radius-pill: 999px;
  --gap:         16px;
  --shadow:      0 24px 60px rgba(0,0,0,.5);
  --shadow-sm:   0 8px 22px rgba(0,0,0,.32);
  --ring:        0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
  --ease:        cubic-bezier(.2,.8,.2,1);
  --t-fast:      .12s;
  --t:           .22s;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 82% -12%, color-mix(in srgb, var(--team-b) 16%, transparent), transparent 60%),
    radial-gradient(1000px 640px at -12% 112%, color-mix(in srgb, var(--team-a) 11%, transparent), transparent 55%),
    radial-gradient(900px 700px at 50% 50%, color-mix(in srgb, var(--royal) 10%, transparent), transparent 70%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  user-select: none;
}

/* ---------------- App shell & écrans ---------------- */
#app { height: 100%; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; animation: screenIn var(--t) var(--ease); }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px) scale(.995); } to { opacity: 1; transform: none; } }

.appbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(14px);
  position: relative; z-index: 5;
}
.appbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .3px; font-size: 17px; }
.appbar .brand img { width: 30px; height: 30px; border-radius: 9px; box-shadow: var(--shadow-sm); }
.appbar .brand b { color: var(--accent); }
.appbar .spacer { flex: 1; }

.iconbtn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); width: 44px; height: 44px; border-radius: var(--radius-sm);
  font-size: 18px; cursor: pointer; display: grid; place-items: center;
  transition: transform var(--t-fast) var(--ease), background var(--t), border-color var(--t);
}
.iconbtn:hover { background: var(--surface-3); border-color: var(--muted-2); }
.iconbtn:active { transform: scale(.92); }
.iconbtn[disabled] { opacity: .3; cursor: not-allowed; }

.content { flex: 1; min-height: 0; overflow-y: auto; padding: 22px; -webkit-overflow-scrolling: touch; }

/* Logo de marque (écran d'accueil) */
.logo-hero { display: flex; justify-content: center; padding: 6px 0 22px; }
.logo-hero img {
  max-height: 124px; max-width: min(82%, 360px); height: auto; width: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 28px rgba(0,0,0,.45));
}

/* ---------------- Boutons & contrôles ---------------- */
.btn {
  appearance: none; border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 16px 22px; font-size: 16px; font-weight: 700; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  transition: transform var(--t-fast) var(--ease), filter var(--t), background var(--t), box-shadow var(--t);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff), var(--accent));
  color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn.primary:hover { filter: brightness(1.04); background: var(--accent); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }

.card {
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, #fff 0%), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
  position: relative;
}
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.input {
  width: 100%; padding: 14px 16px; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color var(--t), box-shadow var(--t);
}
.input::placeholder { color: var(--muted-2); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

/* Menu déroulant (voix) */
select.input {
  -webkit-appearance: none; appearance: none; cursor: pointer; padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2393a3c0' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
select.input option { background: var(--surface-2); color: var(--text); }

/* Curseurs (vitesse / tonalité) */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; margin: 8px 0; border-radius: 999px; background: var(--surface-3); outline: none; cursor: pointer; }
.range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 2px 8px rgba(0,0,0,.45); cursor: pointer; }
.range::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 2px 8px rgba(0,0,0,.45); cursor: pointer; }
.field > label span[id$="-val"] { color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: 0; }

#voice-options { transition: opacity var(--t); }
#voice-options.disabled { opacity: .4; pointer-events: none; filter: grayscale(.3); }

/* Segmented control */
.segmented { display: flex; gap: 6px; background: var(--surface-2); padding: 6px; border-radius: var(--radius-pill); border: 1px solid var(--border); }
.segmented button {
  flex: 1; appearance: none; border: none; background: transparent; color: var(--muted);
  padding: 12px; border-radius: var(--radius-pill); font-weight: 700; font-size: 15px; cursor: pointer;
  transition: color var(--t), background var(--t), transform var(--t-fast) var(--ease);
}
.segmented button:active { transform: scale(.96); }
.segmented button[aria-pressed="true"] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 26%, transparent);
}

/* Toggle row */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; }
.toggle-row .label b { display: block; font-size: 15px; }
.toggle-row .label span { color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: background var(--t); }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: transform var(--t) var(--ease); box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.switch input:checked ~ .track { background: var(--accent); }
.switch input:checked ~ .thumb { transform: translateX(22px); }

.divider { height: 1px; background: var(--border); margin: 4px 0; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------------- Tableau de score ---------------- */
.board {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px;
  position: relative;
}
/* lignes de terrain en filigrane */
.board::before {
  content: ""; position: absolute; inset: 10px; pointer-events: none; border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), color-mix(in srgb, var(--text) 7%, transparent) 50%, transparent calc(50% + 1px));
}

.team {
  position: relative; border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; border: 1px solid var(--border);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t), border-color var(--t);
}
.team.a { background: radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--team-a) 12%, var(--surface)), var(--surface) 70%); }
.team.b { background: radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--team-b) 14%, var(--surface)), var(--surface) 70%); }
.team::after { /* barre d'accent en bas */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px;
}
.team.a::after { background: linear-gradient(90deg, transparent, var(--team-a), transparent); }
.team.b::after { background: linear-gradient(90deg, transparent, var(--team-b), transparent); }
.team:active { transform: scale(.99); }
.team.serving.a { border-color: color-mix(in srgb, var(--team-a) 55%, var(--border)); }
.team.serving.b { border-color: color-mix(in srgb, var(--team-b) 55%, var(--border)); }

/* éclat au point marqué */
.team.flash { animation: teamFlash .45s var(--ease); }
.team.a.flash { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--team-a) 60%, transparent); }
.team.b.flash { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--team-b) 60%, transparent); }
@keyframes teamFlash { 0% { filter: brightness(1.35); } 100% { filter: brightness(1); } }

.team .name {
  display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: clamp(15px, 3.6vw, 24px);
  letter-spacing: .3px; padding: 0 14px; text-align: center;
}
.team.a .name { color: var(--team-a); }
.team.b .name { color: var(--team-b); }
.team .server { width: 11px; height: 11px; border-radius: 50%; background: var(--muted-2); flex: none; transition: box-shadow var(--t), background var(--t); }
.team.serving .server { background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 22%, transparent), 0 0 16px currentColor; }

.team .point {
  font-family: var(--font-score);
  font-weight: 800; line-height: .9; margin: 8px 0;
  font-size: clamp(76px, 27vw, 240px);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 30px color-mix(in srgb, currentColor 22%, transparent);
}
.team.a .point { color: var(--team-a); }
.team.b .point { color: var(--team-b); }
.team .point.pop { animation: pointPop .32s var(--ease); }
@keyframes pointPop { 0% { transform: scale(1.28); } 60% { transform: scale(.97); } 100% { transform: scale(1); } }

.team .sub { display: flex; gap: 18px; color: var(--muted); font-weight: 700; font-size: clamp(13px, 2.4vw, 18px); }
.team .sub .games b { color: var(--text); font-size: 1.25em; }
.team .sets { display: flex; gap: 6px; margin-top: 8px; min-height: 26px; }
.team .sets .chip {
  background: color-mix(in srgb, var(--surface-2) 70%, transparent); border: 1px solid var(--border); border-radius: 8px;
  min-width: 26px; padding: 3px 7px; text-align: center; font-weight: 800; font-size: 13px; color: var(--muted);
}

.match-status {
  align-self: center; margin: 8px auto 0; padding: 6px 16px; border-radius: var(--radius-pill);
  font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: 12px;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
  opacity: 0; transform: translateY(-4px); transition: opacity var(--t), transform var(--t);
}
.match-status.show { opacity: 1; transform: none; }
.match-status.is-accent { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.match-status.is-warn { color: #1b1206; background: var(--warn); border-color: transparent; }

.controls { display: flex; gap: 10px; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); justify-content: center; }
.controls .btn { flex: none; padding: 14px 20px; }

/* ---------------- Overlay vainqueur ---------------- */
.overlay {
  position: fixed; inset: 0; display: none; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(10px); z-index: 50;
  overflow: hidden;
}
.overlay.show { display: grid; animation: screenIn var(--t) var(--ease); }
.overlay .modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px 28px; max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow); position: relative; z-index: 2; }
.overlay .trophy { font-size: 60px; animation: trophyPop .6s var(--ease); }
@keyframes trophyPop { 0% { transform: scale(0) rotate(-25deg); } 60% { transform: scale(1.2) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }
.overlay h2 { margin: 10px 0 2px; font-size: 27px; }
.overlay .final { color: var(--muted); margin: 8px 0 22px; font-weight: 800; letter-spacing: .14em; font-variant-numeric: tabular-nums; }

/* confettis */
.confetti { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; z-index: 1; will-change: transform, opacity; }
@keyframes confettiFall { to { transform: translateY(105vh) rotate(720deg); opacity: .9; } }

/* ---------------- Historique ---------------- */
.history-item { display: flex; align-items: center; gap: 14px; }
.history-item .meta { flex: 1; min-width: 0; }
.history-item .meta .top { display: flex; gap: 8px; align-items: baseline; }
.history-item .sport-tag { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); font-weight: 800; }
.history-item .date { color: var(--muted-2); font-size: 12px; }
.history-item .teams { font-weight: 700; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .winner-name { color: var(--ok); }
.history-item .score { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); letter-spacing: .04em; }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.empty .big { font-size: 46px; margin-bottom: 10px; }

/* ---------------- Ma voix (enregistrements) ---------------- */
.rec-progress { color: var(--muted); font-weight: 700; font-size: 13px; }
.rec-progress b { color: var(--accent); }
.opt-tag { font-size: 11px; color: var(--muted-2); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.rec-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.rec-row .rec-state { width: 18px; text-align: center; color: var(--muted-2); font-weight: 800; }
.rec-row.done .rec-state { color: var(--ok); }
.rec-row .rec-label { flex: 1; font-weight: 600; min-width: 0; }
.rec-row .rec-play { color: var(--team-b); font-size: 14px; }
.rec-row .rec-mic { color: var(--danger); font-size: 13px; }
.rec-row .rec-mic.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: recPulse 1.1s infinite; }
@keyframes recPulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent); }
  70% { box-shadow: 0 0 0 12px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }

/* ---------------- Responsive ---------------- */
@media (orientation: portrait) {
  .board { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .board::before { background: linear-gradient(180deg, transparent calc(50% - 1px), color-mix(in srgb, var(--text) 7%, transparent) 50%, transparent calc(50% + 1px)); }
}
@media (min-width: 720px) {
  .content { max-width: 680px; margin: 0 auto; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
