:root {
  color-scheme: light;
  --background: #fff8f0;
  --surface: #ffffff;
  --ink: #000000;
  --muted: #69645f;
  --line: #242424;
  --green: #00c950;
  --red: #ff2b2b;
  --yellow: #ffd60a;
  /* Réserve la place des compteurs à droite, même sur un écran de 320 px. */
  --board-size: min(300px, calc(100vw - 110px));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--background); }

body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 22%, rgba(0, 201, 80, 0.055) 0 3px, transparent 4px),
    radial-gradient(circle at 86% 70%, rgba(255, 214, 10, 0.14) 0 4px, transparent 5px),
    var(--background);
}

button, a { -webkit-tap-highlight-color: transparent; }

.install-banner {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 14px;
  color: #fff;
  background: #121514;
  font-size: 14px;
  text-align: center;
}

.language-switcher {
  display: flex;
  flex: 0 0 auto;
  gap: 3px;
}

.language-switcher button {
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 50%;
  padding: 0;
  background: rgba(255, 255, 255, .08);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.language-switcher button:hover { background: rgba(255, 255, 255, .2); }
.language-switcher button[aria-current="true"] { border-color: var(--yellow); box-shadow: 0 0 0 2px var(--yellow); }
.language-switcher button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.language-switcher img { display: block; width: 23px; height: 15px; border-radius: 2px; object-fit: cover; box-shadow: 0 0 0 1px rgba(255, 255, 255, .32); }

.banner-link {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 12px;
  color: #101010;
  background: var(--yellow);
  font-weight: 800;
  text-decoration: none;
}

.demo-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 82px 18px 36px;
}

.intro { max-width: 640px; margin: 0 auto 18px; text-align: center; }
.intro p { margin: 8px auto 0; line-height: 1.45; }
.intro h1 { margin: 0; font-size: clamp(38px, 8vw, 64px); letter-spacing: -0.045em; }
.intro .eyebrow { margin: 0 0 4px; color: var(--green); font-size: 13px; font-weight: 900; letter-spacing: .18em; }

.progress {
  display: grid;
  max-width: 520px;
  gap: 8px;
  margin: 0 auto 14px;
  font-size: 14px;
  font-weight: 800;
}

.mode-switcher {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.mode-choice {
  min-width: 0;
  border: 2px solid #77716b;
  border-radius: 999px;
  padding: 8px 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, .78);
  font: 800 12px/1.1 inherit;
  cursor: pointer;
}

.mode-choice:hover { border-color: var(--ink); }
.mode-choice:focus-visible { outline: 4px solid var(--yellow); outline-offset: 2px; }
.mode-choice.current { border-color: var(--ink); background: var(--yellow); }
.mode-choice.complete { border-color: var(--green); }
.mode-choice.complete::before { margin-right: 4px; color: #007b30; content: "✓"; }

.mini-timer {
  display: flex;
  width: fit-content;
  align-items: baseline;
  justify-content: center;
  gap: 9px;
  margin: 0 auto 14px;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  background: rgba(255, 255, 255, .78);
}

.mini-timer span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.mini-timer strong {
  min-width: 76px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.game { text-align: center; }

.board-wrap {
  position: relative;
  width: var(--board-size);
  height: calc(var(--board-size) + 47px);
  margin: 0 auto;
}

.board {
  display: grid;
  width: var(--board-size);
  height: var(--board-size);
  overflow: hidden;
  grid-template: repeat(var(--grid-size, 6), 1fr) / repeat(var(--grid-size, 6), 1fr);
  border: 4px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 14px 32px rgba(37, 28, 18, .10);
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  border-right: 1px solid #88827b;
  border-bottom: 1px solid #88827b;
  border-radius: 0;
  color: var(--ink);
  background: var(--surface);
  font: 900 clamp(20px, 6vw, 28px)/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.cell.last-column { border-right: 0; }
.cell.last-row { border-bottom: 0; }
.cell:focus-visible { z-index: 4; outline: 4px solid var(--yellow); outline-offset: -4px; }
.board.size-8 .cell { font-size: clamp(16px, 4.8vw, 24px); }

.cell.selected {
  z-index: 2;
  color: #006828;
  background: #e4ffed;
  box-shadow: inset 0 0 0 4px var(--green);
}

.cell.crossed { color: #79736d; background: #fffafa; }
.cell.crossed::before,
.cell.crossed::after {
  position: absolute;
  width: 58%;
  height: 5px;
  border-radius: 999px;
  background: var(--red);
  content: "";
}
.cell.crossed::before { transform: rotate(45deg); }
.cell.crossed::after { transform: rotate(-45deg); }

.row-counters {
  position: absolute;
  top: 0;
  left: calc(100% + 7px);
  display: grid;
  width: 36px;
  height: var(--board-size);
  grid-template-rows: repeat(var(--grid-size, 6), 1fr);
}

.column-counters {
  position: absolute;
  top: calc(var(--board-size) + 7px);
  left: 0;
  display: grid;
  width: var(--board-size);
  height: 36px;
  grid-template-columns: repeat(var(--grid-size, 6), 1fr);
}

.counter {
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: clamp(21px, 6vw, 32px);
  font-weight: 900;
  line-height: 1;
  transition: color .15s ease, transform .15s ease;
}
.counter.valid { color: var(--green); transform: scale(1.09); }
.counter.invalid { color: var(--red); transform: scale(1.09); }
.counter.target-counter { font-size: clamp(12px, 3.6vw, 18px); }

.gesture-help {
  display: flex;
  justify-content: center;
  gap: clamp(22px, 10vw, 72px);
  margin: 12px 0 20px;
  text-transform: uppercase;
}
.gesture-help span { display: inline-flex; align-items: center; gap: 8px; }
.gesture-help b { font-size: 14px; }
.gesture-help i { display: inline-grid; width: 28px; height: 28px; place-items: center; font-style: normal; }
.tap-circle { border: 5px solid var(--green); border-radius: 50%; }
.tap-cross { color: var(--red); font-size: 43px; font-weight: 700; line-height: .5; }

.grid-complete {
  max-width: 520px;
  margin: 8px auto 16px;
  padding: 18px;
  border: 2px solid var(--green);
  border-radius: 18px;
  background: #ecfff3;
  text-align: center;
}
.grid-complete strong { display: block; margin-bottom: 12px; font-size: 21px; }

.actions { min-height: 56px; text-align: center; }
.actions span { display: block; min-height: 22px; margin-top: 5px; color: #315a40; font-size: 13px; }

.primary-button,
.secondary-button,
.replay-button {
  border: 0;
  border-radius: 999px;
  padding: 13px 22px;
  font: 800 16px/1.2 inherit;
  cursor: pointer;
}
.primary-button { color: #111; background: var(--yellow); box-shadow: 0 6px 0 #d5ae00; }
.secondary-button { border: 2px solid #242424; color: #111; background: #fff; }

.paywall[hidden], .grid-complete[hidden] { display: none; }
.paywall {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  overflow: auto;
  place-items: center;
  padding: 24px;
  background: rgba(13, 14, 14, .88);
}

.paywall-card {
  width: min(100%, 580px);
  border-radius: 28px;
  padding: clamp(24px, 6vw, 48px);
  background: var(--background);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .35);
  text-align: center;
}
.success-mark { display: grid; width: 58px; height: 58px; place-items: center; margin: 0 auto 12px; border-radius: 50%; color: #fff; background: var(--green); font-size: 38px; font-weight: 900; }
.paywall h2 { margin: 0 0 10px; font-size: clamp(29px, 7vw, 44px); line-height: 1.05; }
.paywall-card > p:not(.success-mark) { margin: 0 auto 24px; font-size: 18px; line-height: 1.45; }
.store-button { display: block; border-radius: 16px; padding: 17px 18px; color: #111; background: var(--yellow); box-shadow: 0 7px 0 #d5ae00; font-size: 17px; font-weight: 900; text-decoration: none; }
.qr-block { display: grid; justify-items: center; gap: 7px; margin: 24px 0 18px; color: var(--muted); font-size: 14px; font-weight: 700; }
.qr-block img { width: 184px; height: 184px; border: 8px solid #fff; border-radius: 12px; image-rendering: pixelated; }
.replay-button { padding: 8px; color: var(--muted); background: transparent; font-size: 14px; text-decoration: underline; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

@media (min-width: 700px) {
  :root {
    /* La hauteur du navigateur devient elle aussi une limite : grille,
       compteurs, légende et partage restent visibles sans défilement. */
    --board-size: min(440px, calc(100vw - 140px), calc(100vh - 420px));
    --board-size: min(440px, calc(100vw - 140px), calc(100dvh - 420px));
  }
  .install-banner { font-size: 16px; }
  .demo-shell { padding-top: 94px; }
  .cell { font-size: 28px; }
}

@media (min-width: 700px) and (max-height: 850px) {
  .demo-shell { padding-top: 72px; padding-bottom: 16px; }
  .intro { margin-bottom: 9px; }
  .intro h1 { font-size: 48px; }
  .intro p { margin-top: 4px; }
  .progress { margin-bottom: 8px; }
  .gesture-help { margin: 6px 0 12px; }
}

@media (min-width: 900px) {
  :root {
    --board-size: min(520px, calc(100vh - 180px));
    --board-size: min(520px, calc(100dvh - 180px));
  }

  .demo-shell {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-columns: minmax(290px, .78fr) minmax(0, 1.22fr);
    grid-template-rows: auto auto auto auto auto 1fr;
    grid-template-areas:
      "intro game"
      "progress game"
      "timer game"
      "gestures game"
      "complete game"
      "actions game";
    column-gap: 44px;
    align-items: start;
    padding: 92px 48px 24px;
  }

  .intro {
    grid-area: intro;
    max-width: none;
    margin: 0 0 26px;
    text-align: left;
  }

  .intro p { margin-left: 0; }
  .intro h1 { font-size: clamp(48px, 4.5vw, 64px); }

  .progress {
    grid-area: progress;
    width: 100%;
    margin: 0 0 24px;
  }

  .mode-choice { font-size: 11px; }

  .mini-timer {
    grid-area: timer;
    margin: 0 0 24px;
  }

  .game {
    grid-area: game;
    align-self: center;
    min-width: 0;
  }

  .board-wrap {
    /* Les 44 px restants accueillent les compteurs situés à droite. */
    width: min(var(--board-size), calc(100% - 44px));
    height: auto;
    padding-bottom: 47px;
  }

  .board {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }

  .row-counters {
    top: 0;
    bottom: 47px;
    height: auto;
  }

  .column-counters {
    top: auto;
    bottom: 4px;
    width: 100%;
  }

  .gesture-help {
    grid-area: gestures;
    justify-content: flex-start;
    margin: 0 0 24px;
  }

  .grid-complete {
    grid-area: complete;
    width: 100%;
    margin: 0 0 20px;
  }

  .actions {
    grid-area: actions;
    text-align: left;
  }
}

@media (max-width: 370px) {
  .install-banner { gap: 7px; font-size: 12px; }
  .banner-link { padding: 7px 8px; }
  .demo-shell { padding-inline: 10px; }
}

@media (max-width: 760px) {
  .install-banner { flex-wrap: wrap; padding-block: 7px; }
  .language-switcher { order: 3; width: 100%; justify-content: center; }
  .demo-shell { padding-top: 122px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
