:root {
  --bg-top: #1a5fb4;
  --bg-bottom: #0b3a78;
  --tile: #ffffff;
  --tile-edge: #c3cad6;
  --tile-text: #3b2a17;
  --sel: #ffe27a;
  --ok: #7cc242;
  --dup: #f5c518;
  --bad: #e5533d;
  --LD: #62b43a;
  --LT: #1f6fd1;
  --MD: #f29a1f;
  --MT: #d8362f;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --panel: #ffffff;
  --panel-text: #1f2a3a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Arial Rounded MT Bold", -apple-system, "SF Pro Rounded", system-ui, sans-serif;
  color: var(--text);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0 14px, transparent 14px 28px),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

.view {
  display: none;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
}
.view.active { display: flex; }

/* ---------- Accueil ---------- */
#home { justify-content: center; gap: 14px; position: relative; }

.logo { display: flex; gap: 6px; }
.logo .tile {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800;
  color: var(--tile-text);
  background: var(--tile);
  border-radius: 9px;
  box-shadow: 0 4px 0 var(--tile-edge);
}
.logo-sub { font-size: 30px; font-weight: 800; letter-spacing: 2px; margin: 4px 0 10px; }

.card {
  width: 100%; max-width: 360px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 18px;
  padding: 16px 18px;
}
.card-title { font-size: 20px; font-weight: 800; }
.card-date { color: var(--muted); font-size: 15px; margin-top: 2px; }
.progress { height: 10px; border-radius: 5px; background: rgba(0, 0, 0, 0.25); margin: 14px 0 8px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--ok); border-radius: 5px; transition: width 0.4s; }
.card-stats { display: flex; justify-content: space-between; font-size: 17px; font-weight: 700; }
.card-timer { color: var(--muted); font-size: 14px; margin-top: 10px; }
.card-timer span { font-variant-numeric: tabular-nums; }

.btn {
  width: 100%; max-width: 360px;
  padding: 16px;
  font-size: 20px; font-weight: 800;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn-primary { background: var(--ok); box-shadow: 0 4px 0 #4f8a22; font-size: 24px; }
.btn-primary:active { box-shadow: 0 2px 0 #4f8a22; }
.btn-link { background: none; box-shadow: none; font-size: 16px; color: var(--muted); padding: 8px; }

/* ---------- Jeu ---------- */
.topbar {
  width: 100%; max-width: 440px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.icon-btn {
  width: 44px; height: 44px; flex: none;
  font-size: 34px; line-height: 1;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
}
.icon-btn-spacer { width: 44px; }
.topbar-title { font-size: 20px; font-weight: 800; }
/* Bandeau du haut, facon Ruzzle */
#game { padding: 0 0 calc(var(--safe-bottom) + 10px); }
.game-head {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 14px 12px;
  background: linear-gradient(180deg, #0f4c9c, #0b3c7f);
  border-bottom: 3px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.clock { text-align: center; }
.clock-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.clock-value { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.score {
  width: 60px; height: 60px; flex: none;
  border-radius: 50%;
  background: #fff; color: #0b3c7f;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.score-value { font-size: 20px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-label { font-size: 11px; font-weight: 700; opacity: 0.7; }

.count-pill {
  margin-top: 12px;
  padding: 7px 16px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 16px; font-weight: 700;
}
.count-pill span:first-child { font-variant-numeric: tabular-nums; }
.count-pill .chev { opacity: 0.7; margin-left: 2px; }
.count-pill:active { background: rgba(0, 0, 0, 0.4); }

.word-zone { flex: 1; min-height: 80px; display: flex; align-items: center; justify-content: center; width: 100%; }
.word {
  position: relative;
  font-size: 32px; font-weight: 800; letter-spacing: 3px;
  padding: 8px 22px; border-radius: 16px;
  color: #1b1b1b;
  background: #fff;
  box-shadow: 0 4px 0 var(--tile-edge);
  visibility: hidden;
}
.word.show { visibility: visible; }
.word .pts {
  position: absolute; top: -12px; right: -14px;
  min-width: 34px; height: 34px; padding: 0 6px;
  border-radius: 17px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; letter-spacing: 0;
  background: #fff; color: #3b7d16;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.word.ok { background: var(--ok); color: #fff; box-shadow: 0 4px 0 #4f8a22; }
.word.dup { background: var(--dup); color: #5a4300; box-shadow: 0 4px 0 #b38e00; }
.word.bad { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #a53322; }

/* Grille en bas de l'ecran, comme dans Ruzzle */
.board-wrap { width: 100%; max-width: 480px; padding: 0 8px; }
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2.5%;
  padding: 3%;
  border-radius: 18px;
  background: #0a2f63;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14%;
  background: linear-gradient(180deg, #ffffff 0%, #eef1f6 100%);
  color: #1b1b1b;
  box-shadow: 0 5px 0 var(--tile-edge);
  font-size: min(14vw, 62px);
  font-weight: 800;
  transition: transform 0.1s ease-out;
}
.cell .val { position: absolute; top: 5%; left: 9%; font-size: 28%; font-weight: 700; opacity: 0.7; }
.cell .bonus {
  position: absolute; top: 6%; right: 7%;
  font-size: 24%; font-weight: 800;
  padding: 2px 5px; border-radius: 6px;
  color: #fff;
}
.cell.b-LD .bonus { background: var(--LD); }
.cell.b-LT .bonus { background: var(--LT); }
.cell.b-MD .bonus { background: var(--MD); }
.cell.b-MT .bonus { background: var(--MT); }

/* Selection : orange vif, la case grossit */
.board .cell.sel {
  background: linear-gradient(180deg, #ffb126 0%, #ff8a00 100%);
  color: #fff;
  box-shadow: 0 5px 0 #c25e00;
  transform: scale(1.08);
  z-index: 1;
}
.board .cell.sel .val { opacity: 0.9; }
.board .cell.flash-ok { background: var(--ok); color: #fff; box-shadow: 0 5px 0 #4f8a22; transform: scale(1.08); z-index: 1; }
.board .cell.flash-dup { background: var(--dup); color: #5a4300; box-shadow: 0 5px 0 #b38e00; transform: scale(1.08); z-index: 1; }
.board .cell.flash-bad { background: var(--bad); color: #fff; box-shadow: 0 5px 0 #a53322; transform: scale(1.08); z-index: 1; }

/* Mot en or */
.board .cell.flash-gold {
  background: linear-gradient(180deg, #ffe066 0%, #ffbf00 100%);
  color: #5a3d00; box-shadow: 0 5px 0 #b37f00, 0 0 18px rgba(255, 210, 60, 0.9);
  transform: scale(1.08); z-index: 1;
  animation: gold-pulse 0.4s ease-in-out 3 alternate;
}
@keyframes gold-pulse { to { transform: scale(1.15); } }
.word.gold {
  background: linear-gradient(180deg, #ffe066 0%, #ffbf00 100%);
  color: #5a3d00; box-shadow: 0 4px 0 #b37f00, 0 0 24px rgba(255, 210, 60, 0.8);
}
.word.gold .pts { color: #8a5e00; }
.word .crown { width: 30px; height: 30px; vertical-align: -3px; margin-right: 8px; }
.chip .crown { width: 16px; height: 16px; vertical-align: -2px; margin-right: 4px; }
.chip.gold { background: linear-gradient(180deg, #ffe066 0%, #ffbf00 100%); color: #5a3d00; }
.sheet .chip.gold { background: linear-gradient(180deg, #ffe066 0%, #ffbf00 100%); }
#y-list .chip.gold:not(.found) { opacity: 0.75; }

.trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; overflow: visible; }
.trail polyline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.6);
  stroke-width: 16;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Bouton son (accueil) */
.sound-btn {
  position: absolute;
  top: calc(var(--safe-top) + 14px); right: 16px;
  display: flex; align-items: center; justify-content: center;
}
.sound-btn svg { width: 26px; height: 26px; }
.sound-btn .sound-off { display: none; }
.sound-btn.muted .sound-on { display: none; }
.sound-btn.muted .sound-off { display: inline; }
.sound-btn.muted { opacity: 0.6; }

/* ---------- Solution d'hier ---------- */
.y-summary { margin: 14px 0 10px; font-size: 17px; font-weight: 700; text-align: center; }
.board-small { max-width: 260px; flex: none; touch-action: auto; }
.board-small .cell { font-size: min(9vw, 34px); box-shadow: 0 3px 0 var(--tile-edge); }
.legend { display: flex; align-items: center; gap: 6px; margin: 14px 0 6px; color: var(--muted); font-size: 14px; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.dot-found { background: var(--ok); }
.dot-missed { background: rgba(255, 255, 255, 0.35); }

/* ---------- Listes de mots ---------- */
.word-list { width: 100%; max-width: 440px; }
.group-title { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; opacity: 0.7; margin: 14px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 16px; font-weight: 700; letter-spacing: 1px;
  padding: 5px 10px; border-radius: 9px;
  background: rgba(255, 255, 255, 0.18);
}
.chip small { font-weight: 600; opacity: 0.75; margin-left: 4px; letter-spacing: 0; }
.chip.found { background: var(--ok); color: #fff; }
.empty { opacity: 0.7; text-align: center; margin: 24px 0; }

/* ---------- Feuilles (modales) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-panel {
  width: 100%; max-width: 480px; max-height: 80%;
  overflow-y: auto;
  background: var(--panel); color: var(--panel-text);
  border-radius: 22px 22px 0 0;
  padding: 16px 18px calc(var(--safe-bottom) + 20px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-title { font-size: 21px; font-weight: 800; }
.sheet .icon-btn { background: #eef1f5; font-size: 28px; }
.sheet .chip { background: #eef1f5; }
.rules p { font-size: 17px; line-height: 1.5; }
.b { display: inline-block; color: #fff; font-weight: 800; font-size: 13px; padding: 1px 6px; border-radius: 5px; }
.tag-LD { background: var(--LD); } .tag-LT { background: var(--LT); }
.tag-MD { background: var(--MD); } .tag-MT { background: var(--MT); }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 90px); z-index: 20;
  transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 32px);
  background: #fff; color: var(--panel-text);
  padding: 14px 20px; border-radius: 16px;
  font-size: 18px; font-weight: 800; text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}
.toast[hidden] { display: none; }

/* ---------- Classement et profils ---------- */
.panel-col { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.panel-col[hidden] { display: none; }
.panel-col .card { max-width: none; }
.panel-col .btn { max-width: none; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 0 10px; }
.msg { font-size: 15px; font-weight: 700; margin: 8px 0 0; min-height: 1em; }
.msg.err { color: #ffb4a8; }
.msg.ok { color: #c8f59f; }

.field {
  width: 100%;
  font: inherit; font-size: 18px; font-weight: 700;
  padding: 12px 14px;
  border: 0; border-radius: 12px;
  background: #fff; color: var(--panel-text);
  margin-bottom: 10px;
  -webkit-user-select: text; user-select: text;
}
.field.code { text-transform: uppercase; letter-spacing: 2px; }
.row { display: flex; gap: 8px; }
.row .field { margin-bottom: 0; }
.row .btn { width: auto; flex: none; }
.btn-small { font-size: 17px; padding: 12px 16px; }
.btn-danger { background: rgba(229, 83, 61, 0.85); box-shadow: 0 4px 0 #a53322; font-size: 17px; }
.badge {
  display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 6px;
  border-radius: 11px; background: var(--MT); font-size: 14px; line-height: 22px; vertical-align: 2px;
}
.badge[hidden] { display: none; }

.board-list { margin-top: 8px; }
.lb-row {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px;
  border-radius: 12px;
  text-align: left;
}
.lb-row + .lb-row { border-top: 1px solid rgba(255, 255, 255, 0.12); }
.lb-row.me { background: rgba(255, 255, 255, 0.14); }
.lb-rank {
  width: 30px; height: 30px; flex: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.25); font-weight: 800;
}
.lb-row:nth-child(1) .lb-rank { background: #f5c518; color: #5a4300; }
.lb-row:nth-child(2) .lb-rank { background: #d7dde6; color: #3a4556; }
.lb-row:nth-child(3) .lb-rank { background: #d9925a; color: #4a2508; }
.lb-name { flex: 1; font-size: 18px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-words { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-score { font-size: 19px; font-weight: 800; min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }

.req { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.req-name { flex: 1; font-size: 18px; font-weight: 800; }
.req .btn { width: auto; padding: 8px 12px; font-size: 15px; }

.mycode { text-align: center; }
.big-code { font-size: 34px; font-weight: 800; letter-spacing: 6px; font-variant-numeric: tabular-nums; }
.reveal {
  display: block; width: 100%; margin: 4px 0 14px;
  padding: 10px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 20px; font-weight: 800; letter-spacing: 2px;
  -webkit-user-select: text; user-select: text;
}

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.kpi { background: rgba(0, 0, 0, 0.2); border-radius: 12px; padding: 10px; text-align: center; }
.kpi-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }

.week { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.wk { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.wk-day { width: 42px; color: var(--muted); font-weight: 700; }
.wk-bar { flex: 1; height: 16px; border-radius: 8px; background: rgba(0, 0, 0, 0.2); overflow: hidden; }
.wk-bar div { height: 100%; background: var(--ok); border-radius: 8px; }
.wk-val { width: 124px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
