:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  --ink: #f5f1df;
  --muted: #a9c1bd;
  --deep: #071f23;
  --panel: #0f3439;
  --line: #2b5558;
  --accent: #ffd166;
  --cell: min(8.8vw, 54px);
}

* { box-sizing: border-box; }

html { scrollbar-gutter: stable; }

html.drag-in-progress,
body.drag-in-progress {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #265c5c 0, transparent 30rem),
    radial-gradient(circle at 90% 45%, #4f343c 0, transparent 28rem),
    linear-gradient(145deg, #071c21, #102f33 56%, #091d22);
  overscroll-behavior: none;
}

button { font: inherit; }

.game-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(22px, env(safe-area-inset-bottom));
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px auto 12px;
}

.eyebrow {
  margin: 0 0 5px;
  color: #7fd7ca;
  font-size: .69rem;
  font-weight: 900;
  letter-spacing: .18em;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.8rem);
  line-height: .94;
  letter-spacing: -.055em;
}

h1 span { color: var(--accent); }
.intro { margin: 8px 0 0; color: var(--muted); }

.round-button {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid #79b6b3;
  border-radius: 50%;
  color: var(--ink);
  background: #173d42;
  cursor: pointer;
  font-size: 1.25rem;
}

.round-button.muted { opacity: .48; }

.game-card {
  position: relative;
  overflow: hidden;
  border: 1px solid #477174;
  border-radius: 26px;
  /* Repli pour les versions de Chrome/Samsung sans color-mix(). */
  background: #0f3439eb;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: 0 24px 70px #0008, inset 0 1px #ffffff12;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  background: #0b292e;
}

.score-strip div { padding: 10px; text-align: center; }
.score-strip div + div { border-left: 1px solid var(--line); }
.score-strip span { display: block; color: var(--muted); font-size: .67rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.score-strip strong { color: var(--accent); font-size: 1.45rem; font-variant-numeric: tabular-nums; }

.board-area {
  position: relative;
  display: grid;
  place-items: center;
  padding: 18px 10px 10px;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows: repeat(9, var(--cell));
  gap: 4px;
  padding: 7px;
  border: 1px solid #4b6c6f;
  border-radius: 16px;
  background: #071d21;
  box-shadow: inset 0 8px 30px #0008, 0 8px 22px #001a;
  touch-action: none;
  contain: layout paint;
}

.cell {
  position: relative;
  border: 0;
  border-radius: 7px;
  background: #17393d;
  box-shadow: inset 0 1px #ffffff0d;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}

.cell.sector-a { background: #193e42; }
.cell.sector-b { background: #16373b; }

.cell.filled,
.mini-cell,
.drag-cell {
  --block: #6fd6c4;
  /* Pas de color-mix() ici : certains Chrome Samsung le rendent en noir. */
  background-color: var(--block);
  background-image: linear-gradient(145deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, 0) 58%);
  box-shadow: inset 0 2px #ffffff55, inset 0 -3px #071f2333, 0 3px 7px #0005;
  forced-color-adjust: none;
}

.cell.filled::after,
.mini-cell::after,
.drag-cell::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 30%;
  background: #ffffff18;
}

.cell.preview-ok {
  background: var(--preview, #6fd6c4);
  transform: scale(.93);
}
.cell.preview-bad { background: #a54c55; animation: shake .18s linear 1; }
.cell.clearing { animation: clear-cell .42s ease forwards; z-index: 2; }

.message {
  position: absolute;
  z-index: 8;
  top: 42%;
  left: 50%;
  padding: 8px 14px;
  border-radius: 20px;
  color: #173138;
  background: var(--accent);
  box-shadow: 0 8px 24px #0007;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(.9);
  transition: .2s ease;
}

.message.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

.tray-area {
  min-height: 148px;
  padding: 8px 14px 12px;
  border-top: 1px solid #2a5256;
  background: #0c292e;
}

.tray-area > p { margin: 0 0 8px; color: var(--muted); font-size: .78rem; text-align: center; }

.tray {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  min-height: 100px;
}

.piece {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 96px;
  padding: 8px;
  border: 0;
  border-radius: 16px;
  color: inherit;
  background: transparent;
  cursor: grab;
  touch-action: none;
  transition: background .15s ease, transform .15s ease, opacity .2s ease;
}

.piece:hover, .piece.selected { background: #ffffff0b; transform: translateY(-3px); }
.piece.selected { outline: 2px solid #ffd166aa; outline-offset: -3px; }
.piece.used { opacity: 0; pointer-events: none; transform: scale(.7); }
.piece-grid { position: relative; }
.mini-cell { position: absolute; width: 23px; height: 23px; border-radius: 6px; }

.drag-ghost {
  position: fixed;
  z-index: 50;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: .78;
  will-change: transform;
  contain: strict;
}

.drag-in-progress .cell { transition: none; }

.drag-cell {
  position: absolute;
  border-radius: 7px;
  box-shadow: inset 0 1px #ffffff44;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #2a5256;
}

.actions button, .modal-card button {
  border: 1px solid #72999a;
  border-radius: 13px;
  padding: 9px 16px;
  color: var(--ink);
  background: #173d42;
  cursor: pointer;
  font-weight: 800;
}

.actions .danger-button {
  border-color: #b97878;
  color: #ffd9d4;
  background: #543035;
}

.rules {
  margin-top: 12px;
  border: 1px solid #365d61;
  border-radius: 16px;
  padding: 12px 15px;
  color: var(--muted);
  background: #0c292ebd;
}

.rules summary { color: var(--ink); cursor: pointer; font-weight: 900; }
.rules div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.rules p { margin: 12px 0 2px; line-height: 1.45; }

.modal {
  position: absolute;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #061b1ed9;
  backdrop-filter: blur(6px);
}

.modal[hidden] { display: none; }

.modal-card {
  width: min(100%, 360px);
  padding: 28px;
  border: 1px solid #78b2ad;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(145deg, #194b4f, #102f35);
  box-shadow: 0 22px 70px #000b;
}

.modal-icon { display: block; color: var(--accent); font-size: 3rem; transform: rotate(45deg); }
.modal-card h2 { margin: 3px 0 10px; font-size: 2.2rem; }
.modal-card p { color: var(--muted); }
.modal-card strong { color: var(--accent); font-size: 1.25rem; }
.modal-card button { margin-top: 9px; color: #173138; background: var(--accent); border-color: var(--accent); }
.record-note { min-height: 1.3em; }

@keyframes clear-cell {
  45% { transform: scale(1.18) rotate(4deg); filter: brightness(1.6); }
  to { transform: scale(0); opacity: 0; }
}

@keyframes shake { 50% { transform: translateX(2px); } }

@media (max-width: 620px) {
  :root { --cell: min(9.1vw, 46px); }
  .game-shell { padding-inline: 7px; }
  .intro { display: none; }
  .hero { padding-inline: 7px; }
  .board { gap: 3px; padding: 5px; border-radius: 13px; }
  .cell { border-radius: 5px; }
  .tray-area { min-height: 132px; }
  .piece { min-height: 86px; padding: 5px; }
  .mini-cell { width: 19px; height: 19px; border-radius: 5px; }
  .rules div { display: block; }
}

@media (max-height: 760px) {
  .hero { margin-bottom: 6px; }
  .eyebrow, .intro, .rules { display: none; }
  .board-area { padding-top: 10px; }
  .tray-area { min-height: 112px; }
  .piece { min-height: 72px; }
  .actions { padding: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
