/* Fiche Match Tennis
 * Idée : un tableau d'affichage de court (bleu dur, balle jaune) pour le score,
 * et des grands boutons verts / rouges pour gagner / perdre un point,
 * comme les deux couleurs de la fiche papier. */

:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #e6ecf1;
  --fg: #12202c;
  --muted: #566878;
  --line: #d3dce4;
  --court: #1b4d78;
  --court-deep: #123a5c;
  --court-fg: #ffffff;
  --ball: #d6e03a;
  --ball-fg: #1b2a00;
  --win: #1c7a4b;
  --win-bg: #e0f1e8;
  --win-line: #a5d3b9;
  --loss: #b8372f;
  --loss-bg: #f8e4e2;
  --loss-line: #e5b0ab;
  --focus: #1f6fb5;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d151c;
    --surface: #16212b;
    --surface-2: #1f2d39;
    --fg: #e7eef3;
    --muted: #96a7b5;
    --line: #2a3a47;
    --court: #1f5a8c;
    --court-deep: #173f61;
    --win: #55c88d;
    --win-bg: #14301f;
    --win-line: #265a3b;
    --loss: #f27d73;
    --loss-bg: #3a1a18;
    --loss-line: #6b2f2a;
    --focus: #7db8ea;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- Structure ---------- */

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  background: var(--court);
  color: var(--court-fg);
}
.topbar h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .iconbtn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font-size: 1.4rem;
}
.topbar .iconbtn:active { background: rgba(255, 255, 255, .15); }

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
}

.page.has-bar { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); }

.h2 {
  margin: 0;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 650;
  text-decoration: none;
  color: var(--fg);
}
.btn:active { background: var(--surface-2); }
.btn.primary {
  background: var(--court);
  border-color: var(--court);
  color: var(--court-fg);
}
.btn.primary:active { background: var(--court-deep); }
.btn.danger { color: var(--loss); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row > .btn { flex: 1 1 140px; }

/* ---------- Accueil ---------- */

.empty {
  padding: 28px 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; margin-bottom: 4px; color: var(--fg); font-size: 1.05rem; }

.matchlist { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.match {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}
.match:active { background: var(--surface-2); }
.match .vs { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.match .meta { grid-column: 1; color: var(--muted); font-size: .88rem; min-width: 0; overflow-wrap: anywhere; }
.match .score { font-weight: 700; text-align: right; white-space: nowrap; }
.chip {
  grid-column: 2;
  justify-self: end;
  padding: 1px 9px;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 700;
}
.chip.win { background: var(--win-bg); color: var(--win); }
.chip.loss { background: var(--loss-bg); color: var(--loss); }
.chip.live { background: var(--ball); color: var(--ball-fg); }

.hint { margin: 0; color: var(--muted); font-size: .88rem; }

/* ---------- Formulaire ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .lbl { font-size: .85rem; font-weight: 650; color: var(--muted); }
.field input[type="text"], .field input[type="date"] {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.fieldrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .fieldrow { grid-template-columns: 1fr; } }

.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button {
  flex: 1;
  min-height: 46px;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  font-weight: 600;
  font-size: .92rem;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--court); color: var(--court-fg); }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.check input { width: 22px; height: 22px; accent-color: var(--court); }

.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---------- Tableau d'affichage ---------- */

.stickyhead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--court);
}
.stickyhead .topbar { position: static; }
.scorebar {
  padding: 0 12px 10px;
  background: var(--court);
  color: var(--court-fg);
}
.board {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.board th {
  padding: 0 0 2px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .62);
  text-align: center;
}
.board td { padding: 3px 0; text-align: center; font-size: 1.35rem; font-weight: 700; }
.board td.name {
  text-align: left;
  font-size: 1rem;
  max-width: 0;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board td.srv { width: 26px; padding-right: 8px; text-align: left; }
.board td.set { width: 38px; color: rgba(255, 255, 255, .85); }
.board td.set.won { color: #fff; }
.board td.set sup { font-size: .6em; font-weight: 600; margin-left: 1px; }
.board td.game { width: 64px; }
.board td.game span {
  display: block;
  margin-left: 6px;
  padding: 2px 0;
  border-radius: 8px;
  background: var(--ball);
  color: var(--ball-fg);
}
.ball {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ball);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12);
  vertical-align: middle;
}
.ball.off { visibility: hidden; }

.lastpoint {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  margin-top: 6px;
  font-size: .85rem;
  color: rgba(255, 255, 255, .85);
}
.lastpoint b { color: #fff; }
.lastpoint .tag {
  padding: 0 7px;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 700;
  background: rgba(255, 255, 255, .18);
}

/* ---------- Grille de saisie ---------- */

.entry { display: flex; flex-direction: column; gap: 8px; }

.longtoggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 650;
  text-align: left;
}
.longtoggle small { font-weight: 500; color: var(--muted); }
.longtoggle .sw {
  flex: none;
  width: 44px;
  height: 26px;
  padding: 3px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: background .15s;
}
.longtoggle .sw i {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s;
}
.longtoggle[aria-pressed="true"] { border-color: var(--court); }
.longtoggle[aria-pressed="true"] .sw { background: var(--court); border-color: var(--court); }
.longtoggle[aria-pressed="true"] .sw i { transform: translateX(18px); background: #fff; }

.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 4px;
}
.cols .colhead {
  padding: 6px 4px;
  border-radius: 8px;
  text-align: center;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.colhead.win { background: var(--win-bg); color: var(--win); }
.colhead.loss { background: var(--loss-bg); color: var(--loss); }

.shotrow { display: flex; flex-direction: column; gap: 4px; }
.shotrow .rowlbl {
  padding-left: 2px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.shotrow .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.pt {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 6px 8px;
  border: 1px solid;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.pt.win { background: var(--win-bg); border-color: var(--win-line); color: var(--win); }
.pt.loss { background: var(--loss-bg); border-color: var(--loss-line); color: var(--loss); }
.pt.win:active { background: var(--win); color: #fff; }
.pt.loss:active { background: var(--loss); color: #fff; }
.pt.dim { opacity: .5; }
.pt.none {
  border-style: dashed;
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  pointer-events: none;
}
.pt small { display: block; margin-top: 1px; font-size: .72rem; font-weight: 600; opacity: .85; }

.gameover {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gameover strong { font-size: 1.15rem; }

/* ---------- Barre du bas ---------- */

.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  justify-content: center;
  padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.bottombar .inner { display: flex; gap: 8px; width: 100%; max-width: 536px; }
.bottombar .btn { flex: 1; min-height: 52px; }
.bottombar .btn.undo { flex: 1.6; }

/* ---------- Feuille d'options ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 16, 24, .55);
}
.sheet {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  border-radius: 18px 18px 0 0;
  background: var(--surface);
}
.sheet h2 { margin: 0 0 2px; font-size: 1.1rem; }
.sheet p { margin: 0; color: var(--muted); font-size: .92rem; }

/* ---------- Fiche d'observation ---------- */

.sheetdoc {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.sheetdoc h2.doc-title { margin: 0; font-size: 1.15rem; letter-spacing: .02em; text-transform: uppercase; }
.ident {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: .95rem;
}
.ident dt { color: var(--muted); }
.ident dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.dd-hint { margin-left: 6px; }
.resultbox { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; }
.resultbox i {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--fg);
  border-radius: 2px;
  position: relative;
}
.resultbox.on i::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 4px;
  height: 9px;
  border: solid var(--fg);
  border-width: 0 2px 2px 0;
  transform: rotate(40deg);
}

.sect-title {
  margin: 4px 0 0;
  font-size: .95rem;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.sect-title.win { color: var(--win); }
.sect-title.loss { color: var(--loss); }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
.stats th, .stats td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: center; }
.stats tr:last-child th, .stats tr:last-child td { border-bottom: 0; }
.stats thead th {
  background: var(--surface-2);
  font-size: .72rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats tbody th { text-align: left; font-weight: 600; width: 50%; }
.doc-note { margin: -6px 0 0; font-size: .8rem; color: var(--muted); }
.stats td.zero { color: var(--muted); }
.stats tr.total th, .stats tr.total td { font-weight: 800; background: var(--surface-2); }
.stats td.tot { font-weight: 700; border-left: 1px solid var(--line); }
.stats .pct { display: block; font-size: .7rem; font-weight: 500; color: var(--muted); }

.bigtotal { margin: 0; font-size: 1rem; font-weight: 800; }
.bigtotal.win { color: var(--win); }
.bigtotal.loss { color: var(--loss); }
.bigtotal span { font-size: 1.4rem; }

.sublist { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: .92rem; }
.sublist li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dotted var(--line); }
.sublist li:last-child { border-bottom: 0; }
.sublist b { font-variant-numeric: tabular-nums; }
.sublist .lbl { min-width: 0; overflow-wrap: anywhere; }
.subhead { margin: 0; font-size: .85rem; text-decoration: underline; color: var(--muted); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 92px);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  transform: translateX(-50%);
  border-radius: 10px;
  background: #1b2630;
  color: #fff;
  font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}

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

/* ---------- Impression / PDF ---------- */

@page { size: A4 portrait; margin: 12mm; }

@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #eef1f4; --fg: #000; --muted: #444;
    --line: #9aa5af; --win: #14633a; --win-bg: #fff; --loss: #a02a23; --loss-bg: #fff;
  }
  html, body { background: #fff; }
  body { font-size: 11pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .topbar, .no-print, .bottombar, .toast, .scrim { display: none !important; }
  #app { max-width: none; min-height: 0; display: block; }
  .page { padding: 0; gap: 10px; }
  .sheetdoc { border: 0; padding: 0; gap: 10px; }
  .tablewrap { overflow: visible; border-color: #777; }
  .stats th, .stats td { padding: 5px 6px; border-color: #bbb; }
  .stats thead th { background: #e8ecef !important; color: #000; }
  .stats tr.total th, .stats tr.total td { background: #eef1f4 !important; }
  table.stats, .sublist, .ident { break-inside: avoid; }
  .sect-title, .bigtotal { break-after: avoid; }
}
