:root {
  --bg: #0b1a14;
  --panel: #12261d;
  --line: #24453a;
  --text: #f2f7f4;
  --muted: #9fb8ad;
  --a: #1f6feb;
  --a-deep: #163f80;
  --b: #e8590c;
  --b-deep: #8a3608;
  --ball: #d8f34a;
  --star: #ffd43b;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

.app { height: 100dvh; display: flex; flex-direction: column; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }

/* Tableau des sets */
.board { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px 10px; }
#sets { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#sets td { padding: 3px 6px; text-align: center; font-weight: 700; font-size: 1.05rem; }
#sets td.n { text-align: left; font-weight: 600; width: 100%; max-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
#sets tr:first-child td.n::before, #sets tr:last-child td.n::before { content: ""; display: inline-block;
  width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: 1px; }
#sets tr:first-child td.n::before { background: var(--a); }
#sets tr:last-child td.n::before { background: var(--b); }
#sets td.cur { color: var(--ball); }
#sets td.lost { color: var(--muted); font-weight: 500; }
#sets sup { font-size: .65em; color: var(--muted); margin-left: 1px; }

/* Zones de jeu */
.courts { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.team { flex: 1; min-height: 0; border: 0; border-radius: 22px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  user-select: none; -webkit-user-select: none; transition: transform .08s ease, filter .2s; }
.team-a { background: linear-gradient(160deg, var(--a), var(--a-deep)); }
.team-b { background: linear-gradient(160deg, var(--b), var(--b-deep)); }
.team:active { transform: scale(.985); filter: brightness(1.12); }
.team.flash::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0;
  animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .35; } to { opacity: 0; } }

.team-head { display: flex; align-items: center; gap: 10px; font-size: clamp(1rem, 4.5vw, 1.4rem);
  font-weight: 700; max-width: 90%; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.serve { width: 18px; height: 18px; border-radius: 50%; background: var(--ball); flex: none;
  box-shadow: 0 0 0 3px rgba(0,0,0,.18); visibility: hidden; }
.team.serving .serve { visibility: visible; }
.points { font-size: clamp(4.5rem, 24vw, 11rem); font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em; text-shadow: 0 4px 18px rgba(0,0,0,.25); }
.games { font-size: clamp(.9rem, 3.8vw, 1.15rem); opacity: .9; font-weight: 600; }

/* Bandeau d'état */
.status { min-height: 2.4em; display: flex; align-items: center; justify-content: center; text-align: center;
  font-weight: 700; font-size: 1.05rem; color: var(--muted); border-radius: 12px; padding: 4px 10px; }
.status.deuce { color: var(--text); background: var(--panel); border: 1px solid var(--line); }
.status.star { color: #1b1300; background: var(--star); animation: pulse 1.2s ease-in-out infinite; }
.status.tb { color: var(--ball); background: var(--panel); border: 1px solid var(--line); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,212,59,.25); } }

/* Barre d'outils */
.toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.toolbar button { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 6px; font-weight: 600; font-size: .95rem; }
.toolbar button:active { background: var(--line); }
.toolbar button:disabled { opacity: .4; }

/* Paysage : équipes côte à côte */
@media (orientation: landscape) and (max-height: 600px) {
  .courts { flex-direction: row; }
  .status { position: absolute; left: 50%; transform: translateX(-50%); bottom: 72px; z-index: 2;
    background: var(--panel); border: 1px solid var(--line); }
  .status:empty { display: none; }
  .points { font-size: clamp(4rem, 24vh, 9rem); }
  .board { padding: 2px 10px; }
  #sets td { padding: 1px 6px; font-size: .95rem; }
}
@media (orientation: landscape) and (min-height: 601px) { .courts { flex-direction: row; } }

/* Dialogues */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px; width: min(92vw, 420px); max-height: 90dvh; }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 12px; font-size: 1.3rem; }
#winner { text-align: center; }
.trophy { font-size: 3.5rem; margin: 0; }
#winnerScore { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ball); }
form label { display: block; margin: 0 0 10px; font-weight: 600; }
form input[type=text], form input:not([type]) { display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 12px; padding: 8px 12px 2px; }
legend { color: var(--muted); font-size: .9rem; padding: 0 4px; }
label.opt { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin-bottom: 8px; }
label.opt input { margin-top: 3px; accent-color: var(--ball); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.dlg-actions button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.dlg-actions .primary { background: var(--ball); color: #142000; border-color: var(--ball); }
#winner .dlg-actions { justify-content: center; }
