:root {
  --bg: #0e0a1f; --card: rgba(255,255,255,.06); --card2: rgba(255,255,255,.1); --text: #f6f2ff; --muted: #a99fcc;
  --accent: #ffb347; --ink: #1a1030; --good: #69db7c; --bad: #ff6b6b; --r: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'DM Sans', system-ui, sans-serif; overscroll-behavior: none; }
body { background: radial-gradient(70vmax 50vmax at 10% -10%, rgba(255,179,71,.16), transparent 70%), radial-gradient(60vmax 40vmax at 110% 110%, rgba(172,141,255,.18), transparent 70%), var(--bg); }
#rpg { max-width: 1100px; margin: 0 auto; min-height: 100%; padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); }
h1, h2, h3, h4 { font-family: Unbounded, sans-serif; margin: 0 0 10px; }
h2 { font-size: 20px; } h3 { font-size: 15px; margin-top: 16px; color: var(--accent); } h4 { font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 13px; } .ok { color: var(--good); font-weight: 700; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn { font: inherit; font-weight: 700; color: var(--text); background: var(--card2); border: 1px solid rgba(255,255,255,.14); border-radius: 12px; padding: 9px 14px; cursor: pointer; transition: transform .1s, background .15s; line-height: 1.2; }
.btn:hover { background: rgba(255,255,255,.16); } .btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--ink); border-color: transparent; box-shadow: 0 4px 0 #b9741d; }
.btn.ghost { background: transparent; } .btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; } .btn.lg { padding: 14px 22px; font-size: 17px; }
.btn.dis, .btn[disabled] { opacity: .45; } .btn small { font-weight: 500; opacity: .8; }
.input { width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(0,0,0,.3); color: var(--text); }
.chip { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--card2); }
#toast { position: fixed; left: 50%; top: 14px; transform: translate(-50%, -150%); max-width: calc(100vw - 32px); background: #fff; color: var(--ink); padding: 10px 16px; border-radius: 14px; font-weight: 700; z-index: 99; transition: transform .3s; box-shadow: 0 10px 30px rgba(0,0,0,.4); text-align: center; }
#toast.show { transform: translate(-50%, 0); }

/* Écran titre */
.title-screen { max-width: 760px; margin: 0 auto; padding: 10px 0 30px; display: flex; flex-direction: column; gap: 12px; }
.back { color: var(--muted); text-decoration: none; font: inherit; background: none; border: none; cursor: pointer; align-self: flex-start; padding: 0; }
.logo { text-align: center; font-size: 46px; padding: 10px 0; }
.logo h1 { font-size: clamp(28px, 7vw, 46px); line-height: 1.05; margin-top: 6px; }
.logo h1 span { color: var(--accent); }
.logo p { font-size: 15px; color: var(--muted); max-width: 520px; margin: 10px auto 0; }
.slots { display: grid; gap: 10px; }
.slot { background: var(--card); border: 1px solid rgba(255,255,255,.1); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.slot.empty { border-style: dashed; }
.slot-h { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.slot-b { display: flex; gap: 12px; align-items: center; }
.big-face { font-size: 44px; line-height: 1; }
.lbl { font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; margin-top: 8px; }
.faces { display: flex; flex-wrap: wrap; gap: 6px; }
.face { font-size: 28px; width: 52px; height: 52px; border-radius: 14px; border: 2px solid transparent; background: var(--card); cursor: pointer; }
.face.on { border-color: var(--accent); background: rgba(255,179,71,.18); }
.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.cls { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; font: inherit; color: var(--text); background: var(--card); border: 2px solid transparent; border-radius: 16px; padding: 12px; cursor: pointer; }
.cls span { font-size: 28px; } .cls small { color: var(--muted); }
.cls.on { border-color: var(--accent); background: rgba(255,179,71,.14); }

/* Monde */
.world { display: flex; flex-direction: column; gap: 8px; height: calc(100dvh - 20px); min-height: 480px; position: relative; }
.hud { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.hud-l { font-family: Unbounded, sans-serif; font-weight: 700; font-size: 15px; }
.hud-l small { font-family: 'DM Sans', system-ui, sans-serif; color: var(--muted); font-weight: 500; }
.pill { background: var(--card2); padding: 5px 11px; border-radius: 99px; font-weight: 700; font-size: 14px; }
.hud-r { display: flex; gap: 6px; }
.hud-menu { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.hud-menu button { flex: 1 0 auto; font: inherit; font-weight: 700; color: var(--text); background: var(--card); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 8px 12px; cursor: pointer; }
.mapwrap { flex: 1; position: relative; overflow: hidden; border-radius: var(--r); border: 2px solid rgba(255,255,255,.12); background: #000; display: flex; align-items: center; justify-content: center; min-height: 260px; }
.map { display: grid; gap: 0; user-select: none; }
.t { width: var(--ts); height: var(--ts); display: flex; align-items: center; justify-content: center; font-size: calc(var(--ts) * .66); line-height: 1; position: relative; cursor: pointer; }
.t-g { background: #5fae4f; box-shadow: inset 0 0 0 1px rgba(0,0,0,.04); }
.t-g::after { content: '"'; position: absolute; font-size: calc(var(--ts) * .35); color: rgba(30,80,20,.45); top: 18%; left: 30%; font-weight: 900; }
.t-p { background: #d9c28a; }
.t-T { background: #4a9a40; } .t-M { background: #8e8a86; } .t-r { background: #b9a57a; }
.t-w { background: #3f7fd0; background-image: radial-gradient(circle at 30% 40%, rgba(255,255,255,.25) 0 8%, transparent 9%); }
.t-W { background: #2d2638; box-shadow: inset 0 -4px 0 rgba(0,0,0,.35); }
.t-f { background: #5a4f66; } .t-fs { background: #73668a; }
.t-l { background: #c43d1d; background-image: radial-gradient(circle at 60% 60%, #ffae42 0 10%, transparent 12%); }
.t-m { background: #5b7a46; } .t-m::after { content: '~'; position: absolute; color: rgba(30,50,20,.5); font-weight: 900; }
.t-s { background: #e8c57a; } .t-s::after { content: '·'; position: absolute; color: rgba(150,100,30,.5); font-weight: 900; font-size: calc(var(--ts) * .5); }
.t-n { background: #e9f1f7; }
.t-void { background: #000; }
.map[data-theme^="foret"] .t-g { background: #3f8a45; } .map[data-theme^="foret"] .t-T { background: #2f6e36; }
.map[data-theme^="montagne"] .t-g { background: #7da36b; } .map[data-theme^="montagne"] .t-M { background: #7d7a88; }
.map[data-theme^="desert"] .t-p { background: #f0d79a; } .map[data-theme^="desert"] .t-r { background: #d9b66a; }
.map[data-theme^="citadelle"] .t-f { background: #3b2730; } .map[data-theme^="citadelle"] .t-p { background: #6e5a62; }
.map[data-theme*="dungeon"] .t-f { background: #4b4058; }
.me { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--ts) * .74); filter: drop-shadow(0 3px 2px rgba(0,0,0,.5)); animation: bob 1s ease-in-out infinite alternate; z-index: 2; }
@keyframes bob { to { transform: translateY(-3px); } }
.team-mini { position: absolute; left: 8px; top: 8px; display: flex; gap: 4px; z-index: 3; }
.tm { position: relative; background: rgba(14,10,31,.75); border-radius: 10px; padding: 3px 5px 6px; font-size: 18px; min-width: 32px; text-align: center; overflow: hidden; }
.tm i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--good); }
.tm.ko { filter: grayscale(1); opacity: .6; }
.team-mini.big { position: static; margin-top: 10px; } .team-mini.big .tm { font-size: 26px; }
.pad { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(2, 50px); gap: 6px; justify-content: center; }
.pad button { font-size: 20px; border-radius: 14px; border: 1px solid rgba(255,255,255,.14); background: var(--card2); color: var(--text); touch-action: manipulation; }
.pad button:nth-child(1) { grid-column: 2; grid-row: 1; } .pad button:nth-child(2) { grid-column: 1; grid-row: 2; } .pad button:nth-child(3) { grid-column: 3; grid-row: 2; } .pad button:nth-child(4) { grid-column: 2; grid-row: 2; }
@media (hover: hover) and (min-width: 900px) { .pad { display: none; } }

/* Overlays */
#ov:empty { display: none; }
#ov { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(5,3,12,.6); backdrop-filter: blur(3px); }
.dlg { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(720px, calc(100% - 20px)); background: #1b1530; border: 2px solid var(--accent); border-radius: 18px; padding: 16px 16px 12px 76px; cursor: pointer; min-height: 100px; animation: up .25s; }
.dlg-who { position: absolute; left: 14px; top: 14px; font-size: 44px; }
.dlg-t { font-size: 16px; line-height: 1.45; }
.dlg-next { text-align: right; color: var(--accent); font-weight: 700; margin-top: 8px; font-size: 13px; }
@keyframes up { from { transform: translate(-50%, 20px); opacity: 0; } }
.panel { position: relative; width: min(860px, 100%); max-height: calc(100dvh - 20px); overflow-y: auto; background: #17122a; border: 1px solid rgba(255,255,255,.12); border-radius: 22px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.panel .close { position: sticky; top: 0; float: right; z-index: 2; width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--card2); color: var(--text); font-size: 18px; cursor: pointer; }
.panel.res { text-align: center; max-width: 520px; }
.res-l { display: flex; flex-direction: column; gap: 4px; margin: 10px 0 16px; text-align: left; background: rgba(0,0,0,.2); border-radius: 14px; padding: 12px; max-height: 50vh; overflow-y: auto; }
.vh { display: flex; gap: 12px; align-items: center; } .vh-e { font-size: 40px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 12px 0; padding-bottom: 4px; scrollbar-width: none; }
.tabs button { flex: 0 0 auto; font: inherit; font-weight: 700; color: var(--muted); background: var(--card); border: 1px solid rgba(255,255,255,.08); border-radius: 99px; padding: 8px 14px; cursor: pointer; }
.tabs button.on { background: var(--accent); color: var(--ink); }
.shop { display: flex; flex-direction: column; gap: 6px; }
.sh-row, .bld, .quest { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--card); border-radius: 14px; padding: 10px 12px; }
.sh-row > span:first-child, .bld > div, .quest > div { flex: 1; min-width: 0; }
.bld-e { font-size: 30px; }
.quest { margin-bottom: 6px; } .quest.main { border: 1px solid rgba(255,179,71,.5); }
.gear { font-weight: 700; } .gear.r0 { color: #e6e0f5; } .gear.r1 { color: #74c0fc; } .gear.r2 { color: #da77f2; } .gear.r3 { color: #ffc847; text-shadow: 0 0 8px rgba(255,200,71,.4); }
.mats { display: flex; flex-wrap: wrap; gap: 6px; }
.hero-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.hero-chip { position: relative; overflow: hidden; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; font: inherit; color: var(--text); background: var(--card); border: 2px solid transparent; border-radius: 14px; padding: 8px 10px; cursor: pointer; }
.hero-chip span { grid-row: span 2; font-size: 28px; } .hero-chip small { color: var(--muted); }
.hero-chip i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--good); }
.hero-chip.act { background: rgba(105,219,124,.1); } .hero-chip.on { border-color: var(--accent); }
.hero-detail { margin-top: 12px; }
.hd-head { display: flex; gap: 12px; align-items: center; } .hd-head > div { flex: 1; }
.hd-head h3 { margin: 0 0 6px; color: var(--text); } .hd-head h3 small { color: var(--muted); font-family: 'DM Sans', system-ui, sans-serif; font-weight: 500; }
.stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; } .stats span { background: var(--card); border-radius: 10px; padding: 5px 9px; font-size: 13px; font-weight: 700; }
.eq { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.eq-slot { display: flex; flex-direction: column; gap: 4px; background: var(--card); border-radius: 14px; padding: 10px; align-items: flex-start; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.skills { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.skill { background: var(--card); border-radius: 12px; padding: 8px 10px; } .skill.locked { opacity: .45; }
.best { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.bst { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; background: var(--card); border-radius: 12px; padding: 8px; font-size: 12px; }
.bst span { font-size: 28px; } .bst.unk { opacity: .45; }
.sys { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.help { color: var(--muted); font-size: 14px; line-height: 1.5; padding-left: 18px; }
.bar { position: relative; height: 16px; background: rgba(0,0,0,.4); border-radius: 99px; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; transition: width .4s; }
.bar b { position: relative; font-size: 10px; padding-left: 6px; line-height: 16px; text-shadow: 0 1px 2px #000; }
.bar.hp i { background: linear-gradient(90deg, #40c057, #8ce99a); } .bar.mp i { background: linear-gradient(90deg, #339af0, #74c0fc); } .bar.xp i { background: linear-gradient(90deg, var(--accent), #ffd43b); }

/* Combat */
.bt { width: min(900px, 100%); max-height: calc(100dvh - 20px); overflow-y: auto; background: linear-gradient(180deg, #221a3d, #120d22); border: 2px solid rgba(255,255,255,.14); border-radius: 22px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bt.boss { border-color: #ff6b6b; box-shadow: 0 0 40px rgba(255,107,107,.25); }
.bt-top { display: flex; justify-content: space-between; align-items: center; font-family: Unbounded, sans-serif; font-weight: 700; gap: 8px; flex-wrap: wrap; }
.bt-foes, .bt-allies { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.unit { position: relative; background: var(--card); border: 2px solid transparent; border-radius: 16px; padding: 10px; display: flex; flex-direction: column; gap: 5px; transition: transform .15s, border-color .15s; }
.unit.foe { align-items: center; text-align: center; background: rgba(255,107,107,.07); }
.unit.foe .bar { width: 100%; }
.unit .u-e { font-size: 40px; line-height: 1; } .unit.ally .u-e { font-size: 28px; }
.unit.ally { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; }
.unit.ally .u-e { grid-row: span 4; }
.unit .u-n { font-weight: 700; font-size: 14px; } .unit .u-n small { color: var(--muted); font-weight: 500; }
.unit .u-st { font-size: 13px; min-height: 16px; }
.unit.boss .u-e { font-size: 64px; }
.unit.cur { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,179,71,.2); }
.unit.ko { opacity: .45; filter: grayscale(.8); }
.unit.tgt { border-color: #ff8787; cursor: pointer; animation: pulse .8s infinite alternate; }
.unit.ally.tgt { border-color: var(--good); }
@keyframes pulse { to { transform: scale(1.03); } }
.unit.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.fx { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); font-family: Unbounded, sans-serif; font-weight: 900; font-size: 20px; pointer-events: none; animation: fx 1.1s forwards; text-shadow: 0 2px 4px #000; z-index: 3; white-space: nowrap; }
.fx.dmg { color: #ff8787; } .fx.crit { color: #ffd43b; font-size: 26px; } .fx.heal { color: #8ce99a; } .fx.mp { color: #74c0fc; } .fx.boss { color: #ff6b6b; font-size: 22px; }
@keyframes fx { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -40px); } }
.bt-log { background: rgba(0,0,0,.3); border-radius: 12px; padding: 8px 12px; font-size: 13px; min-height: 76px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; color: var(--muted); }
.bt-log div:last-child { color: var(--text); font-weight: 700; }
.bt-log .good { color: #8ce99a; } .bt-log .bad { color: #ff8787; } .bt-log .boss { color: #ffa8a8; } .bt-log .skill { color: #ffd8a8; }
.bt-menu { background: rgba(255,179,71,.06); border: 1px solid rgba(255,179,71,.25); border-radius: 16px; padding: 10px; min-height: 64px; }
.bm-h { font-weight: 700; margin-bottom: 8px; }
.bm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.bm-grid .btn { text-align: left; }

@media (max-width: 640px) {
  #rpg { padding-left: 8px; padding-right: 8px; }
  .hud-menu button span { display: none; }
  .hud-menu button { font-size: 18px; padding: 8px; }
  .bt { padding: 8px; gap: 8px; }
  .bt-foes { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 6px; }
  .bt-allies { grid-template-columns: 1fr 1fr; gap: 6px; }
  .unit { padding: 7px; } .unit .u-e { font-size: 32px; } .unit.boss .u-e { font-size: 48px; } .unit .u-n { font-size: 12px; }
  .bm-grid { grid-template-columns: 1fr 1fr; }
  .panel { padding: 14px; border-radius: 18px; }
  .sh-row, .bld, .quest { flex-wrap: wrap; }
  .dlg { padding-left: 64px; } .dlg-who { font-size: 36px; } .dlg-t { font-size: 15px; }
}

/* Version publique : pub et liens légaux sur l'écran titre */
.rpg-ad { width: 100%; max-width: 728px; margin: 10px auto 0; text-align: center; }
.rpg-ad:empty { display: none; }
.rpg-ad .ad-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.rpg-ad .ad-demo { border: 2px dashed rgba(255,255,255,.18); border-radius: 14px; padding: 30px 10px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.rpg-legal { text-align: center; }
.rpg-legal a, .rpg-legal .linkish { color: var(--muted); background: none; border: none; font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
