@font-face { font-family: 'Amiri Quran'; src: url('../assets/fonts/AmiriQuran-Regular.ttf') format('truetype'); font-display: swap; }
:root {
  --ink: #1b1711; --night: #0d111c; --gold: #d9b56a; --gold2: #f0d79a; --parch: #f4ecd8; --parch2: #e9dfc6; --line: #cdbf9c; --mute: #7a705c; --red: #a8402e; --green: #2f7a55;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--parch); font-family: var(--serif); -webkit-font-smoothing: antialiased; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; user-select: none; -webkit-user-select: none; }
#ui button, #ui label, #ui .panel, #dialog, #title { pointer-events: auto; }
.hide { display: none !important; }
.ar { font-family: 'Amiri Quran', 'Geeza Pro', 'Traditional Arabic', serif; font-weight: 400; }
kbd { display: inline-block; min-width: 1.5em; padding: .08em .4em; border: 1px solid currentColor; border-radius: 5px; font: 600 .82em/1.4 ui-sans-serif, system-ui, sans-serif; text-align: center; opacity: .9; }
button { font-family: inherit; color: inherit; cursor: pointer; }
.btn { background: var(--gold); color: #2a2010; border: 0; border-radius: 999px; padding: .62em 1.5em; font-size: 1rem; font-weight: 600; letter-spacing: .01em; transition: transform .12s, filter .12s, opacity .2s; }
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:disabled { opacity: .35; cursor: default; transform: none; filter: none; }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px currentColor; opacity: .85; }
.btn.sm { padding: .3em .9em; font-size: .85rem; margin-left: .6em; }
.row { display: flex; gap: .7em; align-items: center; flex-wrap: wrap; margin-top: 1.1em; }
.row.end { justify-content: flex-end; }
.small { font-size: .85rem; opacity: .7; }

/* HUD */
.hud-tl { position: absolute; top: 18px; left: 22px; max-width: min(520px, 70vw); text-shadow: 0 1px 8px rgba(0,0,0,.8); }
#chap { font-size: .78rem; letter-spacing: .22em; text-transform: uppercase; color: var(--gold2); opacity: .85; }
#obj { margin-top: 4px; font-size: 1.12rem; line-height: 1.35; }
#obj.pop { animation: pop .9s ease; }
@keyframes pop { 0% { opacity: 0; transform: translateY(6px); } 100% { opacity: 1; transform: none; } }
.hud-tr { position: absolute; top: 16px; right: 18px; display: flex; gap: 8px; }
.hud-tr button { background: rgba(13,17,28,.55); border: 1px solid rgba(217,181,106,.45); color: var(--gold2); border-radius: 999px; padding: .4em 1em; font-size: .9rem; backdrop-filter: blur(6px); }
.hud-tr button:hover { background: rgba(217,181,106,.2); }
.hud-tr button.off { text-decoration: line-through; opacity: .6; }
#prompt { position: absolute; left: 50%; bottom: 17vh; transform: translateX(-50%); background: rgba(13,17,28,.72); border: 1px solid rgba(217,181,106,.6); color: var(--parch); border-radius: 999px; padding: .55em 1.3em; font-size: 1.05rem; backdrop-filter: blur(6px); animation: pop .25s ease; }
#prompt kbd { color: var(--gold2); margin-right: .35em; }
#hint { position: absolute; left: 50%; bottom: 7vh; transform: translateX(-50%); background: rgba(13,17,28,.72); border-radius: 14px; padding: .7em 1.3em; font-size: 1rem; text-align: center; max-width: 86vw; }
#gauge { position: absolute; left: 50%; top: 20px; transform: translateX(-50%); display: flex; gap: 10px; align-items: center; font-size: .85rem; letter-spacing: .1em; text-transform: uppercase; color: var(--gold2); text-shadow: 0 1px 6px #000; }
#gauge div { width: 180px; height: 8px; border-radius: 8px; background: rgba(0,0,0,.5); overflow: hidden; border: 1px solid rgba(217,181,106,.5); }
#gauge i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #d0532f); transition: width .15s; }
#vignette { position: absolute; inset: 0; opacity: 0; --vc: 0,0,0; background: radial-gradient(ellipse at center, rgba(var(--vc),0) 35%, rgba(var(--vc),.92) 100%); transition: opacity .25s; }
#counter { position: absolute; inset: auto 0 16vh 0; text-align: center; text-shadow: 0 2px 18px rgba(0,0,0,.9); }
#counter .big { font-size: clamp(2.6rem, 8vw, 5.5rem); font-variant-numeric: tabular-nums; color: var(--gold2); line-height: 1; }
#counter .lbl { font-size: 1rem; letter-spacing: .25em; text-transform: uppercase; opacity: .8; }
#counter .ar { font-size: clamp(1.6rem, 4.5vw, 2.8rem); margin-top: .1em; line-height: 2; }
#toasts { position: absolute; right: 18px; top: 70px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: rgba(13,17,28,.85); border-left: 3px solid var(--gold); border-radius: 8px; padding: .6em 1em; font-size: .95rem; max-width: 340px; animation: tin .4s ease; transition: opacity .5s, transform .5s; }
.toast b { display: block; color: var(--gold2); font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.toast .ar { display: block; font-size: 1.35rem; line-height: 2; direction: rtl; text-align: left; }
.toast.out { opacity: 0; transform: translateX(20px); }
@keyframes tin { from { opacity: 0; transform: translateX(20px); } }
#fade { position: absolute; inset: 0; background: #06080e; opacity: 0; transition: opacity .7s ease; pointer-events: none; }
#fade.on { opacity: 1; }

/* Carton de chapitre */
#card { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: radial-gradient(ellipse at center, rgba(6,8,14,.55), rgba(6,8,14,.9)); animation: cin 3s ease both; }
#card .c-n { letter-spacing: .4em; text-transform: uppercase; font-size: .9rem; color: var(--gold2); }
#card .c-ar { font-size: clamp(2.6rem, 7vw, 4.6rem); line-height: 2.1; color: var(--parch); }
#card .c-t { font-size: clamp(1.5rem, 3.5vw, 2.3rem); font-style: italic; }
@keyframes cin { 0% { opacity: 0; } 18% { opacity: 1; } 82% { opacity: 1; } 100% { opacity: 0; } }

/* Dialogue */
#dialog { position: absolute; left: 50%; bottom: 4vh; transform: translateX(-50%); width: min(780px, 92vw); background: rgba(13,17,28,.86); border: 1px solid rgba(217,181,106,.35); border-radius: 14px; padding: 1.05em 1.4em 1.3em; backdrop-filter: blur(8px); cursor: pointer; }
#dialog .who { color: var(--gold2); font-size: .8rem; letter-spacing: .2em; text-transform: uppercase; margin-bottom: .3em; min-height: 0; }
#dialog .txt { font-size: 1.17rem; line-height: 1.55; transition: opacity .25s; }
#dialog.narr .txt { font-style: italic; }
#dialog .txt .ar { font-style: normal; font-size: 1.35em; line-height: 1.6; color: var(--gold2); }
#dialog .next { position: absolute; right: 14px; bottom: 6px; font-size: .75rem; opacity: .55; letter-spacing: .08em; }

/* Modales */
#modal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6,8,14,.62); backdrop-filter: blur(3px); padding: 16px; pointer-events: auto; animation: fin .3s ease; }
@keyframes fin { from { opacity: 0; } }
.panel { width: min(860px, 100%); max-height: 94vh; overflow: auto; background: var(--parch); color: var(--ink); border-radius: 16px; padding: 26px 30px; box-shadow: 0 30px 80px rgba(0,0,0,.6), inset 0 0 0 1px rgba(255,255,255,.4); animation: pin .35s cubic-bezier(.2,.9,.3,1.1); }
@keyframes pin { from { transform: translateY(14px) scale(.985); opacity: 0; } }
.panel h2 { margin: 0 0 .3em; font-size: 1.5rem; }
.panel p { line-height: 1.6; margin: .5em 0; }
.panel .btn.ghost { color: #4a4030; }

/* Verset */
.v-head { display: flex; justify-content: space-between; align-items: center; font-size: .82rem; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); }
.tjt { text-transform: none; letter-spacing: 0; font-size: .9rem; cursor: pointer; display: flex; gap: .4em; align-items: center; }
.v-ar { font-size: clamp(1.7rem, 3.6vw, 2.5rem); line-height: 2.35; text-align: center; margin: .15em 0 0; padding: .1em 0; word-spacing: .12em; }
.v-ar.long { font-size: clamp(1.35rem, 2.6vw, 1.9rem); line-height: 2.15; }
.v-ar .w { cursor: pointer; border-radius: 8px; padding: 0 .08em; transition: background .15s, color .15s; }
.v-ar .w:hover { background: rgba(217,181,106,.28); }
.v-ar .w.on { background: rgba(217,181,106,.5); }
.mk { font-style: normal; color: #9b7a35; }
.ayah { color: #9b7a35; }
b.tj { font-weight: inherit; }
.tjon b.tj { color: var(--c, inherit); }
.tjon .qalaqah { --c: #dd0008; } .tjon .ghunnah { --c: #f06a00; } .tjon .madda_normal { --c: #3f6ff0; } .tjon .madda_permissible { --c: #4050ff; } .tjon .madda_necessary { --c: #000ebc; } .tjon .madda_obligatory { --c: #1a3db5; }
.tjon .ikhafa { --c: #9400a8; } .tjon .ikhafa_shafawi { --c: #d500b7; } .tjon .idgham_ghunnah { --c: #12876a; } .tjon .idgham_wo_ghunnah { --c: #169200; } .tjon .idgham_shafawi { --c: #4a9c00; } .tjon .iqlab { --c: #0f9fdc; }
.tjon .ham_wasl, .tjon .laam_shamsiyah, .tjon .slnt, .tjon .idgham_mutaqaribayn, .tjon .idgham_mutajanisayn { --c: #a39a88; }
.v-wd { min-height: 3.1em; display: flex; flex-wrap: wrap; gap: .5em 1em; align-items: center; justify-content: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: .35em 0; margin: .3em 0 .7em; color: var(--mute); }
.v-wd b.ar { font-size: 1.7rem; line-height: 1.9; color: var(--ink); }
.v-wd .tr { font-style: italic; } .v-wd .gl { color: var(--ink); font-weight: 600; }
.v-wd .rt b { font-size: 1.2rem; color: var(--ink); }
.rl { font-size: .78rem; border: 1px solid var(--c); color: var(--c); border-radius: 999px; padding: .1em .7em; }
.v-fr { font-size: 1.16rem; line-height: 1.6; text-align: center; max-width: 46em; margin: 0 auto; }
.v-kw { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-top: 1em; }
.v-kw > span { font-size: .75rem; letter-spacing: .16em; text-transform: uppercase; color: var(--mute); margin-right: .3em; }
.chip { background: var(--parch2); border: 1px solid var(--line); border-radius: 12px; padding: .1em .8em .25em; font-size: .88rem; display: flex; flex-direction: column; align-items: center; line-height: 1.3; }
.chip b { font-size: 1.35rem; line-height: 1.9; }
.chip:hover { border-color: var(--gold); background: #f3e6c2; }
.v-foot { display: flex; align-items: center; gap: .7em; margin-top: 1.2em; flex-wrap: wrap; }
.v-foot .src { font-size: .74rem; color: var(--mute); max-width: 22em; line-height: 1.35; } .v-foot .sp { flex: 1; }

/* Sceaux et portes */
.seal .panel { background: linear-gradient(180deg, #171c2c, #10141f); color: var(--parch); width: min(760px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.7), inset 0 0 0 1px rgba(217,181,106,.35); }
.seal .panel .btn.ghost { color: var(--gold2); }
.s-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.s-head h2 { color: var(--gold2); margin: 0; } .s-head p { margin: .15em 0 0; opacity: .82; font-style: italic; }
.s-ico { flex: none; width: 54px; height: 54px; border-radius: 50%; border: 2px solid var(--gold); position: relative; box-shadow: 0 0 22px rgba(217,181,106,.4); }
.s-ico::before { content: ''; position: absolute; inset: 9px; border: 2px solid var(--gold); transform: rotate(45deg); }
.s-ico::after { content: ''; position: absolute; inset: 9px; border: 2px solid var(--gold); }
.s-ico.door { border-radius: 27px 27px 4px 4px; } .s-ico.door::before { inset: 10px 25px 0; border-width: 0 0 0 2px; transform: none; } .s-ico.door::after { display: none; }
.dots { display: flex; gap: 7px; justify-content: center; margin: 4px 0 10px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--gold); opacity: .5; } .dots i.d { background: var(--gold); opacity: 1; } .dots i.c { opacity: 1; box-shadow: 0 0 8px var(--gold); }
.lesson .l-name { display: flex; gap: .8em; align-items: baseline; flex-wrap: wrap; border-left: 4px solid var(--c); padding-left: .8em; }
.lesson .l-name b { font-size: 1.4rem; } .lesson .l-name .ar { font-size: 1.5rem; line-height: 1.8; color: var(--gold2); } .lesson .l-name i { opacity: .75; }
.l-ex, .ch-ar { font-size: clamp(2.2rem, 6vw, 3.4rem); line-height: 2.3; text-align: center; margin: .1em 0; }
.l-ex, .ch-ar { color: rgba(244,236,216,.6); }
.l-ex .w, .ch-ar .w { margin: 0 .12em; }
b.tj.focus { color: #ffd27a; text-shadow: 0 0 18px rgba(255,210,122,.7); }
.lesson p .ar, .k-r p .ar { font-size: 1.3em; line-height: 1.4; }
.ch-q { text-align: center; font-size: 1.08rem; margin-bottom: .8em; } .ch-q.big { font-size: 1.3rem; line-height: 1.5; margin: .4em 0 1em; } .ch-q .ar { font-size: 1.4em; color: var(--gold2); line-height: 1.5; }
.opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; } .opts.col { grid-template-columns: 1fr; }
.opt { background: rgba(255,255,255,.05); border: 1.5px solid rgba(217,181,106,.4); border-radius: 12px; padding: .75em .8em; font-size: 1.02rem; line-height: 1.35; transition: background .15s, border-color .15s; }
.opt small { display: block; font-size: .78rem; opacity: .65; margin-top: .15em; } .opt .ar { font-size: 1.25em; line-height: 1.4; }
.opt:hover:not(:disabled) { background: rgba(217,181,106,.16); border-color: var(--gold); }
.opt.good { background: rgba(47,122,85,.45); border-color: #58c794; } .opt.bad { background: rgba(168,64,46,.3); border-color: #c9634f; opacity: .6; animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.fb { min-height: 3.6em; margin-top: .8em; } .fb p { margin: 0 0 .7em; opacity: .92; } .fb .warn { color: #f0a48f; } .fb .ar { font-size: 1.3em; line-height: 1.5; color: var(--gold2); } .fb .btn { float: right; }

/* Notes, aide, fin */
.note .panel { width: min(600px, 100%); background: linear-gradient(180deg, #fbf5e4, #efe4c8); }
.note.wide .panel { width: min(720px, 100%); }
.n-tag { font-size: .76rem; letter-spacing: .2em; text-transform: uppercase; color: #9b7a35; margin-bottom: .4em; }
.n-src { font-size: .88rem; color: var(--mute); font-style: italic; border-top: 1px solid var(--line); padding-top: .6em; margin-top: .9em; }
.help { display: grid; grid-template-columns: auto 1fr; gap: .55em 1.4em; align-items: center; margin: 1em 0; } .help kbd { margin-right: 3px; }
.end .t-ar { font-size: 2.4rem; line-height: 2.2; text-align: center; color: #7a5a1c; }

/* Carnet */
.carnet .panel { width: min(960px, 100%); height: min(88vh, 780px); display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.k-head { display: flex; align-items: center; gap: 18px; padding: 16px 24px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.k-head h2 { margin: 0 0 12px; font-size: 1.3rem; } .tabs { display: flex; gap: 2px; flex: 1; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: .5em 1em .7em; font-size: 1rem; color: var(--mute); } .tabs button.on { color: var(--ink); border-color: var(--gold); font-weight: 600; }
.k-head .x { background: none; border: 0; font-size: 1.2rem; margin-bottom: 12px; color: var(--mute); }
.k-body { overflow: auto; padding: 14px 24px 24px; flex: 1; } .k-info { color: var(--mute); font-size: .92rem; margin: .2em 0 1em; }
.k-v { display: grid; grid-template-columns: 2.2em 1fr; gap: 0 12px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: .5em .3em; }
button.k-v:hover { background: var(--parch2); } .k-v .num { grid-row: span 2; color: #9b7a35; font-size: 1.1rem; padding-top: .7em; } .k-v .ar { font-size: 1.5rem; line-height: 2.2; text-align: right; } .k-v .fr { font-size: .95rem; color: #4a4030; line-height: 1.45; } .k-v.lock { opacity: .45; padding: .9em .3em; } .k-v.lock .num { padding: 0; }
.k-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.k-w { background: var(--parch2); border: 1px solid var(--line); border-radius: 12px; padding: .3em .5em .6em; display: flex; flex-direction: column; align-items: center; gap: 1px; position: relative; }
.k-w:hover { border-color: var(--gold); } .k-w b { font-size: 1.7rem; line-height: 2; } .k-w .tr { font-style: italic; color: var(--mute); font-size: .88rem; } .k-w .gl { font-weight: 600; font-size: .95rem; text-align: center; } .k-w .rt { font-size: 1rem; color: #9b7a35; line-height: 1.6; } .k-w i { position: absolute; top: 6px; left: 8px; font-size: .68rem; color: var(--mute); font-style: normal; }
.k-r { border-left: 4px solid var(--c); padding: .2em 0 .2em 1em; margin-bottom: 1em; } .k-r div { display: flex; gap: .8em; align-items: baseline; flex-wrap: wrap; } .k-r b { font-size: 1.12rem; } .k-r .ar { font-size: 1.3rem; line-height: 1.7; } .k-r i { color: var(--mute); } .k-r p { margin: .2em 0 0; font-size: .96rem; } .k-r.lock { opacity: .45; --c: #b8ad94 !important; }
.k-leg { display: flex; flex-direction: column; gap: .35em; font-size: .92rem; } .k-leg b { display: inline-block; width: .8em; height: .8em; border-radius: 50%; background: var(--c); margin-right: .6em; }
.k-n { border-bottom: 1px solid var(--line); padding: .7em 0; } .k-n b { font-size: 1.1rem; } .k-n i { color: #9b7a35; margin-left: .8em; font-size: .85rem; } .k-n p { margin: .3em 0; } .k-n small { color: var(--mute); font-style: italic; } .k-n.lock { opacity: .4; }

/* Titre */
#title { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; background: radial-gradient(ellipse at 50% 40%, rgba(13,17,28,.25), rgba(6,8,14,.86)); transition: opacity .8s; padding: 20px; }
#title.out { opacity: 0; pointer-events: none; }
.t-in { max-width: 760px; animation: pop 1.6s ease both; }
#title .t-ar { font-size: clamp(3rem, 10vw, 6rem); line-height: 2; color: var(--gold2); text-shadow: 0 0 40px rgba(217,181,106,.35); }
#title h1 { font-size: clamp(1.9rem, 5vw, 3.2rem); margin: 0; font-weight: 500; letter-spacing: .02em; }
.t-sub { opacity: .8; font-style: italic; font-size: 1.1rem; margin: .5em 0 1.8em; }
.t-btn { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; } .t-btn .btn { font-size: 1.1rem; padding: .75em 1.8em; }
.t-note { margin-top: 2em; font-size: .9rem; opacity: .6; }

@media (max-width: 640px) { .panel { padding: 18px 16px; } .opts { grid-template-columns: 1fr; } .v-foot .src { display: none; } #obj { font-size: 1rem; } .hud-tr button { padding: .35em .7em; font-size: .8rem; } }

/* Combat : cœurs, barre de boss, boutons tactiles, objets */
#hearts { position: absolute; left: 22px; bottom: 22px; display: flex; gap: 5px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.8)); }
#hearts i { width: 26px; height: 24px; display: block; background: currentColor; color: #d8344a; -webkit-mask: var(--hm) center/contain no-repeat; mask: var(--hm) center/contain no-repeat;
  --hm: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26 24'%3E%3Cpath d='M13 23C3 15 0 10 2 5.5 4 1 10 .5 13 5c3-4.5 9-4 11 .5 2 4.5-1 9.5-11 17.5z'/%3E%3C/svg%3E"); }
#hearts i.h { background: linear-gradient(90deg, #d8344a 50%, rgba(40,20,24,.85) 50%); }
#hearts i.e { color: rgba(40,20,24,.85); }
#hearts.low i.f, #hearts.low i.h { animation: beat .7s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.15); } }
#bossbar { position: absolute; left: 50%; top: 86px; transform: translateX(-50%); width: min(520px, 70vw); text-align: center; text-shadow: 0 1px 8px #000; }
#bossbar span { display: block; font-size: .95rem; letter-spacing: .2em; text-transform: uppercase; color: var(--gold2); margin-bottom: 6px; }
#bossbar div { height: 12px; border-radius: 10px; background: rgba(0,0,0,.6); border: 1px solid rgba(217,181,106,.6); overflow: hidden; }
#bossbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #8f1f1f, #d0532f); transition: width .25s; }
#pad { position: absolute; right: 18px; bottom: 18px; display: flex; gap: 10px; align-items: flex-end; }
#pad button { pointer-events: auto; width: 64px; height: 64px; border-radius: 50%; background: rgba(13,17,28,.6); border: 1.5px solid rgba(217,181,106,.7); color: var(--gold2); font-size: .72rem; touch-action: none; }
#pad button.big { width: 86px; height: 86px; font-size: .9rem; }
#card .c-t.boss { font-style: normal; font-size: clamp(2rem, 5vw, 3.4rem); color: var(--parch); letter-spacing: .04em; }
#modal.item .panel { text-align: center; }
.it-ico { color: var(--gold); display: flex; justify-content: center; margin-bottom: .4em; }
.it-how { font-size: .95rem; background: rgba(217,181,106,.12); border-radius: 10px; padding: .7em 1em; }
.h2b { margin-top: 1.2em; }
