/* ── Arrows — Puzzle Escape ──────────────────────────────────────
   Esthétique minimaliste façon "calm puzzle game" : crème, brun,
   accents corail. Tout est optimisé tactile (boutons ≥ 44px, pas de
   hover requis, pas de double-tap zoom).
*/

:root {
  --bg: #f3ecdf;
  --bg-soft: #ece2cf;
  --ink: #4a2e1a;
  --ink-2: #7a5a40;
  --ink-3: #b89d7c;
  --dot: #d9c9a8;
  --accent: #c75b3a;
  --accent-2: #e08365;
  --good: #4a8a45;
  --bad: #c54338;
  --card: #fbf6ec;
  --shadow: 0 6px 24px -10px rgba(74, 46, 26, 0.35);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

html, body, #app { height: 100%; }

#app {
  position: relative;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ── Écrans (single-page transitions) ─────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
  animation: fadeIn .22s ease-out;
}
.screen.is-active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── MENU ───────────────────────────────────────────────────── */
#screen-menu {
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 20% 0%, rgba(199, 91, 58, 0.08), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(74, 46, 26, 0.07), transparent 55%),
    var(--bg);
}
.menu-inner {
  width: min(420px, 88vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.menu-brand {
  color: var(--ink);
  margin-bottom: 4px;
}
.menu-title {
  font-size: clamp(2.4rem, 8vw, 3.2rem);
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.menu-title-em { color: var(--accent); }
.menu-tagline {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: .98rem;
  line-height: 1.5;
  max-width: 28em;
}
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.menu-stats {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
}
.menu-stats > div {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.menu-stats strong {
  font-size: 1.4rem;
  color: var(--ink);
  font-weight: 700;
}
.menu-stats span {
  font-size: .72rem;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .08em;
}
/* ── Compte joueur (menu) ─────────────────────────────────── */
.auth-box {
  margin-top: 16px;
  width: 100%;
  background: var(--card);
  border-radius: 16px;
  padding: 14px 14px 12px;
  text-align: left;
}
.auth-title {
  margin: 0 0 10px;
  font-size: .78rem;
  color: var(--ink-2);
  line-height: 1.45;
}
.auth-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.auth-fields input {
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--dot);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  width: 100%;
  transition: border-color .15s;
}
.auth-fields input:focus { border-color: var(--ink-2); }
.auth-error {
  margin: 8px 0 0;
  color: var(--bad);
  font-size: .78rem;
}
.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.auth-btn { min-height: 42px; padding: 10px 8px; font-size: .88rem; }
#authUser { text-align: center; }
.auth-logged {
  margin: 2px 0 4px;
  font-size: .92rem;
  color: var(--ink);
}

/* ── Classement ───────────────────────────────────────────── */
#screen-board { overflow-y: auto; }
.board-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 16px 16px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.board-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 11px 14px;
}
.board-row.is-me { outline: 2px solid var(--accent); outline-offset: -2px; }
.board-rank {
  font-weight: 700;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.board-row:nth-child(1) .board-rank,
.board-row:nth-child(2) .board-rank,
.board-row:nth-child(3) .board-rank { color: var(--accent); }
.board-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-done {
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}
.board-best {
  color: var(--ink-2);
  font-size: .76rem;
}
.board-empty {
  text-align: center;
  color: var(--ink-2);
  padding: 34px 12px;
  font-size: .9rem;
  line-height: 1.5;
}
.board-me {
  text-align: center;
  color: var(--ink-2);
  font-size: .84rem;
  margin: 0;
  padding: 0 16px calc(18px + var(--safe-bot));
}

.menu-reset {
  margin-top: 18px;
  background: none;
  border: none;
  color: var(--ink-3);
  font-size: .78rem;
  padding: 8px 12px;
}
.menu-reset:hover { color: var(--bad); }

.menu-back {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  left: 14px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: .82rem;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(251, 246, 236, 0.6);
  backdrop-filter: blur(6px);
}
.menu-back:hover { color: var(--ink); }

/* ── Boutons ───────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 22px;
  font-size: 1rem;
  font-weight: 600;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform .12s ease, background .15s ease, opacity .15s;
  min-height: 50px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 18px -10px rgba(199, 91, 58, 0.7);
}
.btn-primary:hover { background: var(--accent-2); }

.btn-ghost {
  background: var(--card);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--bg-soft); }

.btn-link {
  background: none;
  color: var(--ink-2);
  padding: 8px 12px;
  min-height: 0;
  font-size: .9rem;
}
.btn-link:hover { color: var(--ink); }

.btn-sub {
  font-size: .72rem;
  font-weight: 500;
  opacity: .8;
  letter-spacing: .03em;
}

/* ── Header de jeu (utilisé par game/levels/how) ──────────── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 6px;
  gap: 12px;
}
.header-title {
  text-align: center;
  flex: 1;
  min-width: 0;
}
.header-title h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}
.header-title p {
  margin: 0;
  font-size: .76rem;
  color: var(--ink-2);
}
.header-actions {
  display: flex;
  gap: 6px;
}
.hbtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--card);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .12s, opacity .15s;
}
.hbtn:hover { background: var(--bg-soft); }
.hbtn:active { transform: scale(0.94); }
.hbtn:disabled { opacity: .35; cursor: not-allowed; }
.hbtn-placeholder { background: transparent; pointer-events: none; }

/* ── Status (vies / compteur) ─────────────────────────────── */
.game-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px 6px;
  min-height: 28px;
}
.lives {
  display: flex;
  gap: 6px;
}
.life {
  width: 18px;
  height: 16px;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 21s-7-4.35-9.5-9A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.5 6c-2.5 4.65-9.5 9-9.5 9z'/></svg>") no-repeat center/contain;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 21s-7-4.35-9.5-9A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.5 6c-2.5 4.65-9.5 9-9.5 9z'/></svg>") no-repeat center/contain;
  transition: background .25s, transform .25s;
}
.life.is-lost {
  background: var(--ink-3);
  opacity: .35;
  transform: scale(0.85);
}
.counter {
  color: var(--ink-2);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

/* ── Plateau ──────────────────────────────────────────────── */
.board-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  min-height: 0;
}
.board-dots {
  position: absolute;
  inset: 14px;
  background-image: radial-gradient(circle, var(--dot) 1.2px, transparent 1.4px);
  background-size: 18px 18px;
  background-position: center;
  opacity: .55;
  pointer-events: none;
  border-radius: 12px;
}
.board {
  position: relative;
  width: min(96vw, 78vh, 560px);
  height: min(96vw, 78vh, 560px);
  touch-action: none;
}

/* Cell + arrow.
   IMPORTANT : le plateau a un viewBox en unités-cellule (1 cellule = 1 unité),
   donc toutes les épaisseurs de trait sont en fractions de cellule (≈ 0.1),
   pas en px — sinon une flèche ferait plusieurs cellules de large. */
.cell {
  cursor: pointer;
}
.cell-hit {
  fill: transparent;
}
.arrow-line, .arrow-head {
  stroke: var(--ink);
  stroke-width: 0.11;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  pointer-events: none;
  transition: stroke .18s;
}
.cell.is-collide .arrow-line,
.cell.is-collide .arrow-head { stroke: var(--bad); }

.path-line {
  stroke: var(--bad);
  stroke-width: 0.08;
  stroke-linecap: round;
  fill: none;
  opacity: .8;
  pointer-events: none;
}
.path-line.is-bad { stroke: var(--bad); }

.collision-mark {
  fill: var(--bad);
  pointer-events: none;
  animation: pop .35s ease-out;
}
@keyframes pop {
  from { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  to { transform: scale(1); opacity: 1; }
}

.board-toast {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: .85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  box-shadow: var(--shadow);
}
.board-toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Footer du jeu ────────────────────────────────────────── */
.game-footer {
  display: flex;
  gap: 10px;
  padding: 8px 14px 18px;
}
.game-footer .btn {
  flex: 1;
  min-height: 44px;
}

/* ── Sélecteur de niveaux ─────────────────────────────────── */
#screen-levels { overflow-y: auto; }
.levels-bands {
  display: flex;
  gap: 6px;
  padding: 4px 14px 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.band-btn {
  background: var(--card);
  border: none;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .78rem;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.band-btn.is-active {
  background: var(--ink);
  color: var(--bg);
}
.band-btn:hover:not(.is-active) { background: var(--bg-soft); }

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  padding: 6px 14px 28px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.lvl-tile {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: none;
  background: var(--card);
  color: var(--ink-2);
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform .12s ease, background .15s ease, color .15s;
}
.lvl-tile:active { transform: scale(0.94); }
.lvl-tile.is-done {
  background: var(--accent);
  color: white;
}
.lvl-tile.is-done::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: .6rem;
  opacity: .8;
}
.lvl-tile.is-locked {
  opacity: .35;
  pointer-events: none;
}
.lvl-tile.is-current {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ── Comment jouer ────────────────────────────────────────── */
#screen-how { overflow-y: auto; }
.how-inner {
  padding: 14px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.how-card {
  background: var(--card);
  padding: 16px 18px;
  border-radius: 16px;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
}
.how-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.how-card h3 {
  margin: 4px 0 4px;
  font-size: 1rem;
}
.how-card p {
  margin: 0;
  color: var(--ink-2);
  font-size: .88rem;
  line-height: 1.45;
  grid-column: 2;
}
.how-card > div:first-child + h3 { grid-column: 2; }
.how-card h3 { grid-column: 2; }
.how-demo {
  background: var(--card);
  border-radius: 16px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.how-go { margin-top: 8px; }

/* ── Modals ───────────────────────────────────────────────── */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(74, 46, 26, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 10;
  animation: fadeIn .2s ease;
  backdrop-filter: blur(3px);
}
.modal.is-on { display: flex; }
.modal-card {
  background: var(--bg);
  border-radius: 22px;
  padding: 26px 22px 22px;
  width: min(380px, 100%);
  text-align: center;
  position: relative;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.4);
  animation: popIn .28s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-card h3 {
  margin: 4px 0 8px;
  font-size: 1.4rem;
}
.modal-card p {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: .92rem;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-actions .btn { flex: 1; }

.win-burst {
  width: 60px;
  height: 60px;
  margin: 0 auto 6px;
  border-radius: 50%;
  background: var(--accent);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.win-burst::before {
  content: "✓";
  color: white;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}
.win-burst::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: .3;
  animation: ripple 1.2s ease-out infinite;
}
@keyframes ripple {
  from { transform: scale(0.8); opacity: .55; }
  to { transform: scale(1.5); opacity: 0; }
}

/* ── Responsive — desktop ─────────────────────────────────── */
@media (min-width: 720px) {
  .board { width: min(70vmin, 600px); height: min(70vmin, 600px); }
  .game-header { padding: 18px 24px 8px; }
  .game-status { padding: 0 24px 8px; }
  .game-footer { padding: 10px 24px 22px; }
  .menu-back { top: 22px; left: 22px; }
}
@media (min-width: 1024px) {
  #screen-menu { padding-top: 6vh; align-items: center; }
}

/* Évite que le bouton iOS "open in app" prenne le focus */
@supports (-webkit-touch-callout: none) {
  body { -webkit-user-select: none; user-select: none; }
}
