/* Avaloon II — L'Art des Glyphes · feuille de style
 * Une alchimie artisanale, mystérieuse et lumineuse : nuit violette, encre dorée, parchemin. */
:root {
  --night: #120d1c;
  --night-2: #1d1530;
  --ink-gold: #f0c96a;
  --ink-gold-2: #ffe27a;
  --parchment: #efe3c6;
  --parchment-2: #e2d2ac;
  --sepia: #4a3420;
  --text: #f6efe2;
  --muted: #bfb3cc;
  --flamme: #ff8a3d;
  --cercle: #8fd8ff;
  --danger: #e0645a;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Nunito', system-ui, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--text); font-family: var(--sans); overflow: hidden; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

#game { position: fixed; inset: 0; display: grid; place-items: center; background: #07060c; }
#world { image-rendering: pixelated; image-rendering: crisp-edges; display: block; background: #000; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud-top { position: absolute; top: 10px; left: calc(12px + var(--safe-l)); display: flex; flex-direction: column; gap: 4px; }
#level-name { font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--ink-gold); text-shadow: 0 1px 3px #000; }
#hearts, .dh-hearts { display: flex; gap: 4px; }
#hearts i, .dh-hearts i { width: 14px; height: 14px; border-radius: 50%; background: rgba(255,255,255,0.15); box-shadow: inset 0 0 0 2px rgba(0,0,0,0.4); }
#hearts i.on, .dh-hearts i.on { background: radial-gradient(circle at 35% 35%, #ffd3a0, #e86a4a 60%, #a33a2a); }
#objective { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: 46%; padding: 6px 14px; border-radius: 999px; background: rgba(18,13,28,0.78); border: 1px solid rgba(240,201,106,0.35); font-size: 13px; font-weight: 700; text-align: center; line-height: 1.25; }
#objective::before { content: '◆ '; color: var(--ink-gold); }
#objective.pulse { animation: pulse 0.9s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(240,201,106,0.7); } 100% { box-shadow: 0 0 0 14px rgba(240,201,106,0); } }
.hud-btn { pointer-events: auto; position: absolute; width: 52px; height: 52px; border-radius: 50%; border: 2px solid rgba(240,201,106,0.55); background: rgba(18,13,28,0.82); display: grid; place-items: center; padding: 0; box-shadow: 0 4px 14px rgba(0,0,0,0.5); }
.hud-btn svg { width: 26px; height: 26px; fill: none; stroke: var(--ink-gold); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hud-btn:active { transform: scale(0.94); }
#btn-grimoire { top: 10px; right: calc(12px + var(--safe-r)); }
#btn-palm { bottom: 18px; right: calc(18px + var(--safe-r)); width: 76px; height: 76px; border-width: 3px; background: radial-gradient(circle, rgba(70,48,110,0.95), rgba(18,13,28,0.92)); animation: palmglow 3s ease-in-out infinite; }
#btn-palm svg { width: 38px; height: 38px; }
@keyframes palmglow { 50% { box-shadow: 0 0 22px rgba(240,201,106,0.45), 0 4px 14px rgba(0,0,0,0.5); } }

#banner { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; opacity: 0; }
#banner small { display: block; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
#banner strong { display: block; font-family: var(--serif); font-size: clamp(28px, 6vw, 46px); color: var(--ink-gold-2); text-shadow: 0 0 18px rgba(240,201,106,0.5), 0 2px 4px #000; white-space: nowrap; }
#banner.show { animation: banner 2.4s ease both; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 10px); } 15%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -6px); } }

#toast-area { position: absolute; top: 70px; right: calc(12px + var(--safe-r)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; z-index: 21; }
.toast { max-width: 300px; padding: 7px 12px; border-radius: 10px; background: rgba(18,13,28,0.9); border-left: 3px solid var(--ink-gold); font-size: 13px; font-weight: 700; animation: tin 0.3s ease; transition: opacity 0.5s, transform 0.5s; }
.toast.journal { border-color: var(--cercle); }
.toast.rank { border-color: var(--flamme); color: var(--ink-gold-2); }
.toast.out { opacity: 0; transform: translateX(20px); }
@keyframes tin { from { opacity: 0; transform: translateX(20px); } }

/* ---------- dialogue ---------- */
#dialog { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; padding: 0 calc(12px + var(--safe-r)) 12px calc(12px + var(--safe-l)); }
.dlg-box { position: relative; width: min(860px, 100%); min-height: 92px; display: flex; gap: 12px; align-items: flex-start; padding: 12px 18px 14px 14px; border-radius: 14px; background: linear-gradient(180deg, rgba(36,26,58,0.97), rgba(20,14,34,0.97)); border: 2px solid rgba(240,201,106,0.5); box-shadow: 0 8px 30px rgba(0,0,0,0.6); }
#dlg-portrait { width: 64px; height: 40px; margin-top: 4px; image-rendering: pixelated; border-radius: 8px; background: rgba(255,255,255,0.06); flex: none; }
.dlg-body { flex: 1; min-width: 0; }
#dlg-name { font-family: var(--serif); font-weight: 700; font-size: 18px; color: var(--ink-gold); margin-bottom: 2px; }
#dlg-text { font-size: clamp(15px, 2.3vw, 18px); line-height: 1.42; font-weight: 600; }
#dialog.narr #dlg-text { font-style: italic; color: #e6dcf2; }
.dlg-next { position: absolute; right: 14px; bottom: 6px; color: var(--ink-gold); opacity: 0; font-size: 18px; }
#dialog.done .dlg-next { opacity: 1; animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
#dlg-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
#dlg-choices button { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--ink-gold); background: rgba(240,201,106,0.12); color: var(--text); font-weight: 700; }

/* ---------- surface de tracé ---------- */
#trace { position: absolute; inset: 0; z-index: 15; background: rgba(10,6,20,0.55); backdrop-filter: blur(1.5px); }
#trace-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#trace-prompt { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); max-width: 70%; text-align: center; font-family: var(--serif); font-weight: 700; font-size: clamp(18px, 3vw, 24px); color: var(--ink-gold-2); text-shadow: 0 2px 6px #000; pointer-events: none; }
#trace-feedback { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); max-width: 60%; text-align: center; font-weight: 700; font-size: 15px; pointer-events: none; text-shadow: 0 1px 4px #000; }
#trace-feedback.ok { color: var(--cercle); font-size: 18px; }
#trace-feedback.combo { color: var(--ink-gold-2); }
#trace-feedback.fail { color: #d9c6ee; }
#trace-actions { position: absolute; right: calc(14px + var(--safe-r)); bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
#trace-actions button, #trace-chips button { padding: 10px 16px; border-radius: 12px; border: 1px solid rgba(240,201,106,0.5); background: rgba(18,13,28,0.85); color: var(--text); font-weight: 800; }
#trace-chips { position: absolute; left: calc(14px + var(--safe-l)); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; }
#trace-chips button { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; font-size: 13px; }
#trace-chips canvas { width: 34px; height: 34px; }

/* ---------- duel ---------- */
#duel-hud { position: absolute; inset: 0; pointer-events: none; }
.dh-side { position: absolute; top: 10px; padding: 8px 12px; border-radius: 12px; background: rgba(18,13,28,0.8); border: 1px solid rgba(240,201,106,0.3); min-width: 150px; }
.dh-side.left { left: calc(10px + var(--safe-l)); }
.dh-side.right { right: calc(10px + var(--safe-r)); text-align: right; }
.dh-name { font-family: var(--serif); font-weight: 700; font-size: 17px; color: var(--ink-gold); }
.bar { position: relative; height: 11px; margin-top: 6px; border-radius: 6px; background: rgba(255,255,255,0.1); overflow: hidden; }
.bar span { position: absolute; inset: 0 auto 0 0; border-radius: 6px; transition: width 0.4s; }
.bar em { position: absolute; left: 6px; top: -1px; font-size: 9px; font-style: normal; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: rgba(255,255,255,0.85); }
.bar.ink span { background: linear-gradient(90deg, #c98e2c, var(--ink-gold-2)); }
.bar.conc span { background: linear-gradient(90deg, #6a7ad8, var(--cercle)); }
.bar.conc.full { box-shadow: 0 0 10px var(--cercle); }
.dh-touches { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.dh-touches i { width: 16px; height: 16px; transform: rotate(45deg); border: 2px solid var(--flamme); }
.dh-touches i.on { background: var(--flamme); box-shadow: 0 0 8px var(--flamme); }
.dh-sub { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; }
#trace:not(.hidden) ~ #duel-hud #dh-phase { display: none; }
#dh-phase { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); padding: 4px 14px; border-radius: 999px; background: rgba(240,201,106,0.16); border: 1px solid rgba(240,201,106,0.5); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-gold-2); z-index: 16; }
#dh-msg { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); font-family: var(--serif); font-weight: 700; font-size: clamp(20px, 3.6vw, 30px); color: #fff; text-shadow: 0 2px 8px #000, 0 0 16px rgba(240,201,106,0.5); text-align: center; width: 80%; opacity: 0; }
#dh-msg.show { animation: msg 1.5s ease both; }
@keyframes msg { 0% { opacity: 0; transform: translate(-50%, 8px); } 15%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ---------- apprentissage ---------- */
#learn { position: absolute; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(8,5,16,0.82); }
.learn-page { width: min(420px, 86vw); max-height: 94vh; padding: 14px 20px 16px; border-radius: 8px; text-align: center; color: var(--sepia); background: radial-gradient(circle at 50% 30%, var(--parchment), var(--parchment-2)); box-shadow: 0 10px 40px rgba(0,0,0,0.7), inset 0 0 30px rgba(120,80,30,0.25); }
.learn-page small { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #8a6a3a; }
#learn-canvas { width: min(160px, 34vh); height: min(160px, 34vh); display: block; margin: 4px auto; background: #241a30; border-radius: 50%; }
#learn-name { font-family: var(--serif); font-size: 32px; margin: 4px 0 0; }
#learn-sens { margin: 0; font-weight: 700; }
#learn-src { margin: 4px 0 6px; font-size: 13px; font-style: italic; color: #7a5a3a; }
.tap { font-size: 12px; color: #8a6a3a; animation: bob 1.2s ease-in-out infinite; display: inline-block; }

/* ---------- grimoire ---------- */
#grimoire { position: absolute; inset: 0; z-index: 22; display: grid; place-items: center; background: rgba(8,5,16,0.7); padding: 8px; }
.gr-book { width: min(980px, 100%); height: 100%; max-height: 640px; display: flex; flex-direction: column; border-radius: 10px; color: var(--sepia); background: radial-gradient(circle at 50% 0%, var(--parchment), var(--parchment-2)); box-shadow: 0 10px 40px rgba(0,0,0,0.7), inset 0 0 40px rgba(120,80,30,0.25); overflow: hidden; }
.gr-book header { display: flex; align-items: center; gap: 14px; padding: 8px 14px 4px; }
.gr-book h2 { font-family: var(--serif); font-size: 26px; margin: 0; }
.gr-rank { font-size: 13px; }
#gr-close { margin-left: auto; width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(74,52,32,0.4); background: transparent; color: var(--sepia); font-size: 18px; }
#gr-tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid rgba(74,52,32,0.25); overflow-x: auto; }
#gr-tabs button { padding: 8px 12px; border: 0; background: transparent; color: #7a5a3a; font-weight: 800; border-bottom: 3px solid transparent; white-space: nowrap; }
#gr-tabs button.on { color: var(--sepia); border-color: #b0782e; }
#gr-body { flex: 1; overflow-y: auto; padding: 12px 14px 16px; user-select: text; -webkit-user-select: text; touch-action: pan-y; }
.ggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.gcard { padding: 10px; border-radius: 10px; background: rgba(255,255,255,0.35); border: 1px solid rgba(74,52,32,0.18); }
.gcard h4 { font-family: var(--serif); font-size: 21px; margin: 4px 0 0; text-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.gcard p { margin: 2px 0; font-size: 13px; }
.gcard .sens { font-weight: 800; }
.gcard .src { font-style: italic; color: #7a5a3a; }
.gcard ul { margin: 6px 0; padding-left: 18px; font-size: 13px; }
.gcard .mastery { font-size: 12px; color: #6a4a2a; font-weight: 700; }
.gcard textarea { width: 100%; min-height: 44px; margin-top: 6px; border-radius: 6px; border: 1px dashed rgba(74,52,32,0.4); background: rgba(255,250,235,0.6); font: 13px var(--sans); color: var(--sepia); padding: 6px; resize: vertical; }
.gthumb { width: 72px; height: 72px; border-radius: 50%; background: #241a30; display: grid; place-items: center; font-family: var(--serif); font-size: 32px; color: rgba(255,255,255,0.25); }
.gcard.unknown { opacity: 0.55; }
.gcard.secret { border-color: #9a7ad0; }
.hint { font-size: 13px; color: #7a5a3a; font-style: italic; }
.formules { list-style: none; padding: 0; margin: 0; }
.formules li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-bottom: 1px dashed rgba(74,52,32,0.25); font-size: 14px; }
.formules li.inconnue { opacity: 0.45; }
.formules li.pressentie span { color: #b0782e; font-style: italic; }
#gr-body article { padding: 8px 0; border-bottom: 1px dashed rgba(74,52,32,0.25); }
#gr-body article h4 { margin: 0; font-family: var(--serif); font-size: 19px; }
#gr-body article p { margin: 2px 0 0; font-size: 14px; line-height: 1.4; }
.row { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-weight: 700; font-size: 14px; }
.row select, .row button { padding: 8px 12px; border-radius: 8px; border: 1px solid rgba(74,52,32,0.4); background: rgba(255,250,235,0.7); color: var(--sepia); font-weight: 700; }
.row button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }

/* ---------- titre et fin ---------- */
#title, #endscreen { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; text-align: center; background: radial-gradient(circle at 50% 40%, rgba(60,40,96,0.55), rgba(10,6,20,0.25)); }
#endscreen { background: rgba(10,6,20,0.88); }
.title-inner, .end-inner { padding: 16px; }
.kicker { margin: 0; font-size: 13px; letter-spacing: 0.35em; text-transform: uppercase; color: var(--muted); }
#title h1 { margin: 2px 0 0; font-family: var(--serif); font-size: clamp(38px, 8vw, 68px); color: var(--ink-gold-2); text-shadow: 0 0 24px rgba(240,201,106,0.45), 0 3px 6px #000; line-height: 1; }
.sub { margin: 4px 0 14px; font-family: var(--serif); font-style: italic; font-size: 20px; color: #e3d6f0; }
.name { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.name input { display: block; margin: 6px auto 0; width: 200px; padding: 9px 12px; border-radius: 10px; border: 1px solid rgba(240,201,106,0.5); background: rgba(18,13,28,0.85); color: var(--text); font: 700 17px var(--sans); text-align: center; user-select: text; -webkit-user-select: text; }
.title-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.title-btns button { padding: 12px 24px; border-radius: 12px; border: 2px solid var(--ink-gold); background: linear-gradient(180deg, rgba(240,201,106,0.25), rgba(240,201,106,0.08)); color: var(--text); font-weight: 800; font-size: 16px; }
.title-btns button.quiet { border-color: rgba(240,201,106,0.4); background: transparent; font-weight: 700; }
.dh-workers { margin-top: 6px; font-size: 11px; font-weight: 800; color: var(--cercle); }
.foot { margin-top: 14px; font-size: 12px; color: var(--muted); }
.end-inner small { letter-spacing: 0.25em; text-transform: uppercase; color: var(--muted); font-size: 12px; }
.end-inner h2 { margin: 4px 0 10px; font-family: var(--serif); font-size: clamp(32px, 6vw, 48px); color: var(--ink-gold-2); }
.end-inner ul { list-style: none; padding: 0; margin: 0 0 12px; line-height: 1.9; }
.end-inner b { color: var(--ink-gold); }
.next { font-family: var(--serif); font-style: italic; font-size: 20px; color: #e3d6f0; }

#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 50; }
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate { position: absolute; inset: 0; z-index: 60; display: grid; place-content: center; text-align: center; background: var(--night); }
  #rotate div { font-size: 64px; color: var(--ink-gold); animation: spin 2.5s ease-in-out infinite; }
  #rotate p { font-family: var(--serif); font-size: 22px; }
  @keyframes spin { 50% { transform: rotate(90deg); } }
}
@media (max-height: 420px) {
  #level-name { font-size: 13px; }
  .dlg-box { min-height: 74px; padding: 8px 14px 10px 10px; }
  #objective { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; } }
