/* Équation colorée — cases, clavier, onglets, barre de joueurs, zone d'action.
   Les trois couleurs du jeu suivent un feu tricolore : vert, jaune, rouge. Le jaune porte en plus un liseré
   pointillé, et le rouge est le plus sombre des trois : les couleurs ne sont jamais la seule information. */
:root { --eq-g: #35c88a; --eq-y: #ffd23f; --eq-r: #dc4b5f; }

/* ================= cases ================= */
.eq-row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; width: 100%; }
.eq-tile {
  appearance: none; border: 0; margin: 0; padding: 0; min-width: 0; aspect-ratio: 1 / 1.14; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font: 700 clamp(16px, 5.2vw, 22px) / 1 var(--font); font-variant-numeric: tabular-nums; color: inherit;
  -webkit-user-select: none; user-select: none;
}
.eq-tile.plain { background: var(--sky); color: var(--navy); }
.eq-tile.g { background: var(--eq-g); color: #062a1c; }
.eq-tile.y { background: var(--eq-y); color: #3b2c00; outline: 2px dashed rgba(59, 44, 0, 0.5); outline-offset: -5px; }
.eq-tile.r { background: var(--eq-r); color: #fff; box-shadow: inset 0 0 0 2px rgba(7, 29, 54, 0.22); }
.eq-tile.hidden { background: rgba(224, 239, 255, 0.12); color: rgba(169, 196, 228, 0.7); }

/* case à remplir : un bouton, celle du curseur est entourée */
.eq-tile.cell { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1.5px rgba(224, 239, 255, 0.3); cursor: pointer; touch-action: manipulation; transition: box-shadow 0.15s, background 0.15s; }
.eq-tile.cell.filled { background: var(--sky); color: var(--navy); box-shadow: none; }
.eq-tile.cell.cur { box-shadow: 0 0 0 2.5px var(--sky); }
.eq-tile.cell.cur:not(.filled) { background: rgba(224, 239, 255, 0.16); }

/* proposition envoyée, en attente de l'autre */
.eq-row.sent .eq-tile { opacity: 0.85; animation: eq-wait 1.5s ease-in-out infinite; }
.eq-row.sent .eq-tile.hidden { background: rgba(224, 239, 255, 0.18); }
@keyframes eq-wait { 50% { opacity: 0.45; } }
.eq-row.locked .eq-tile { box-shadow: 0 8px 20px -12px var(--sky); }
.eq-row.past { max-width: 300px; align-self: center; }
.eq-row.past .eq-tile { opacity: 0.6; font-size: clamp(13px, 4vw, 17px); }

/* manche révélée : les cases se retournent l'une après l'autre */
.eq-row.fresh .eq-tile { animation: eq-flip 0.55s var(--spring) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes eq-flip { from { transform: rotateX(90deg) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }

/* ================= plateau ================= */
.eq-stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; padding: 3px 4px; scrollbar-width: thin; }
.eq-list, .eq-setup { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 408px; }
.eq-list { margin: 0 auto auto; }
.eq-setup { margin: auto; gap: 10px; }
.eq-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.eq-note { color: var(--muted); font-size: 14px; line-height: 1.5; text-align: center; padding: 6px 4px; }
.eq-note b { color: var(--text); letter-spacing: 0.04em; }
.eq-clear { align-self: center; min-height: 36px; font-size: 15px; }
.eq-legend { list-style: none; padding: 8px 0 0; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.eq-legend li { display: flex; align-items: center; gap: 10px; }
.eq-legend i { width: 20px; height: 20px; border-radius: 6px; flex: none; }
.eq-legend i.g { background: var(--eq-g); }
.eq-legend i.y { background: var(--eq-y); outline: 2px dashed rgba(59, 44, 0, 0.5); outline-offset: -4px; }
.eq-legend i.r { background: var(--eq-r); }

/* ================= onglets : mes essais / ses essais ================= */
.eq-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; border-radius: 999px; background: rgba(7, 29, 54, 0.55); box-shadow: inset 0 0 0 1.5px var(--line); }
.eq-tabs[hidden] { display: none; }
.eq-tab {
  appearance: none; border: 0; cursor: pointer; position: relative; min-height: 36px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; gap: 6px; background: transparent; color: var(--muted);
  font: 500 14px/1 var(--font); touch-action: manipulation; transition: background 0.2s, color 0.2s;
}
.eq-tab.on { background: var(--sky); color: var(--navy); font-weight: 700; }
.eq-tab b { font-size: 12px; min-width: 18px; padding: 2px 6px; border-radius: 9px; background: rgba(224, 239, 255, 0.14); color: inherit; }
.eq-tab.on b { background: rgba(13, 51, 93, 0.14); }
.eq-tab b:empty { display: none; }
.eq-tab.new::after { content: ''; position: absolute; top: 6px; right: 12px; width: 9px; height: 9px; border-radius: 50%; background: var(--p0); box-shadow: 0 0 0 2px var(--ink); }

/* ================= clavier ================= */
.eq-bottom { flex: none; }
.eq-keys { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; width: 100%; max-width: 408px; margin: 0 auto; transition: opacity 0.2s; }
.eq-keys[hidden], .eq-reveal[hidden] { display: none; }
.eq-keys.off { opacity: 0.45; }
.eq-key {
  appearance: none; border: 0; cursor: pointer; min-height: 44px; border-radius: 12px; background: var(--tile); color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--line); font: 700 20px/1 var(--font);
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation; -webkit-user-select: none; user-select: none; transition: transform 0.12s var(--spring), background 0.2s;
}
.eq-key:active { transform: scale(0.93); }
.eq-key.g { background: var(--eq-g); color: #062a1c; box-shadow: none; }
.eq-key.y { background: var(--eq-y); color: #3b2c00; box-shadow: none; }
.eq-key.r { background: rgba(7, 29, 54, 0.75); color: rgba(169, 196, 228, 0.5); box-shadow: inset 0 -3px 0 var(--eq-r); }
.eq-key-del { grid-column: span 2; }
.eq-key-del svg { width: 26px; height: 26px; }

/* fin de partie : les deux équations, dévoilées à la place du clavier */
.eq-reveal { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 408px; margin: 0 auto; }
.eq-reveal .eq-tile { font-size: clamp(15px, 4.6vw, 20px); }

/* ================= écran de partie ================= */
.eq-screen { height: 100vh; height: 100dvh; min-height: 0; gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); overflow: hidden; }
.eq-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.eq-round { color: var(--muted); font-weight: 700; font-size: 15px; }
.eq-rules {
  appearance: none; border: 0; cursor: pointer; min-height: 44px; padding: 0 16px 0 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 8px; background: transparent; color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--line); font: inherit; font-weight: 500; font-size: 15px; touch-action: manipulation;
}
.eq-rules span {
  width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--sky); color: var(--navy); font-weight: 700; font-size: 16px; line-height: 1;
}
.eq-rules:active { opacity: 0.75; }
.eq-players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.eq-player {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0;
  padding: 8px 12px 8px 14px; border-radius: 20px; background: var(--night); opacity: 0.62;
  box-shadow: inset 0 0 0 1.5px var(--line); transition: opacity 0.4s var(--ease), box-shadow 0.4s var(--ease), transform 0.4s var(--spring);
}
.eq-player.active { opacity: 1; transform: translateY(-2px); }
.eq-player.p0.active { box-shadow: inset 0 0 0 2px var(--p0), 0 10px 26px -12px var(--p0); }
.eq-player.p1.active { box-shadow: inset 0 0 0 2px var(--p1), 0 10px 26px -12px var(--p1); }
.eq-player.done { opacity: 0.9; }
.eq-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.eq-pname { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eq-pname small { font-size: 12px; font-weight: 700; color: var(--ink); background: var(--text); border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.eq-pmeta { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.eq-presence { width: 8px; height: 8px; border-radius: 50%; background: #7f9cc0; flex: none; }
.eq-presence.on { background: #4be3a3; box-shadow: 0 0 8px #4be3a3; }
/* pastille « a joué » : un rond vide, qui se remplit d'une coche */
.eq-pdone { position: relative; flex: none; width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--line); transition: background 0.3s var(--ease), transform 0.3s var(--spring); }
.eq-player.done .eq-pdone { background: var(--sky); box-shadow: none; transform: scale(1.08); }
.eq-player.done .eq-pdone::after { content: ''; position: absolute; left: 7.5px; top: 3.5px; width: 5px; height: 10px; border: solid var(--navy); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }

.eq-dock { display: flex; flex-direction: column; gap: 8px; padding-bottom: 2px; margin-top: 4px; }
.eq-title { font-size: 21px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.1; }
.eq-sub { color: var(--muted); font-size: 15px; line-height: 1.35; min-height: 2.7em; }
.eq-sub[data-tone="bad"] { color: var(--danger); }
.eq-sub[data-tone="good"] { color: #7be5b4; }
.eq-sub .c0 { color: var(--p0); font-weight: 700; }
.eq-sub .c1 { color: var(--p1); font-weight: 700; }
.eq-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }
.eq-actions .btn { padding: 0 10px; white-space: nowrap; }

.eq-confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }
.eq-stage.nudge { animation: eq-nudge 0.32s ease; }
@keyframes eq-nudge { 20% { transform: translateX(-7px); } 45% { transform: translateX(7px); } 70% { transform: translateX(-4px); } }

/* téléphones courts (≈ 640 px de haut) : on resserre pour que tout reste visible sans défiler la page */
@media (max-height: 700px) {
  .eq-key { min-height: 40px; font-size: 19px; }
  .eq-title { font-size: 19px; }
  .eq-sub { font-size: 14px; }
  .eq-tab { min-height: 32px; }
  .eq-player { padding-top: 6px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .eq-row.fresh .eq-tile, .eq-row.sent .eq-tile, .eq-stage.nudge { animation: none; }
}

/* ================= illustrations des règles ================= */
.eq-art { max-width: 310px; }
.eq-art-tile.plain { fill: var(--sky); }
.eq-art-tile.g { fill: var(--eq-g); }
.eq-art-tile.y { fill: var(--eq-y); }
.eq-art-tile.r { fill: var(--eq-r); }
.eq-art-tile.hidden { fill: rgba(224, 239, 255, 0.14); }
.eq-art-num { fill: var(--navy); font: 700 15px var(--font); }
.eq-art-num.g { fill: #062a1c; }
.eq-art-num.y { fill: #3b2c00; }
.eq-art-num.r { fill: #fff; }
.eq-art-num.hidden { fill: var(--muted); }
.eq-art-label { fill: var(--muted); font: 500 11.5px var(--font); }
.eq-art-label.ok { fill: #7be5b4; }
.eq-art-label.no { fill: var(--danger); }

/* ================= accueil : le visuel de la carte ================= */
/* Chaque rangée se colore à son tour (cycle de 10 s), case par case, en fondu ; tout s'efface avant de recommencer. */
.ea-art { display: block; width: 100%; height: auto; overflow: visible; }
.ea-hide { fill: rgba(224, 239, 255, 0.12); }
.ea-q { fill: rgba(169, 196, 228, 0.7); font: 700 16px var(--font); }
.ea-plain { fill: var(--sky); }
.ea-num { fill: var(--navy); font: 700 17px var(--font); }
.ea-c { opacity: 0; animation: ea-r0 10s ease-out infinite both; animation-delay: calc(var(--c) * 0.09s); }
.ea-row1 .ea-c { animation-name: ea-r1; }
.ea-row2 .ea-c { animation-name: ea-r2; }
.ea-c text { font: 700 17px var(--font); }
.ea-c.g rect { fill: var(--eq-g); }
.ea-c.g text { fill: #062a1c; }
.ea-c.y rect { fill: var(--eq-y); }
.ea-c.y text { fill: #3b2c00; }
.ea-c.r rect { fill: var(--eq-r); }
.ea-c.r text { fill: #fff; }
@keyframes ea-r0 { 0%, 6% { opacity: 0; } 9%, 88% { opacity: 1; } 95%, 100% { opacity: 0; } }
@keyframes ea-r1 { 0%, 30% { opacity: 0; } 33%, 88% { opacity: 1; } 95%, 100% { opacity: 0; } }
@keyframes ea-r2 { 0%, 54% { opacity: 0; } 57%, 88% { opacity: 1; } 95%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .ea-c { animation: none; opacity: 1; }
}
