/* SUMCROX – identité visuelle : bleu nuit, bleu foncé, doré, blanc cassé, rouge promo, vert réussite */
:root {
  --navy: #10243A; --blue: #173B61; --gold: #F2C46D; --cream: #F8F5ED;
  --red: #C83C42; --green: #22A06B; --sky: #CFE8FF; --given: #E6DCC0;
  --cell: #F8F5ED; --cell-ink: #10243A; --cell-fill: #173B61;
  --radius: 12px; --maxw: 1100px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
html.hc {
  --navy: #000; --blue: #0a0a0a; --gold: #FFD24D; --cream: #FFF; --given: #FFE9A8;
  --cell: #FFFFFF; --cell-ink: #000; --cell-fill: #000; --green: #00A650;
}

* { -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body {
  margin: 0; color: var(--cream); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP", Arial, sans-serif;
  background:
    radial-gradient(ellipse at 50% -10%, #1d4a7a 0%, rgba(23,59,97,0) 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.028) 0 2px, transparent 2px 56px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.028) 0 2px, transparent 2px 56px),
    var(--navy);
  background-attachment: fixed;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  overscroll-behavior-y: none;
}
a { color: var(--gold); }
h1, h2, h3 { color: var(--gold); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; inset-inline-start: -999px; top: 0; background: var(--gold); color: var(--navy); padding: 8px 14px; z-index: 2000; }
.skip-link:focus { inset-inline-start: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.muted { opacity: .75; }

/* ---------- barre du haut ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; max-width: var(--maxw); margin: 0 auto; }
.brand { font-weight: 900; font-size: 1.6rem; letter-spacing: .02em; color: #fff; text-decoration: none; font-style: italic; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.brand span { color: var(--gold); }
.topnav { display: flex; gap: 4px; flex: 1; white-space: nowrap; }
.topnav a { color: var(--cream); text-decoration: none; padding: 8px 12px; border-radius: 10px; font-size: .95rem; }
.topnav a.active { background: rgba(242,196,109,.16); color: var(--gold); }
.topactions { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: rgba(248,245,237,.08); color: var(--cream); border: 1px solid rgba(248,245,237,.25); border-radius: 10px; width: 40px; height: 40px; font-size: 1.15rem; cursor: pointer; }
.icon-btn:hover { background: rgba(242,196,109,.2); }
.net-badge { font-size: .78rem; padding: 4px 10px; border-radius: 99px; background: rgba(248,245,237,.15); }
.net-badge.off { background: var(--red); color: #fff; }
.net-badge.sync { background: var(--gold); color: var(--navy); }
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 8px 10px; } .topnav { gap: 0; min-width: 0; overflow: hidden; }
  .topnav a { padding: 8px 7px; font-size: .8rem; white-space: nowrap; } .brand { font-size: 1.15rem; }
  .icon-btn { width: 36px; height: 36px; }
  .consent { padding: 10px 12px calc(10px + var(--safe-b)); } .consent h2 { font-size: 1rem; }
  .consent p { font-size: .82rem; margin-bottom: 8px; } .consent .btn { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
}

/* ---------- mise en page ---------- */
.view { max-width: var(--maxw); margin: 0 auto; padding: 8px 16px 32px; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; justify-content: center; }
@media (min-width: 992px) { .game-layout { grid-template-columns: minmax(0, 620px) minmax(0, 340px); } }
.game-main { width: 100%; max-width: 620px; margin: 0 auto; }
.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.level-badge { background: var(--gold); color: var(--navy); border: 0; border-radius: 99px; padding: 6px 16px; font-weight: 700; cursor: pointer; }
.timer { font-size: 1.05rem; opacity: .95; }
.moves { opacity: .8; font-size: .95rem; }

/* ---------- plateau ---------- */
.board-frame {
  padding: clamp(10px, 3vw, 22px); border-radius: 20px;
  background: linear-gradient(160deg, rgba(23,59,97,.95), rgba(16,36,58,.95));
  border: 2px solid rgba(111,183,255,.55);
  box-shadow: 0 10px 34px rgba(0,0,0,.35), inset 0 0 40px rgba(111,183,255,.08);
  transition: border-color .4s, box-shadow .4s;
}
.board-frame.solved { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,160,107,.4), 0 0 34px rgba(34,160,107,.55); }
.board {
  direction: ltr;                       /* la géométrie du plateau ne dépend pas de la langue */
  display: grid; width: 100%; aspect-ratio: 1 / 1;
  grid-template-columns: repeat(5, 1fr) .62fr .62fr;
  grid-template-rows: repeat(5, 1fr) .62fr .62fr;
  gap: clamp(3px, 1.1vw, 7px);
}
.cell {
  appearance: none; border: 2px solid rgba(16,36,58,.25); border-radius: 12%;
  background: var(--cell); color: var(--cell-ink); font-family: inherit; font-weight: 700; font-size: clamp(1rem, 4vw, 1.5rem); line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: background-color .35s, transform .15s, box-shadow .15s, border-color .3s;
  box-shadow: 0 2px 0 rgba(0,0,0,.18);
}
.cell.filled { color: var(--cell-fill); }
.cell.given { background: var(--given); border-color: var(--gold); cursor: default; color: var(--cell-ink); }
.cell.hl { background: #FFF3CE; }
html.hc .cell.hl { background: #FFE17A; }
.cell.sel, .cell:focus-visible { box-shadow: 0 0 0 3px var(--gold), 0 0 18px 4px rgba(242,196,109,.75); outline: none; }
.cell.drop { transform: scale(1.07); box-shadow: 0 0 0 3px var(--gold), 0 0 18px 4px rgba(242,196,109,.75); }
.cell.drag-src { opacity: .35; }
.cell.solved { background: var(--green); border-color: #138457; color: #fff; }
.cell.pop { animation: pop .28s ease-out; }
.sum {
  display: flex; align-items: center; justify-content: center; font-weight: 800; border-radius: 999px;
  font-size: clamp(.62rem, 2.9vw, .95rem); box-shadow: 0 2px 0 rgba(0,0,0,.25); margin: 8%; user-select: none;
}
.sum-21 { background: var(--sky); color: var(--navy); }
.sum-35 { background: var(--gold); color: var(--navy); }
.sum { transition: background-color .3s, color .3s; }
.sum.ok { background: var(--green); color: #fff; }
.sum.hl { box-shadow: 0 0 0 3px #fff, 0 0 14px 2px rgba(255,255,255,.8); }
.board.shake { animation: shake .38s; }
.message { min-height: 1.6em; text-align: center; margin: 10px 0 0; font-size: 1rem; }
.message.warn { color: #ffd9d6; }

/* ---------- réserve ---------- */
.pool-wrap { margin-top: 8px; }
.pool { direction: ltr; display: grid; grid-template-columns: repeat(7, 1fr); gap: clamp(5px, 1.6vw, 10px); }
@media (min-width: 640px) { .pool { grid-template-columns: repeat(13, 1fr); } }
.chip {
  aspect-ratio: 1; border: 0; border-radius: 14%; font-weight: 800; font-size: clamp(1rem, 4.6vw, 1.5rem); font-family: inherit;
  background: linear-gradient(180deg, #FFD98A, var(--gold)); color: var(--navy); cursor: grab;
  box-shadow: 0 3px 0 rgba(0,0,0,.3); touch-action: none; user-select: none; -webkit-user-select: none; padding: 0;
  transition: transform .12s, opacity .2s, box-shadow .2s;
}
.chip:active { cursor: grabbing; }
.chip.sel { transform: translateY(-3px) scale(1.08); box-shadow: 0 0 0 3px #fff, 0 0 18px 4px rgba(242,196,109,.9); }
.chip.given { background: #7d8794; color: #d7dbe0; opacity: .55; cursor: not-allowed; box-shadow: none; }
.chip.placed { background: transparent; color: rgba(248,245,237,.45); border: 2px dashed rgba(248,245,237,.35); cursor: default; box-shadow: none; }
.chip.drag-src { opacity: .35; }
.pool-hint { text-align: center; font-size: .82rem; opacity: .7; margin: 8px 0 0; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 3000; pointer-events: none; width: 64px; height: 64px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.7rem;
  background: var(--gold); color: var(--navy); box-shadow: 0 12px 28px rgba(0,0,0,.5); opacity: .95;
}
body.dragging { cursor: grabbing; user-select: none; }

/* ---------- boutons ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.btn { border-radius: 10px; font-weight: 700; padding: 10px 18px; border: 2px solid transparent; font-size: 1rem; cursor: pointer; text-decoration: none; display: inline-block; min-height: 44px; line-height: 1.3; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: #ffd98a; color: var(--navy); }
.btn-ghost { background: transparent; color: var(--cream); border-color: rgba(248,245,237,.45); }
.btn-ghost:hover { background: rgba(248,245,237,.12); color: var(--cream); border-color: var(--cream); }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: #a92f35; color: #fff; }
.btn-next { background: var(--green); color: #fff; animation: glow 1.8s ease-in-out infinite; }
.btn-next:hover { background: #1b8a5c; color: #fff; }
.btn-gold.btn-success { background: var(--green); color: #fff; animation: glow 1.8s ease-in-out infinite; }
.btn-gold.btn-success:hover { background: #1b8a5c; color: #fff; }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: .9rem; }
.btn-lg { font-size: 1.25rem; padding: 14px 32px; }

/* ---------- colonne latérale / promo ---------- */
.game-side { display: flex; flex-direction: column; gap: 16px; }
.side-card, .promo { background: rgba(23,59,97,.85); border: 1px solid rgba(242,196,109,.35); border-radius: 16px; padding: 16px; }
.promo { display: flex; gap: 14px; align-items: flex-start; }
.promo img { width: 96px; height: auto; border-radius: 6px; box-shadow: 0 6px 16px rgba(0,0,0,.45); flex: none; }
.promo h3 { margin: 0 0 6px; font-size: 1.1rem; }
.promo p { margin: 0 0 10px; font-size: .92rem; opacity: .92; }
.promo .disclosure { display: block; margin-top: 8px; opacity: .7; }
.promo-small { margin: 12px 0; padding: 12px; }
.promo-small img { width: 64px; }
@media (max-width: 991px) { .game-side { max-width: 620px; margin: 0 auto; width: 100%; } }

/* ---------- pages ---------- */
.page { max-width: 760px; line-height: 1.6; }
.rules li, .level-list li { margin: .5rem 0; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 16px 0; }
.stat-card { background: rgba(23,59,97,.85); border: 1px solid rgba(242,196,109,.3); border-radius: 14px; padding: 12px 16px; }
.stat-card h3 { margin: 0 0 6px; font-size: 1.05rem; } .stat-card p { margin: 2px 0; }
.history { padding-inline-start: 18px; opacity: .9; font-size: .9rem; }
.privacy-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.footer { display: flex; justify-content: center; gap: 18px; padding: 18px 16px 28px; opacity: .75; font-size: .85rem; }

/* ---------- dialogues / consentement / toast ---------- */
.dlg { background: var(--blue); color: var(--cream); border: 2px solid var(--gold); border-radius: 18px; padding: 22px; max-width: min(460px, 92vw); width: 100%; }
.dlg::backdrop { background: rgba(5,12,22,.72); backdrop-filter: blur(2px); }
.dlg h2 { margin-top: 0; font-size: 1.35rem; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.dlg-win { text-align: center; border-color: var(--green); box-shadow: 0 0 0 4px rgba(34,160,107,.35), 0 0 60px rgba(34,160,107,.5); }
.dlg-win h2 { color: #fff; font-size: 1.5rem; }
.dlg-win .dlg-actions { justify-content: center; }
.win-sub { font-style: italic; opacity: .9; }
.win-stats { display: flex; justify-content: center; gap: 22px; margin: 16px 0; }
.win-stats dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
.win-stats dd { margin: 0; font-size: 1.5rem; font-weight: 800; color: var(--gold); }
.level-choices { display: grid; gap: 10px; }
.level-choice { text-align: start; background: rgba(248,245,237,.08); color: var(--cream); border: 1px solid rgba(248,245,237,.3); border-radius: 12px; padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.level-choice:hover { background: rgba(242,196,109,.18); border-color: var(--gold); }
.level-choice span { font-size: .88rem; opacity: .85; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field select, .field input[type=text] { background: var(--navy); color: var(--cream); border: 1px solid rgba(248,245,237,.4); border-radius: 8px; padding: 8px; font-size: 1rem; }
.switch { display: flex; align-items: center; gap: 10px; margin: 12px 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; }
.consent { position: fixed; inset-inline: 0; bottom: 0; z-index: 900; background: var(--blue); border-top: 2px solid var(--gold); padding: 16px 16px calc(16px + var(--safe-b)); box-shadow: 0 -10px 30px rgba(0,0,0,.4); }
.consent[hidden] { display: none; }
.consent h2 { font-size: 1.1rem; margin: 0 0 6px; } .consent p { margin: 0 0 10px; max-width: 760px; font-size: .92rem; }
.consent-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + var(--safe-b)); background: var(--cream); color: var(--navy); padding: 10px 18px; border-radius: 12px; z-index: 1500; box-shadow: 0 8px 22px rgba(0,0,0,.4); max-width: 90vw; text-align: center; }
.toast[hidden] { display: none; }
#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 2500; display: none; }

/* ---------- animations ---------- */
@keyframes pop { 0% { transform: scale(.7); } 60% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(34,160,107,.6); } 50% { box-shadow: 0 0 0 12px rgba(34,160,107,0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* petits écrans : le plateau et la réserve restent utilisables sans zoom */
@media (max-width: 380px) { .controls .btn { padding: 8px 12px; font-size: .92rem; } }
@media (orientation: landscape) and (max-height: 520px) {
  .game-main { max-width: none; display: grid; grid-template-columns: minmax(0, 360px) 1fr; column-gap: 16px; }
  .statusbar { grid-column: 1 / -1; } .board-frame { grid-row: 2 / 5; } .pool-wrap, .controls, .message { grid-column: 2; }
}

/* ---------- score, palmarès, pseudonyme ---------- */
/* les 4 boutons occupent toute la largeur du cadre du jeu */
.controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.controls .btn { padding: 10px 6px; font-size: .95rem; text-align: center; white-space: normal; line-height: 1.15; display: flex; align-items: center; justify-content: center; }
.score { font-weight: 700; color: var(--gold); }
.statusbar > span { white-space: nowrap; }
@media (max-width: 420px) { .statusbar { gap: 6px; font-size: .9rem; } .level-badge { padding: 6px 12px; } }
.lb-card { display: flex; flex-direction: column; min-height: 0; }
.lb-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; }
.lb-row { display: grid; grid-template-columns: minmax(1.3em, auto) 1fr auto; gap: 4px; align-items: baseline; padding: 4px 8px; border-radius: 8px; font-size: .92rem; font-variant-numeric: tabular-nums; }
.lb-row + .lb-row { margin-top: 2px; }
.lb-rank { opacity: .75; text-align: left; }
.lb-row.norank { grid-template-columns: 1fr auto; }   /* sans place (joueur sans pseudonyme) : le nom est collé à gauche, sans retrait */
.lb-row.norank .lb-rank { display: none; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; }
.lb-row.you { background: var(--green); color: #fff; }
.lb-row.you .lb-rank { opacity: .9; }
.lb-dots { text-align: center; opacity: .7; line-height: 1; letter-spacing: .2em; padding: 2px 0; }
#lbEmpty { margin: 0; font-size: .9rem; }
@media (min-width: 992px) {
  /* le palmarès ne dépasse jamais le bas du cadre du jeu : la colonne latérale prend la hauteur du jeu et défile au besoin */
  .game-side { contain: size; align-self: start; min-height: 0; height: 620px; }   /* la hauteur exacte (bas du plateau) est ajustée par fitSide() dans main.js */
  .lb-card { flex: 1 1 0; }
}
.nick-field .nick-row { display: flex; gap: 8px; }
.nick-field input { flex: 1; min-width: 0; }
.nick-msg { display: block; min-height: 1.2em; }
.nick-msg.ok { color: #7be0a8; }
.nick-msg.bad { color: #ff9a9f; }
@media (max-width: 340px) { .statusbar { flex-wrap: wrap; justify-content: center; } }
