:root {
  --btn: min(80px, 9vh);
  --ink: #26264f;
  --card: rgba(255, 255, 255, 0.92);
  --accent: #ff7a1a;
  --good: #34c759;
  font-family: ui-rounded, system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100vh; height: 100dvh; overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
body { background: #5fb4ff; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
.hidden { display: none !important; }

#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.screen { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 12px; pointer-events: none; }
.screen > * { pointer-events: auto; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(0.94); }
.big { min-height: 72px; min-width: 72px; padding: 10px 22px; border-radius: 28px; background: var(--accent); color: #fff; font-size: 28px; font-weight: 800; box-shadow: 0 6px 0 rgba(0,0,0,.2); }
.big small { display: block; font-size: 20px; font-weight: 700; opacity: .95; }
.big.small { font-size: 22px; min-height: 64px; }
.round { width: 64px; height: 64px; border-radius: 50%; background: var(--card); font-size: 30px; box-shadow: 0 5px 0 rgba(0,0,0,.18); flex: none; }
.round.small { width: 64px; height: 64px; font-size: 28px; }

/* Titre */
#screen-title { inset: 0; justify-content: center; padding: 16px; }
#screen-title h1 { margin: 0; font-size: clamp(32px, 6vw, 60px); background: var(--card); padding: 8px 24px; border-radius: 32px; text-align: center; }
.levels { display: flex; flex-direction: column; gap: 14px; width: min(420px, 90vw); }
.level:nth-child(1) { background: #34c759; }
.level:nth-child(2) { background: #4da6ff; }
.level:nth-child(3) { background: #b06cff; }
.planets-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 36px; background: var(--card); padding: 6px 12px; border-radius: 24px; }
.pastille { width: 30px; height: 30px; border-radius: 50%; box-shadow: inset -4px -4px 0 rgba(0,0,0,.18); }
.pastille.ring { outline: 3px solid #fff; outline-offset: 2px; }
.pastille.off { background: #d0d3e0 !important; box-shadow: none; outline: none; opacity: .6; }
#btn-parents { position: absolute; right: 16px; bottom: 16px; }
.parents { position: absolute; inset: 0; margin: auto; width: min(460px, 92vw); height: fit-content; background: var(--card); padding: 18px; border-radius: 28px; display: flex; flex-direction: column; align-items: center; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3); pointer-events: auto; }
.parents p { margin: 0; font-size: 26px; font-weight: 800; }
.table-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.table-pick button { height: 72px; border-radius: 22px; background: #4da6ff; color: #fff; font-size: 34px; font-weight: 800; box-shadow: 0 5px 0 rgba(0,0,0,.2); }

/* Jeu : paysage = UI à droite */
#screen-game { top: 0; right: 0; bottom: 0; width: 56%; padding: 12px 16px; justify-content: flex-start; gap: 8px; }
.topbar { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 12px; }
.portholes { display: flex; gap: 10px; background: var(--card); padding: 8px 16px; border-radius: 40px; }
.porthole { width: 34px; height: 34px; border-radius: 50%; background: #c8cde0; border: 4px solid #8a90ad; transition: background .3s, transform .3s; }
.porthole.on { background: #ffd23f; border-color: #ff9f1c; transform: scale(1.15); }
.play { display: grid; grid-template-columns: auto auto; justify-content: center; align-content: start; align-items: start; gap: 8px 14px; width: 100%; min-height: 0; flex: 1; }
.question { grid-column: 1 / -1; }
.question { text-align: center; background: var(--card); border-radius: 28px; padding: 6px 24px; width: 100%; }
.operation { font-size: clamp(40px, 9vh, 84px); font-weight: 900; line-height: 1.1; }
.message { font-size: clamp(18px, 3vh, 26px); font-weight: 800; min-height: 1.3em; color: #d9590b; }
.message.good { color: #1f9d3f; }
.gridzone { background: var(--card); border-radius: 28px; padding: 8px 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dots { display: grid; gap: 4px; }
.dot { width: var(--dot, 24px); height: var(--dot, 24px); border-radius: 50%; background: #c8cde0; padding: 0; transition: background .2s, transform .2s; }
.dot.on { background: #ff7a1a; transform: scale(1.1); }
.dot.lit { background: #ffd23f; transform: scale(1.25); box-shadow: 0 0 10px #ffb02e; }
.gridinfo { display: flex; align-items: center; gap: 14px; }
.count { font-size: 34px; font-weight: 900; min-width: 2.5ch; text-align: center; }
.skip { font-size: 26px; font-weight: 800; color: #3b6fd8; min-height: 1.3em; }

.answers { display: flex; flex-direction: column; gap: 14px; justify-content: center; align-items: center; }
.choice { min-width: 110px; height: 88px; padding: 0 18px; border-radius: 28px; color: #fff; font-size: 48px; font-weight: 900; box-shadow: 0 6px 0 rgba(0,0,0,.22); }
.choice:nth-child(1) { background: #4da6ff; }
.choice:nth-child(2) { background: #34c759; }
.choice:nth-child(3) { background: #b06cff; }
.pad { display: grid; grid-template-columns: repeat(3, var(--btn)); gap: 8px; }
.pad .key { width: var(--btn); height: var(--btn); border-radius: 22px; background: #fff; font-size: 36px; font-weight: 900; box-shadow: 0 5px 0 rgba(0,0,0,.2); }
.pad .key.ok { background: var(--good); color: #fff; }
.pad .key.del { background: #ffd0d0; }
.padwrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.padshow { min-width: 160px; height: 56px; border-radius: 20px; background: #fff; font-size: 42px; font-weight: 900; text-align: center; line-height: 56px; box-shadow: inset 0 3px 0 rgba(0,0,0,.12); }

/* Compte à rebours */
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: min(40vw, 40vh); font-weight: 900; color: #fff; text-shadow: 0 8px 0 rgba(0,0,0,.25), 0 0 40px rgba(255,160,0,.8); animation: pop .8s ease-out; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 40% { transform: scale(1.2); opacity: 1; } 100% { transform: scale(1); } }

/* Planète */
#screen-planet { inset: 0; justify-content: flex-end; padding-bottom: 6vh; }
#screen-planet h2 { margin: 0; font-size: clamp(30px, 6vw, 56px); background: var(--card); padding: 6px 24px; border-radius: 28px; }
.planet-name { font-size: clamp(26px, 5vw, 44px); font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.4); }
.planet-stars { font-size: 40px; text-shadow: 0 3px 0 rgba(0,0,0,.3); min-height: 1.2em; }
.planet-actions { display: flex; gap: 16px; align-items: center; }

/* Portrait : UI en bas */
@media (orientation: portrait) {
  #screen-game { top: auto; left: 0; right: 0; width: 100%; height: 66%; background: linear-gradient(transparent, rgba(255,255,255,.0)); }
  #screen-planet { justify-content: flex-end; }
}
@media (max-height: 700px) { :root { --btn: 64px; } }

/* Téléphones : tailles des points calculées selon la grille (--r lignes, --c colonnes) */
@media (max-width: 480px) and (orientation: portrait) {
  :root { --btn: 56px; }
  .round, .round.small { width: 52px; height: 52px; font-size: 26px; }
  .topbar { gap: 6px; min-width: 0; }
  .portholes { gap: 6px; padding: 6px 12px; min-width: 0; }
  .porthole { width: 26px; height: 26px; border-width: 3px; }
  #screen-game { height: 68%; padding: 8px 10px max(8px, env(safe-area-inset-bottom)); gap: 6px; }
  .play { gap: 6px 8px; }
  .question { padding: 2px 12px; border-radius: 22px; }
  .operation { font-size: 40px; }
  .message { font-size: 18px; }
  .dots { --dot: clamp(8px, min(24px, calc((68dvh - 250px) / var(--r, 6) - 4px), calc((100vw - 170px) / var(--c, 6) - 4px)), 24px); }
  .gridzone { padding: 6px 8px; border-radius: 22px; }
  .gridinfo { gap: 8px; }
  .count { font-size: 28px; }
  .skip { font-size: 18px; }
  .answers { gap: 8px; }
  .choice { min-width: 96px; height: 60px; font-size: 36px; border-radius: 22px; }
  #screen-title { padding: 12px; gap: 10px; }
  #screen-title h1 { font-size: 30px; padding: 6px 14px; }
  .levels { gap: 10px; }
  .big { min-height: 64px; font-size: 24px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  :root { --btn: 52px; }
  .round, .round.small { width: 48px; height: 48px; font-size: 24px; }
  #screen-game { width: 62%; padding: 8px max(12px, env(safe-area-inset-right)) 8px 8px; gap: 6px; }
  .topbar { gap: 8px; min-width: 0; }
  .portholes { gap: 6px; padding: 6px 12px; min-width: 0; }
  .porthole { width: 26px; height: 26px; border-width: 3px; }
  .play { gap: 6px 8px; }
  .question { padding: 0 12px; border-radius: 20px; }
  .operation { font-size: 36px; }
  .message { font-size: 16px; min-height: 1.2em; }
  .gridzone { display: grid; grid-template-columns: auto auto; grid-template-areas: "dots info" "skip skip"; align-items: center; justify-items: center; gap: 2px 8px; padding: 6px 10px; border-radius: 20px; }
  .dots { grid-area: dots; --dot: clamp(8px, min(24px, calc((100dvh - 172px) / var(--r, 6) - 4px), calc((62vw - 228px) / var(--c, 6) - 4px)), 24px); }
  .gridinfo { grid-area: info; flex-direction: column; gap: 4px; }
  .skip { grid-area: skip; font-size: 16px; min-height: 1.2em; }
  .count { font-size: 26px; }
  .answers { gap: 8px; }
  .choice { min-width: 96px; height: 60px; font-size: 34px; border-radius: 20px; }
  #screen-title { padding: 8px; gap: 8px; }
  #screen-title h1 { font-size: 26px; padding: 4px 16px; }
  .levels { flex-direction: row; width: min(640px, 92vw); gap: 8px; }
  .levels .big { flex: 1; min-height: 64px; font-size: 20px; padding: 6px 8px; }
  .big small { font-size: 15px; }
  .planets-row { min-height: 28px; padding: 4px 10px; }
  .pastille { width: 22px; height: 22px; }
  #btn-parents { right: max(12px, env(safe-area-inset-right)); bottom: 8px; }
  .parents { max-height: 96dvh; overflow-y: auto; padding: 10px; gap: 8px; }
  .table-pick button { height: 56px; font-size: 28px; }
}
