/* ==========================================================
   Trèfle — styles
   Couleurs des feuilles : palette Okabe-Ito (lisible par les
   personnes daltoniennes), toujours doublée d'un symbole ▲▶▼◀
   et d'une position. Juste/faux : bleu ✓ / vermillon ✗ pointillé.
   ========================================================== */

/* Police des cartes : Barlow Condensed (licence SIL Open Font License 1.1), incluse dans le jeu */
@font-face {
  font-family: "Trefle Cartes";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/barlow-condensed-600.woff2") format("woff2");
}

:root {
  --bg: #e6ede3;
  --surface: #ffffff;
  --surface-2: #f2f6f0;
  --ink: #17251c;
  --muted: #4c5f52;
  --line: #c6d3c4;
  --accent: #2f6b3f;
  --accent-hover: #24552f;
  --accent-ink: #ffffff;
  --card: #fffcf1;
  --card-ink: #1c1c1a;
  --card-edge: #22302a;

  --l0: #0072b2;   /* haut   ▲ bleu            */
  --l1: #e69f00;   /* droite ▶ orange          */
  --l2: #cc79a7;   /* bas    ▼ pourpre rosé    */
  --l3: #009e73;   /* gauche ◀ vert bleuté     */

  --ok: #0072b2;
  --ko: #d55e00;
  --badge-ink: #ffffff;

  --radius: 14px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-card: "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", sans-serif-condensed, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1914;
  --surface: #17251e;
  --surface-2: #1e3027;
  --ink: #e5eee7;
  --muted: #a3b6a8;
  --line: #2e4237;
  --accent: #7fc792;
  --accent-hover: #9bd8ab;
  --accent-ink: #0b1a10;
  --card: #f1ecdb;
  --card-ink: #1b1b19;
  --card-edge: #050806;

  --l0: #56b4e9;
  --l1: #e69f00;
  --l2: #cc79a7;
  --l3: #1fb388;

  --ok: #56b4e9;
  --ko: #ef8a3c;
  --badge-ink: #0b1410;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3 { line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(1.6rem, 4.2vw, 2.4rem); font-weight: 800; letter-spacing: -.015em; }
h2 { font-size: 1.15rem; font-weight: 800; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }

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

/* ---------- Barre du haut ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: calc(.6rem + env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) .6rem max(1rem, env(safe-area-inset-left, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .4rem; color: var(--ink); text-decoration: none; }
.brand-mark { font-size: 1.5rem; }
.brand-name { font-weight: 900; font-size: 1.25rem; letter-spacing: -.02em; }
.topbar-right { display: flex; align-items: center; gap: .4rem; }
.room-code {
  font-weight: 800; letter-spacing: .12em; font-size: .95rem;
  padding: .2rem .55rem; border: 2px solid var(--line); border-radius: 8px;
}

main { max-width: 1120px; margin: 0 auto; padding: 1.2rem max(1rem, env(safe-area-inset-left, 0px)) 3rem; outline: none; }

/* ---------- Boutons et champs ---------- */

.btn {
  appearance: none; font: inherit; font-weight: 800; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.1rem;
  border-radius: 11px; border: 2px solid var(--ink);
  background: var(--surface); color: var(--ink);
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: var(--line); background: transparent; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn.big { min-height: 52px; font-size: 1.1rem; padding: .7rem 1.5rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; }

input[type="text"], input:not([type]), select, textarea {
  font: inherit; color: var(--ink);
  width: 100%; min-height: 44px; padding: .5rem .7rem;
  background: var(--surface); border: 2px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; }
textarea { min-height: 96px; resize: vertical; }
label.field { display: block; font-weight: 700; margin-bottom: .8rem; }
label.field > span { display: block; margin-bottom: .25rem; }

.panel {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

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

.hero {
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 2rem; align-items: center;
  margin: .5rem 0 2rem;
}
.hero h1 { font-size: clamp(2rem, 6vw, 3.6rem); line-height: 1.02; letter-spacing: -.03em; }
.hero .lead { font-size: 1.1rem; color: var(--muted); max-width: 34em; }
.hero .clover { max-width: 340px; margin-inline: auto; }

.home-panel { max-width: 720px; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: .4rem; }
.home-actions > div { border-top: 2px solid var(--line); padding-top: .9rem; }
.join-row { display: flex; gap: .5rem; }
.join-row input { text-transform: uppercase; letter-spacing: .15em; font-weight: 800; }
.invited { font-size: 1.05rem; }
.invited strong { letter-spacing: .12em; }

.rules { margin-top: 1.5rem; max-width: 720px; }
.rules summary { cursor: pointer; font-weight: 800; font-size: 1.05rem; padding: .3rem 0; }
.rules ol { padding-left: 1.3rem; margin: .5rem 0 0; }
.rules li { margin-bottom: .5rem; }

/* ---------- Salon ---------- */

.lobby { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.lobby .invite { grid-column: 1 / -1; }
.code-big { font-size: clamp(2rem, 8vw, 3rem); font-weight: 900; letter-spacing: .2em; display: block; margin: .2rem 0 .6rem; }
.link-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.link-row input { flex: 1 1 240px; font-size: .9rem; }
.start-row { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: .4rem; text-align: center; padding: .5rem 0; }

.players { list-style: none; margin: 0; padding: 0; }
.players li {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem 0; border-bottom: 1px solid var(--line);
}
.players li:last-child { border-bottom: 0; }
.p-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-tag { font-size: .8rem; font-weight: 700; padding: .05rem .45rem; border-radius: 6px; border: 1.5px solid var(--line); color: var(--muted); }
.p-status { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.p-status::before { content: "●"; margin-right: .25rem; color: var(--l3); }
.p-status.off::before { content: "○"; color: var(--muted); }
.p-done { font-size: .85rem; font-weight: 800; color: var(--ok); white-space: nowrap; }
.p-wait { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.kick { border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; min-width: 36px; min-height: 36px; border-radius: 8px; }
.kick:hover { color: var(--ko); background: var(--surface-2); }

.settings fieldset { border: 0; margin: 0 0 1.1rem; padding: 0; }
.settings legend { font-weight: 800; margin-bottom: .45rem; padding: 0; }
.hint { font-size: .88rem; color: var(--muted); margin: .35rem 0 0; }
.hint.warn { color: var(--ko); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .7rem; min-height: 38px;
  border: 2px solid var(--line); border-radius: 999px; font-weight: 700; font-size: .92rem;
  background: var(--surface);
}
.chip span::before { content: "+"; font-weight: 900; color: var(--muted); }
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip input:checked + span::before { content: "✓"; color: inherit; }
.chip input:focus-visible + span { outline: 3px solid var(--l0); outline-offset: 2px; }
.chip small { font-weight: 600; opacity: .7; }

.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg label { position: relative; flex: 1 1 0; min-width: 6.5rem; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span {
  display: flex; flex-direction: column; justify-content: center; height: 100%;
  padding: .45rem .7rem; min-height: 44px;
  border: 2px solid var(--line); border-radius: 10px; font-weight: 700; font-size: .92rem;
}
.seg span small { font-weight: 500; color: var(--muted); font-size: .82rem; line-height: 1.3; margin-top: .15rem; }
.seg input:checked + span { border-color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); background: var(--surface-2); }
.seg input:checked + span::after { content: "✓ choisi"; font-size: .75rem; font-weight: 800; margin-top: .2rem; }
.seg input:focus-visible + span { outline: 3px solid var(--l0); outline-offset: 2px; }
.seg.stack label { flex-basis: 100%; }

.summary { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; }
.summary dt { font-weight: 800; }
.summary dd { margin: 0; color: var(--muted); }

/* ---------- En-tête des phases ---------- */

.phase-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.phase-head p { margin: 0; }
.score-pill { font-weight: 800; padding: .3rem .75rem; border-radius: 999px; border: 2px solid var(--ink); white-space: nowrap; }

.timer { min-width: 200px; text-align: right; font-weight: 800; }
.head-right { min-width: 200px; text-align: right; }
.ready-count { margin: .35rem 0 0; font-weight: 800; }
.ready-count .muted { font-weight: 600; }
.timer .t-num { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.timer .t-bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: .25rem; }
.timer .t-bar i { display: block; height: 100%; background: var(--accent); transition: width .3s linear; }
.timer.urgent .t-num { color: var(--ko); }
.timer.urgent .t-bar i { background: var(--ko); }

.play-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 1.4rem; align-items: start; }
.side-col { display: flex; flex-direction: column; gap: 1rem; }

.notice {
  border-left: 5px solid var(--ink); background: var(--surface);
  padding: .75rem 1rem; border-radius: 0 10px 10px 0;
}
.notice.owner { border-left-color: var(--l1); }
.notice strong { display: block; }

/* ---------- Le trèfle ---------- */

.clover {
  --leaf: clamp(2.3rem, 8vw, 3.1rem);
  display: grid;
  grid-template-columns: var(--leaf) 1fr 1fr var(--leaf);
  grid-template-rows: var(--leaf) auto auto var(--leaf);
  grid-template-areas:
    ".  l0 l0 ."
    "l3 s0 s1 l1"
    "l3 s3 s2 l1"
    ".  l2 l2 .";
  gap: 6px;
  width: 100%; max-width: 540px; margin-inline: auto;
}
.clover.mini { max-width: 340px; --leaf: 2.2rem; }

.leaf {
  display: flex; align-items: center; justify-content: center; gap: .4rem;
  border: 3px solid var(--lc);
  background: color-mix(in srgb, var(--lc) 16%, var(--surface));
  color: var(--ink);
  font-weight: 900; text-transform: uppercase; letter-spacing: .03em;
  font-size: clamp(.8rem, 2.6vw, 1.05rem);
  overflow: hidden; min-width: 0; min-height: 0;
}
.leaf0 { --lc: var(--l0); border-radius: 60% 60% 14px 14px / 100% 100% 14px 14px; }
.leaf2 { --lc: var(--l2); border-radius: 14px 14px 60% 60% / 14px 14px 100% 100%; }
.leaf1 { --lc: var(--l1); border-radius: 14px 100% 100% 14px / 14px 60% 60% 14px; flex-direction: column; }
.leaf3 { --lc: var(--l3); border-radius: 100% 14px 14px 100% / 60% 14px 14px 60%; flex-direction: column; }
.leaf .sym { color: var(--lc); font-size: .9em; flex: none; }
.leaf-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.leaf1 .leaf-text, .leaf3 .leaf-text { writing-mode: vertical-rl; max-height: 100%; }
.leaf3 .leaf-text { transform: rotate(180deg); }
.leaf-text i { font-style: normal; opacity: .45; }

.slot {
  position: relative; aspect-ratio: 1;
  border: 2px dashed var(--line); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  min-width: 0;
}
.slot.filled { border-style: solid; border-color: transparent; background: transparent; }
.slot.drop { cursor: pointer; }
.slot.drop:not(.filled):hover, .slot.over { border-color: var(--ink); background: var(--surface-2); }
.slot-empty { font-size: .82rem; color: var(--muted); text-align: center; padding: .4rem; }
.slot.locked .card { box-shadow: 0 0 0 4px var(--ok); }
.slot.ok .card { box-shadow: 0 0 0 4px var(--ok); }
.slot.ko .card { box-shadow: none; outline: 4px dashed var(--ko); outline-offset: 1px; }

.badge {
  position: absolute; top: -9px; left: -9px; z-index: 3;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1rem; color: var(--badge-ink);
  border: 2px solid var(--surface);
}
.badge.ok { background: var(--ok); }
.badge.ko { background: var(--ko); border-radius: 6px; }

/* ---------- Les cartes ---------- */

.card {
  container-type: inline-size;
  position: relative; width: 100%; aspect-ratio: 1;
  background: var(--card); color: var(--card-ink);
  border: 2px solid var(--card-edge); border-radius: 10px;
  box-shadow: 0 3px 0 var(--card-edge);
  font-family: "Trefle Cartes", var(--font-card); font-weight: 600;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.card::after {           /* petit losange central, comme un dos de carte */
  content: ""; position: absolute; left: 50%; top: 50%; width: 14%; height: 14%;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid color-mix(in srgb, var(--card-edge) 25%, transparent); border-radius: 3px;
}
.card[role="button"] { cursor: pointer; }
.card.selected { outline: 4px solid var(--ink); outline-offset: 3px; transform: translateY(-3px); box-shadow: 0 6px 0 var(--card-edge); }
.card.dragging { opacity: .45; }

.w {
  position: absolute; z-index: 1;
  font-size: 12px; font-size: clamp(9px, 11.5cqi, 17px);
  line-height: 1.05; text-transform: uppercase; letter-spacing: .02em;
  text-align: center; white-space: nowrap;
  padding: .08em .25em; border-radius: 4px;
}
.w.len7  { font-size: clamp(8px, 10cqi, 15px); }
.w.len9  { font-size: clamp(7px, 8.4cqi, 13px); }
.w.len11 { font-size: clamp(6.5px, 7cqi, 12px); letter-spacing: 0; }
.w.len14 { font-size: clamp(6px, 5.8cqi, 11px); letter-spacing: 0; }
.w0 { top: 5%; left: 50%; transform: translateX(-50%); }
.w2 { bottom: 5%; left: 50%; transform: translateX(-50%); }
.w1 { right: 5%; top: 50%; transform: translateY(-50%); writing-mode: vertical-rl; }
.w3 { left: 5%; top: 50%; transform: translateY(-50%) rotate(180deg); writing-mode: vertical-rl; }
.w.inner { opacity: .42; }
.w.o0 { background: color-mix(in srgb, var(--l0) 30%, transparent); box-shadow: inset 0 -3px 0 var(--l0); }
.w.o1 { background: color-mix(in srgb, var(--l1) 34%, transparent); box-shadow: inset -3px 0 0 var(--l1); }
.w.o2 { background: color-mix(in srgb, var(--l2) 34%, transparent); box-shadow: inset 0 3px 0 var(--l2); }
.w.o3 { background: color-mix(in srgb, var(--l3) 30%, transparent); box-shadow: inset -3px 0 0 var(--l3); }

.rot-btn {
  position: absolute; z-index: 2; right: 3%; top: 3%;
  width: 18%; height: 18%; min-width: 24px; min-height: 24px;
  border-radius: 50%; border: 2px solid var(--card-edge);
  background: var(--card); color: var(--card-ink);
  font-size: clamp(12px, 11cqi, 18px); line-height: 1; font-weight: 900; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.rot-btn:hover { background: var(--card-edge); color: var(--card); }

/* ---------- Pioche et commandes ---------- */

.pool-wrap h2 { display: flex; justify-content: space-between; align-items: baseline; }
.pool {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(28vw, 140px), 1fr));
  gap: 14px; padding: 12px; min-height: 120px;
  border: 2px dashed var(--line); border-radius: var(--radius);
}
.pool.over { border-color: var(--ink); background: var(--surface-2); }
.pool-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; align-self: center; margin: 0; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  padding: .6rem .8rem; border: 2px solid var(--ink); border-radius: 12px; background: var(--surface);
}
.toolbar .t-label { font-weight: 800; margin-right: auto; }

.actions-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

.clue-form .clue-row { margin-bottom: .9rem; padding-left: .8rem; border-left: 5px solid var(--lc); }
.clue-row label { display: block; font-weight: 600; margin-bottom: .25rem; }
.clue-row label .sym { color: var(--lc); font-weight: 900; }
.clue-row label b { text-transform: uppercase; font-family: var(--font-card); letter-spacing: .02em; }
.clue-row input { text-transform: uppercase; font-weight: 800; letter-spacing: .03em; }
.clue-row .err { color: var(--ko); font-weight: 700; font-size: .88rem; margin: .25rem 0 0; min-height: 0; }
.clue-row .err:empty { display: none; }
.clue-row .err::before { content: "✗ "; }
.lc0 { --lc: var(--l0); } .lc1 { --lc: var(--l1); } .lc2 { --lc: var(--l2); } .lc3 { --lc: var(--l3); }
.sent { font-weight: 800; color: var(--ok); }

/* ---------- Révélation et fin ---------- */

.result-banner {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.2rem; border-radius: var(--radius);
  border: 3px solid var(--ink); background: var(--surface); margin-bottom: 1rem;
}
.result-banner .pts { font-size: 2.4rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.result-banner p { margin: 0; }
.reveal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; align-items: start; }
.reveal-grid h2 { text-align: center; }

.final {
  text-align: center; padding: 2rem 1rem;
}
.final .big-score { font-size: clamp(3.5rem, 14vw, 6.5rem); font-weight: 900; letter-spacing: -.04em; line-height: 1; }
.final .big-score small { font-size: .4em; color: var(--muted); letter-spacing: 0; }
.final .rating { font-size: 1.4rem; font-weight: 800; margin: .6rem 0 1.5rem; }
.history { max-width: 520px; margin: 0 auto 1.5rem; text-align: left; }
.history table { width: 100%; border-collapse: collapse; }
.history th, .history td { padding: .45rem .3rem; border-bottom: 1px solid var(--line); }
.history th { text-align: left; font-size: .9rem; color: var(--muted); }
.history td.num { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }

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

.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, calc(100% + 3rem)); z-index: 50; visibility: hidden;
  max-width: min(92vw, 480px); padding: .75rem 1.1rem; border-radius: 12px;
  background: var(--ink); color: var(--surface); font-weight: 700;
  transition: transform .25s ease, visibility .25s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.error::before { content: "✗ "; color: var(--ko); }

/* ---------- Responsive ---------- */

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 1.2rem; }
  .hero .clover { max-width: 300px; }
  .lobby { grid-template-columns: 1fr; }
  .play-grid { grid-template-columns: 1fr; }
  .reveal-grid { grid-template-columns: 1fr; }
  .timer { text-align: left; min-width: 0; width: 100%; }
  .head-right { text-align: left; min-width: 0; width: 100%; }
}
@media (max-width: 560px) {
  main { padding-top: .8rem; }
  .home-actions { grid-template-columns: 1fr; }
  .brand-name { font-size: 1.1rem; }
  .theme-label { display: none; }
  .panel { padding: .9rem; }
  .clover { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .card.selected { transform: none; }
}
