@font-face {
  font-family: "p361";
  src: url("fonts/p361-colrv1.woff2") format("woff2") tech(color-COLRv1),
       url("fonts/p361-svg.woff2") format("woff2") tech(color-SVG),
       url("fonts/p361-v2.woff2") format("woff2");
  font-display: block;
}

:root {
  --cover: #123c36;      /* vert de la reliure */
  --cover-2: #0c2b27;
  --paper: #fbf7e9;      /* papier du mushaf */
  --ink: #17140f;
  --gold: #c39a3b;       /* dorure du cadre */
  --wrong: #b3402f;
  --right: #2f7d5b;
  --soft: #cfe0d8;
  --fs: 22px;            /* taille du texte de la page, calculee */
  --lh: 40px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--cover-2); overscroll-behavior: none; }
body { font-family: "Instrument Sans", system-ui, sans-serif; color: var(--soft); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

#app {
  height: 100dvh; max-width: 520px; margin: 0 auto;
  display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); overflow: hidden;
  background: var(--cover);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

#top { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 6px; font-size: 13px; }
#where { opacity: .8; }
#speed {
  min-width: 58px; height: 32px; border-radius: 16px; font-weight: 600; font-size: 14px;
  color: var(--paper); border: 1px solid rgba(251, 247, 233, .35);
}

/* ---------- la page ---------- */
#sheet { min-height: 0; min-width: 0; padding: 0 8px; display: flex; }
#page {
  flex: 1; min-height: 0; min-width: 0; overflow: hidden; background: var(--paper); color: var(--ink);
  border-radius: 4px; box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 0 4px var(--paper), inset 0 0 0 5px rgba(195, 154, 59, .5);
  padding: 10px 14px; display: grid; grid-template-rows: repeat(15, 1fr);
  font-family: "p361"; font-size: var(--fs); user-select: none; -webkit-user-select: none;
}
.line {
  display: flex; justify-content: space-between; align-items: center;
  position: relative; white-space: nowrap; line-height: 1;
  transition: opacity .25s;
}
.line.todo { opacity: .16; }
.line.known { opacity: .5; }
.line.lit, .line.known.lit { opacity: 1; }
/* repere de progression dans la marge : la page se remplit */
.line::after {
  content: ""; position: absolute; right: -10px; top: 22%; bottom: 22%; width: 3px; border-radius: 2px;
  background: transparent; transition: background .3s;
}
.line.known::after { background: var(--gold); }

.w { border-radius: 5px; padding: 0 1px; transition: background .12s; }
.w.on { background: rgba(195, 154, 59, .34); }
/* mot masque : le trou garde exactement la place du mot */
.w.gap { color: transparent; background: rgba(23, 20, 15, .07); box-shadow: inset 0 -2px 0 rgba(23, 20, 15, .35); }
.w.gap.next { background: rgba(195, 154, 59, .3); box-shadow: inset 0 -2px 0 var(--gold); }
.w.pop { animation: pop .35s; }
@keyframes pop { 0% { background: rgba(47, 125, 91, .45); transform: scale(1.12); } 100% { background: transparent; transform: none; } }

/* ligne entierement masquee (quiz de place, recitation finale) */
.line.veil .w { color: transparent; }
.line.veil::before {
  content: ""; position: absolute; inset: 18% 0; border-radius: 6px;
  background: rgba(23, 20, 15, .09);
}
.line.veil.pick::before { background: rgba(195, 154, 59, .28); }
.line.tap { cursor: pointer; }
.line.no { animation: shake .3s; }
.line.no::before { background: rgba(179, 64, 47, .3); }

/* ---------- le plateau du bas ---------- */
#tray {
  height: 232px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px;
}
#ask { margin: 0; font-size: 15px; line-height: 1.35; color: var(--paper); min-height: 20px; }
#ask small { display: block; font-size: 13px; color: var(--soft); opacity: .85; margin-top: 3px; }
#choices {
  flex: 1; min-height: 0; display: flex; flex-wrap: wrap; gap: 8px;
  align-content: center; justify-content: center; direction: rtl;
}
.tile {
  font-family: "p361"; font-size: calc(var(--fs) * 1.08); line-height: 1;
  background: var(--paper); color: var(--ink); border-radius: 10px;
  padding: 9px 12px 11px; min-width: 56px; min-height: 48px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.tile:active { transform: translateY(2px); box-shadow: none; }
.tile.used { visibility: hidden; }
.tile.no { animation: shake .3s; background: #f0cdc6; }
.tile.wide { font-size: calc(var(--fs) * .78); padding: 8px 10px; white-space: nowrap; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

#actions { display: flex; gap: 8px; }
.btn {
  flex: 1; height: 50px; border-radius: 12px; font-weight: 600; font-size: 16px;
  background: var(--gold); color: #1d1606;
}
.btn.ghost { background: none; color: var(--paper); border: 1px solid rgba(251, 247, 233, .35); flex: 0 0 auto; padding: 0 16px; }
.btn:active { filter: brightness(.92); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.reset { align-self: flex-end; font-size: 13px; color: var(--soft); text-decoration: underline; text-underline-offset: 3px; padding: 10px; direction: ltr; }
