/* Le défi des tables: cut-paper style of Mémo en Chanson (style/palette.json). */
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('fonts/BricolageGrotesque.ttf') format('truetype');
  font-weight: 200 800;
  font-display: swap;
}
:root {
  --ivory: #FFF2DB; --paper: #FFFBF3; --ink: #201E32; --ink-soft: rgba(32, 30, 50, .62);
  --coral: #FF5A3D; --butter: #FFE76D; --mint: #86F4CC; --cobalt: #234EFA;
  --tone-a: #FFE27A; --tone-b: #9FF0CF; --tone-c: #FFBDAE; --tone-d: #BFCBFF;
  --right: #3FE0A5; --right-ink: #0E9F6E; --wrong-ink: #E2401F;
  --lift: 0 4px 0 rgba(32, 30, 50, .14), 0 10px 24px -12px rgba(32, 30, 50, .35);
  --radius: 18px;
  --ease-out: cubic-bezier(.2, .9, .3, 1);
  --pad: max(14px, env(safe-area-inset-left));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ivory); color: var(--ink); overflow: hidden; }
body { font: 500 17px/1.35 'Bricolage Grotesque', system-ui, sans-serif; -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app {
  position: relative; height: 100%; height: 100dvh; max-width: 1280px; margin: 0 auto;
  background:
    radial-gradient(circle at 85% 8%, rgba(191, 203, 255, .45), transparent 38%),
    radial-gradient(circle at 10% 92%, rgba(255, 231, 109, .35), transparent 40%);
}
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 10px var(--pad) max(14px, env(safe-area-inset-bottom)); }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: var(--radius); background: var(--paper); box-shadow: var(--lift); padding: 15px 22px; font-size: 19px; font-weight: 700; letter-spacing: -.01em; transition: transform .12s var(--ease-out), box-shadow .12s; }
.btn:active, .key:active, .table-card:active, .channel:active, .gcell:active { transform: translateY(2px) scale(.97); box-shadow: 0 1px 0 rgba(32, 30, 50, .16); }
.btn-primary { background: var(--cobalt); color: var(--ivory); }
.btn-ghost { background: transparent; box-shadow: inset 0 0 0 2px rgba(32, 30, 50, .14); }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--paper); box-shadow: var(--lift); font-size: 19px; font-weight: 700; display: grid; place-items: center; }
.btn:focus-visible, .key:focus-visible, .icon-btn:focus-visible, .table-card:focus-visible, .gcell:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; }
.bar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 10px; min-height: 48px; }
.bar h2 { margin: 0; text-align: center; font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.toggles { position: absolute; right: var(--pad); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.app:not([data-screen="home"]) .toggles { display: none; }
#toggle-music.is-off { opacity: .45; text-decoration: line-through; }
.mascot { display: block; }

/* ---------- fact states (grids) ---------- */
.is-new { background: rgba(32, 30, 50, .07); }
.is-missed { background: var(--tone-c); }
.is-learning { background: var(--butter); }
.is-mastered { background: var(--right); }

/* ---------- home ---------- */
.home { justify-content: flex-end; }
.home-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(9, 1fr); gap: 5px; width: min(100%, 52vh); margin: 8px auto 14px; aspect-ratio: 10 / 9; align-self: center; }
.home-grid .cell { border-radius: 7px; box-shadow: 0 2px 0 rgba(32, 30, 50, .1); animation: cell-in .45s var(--d) cubic-bezier(.3, 1.4, .5, 1) backwards; }
@keyframes cell-in { from { transform: scale(0); opacity: 0; } }
.home-panel { display: grid; justify-items: center; text-align: center; gap: 4px; padding-bottom: 52px; }
.mascot-big { width: 92px; height: 92px; margin-bottom: -8px; }
.title { margin: 0; font-size: clamp(42px, min(11vw, 7.5vh), 78px); line-height: .9; font-weight: 800; letter-spacing: -.045em; }
.tagline { margin: 6px 0 14px; color: var(--ink-soft); font-weight: 600; }
.home-actions { display: grid; gap: 10px; width: min(360px, 100%); }
.home-progress { margin: 14px 0 0; font-size: 14px; color: var(--ink-soft); font-weight: 600; min-height: 1.3em; }

/* ---------- pick ---------- */
.table-list { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: center; width: min(560px, 100%); margin: 0 auto; }
.table-card { display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 10px; text-align: left; border: 0; border-radius: 20px; background: var(--paper); box-shadow: var(--lift); padding: 12px 14px; transition: transform .12s var(--ease-out); }
.table-num { grid-row: 1 / 3; width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; font-weight: 800; background: var(--butter); }
.table-card:nth-child(3n + 2) .table-num { background: var(--tone-b); }
.table-card:nth-child(3n) .table-num { background: var(--tone-d); }
.table-card.is-mix { grid-column: 1 / -1; }
.table-card.is-mix .table-num { width: auto; padding: 0 12px; font-size: 20px; background: var(--tone-c); }
.table-card.is-mix { grid-template-columns: auto 1fr auto; }
.table-body small { color: var(--ink-soft); font-size: 14px; font-weight: 650; }
.meter { display: block; height: 8px; border-radius: 99px; background: rgba(32, 30, 50, .08); margin-top: 6px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--right); border-radius: 99px; }
.table-stars { grid-column: 2; font-size: 15px; color: #F2B300; letter-spacing: 1px; }
.table-card.is-mix .table-stars { grid-column: 3; grid-row: 1 / 3; }
.table-stars i { font-style: normal; color: rgba(32, 30, 50, .14); }

/* ---------- play ---------- */
.progress { display: flex; gap: 6px; justify-content: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(32, 30, 50, .14); transition: background .25s, transform .25s; }
.dot.is-now { background: var(--ink); transform: scale(1.25); }
.dot.is-right { background: var(--right-ink); } .dot.is-wrong { background: var(--coral); }
.score { justify-self: end; display: flex; gap: 6px; align-items: center; font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums; min-width: 44px; justify-content: flex-end; grid-column: 3; }
.streak { font-size: 15px; }
.timer { height: 12px; border-radius: 99px; background: rgba(32, 30, 50, .08); overflow: hidden; margin: 4px 0 2px; }
.timer span { display: block; height: 100%; background: var(--cobalt); border-radius: 99px; transform-origin: left; }
.timer.is-low span { background: var(--coral); animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .55; } }

.question { position: relative; display: grid; justify-items: center; text-align: center; margin: 8px 0 0; }
.mascot-small { position: absolute; left: 0; top: -2px; width: 60px; height: 60px; }
.kicker { margin: 4px 0 2px; font-weight: 700; color: var(--ink-soft); min-height: 1.3em; }
.equation { margin: 0; font-size: clamp(46px, 13vw, 76px); font-weight: 800; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.slot { display: inline-grid; place-items: center; min-width: 1.5em; padding: 0 .12em; border-radius: .22em; background: var(--paper); box-shadow: inset 0 -4px 0 rgba(32, 30, 50, .1), var(--lift); color: rgba(32, 30, 50, .3); transition: background .2s, color .2s; }
.slot.is-filled { color: var(--ink); }
.slot.is-right { background: var(--right); }
.slot.is-wrong { background: var(--coral); color: var(--paper); }
.slot.is-fix { background: var(--right); color: var(--ink); }
.slot.is-struck { text-decoration: line-through; text-decoration-thickness: .08em; color: var(--wrong-ink); }

.picture { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; margin: 8px 0; }
.picture.is-defi { flex: .4; }
.array-host { width: 100%; height: 100%; display: grid; place-items: center; min-height: 0; }
/* Pinned to its box so the viewBox scales down to fit both width and height. */
.array-host, .grid-picture { position: relative; }
.array { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.array circle { transform-box: fill-box; transform-origin: center; stroke: var(--ink); stroke-width: 1.5; }
.array .tone-a circle { fill: var(--tone-a); } .array .tone-b circle { fill: var(--tone-b); }
.array-count { font-size: 22px; font-weight: 700; fill: var(--ink-soft); font-variant-numeric: tabular-nums; }
.array-count.is-total { font-size: 28px; font-weight: 800; fill: var(--ink); }
.hint { position: absolute; border: 0; border-radius: 999px; padding: 10px 16px; background: rgba(255, 251, 243, .85); box-shadow: var(--lift); font-weight: 700; font-size: 16px; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(420px, 100%); margin: 0 auto; }
.key { border: 0; border-radius: 16px; background: var(--paper); box-shadow: var(--lift); min-height: 54px; font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; transition: transform .1s var(--ease-out), opacity .2s; }
.key:disabled { opacity: .5; cursor: default; }
.key-soft { background: rgba(255, 251, 243, .6); font-size: 22px; }
.key-ok { background: var(--cobalt); color: var(--ivory); font-size: 20px; }
.pad-truth { grid-template-columns: 1fr 1fr; }
.pad-truth .key { min-height: 76px; font-size: 26px; }
.key-true { background: var(--tone-b); } .key-false { background: var(--tone-c); }

.sheet { position: absolute; left: var(--pad); right: var(--pad); bottom: max(14px, env(safe-area-inset-bottom)); background: var(--paper); border-radius: 24px; box-shadow: 0 -2px 0 rgba(32, 30, 50, .06), 0 18px 40px -16px rgba(32, 30, 50, .45); padding: 18px 18px 16px; display: grid; gap: 8px; z-index: 3; }
.sheet-verdict { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.02em; color: var(--wrong-ink); }
.sheet-text { margin: 0 0 6px; font-size: 18px; font-weight: 550; }
.fly { position: fixed; z-index: 9; pointer-events: none; font-weight: 800; font-size: 22px; color: var(--right-ink); text-shadow: 0 2px 0 var(--paper); }

/* ---------- result ---------- */
.result { justify-content: center; align-items: center; gap: 18px; }
.result-card { width: min(460px, 100%); background: var(--paper); border-radius: 28px; box-shadow: var(--lift); padding: 26px 22px 20px; text-align: center; display: grid; gap: 8px; }
.result-kicker { margin: 0; font-weight: 700; color: var(--ink-soft); }
.stars { display: flex; justify-content: center; gap: 6px; font-size: 54px; line-height: 1; }
.stars span { color: rgba(32, 30, 50, .12); transition: color .2s; }
.stars span.is-on { color: #F2B300; animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { 0% { transform: scale(.4) rotate(-20deg); } 100% { transform: none; } }
.result-score { margin: 4px 0 0; font-size: 20px; font-weight: 800; }
.result-review { margin: 0 0 8px; font-size: 15px; color: var(--ink-soft); font-weight: 550; }
.result-actions { display: grid; gap: 10px; }
.channel { display: flex; align-items: center; gap: 12px; text-align: left; width: min(460px, 100%); border: 0; border-radius: 20px; background: var(--ink); color: var(--ivory); padding: 10px 16px 10px 10px; box-shadow: var(--lift); font-size: 15px; }
.channel img { border-radius: 50%; background: var(--ivory); flex: none; }
.channel strong { font-size: 17px; }

/* ---------- ma grille ---------- */
.grid-legend { margin: 4px 0 8px; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; font-size: 12px; font-weight: 650; color: var(--ink-soft); }
.grid-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }
.lg-mastered { background: var(--right); } .lg-learning { background: var(--butter); } .lg-missed { background: var(--tone-c); } .lg-new { background: rgba(32, 30, 50, .1); }
.big-grid { flex: none; display: grid; grid-template-columns: 26px repeat(10, 1fr); grid-template-rows: 22px repeat(9, 1fr); gap: 4px; width: min(100%, 560px, 58vh); aspect-ratio: 1; margin: 0 auto; align-self: center; }
.gh { display: grid; place-items: center; font-size: 12px; font-weight: 750; color: var(--ink-soft); }
.gcell { border: 0; border-radius: 8px; font-size: clamp(11px, 2.6vw, 15px); font-weight: 750; font-variant-numeric: tabular-nums; box-shadow: 0 2px 0 rgba(32, 30, 50, .1); padding: 0; transition: transform .12s var(--ease-out); }
.gcell.is-picked { outline: 3px solid var(--ink); outline-offset: 1px; }
.grid-sheet { gap: 6px; }
.grid-sheet .sheet-verdict { color: var(--ink); font-size: 30px; text-align: center; }
.grid-picture { height: 22vh; min-height: 120px; display: grid; place-items: center; overflow: hidden; }

.grid-actions { display: flex; gap: 8px; }
.grid-actions .btn { flex: 1; font-size: 16px; padding: 13px 12px; }

/* ---------- landscape ---------- */
@media (min-aspect-ratio: 5/4) {
  .play { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, 1fr); grid-template-rows: auto auto auto 1fr; column-gap: 32px; }
  .play .bar, .play .timer { grid-column: 1 / -1; }
  .play .question { grid-column: 1; grid-row: 3; }
  .play .picture { grid-column: 1; grid-row: 4; }
  .play .pad { grid-column: 2; grid-row: 3 / 5; align-self: center; }
  .play .sheet { left: auto; width: min(460px, 42%); }
  .home { flex-direction: row; align-items: center; justify-content: space-between; gap: 32px; }
  .home-grid { flex: none; width: min(52%, 80vh); height: auto; margin: 0; }
  .home-panel { flex: 1; padding: 0 0 20px; }
  .table-list { grid-template-columns: repeat(3, 1fr); width: min(820px, 100%); }
  .table-card.is-mix { grid-column: 1 / -1; }
  .grid { display: grid; grid-template-columns: 1fr minmax(300px, 36%); grid-template-rows: auto auto 1fr; column-gap: 24px; }
  .grid .bar, .grid .grid-legend { grid-column: 1 / -1; }
  .grid .big-grid { grid-column: 1; grid-row: 3; width: min(100%, 72vh); }
  .grid .grid-sheet { position: static; grid-column: 2; grid-row: 3; align-self: center; }
}

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