/* Cap'Tour — styles. Une seule feuille, mobile d'abord. */
:root {
  --bg: #f4efe4;
  --surface: #fffdf8;
  --ink: #1d2623;
  --muted: #5d6b66;
  --line: #ddd5c4;
  --brand: #1f3a34;
  --brand-ink: #f4efe4;
  --accent: #c9542f;
  --focus: #2f7fd1;
  --board: #26473f;
  --board-2: #2e554b;
  --sq: #f4efe4;
  --sq-line: #a9b8b1;
  --p0: #e0533d;  /* rouge   */
  --p1: #2f7fd1;  /* bleu    */
  --p2: #2ea86b;  /* vert    */
  --p3: #e3a91b;  /* jaune   */
  --p4: #8e5bd1;  /* violet  */
  --p5: #e07b2a;  /* orange  */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  --t-fast: 120ms;
  --t-med: 220ms;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a18;
    --surface: #1b2421;
    --ink: #ecebe5;
    --muted: #9aa8a2;
    --line: #2f3b37;
    --brand: #26473f;
    --board: #1c3530;
    --board-2: #223f38;
    --sq: #e9e4d8;
    --sq-line: #6f8580;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; color: var(--muted); font-weight: 600; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* --- Barre du haut ------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; align-items: center; gap: 16px; font-size: .95rem; }
.topbar nav a { min-height: 44px; display: inline-flex; align-items: center; }
.who { opacity: .8; }

/* --- Mise en page -------------------------------------------------------- */
.wrap { padding: 16px; margin: 0 auto; max-width: 1200px; }
.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hero { text-align: center; padding: 24px 0 8px; }
.hero h1 { font-size: 2.2rem; margin-bottom: .3rem; }
.hero-ring { width: 96px; height: 96px; color: var(--ink); }

/* --- Formulaires --------------------------------------------------------- */
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input:not([type]) {
  width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
input[aria-invalid=true] { border-color: var(--accent); }
.field { margin-bottom: 16px; }
.hint { font-size: .85rem; color: var(--muted); margin: 4px 0 0; }
.field-error, .form-error { color: var(--accent); font-size: .9rem; margin: 4px 0 0; }
.form-error { margin-bottom: 12px; }
.join-form .row input { flex: 1 1 160px; text-transform: uppercase; letter-spacing: .15em; }
fieldset.choice { border: 0; padding: 0; margin: 0 0 16px; }
fieldset.choice legend { font-weight: 600; margin-bottom: 6px; }
fieldset.choice label { display: inline-block; margin: 0 8px 8px 0; font-weight: 500; }
fieldset.choice input { position: absolute; opacity: 0; }
fieldset.choice span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); cursor: pointer;
}
fieldset.choice input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
fieldset.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a[aria-selected=true] { color: var(--ink); border-color: var(--brand); font-weight: 600; }

/* --- Boutons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  text-decoration: none; transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { background: #2b4e46; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.chip:hover { border-color: var(--brand); }

.game-list { list-style: none; margin: 0; padding: 0; }
.game-list li a { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.game-list li:last-child a { border-bottom: 0; }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: 10px 16px;
  border-radius: 8px; box-shadow: var(--shadow); z-index: 50;
}

/* --- Salon --------------------------------------------------------------- */
.lobby { padding: 16px; max-width: 960px; margin: 0 auto; display: grid; gap: 16px; }
@media (min-width: 800px) { .lobby { grid-template-columns: 1fr 1fr; align-items: start; } .lobby .panel { margin: 0; } }
.invite { text-align: center; }
.qr { width: min(260px, 70vw); margin: 0 auto 12px; background: #fff; padding: 8px; border-radius: 8px; }
.qr svg { display: block; width: 100%; height: auto; }
.code-big { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.6rem; letter-spacing: .2em; font-weight: 700; }
.link-line { font-size: .85rem; word-break: break-all; color: var(--muted); }
.seats { display: grid; gap: 12px; margin-bottom: 16px; }
.seat-group { display: grid; gap: 8px; }
.seat-row { display: flex; gap: 8px; align-items: center; }
.seat {
  flex: 1; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 12px;
  font: inherit; text-align: left; cursor: pointer; color: var(--ink);
  background: var(--bg); border: 1px dashed var(--line); border-radius: 10px;
}
.seat.taken { border-style: solid; background: var(--surface); cursor: default; }
.seat.mine { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.seat:not(.taken):hover { border-color: var(--c); }
.seat-name { flex: 1; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--ink); }
.tag.off { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* --- Partie -------------------------------------------------------------- */
.page-game { overscroll-behavior: none; }
.game {
  display: grid; gap: 12px; padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  grid-template-columns: minmax(0, 1fr);
  max-width: 1280px; margin: 0 auto;
}
@media (min-width: 900px) {
  .game { grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: auto 1fr; align-items: start; }
  .players-bar { grid-column: 1 / -1; }
  .board-wrap { grid-row: 2; }
  .side { grid-row: 2; position: sticky; top: 12px; }
}
.players-bar { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.players-bar::-webkit-scrollbar { display: none; }
.pchip {
  flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: .9rem; white-space: nowrap;
}
.pchip.turn { border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
.pchip.me .pname { font-weight: 700; }
.pchip.info { color: var(--muted); }
.pmeta { color: var(--muted); font-size: .8rem; }
.board-wrap { width: 100%; max-width: min(100%, calc(100vh - 220px)); margin: 0 auto; }
@media (max-width: 899px) { .board-wrap { max-width: 640px; } }
.board { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; }
.board-bg { fill: var(--board); }
.track-line { fill: none; stroke: var(--board-2); stroke-width: 36; }
.sq { fill: var(--sq); stroke: var(--sq-line); stroke-width: 2; }
.sq-start { stroke-width: 6; }
.sq-home { fill: var(--sq); stroke-width: 4; opacity: .9; }
.sq-res { fill: transparent; stroke-width: 2; stroke-dasharray: 4 3; opacity: .7; }
.center-disc { fill: var(--board-2); }
.pawn { transition: transform var(--t-med) ease-out; }
.pawn-body { stroke: rgba(0,0,0,.45); stroke-width: 2.5; }
.pawn-num { fill: #fff; text-anchor: middle; font-weight: 700; pointer-events: none; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 2px; }
.pieu { fill: none; stroke-width: 4; stroke-dasharray: 5 4; }
.pawn.selectable { cursor: pointer; }
.pawn.selectable .pawn-body { stroke: #fff; stroke-width: 4; }
.pawn.selected .pawn-body { stroke: #fff; stroke-width: 6; }
.pawn.selectable:focus-visible { outline: none; }
.pawn.selectable:focus-visible .pawn-body { stroke: var(--focus); stroke-width: 6; }
.dest { cursor: pointer; }
.hit { fill: transparent; }
.dest-ring { fill: rgba(255,216,77,.25); stroke: #ffd84d; stroke-width: 5; stroke-dasharray: 6 4; }
.dest-dot { fill: #ffd84d; }
.dest:focus-visible { outline: none; }
.dest:focus-visible .dest-ring { stroke: var(--focus); }
@media (prefers-reduced-motion: no-preference) {
  .pawn.selectable .pawn-body { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 50% { stroke-width: 7; } }
}
@media (prefers-reduced-motion: reduce) { .pawn { transition: none; } }

.side { display: grid; gap: 12px; }
.side .panel { margin: 0; }
.prompt { min-height: 72px; }
.prompt h2.your-turn { color: var(--accent); }
.turn-of { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 0; }
.seven-left { font-weight: 700; }
.seven-row { display: flex; gap: 10px; align-items: flex-start; }
.mini-pawn { flex: none; width: 32px; height: 32px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 700; margin-top: 4px; }

/* Main du joueur : collée en bas sur mobile */
.hand-box { order: -1; }
@media (max-width: 899px) {
  .side { display: contents; }
  .prompt { order: 2; }
  .hand-box { order: 3; position: sticky; bottom: 0; z-index: 5; background: var(--bg); padding: 8px 0 max(8px, env(safe-area-inset-bottom)); }
  .history { order: 4; }
}
.hand { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 420px; margin: 0 auto; }
.card-btn { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 10px; transition: transform var(--t-fast); }
.card-btn.active { transform: translateY(-8px); }
.card-btn.active .card { box-shadow: 0 0 0 3px var(--ink), var(--shadow); }
.card-btn.dim { cursor: default; }
.card-btn.dim .card { opacity: .55; }

/* --- Cartes Cap'Tour ----------------------------------------------------- */
.card {
  --k: #1f6f63;
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  aspect-ratio: 5 / 7; width: 100%; padding: 6px 4px; border-radius: 10px;
  background: #fffaf0; color: var(--k); border: 2px solid var(--k);
  box-shadow: var(--shadow); font-family: system-ui, sans-serif; overflow: hidden;
}
.card::before { content: ""; position: absolute; inset: 4px; border: 1px solid currentColor; border-radius: 7px; opacity: .25; }
.card-start { --k: #b7791f; }
.card-seven { --k: #6b46c1; }
.card-back  { --k: #c0392b; }
.card-swap  { --k: #2563a8; }
.card-joker { --k: #1d2623; background: linear-gradient(135deg, #fde8e3, #e3eefc 50%, #e2f4ea); }
.card-corner { position: absolute; top: 4px; left: 7px; font-weight: 800; font-size: clamp(.7rem, 2.6vw, .9rem); }
.card-big { font-weight: 800; font-size: clamp(1.4rem, 7vw, 2.2rem); line-height: 1; }
.card-icon svg { width: clamp(20px, 6vw, 30px); height: clamp(20px, 6vw, 30px); fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.card-joker .card-icon svg { fill: currentColor; stroke: none; }
.card-label { font-weight: 700; font-size: clamp(.55rem, 2.2vw, .72rem); text-transform: uppercase; letter-spacing: .04em; }
.card-sub { font-size: clamp(.5rem, 2vw, .65rem); opacity: .85; }
.card-mini { width: 84px; padding: 4px; }
.card-mini .card-big { font-size: 2rem; }
.card-mini .card-icon svg { width: 24px; height: 24px; }
.card-mini .card-label { font-size: .6rem; }
.card-mini .card-sub { font-size: .55rem; }
.card-mini .card-corner { font-size: .75rem; }

.history ul { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.history li { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.history li:last-child { border-bottom: 0; }

.over { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); z-index: 40; padding: 16px; }
.over-card { background: var(--surface); border-radius: var(--radius); padding: 24px; text-align: center; max-width: 360px; width: 100%; box-shadow: var(--shadow); }
.over-card h2 { font-size: 1.5rem; }

.loading { padding: 48px; text-align: center; color: var(--muted); }

/* --- Règles -------------------------------------------------------------- */
.rules table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.rules th, .rules td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rules .card { width: 56px; }
.rules .card-big { font-size: 1.3rem; }
.rules .card-icon svg { width: 18px; height: 18px; }
.rules .card-label, .rules .card-sub, .rules .card-corner { display: none; }
