/* KmerPing Live — feuille de styles unique, pensée d'abord pour le téléphone.
   Polices système : aucun téléchargement de police sur les connexions mobiles. */

:root {
  /* Couleurs du logo KmerPing : noir, orange, blanc */
  --black: #000000;
  --orange: #ff7a00;      /* orange du logo : fonds et accents, texte noir dessus */
  --orange-deep: #e85d04; /* dégradé du logo */
  --orange-ink: #b34700;  /* orange lisible sur fond clair (contraste 5,5:1) */
  --orange-tint: #fff1e5;
  --white: #ffffff;
  --paper: #f4f4f2;
  --surface: #ffffff;
  --ink: #141414;
  --muted: #5c5f66;
  --rule: #dcdcd8;
  --danger: #b3261e;
  --warn-bg: #fff4e5;
  --warn-ink: #7a3f00;
  --ok-bg: #e9f5ec;
  --ok-ink: #1d5c33;
  --radius-s: 6px;
  --radius-m: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}
a { color: var(--orange-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

/* En-tête : noir du logo, soulignement orange en dégradé comme le trait du logo */
.top { background: var(--black); position: sticky; top: 0; z-index: 10; }
.top::after { content: ""; display: block; height: 3px; background: linear-gradient(90deg, var(--orange-deep), var(--orange) 60%, #ffb000); }
.top-inner { max-width: 960px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { height: 40px; width: auto; display: block; }
.brand-sub { color: var(--white); font-size: 13px; font-weight: 600; padding-left: 10px; border-left: 1px solid #3a3a3a; }
.top-nav { display: flex; gap: 14px; align-items: center; }
.top-nav a, .top-nav .linklike { color: var(--white); font-size: 14px; text-decoration: none; }
.top-nav a:hover, .top-nav .linklike:hover { color: var(--orange); }
@media (max-width: 400px) { .brand-sub { display: none; } }
.top-nav form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

.page { max-width: 960px; margin: 0 auto; padding: 20px 16px 48px; }
.narrow { max-width: 420px; margin: 0 auto; }
/* Pied de page */
.foot { background: var(--black); color: #c9c9c6; font-size: 14px; margin-top: 32px; }
.foot-inner { max-width: 960px; margin: 0 auto; padding: 24px 16px 28px; display: grid; gap: 16px; }
.foot p { margin: 0; }
.foot a { color: var(--white); }
.foot-title { color: var(--white); font-weight: 700; margin-bottom: 4px !important; }
.foot-contact { display: grid; gap: 2px; }
.foot-contact a { text-decoration: none; }
.foot-contact a:hover { color: var(--orange); }
.foot-note { color: #9a9a96; font-size: 13px; }
.signature { display: inline-flex; align-items: center; gap: 10px; color: #c9c9c6; text-decoration: none; padding-top: 16px; border-top: 1px solid #2a2a2a; }
a.signature:hover span { color: var(--orange); }
.signature img { height: 32px; width: auto; background: var(--white); border-radius: 6px; padding: 2px; }

.page-title { font-size: 24px; font-weight: 750; letter-spacing: -.015em; }
.lead { color: var(--muted); margin: 8px 0 20px; max-width: 60ch; }
.section-title { font-size: 17px; margin: 28px 0 10px; display: flex; align-items: center; gap: 8px; }
.note { color: var(--muted); font-size: 14px; margin: 8px 0; }
.empty { color: var(--muted); margin: 12px 0; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

/* Messages */
.messages { margin-bottom: 16px; }
.msg { padding: 10px 12px; border-radius: var(--radius-s); margin: 8px 0; font-size: 15px; }
.msg-success, .msg-info { background: var(--ok-bg); color: var(--ok-ink); }
.msg-error { background: #fdecea; color: var(--danger); }
.msg-warning { background: var(--warn-bg); color: var(--warn-ink); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px;
  border-radius: var(--radius-s); border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: var(--black); }
.btn-primary:hover { background: var(--orange-deep); border-color: var(--orange-deep); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #e8b4b0; background: var(--surface); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn-block { display: flex; width: 100%; margin-top: 10px; }

/* Formulaires */
.form { display: grid; gap: 14px; }
.form label, .field > label { display: grid; gap: 4px; font-weight: 600; font-size: 15px; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=email], select, textarea {
  font: inherit; font-size: 16px; /* 16px : pas de zoom automatique sur iPhone */
  width: 100%; min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--surface); color: var(--ink);
}
textarea { min-height: 80px; }
.input-lg { min-height: 52px; font-size: 18px; }
.input-xs { width: 80px; }
.field fieldset { border: 0; padding: 0; margin: 0; }
.field legend { font-weight: 600; margin-bottom: 6px; }
.field ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.field ul label { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.field-check label { display: flex; gap: 10px; align-items: center; font-weight: 400; }
.field-check input { width: 20px; height: 20px; }
.help { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0 0; }
.has-error input, .has-error select { border-color: var(--danger); }
.optional { color: var(--muted); font-weight: 400; font-size: 13px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 0; }
.form-row label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.grid-2 { display: grid; gap: 12px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--rule); }
/* Format « tableau direct » : les réglages de poules sont inutiles */
form:has(input[value=ko_only]:checked) [data-field=pool_size],
form:has(input[value=ko_only]:checked) [data-field=pool_best_of] { display: none; }

.search { display: flex; gap: 8px; margin-bottom: 8px; }

/* Panneaux */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 16px; margin: 16px 0; }
.panel-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary::after { content: " +"; color: var(--muted); }
details.panel[open] > summary::after { content: " −"; }
.count { color: var(--muted); font-weight: 400; }

/* Puces de statut */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #ececea; color: var(--ink); white-space: nowrap; }
.chip-draft { background: #eceeed; color: var(--muted); }
.chip-live { background: var(--orange-tint); color: var(--orange-ink); }
.chip-finished { background: var(--black); color: var(--white); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); display: inline-block; }
@media (prefers-reduced-motion: no-preference) {
  .chip-live .live-dot { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: .35; } }
}
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--rule); border-radius: 4px; padding: 0 4px; }

/* Listes de tournois */
.t-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.t-item { display: grid; gap: 2px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); text-decoration: none; color: var(--ink); position: relative; }
.t-item .chip { position: absolute; right: 12px; top: 12px; }
.t-name { font-weight: 700; padding-right: 90px; }
.t-meta, .t-org { color: var(--muted); font-size: 14px; }
.filters, .tabs, .steps { display: flex; gap: 4px; overflow-x: auto; margin: 12px 0 16px; scrollbar-width: none; }
.filters a, .tabs a, .steps a {
  flex: none; padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink);
  font-size: 15px; font-weight: 600; border: 1px solid var(--rule); background: var(--surface);
}
.filters a[aria-current], .tabs a[aria-current], .steps a[aria-current] { background: var(--black); border-color: var(--black); color: var(--white); box-shadow: inset 0 -3px 0 var(--orange); }

/* En-tête de tournoi */
.t-header { margin-bottom: 8px; }
.t-by { font-weight: 600; margin: 6px 0 0; }
.t-desc { margin: 8px 0 0; max-width: 65ch; }
.t-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.updated { color: var(--muted); font-size: 13px; }
.orga-head { margin-bottom: 4px; }
.orga-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.orga-actions form { margin: 0; }

/* Poules */
.pool { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 14px; margin: 16px 0; scroll-margin-top: 80px; }
.pool-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.pool-head h2 { font-size: 18px; }
.progress { color: var(--muted); font-size: 14px; }
.standings { width: 100%; border-collapse: collapse; font-size: 15px; }
.standings th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--rule); }
.standings td { padding: 8px 6px; border-bottom: 1px solid var(--rule); }
.standings tr:last-child td { border-bottom: 0; }
.c-rank { width: 44px; font-weight: 700; }
.c-num { text-align: right; white-space: nowrap; }
.is-tied .c-rank { color: var(--warn-ink); }
@media (max-width: 420px) { .c-points { display: none; } }
.tie-form { background: var(--warn-bg); border-radius: var(--radius-s); padding: 12px; margin: 10px 0; display: grid; gap: 8px; }
.tie-form p { margin: 0; }
.tie-row { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 8px; font-weight: 600; }
.matches { display: grid; gap: 8px; margin-top: 12px; }
@media (min-width: 720px) { .matches { grid-template-columns: 1fr 1fr; } }

/* Carte de match */
.match { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-s); padding: 8px 10px; display: grid; gap: 2px; }
.match .side { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.match .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .name em { color: var(--muted); font-style: normal; }
.match .score { font-weight: 700; min-width: 2ch; text-align: right; }
.match .side.win .name, .match .side.win .score { font-weight: 750; }
.match.is-done .side:not(.win) { color: var(--muted); }
.match-detail { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.match.is-bye { border-style: dashed; }
.match-edit { margin-top: 6px; min-height: 36px; border: 1px solid var(--rule); background: transparent; border-radius: var(--radius-s); font: inherit; font-size: 14px; font-weight: 600; color: var(--orange-ink); cursor: pointer; }
.match-edit.is-todo { background: var(--orange); border-color: var(--orange); color: var(--black); }

/* Formulaire de résultat */
.match-form { border-color: var(--black); box-shadow: 0 0 0 1px var(--black); gap: 10px; padding: 12px; }
.mf-head { display: grid; gap: 2px; }
.mf-title { font-weight: 700; }
.vs { color: var(--muted); font-weight: 400; }
.mf-label { margin: 6px 0 4px; font-size: 14px; font-weight: 600; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--rule); border-radius: var(--radius-s); overflow: hidden; }
.segmented button { min-height: 40px; border: 0; background: var(--surface); font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed=true] { background: var(--black); color: var(--white); }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.qbtn { min-height: 52px; font: inherit; font-size: 20px; font-weight: 750; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); cursor: pointer; touch-action: manipulation; }
.qbtn:active { background: var(--orange-tint); }
.qbtn.is-current { border-color: var(--orange); box-shadow: inset 0 0 0 2px var(--orange); }
.sets-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; align-items: center; }
.sets-grid input { text-align: center; font-size: 20px; font-weight: 700; min-height: 48px; }
.sg-head { font-size: 13px; font-weight: 700; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-label { font-size: 14px; color: var(--muted); }
.mf-more summary { cursor: pointer; color: var(--muted); font-size: 14px; }

/* Inscriptions */
.results { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.result { display: grid; width: 100%; text-align: left; gap: 0; padding: 10px 12px; min-height: 48px; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--surface); font: inherit; color: var(--ink); cursor: pointer; }
.result .name { font-weight: 650; }
.result .club, .who .club { color: var(--muted); font-size: 13px; }
.result.is-registered { cursor: default; opacity: .6; }
.result-create { color: var(--orange-ink); font-weight: 650; border-style: dashed; }
.form-inline-card { border: 1px solid var(--black); border-radius: var(--radius-m); padding: 14px; margin-top: 12px; }
.similar { background: var(--warn-bg); padding: 10px 12px; border-radius: var(--radius-s); }
.similar p { margin: 0 0 6px; }
.entries { list-style: none; counter-reset: entry; padding: 0; margin: 8px 0 0; }
.entries li { counter-increment: entry; display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.entries li::before { content: counter(entry); color: var(--muted); width: 2.2ch; text-align: right; font-size: 14px; flex: none; }
.entries .who { flex: 1; display: grid; min-width: 0; }
.entries .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-actions { display: flex; gap: 4px; flex: none; }
.icon-btn { width: 40px; height: 40px; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--surface); font-size: 18px; cursor: pointer; color: var(--ink); }
.icon-btn[disabled] { opacity: .3; }
.icon-danger { color: var(--danger); }

/* Composition des poules */
.assign { list-style: none; padding: 0; margin: 8px 0; }
.assign-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.assign-row .name { flex: 1 1 140px; font-weight: 600; }
.assign-form { margin: 0; }
.assign-row select { width: auto; min-width: 120px; }
.assign-row form { margin: 0; }
.next-step { margin: 20px 0; display: grid; gap: 4px; }
.next-step form { margin: 0; }

/* Qualification */
.qualif { list-style: none; padding: 0; margin: 0; }
.qualif label { display: grid; grid-template-columns: 28px 64px 1fr auto; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.qualif input { width: 22px; height: 22px; }
.qualif .rank { color: var(--muted); font-size: 14px; }
.qualif .name { font-weight: 600; }

/* Tableau : les tours défilent horizontalement, un tour par écran sur téléphone */
.bracket {
  display: grid; grid-auto-flow: column; grid-auto-columns: 86%;
  gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 720px) { .bracket { grid-auto-columns: minmax(240px, 1fr); } .bracket-hint { display: none; } }
.round { scroll-snap-align: start; display: flex; flex-direction: column; }
.round-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 3px solid var(--orange); }
.round-matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 8px; }
.round:last-child .match { border-color: var(--black); box-shadow: 0 0 0 1px var(--black); }

/* Placement */
.placement { list-style: none; padding: 0; margin: 12px 0; counter-reset: pm; display: grid; gap: 10px; }
.placement-match { counter-increment: pm; display: grid; gap: 4px; padding: 8px; border: 1px solid var(--rule); border-radius: var(--radius-s); position: relative; padding-left: 36px; }
.placement-match::before { content: counter(pm); position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.placement-slot { margin: 0; }
.unplaced { font-size: 14px; }
@media (min-width: 720px) { .placement { grid-template-columns: 1fr 1fr; } }

/* Classement final */
.ranking { list-style: none; padding: 0; margin: 0; }
.rank-row { display: grid; grid-template-columns: 72px 1fr; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.rank-row .rank { font-weight: 750; font-size: 18px; grid-row: span 2; }
.rank-row .rank small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.rank-row .who { display: grid; }
.rank-row .name { font-weight: 650; }
.rank-row .stage { color: var(--muted); font-size: 13px; }
.podium-1 .rank { color: var(--orange-ink); }

.empty-state { background: var(--surface); border: 1px dashed var(--rule); border-radius: var(--radius-m); padding: 24px; text-align: center; }

@media (min-width: 720px) {
  .page-title { font-size: 28px; }
  .page { padding-top: 28px; }
}

/* Requêtes htmx : léger retour visuel sur l'élément en cours d'envoi */
.htmx-request.match, .htmx-request .qbtn { opacity: .6; }
