:root {
  --bg: #14111c;
  --panel: #1f1a2b;
  --panel-2: #2a2340;
  --line: #3a3150;
  --text: #f3eefc;
  --muted: #b3a8c9;
  --accent: #f5b942;
  --accent-ink: #261a00;
  --good: #5fd39a;
  --bad: #ff6b6b;
  --ph-debut: #6fb6ff;
  --ph-main: #f5b942;
  --ph-combat: #ff6b6b;
  --ph-fin: #b48cff;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% 0%, #2b2142 0%, var(--bg) 60%);
  background-color: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }

#app {
  max-width: 560px; margin: 0 auto; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 10px) 16px calc(var(--safe-b) + 96px);
}

/* ---------- Écran d'accueil ---------- */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { margin: 0; font-size: 34px; letter-spacing: .5px; }
.hero p { margin: 6px 0 0; color: var(--muted); }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-top: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 14px; }
.field input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 8px; min-height: 48px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 10px 0; text-align: left;
}
.toggle .sw {
  flex: none; width: 52px; height: 30px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s;
}
.toggle .sw::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform .2s;
}
.toggle.on .sw { background: var(--good); }
.toggle.on .sw::after { transform: translateX(22px); }
.toggle small { display: block; color: var(--muted); font-size: 13px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 18px; border-radius: 14px;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 800; }
.btn.good { background: var(--good); color: #062b19; border-color: var(--good); font-weight: 800; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 8px 12px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }

/* ---------- Points de vie ---------- */
.lives { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.life {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 8px; text-align: center; transition: border-color .2s;
}
.life.active { border-color: var(--accent); box-shadow: 0 0 0 3px #f5b94222; }
.life .who { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.life.active .who { color: var(--accent); font-weight: 700; }
.life .pv { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.life .pv b { font-size: 38px; line-height: 1; font-variant-numeric: tabular-nums; }
.life .pv button {
  height: 44px; border-radius: 12px; background: var(--panel-2); font-size: 24px; font-weight: 700;
}
.life .poison { font-size: 13px; color: var(--good); min-height: 18px; }
.life.low .pv b { color: var(--bad); }

/* ---------- Frise des phases ---------- */
.turnline { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 2px 8px; }
.turnline .t { font-size: 15px; color: var(--muted); }
.turnline .t b { color: var(--text); }
.rail { display: flex; gap: 4px; }
.rail .seg-ph { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.rail .bars { display: flex; gap: 3px; }
.rail .bar { flex: 1; height: 7px; border-radius: 4px; background: var(--line); }
.rail .bar.done { background: color-mix(in srgb, var(--c) 45%, var(--line)); }
.rail .bar.now { background: var(--c); box-shadow: 0 0 10px var(--c); }
.rail .lbl { font-size: 11px; text-align: center; color: var(--muted); white-space: nowrap; overflow: hidden; }
.rail .seg-ph.cur .lbl { color: var(--c); font-weight: 700; }

/* ---------- Carte d'étape ---------- */
.step {
  margin-top: 14px; background: var(--panel); border: 1px solid var(--line);
  border-top: 4px solid var(--c); border-radius: var(--radius); padding: 16px;
}
.step.enter { animation: pop .25s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.step .head { display: flex; gap: 12px; align-items: center; }
.step .ico { font-size: 34px; }
.step h2 { margin: 0; font-size: 24px; }
.step .ph { font-size: 13px; color: var(--c); font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }
.step .intro { margin: 10px 0 4px; font-size: 18px; }
.note {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 12px;
  background: #6fb6ff1f; border: 1px solid #6fb6ff55;
}
.note.warn { background: #f5b9421f; border-color: #f5b94266; }
.blk { margin-top: 16px; }
.blk h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.check {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  padding: 12px; border-radius: 12px; background: var(--panel-2); margin-bottom: 8px;
  border: 1px solid transparent;
}
.check .box {
  flex: none; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted);
  display: grid; place-items: center; font-size: 16px; font-weight: 900; margin-top: 1px;
}
.check.on { border-color: #5fd39a55; }
.check.on .box { background: var(--good); border-color: var(--good); color: #062b19; }
.check.on span { color: var(--muted); text-decoration: line-through; text-decoration-color: #fff5; }
ul.mind { list-style: none; padding: 0; margin: 0; }
ul.mind li { position: relative; padding: 8px 0 8px 30px; border-bottom: 1px dashed var(--line); }
ul.mind li:last-child { border-bottom: 0; }
ul.mind li::before { content: "💡"; position: absolute; left: 0; top: 7px; }
.actions { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 16px; }

/* ---------- Barre du bas ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 16px calc(var(--safe-b) + 10px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.dock .in { max-width: 528px; margin: 0 auto; display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; }
.dock .icon { min-height: 60px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); font-size: 22px; }
.dock .icon:disabled { opacity: .35; }
.dock .go { min-height: 60px; font-size: 19px; }

/* ---------- Feuilles (modales du bas) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 20; background: #0009; display: flex; align-items: flex-end;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; max-height: 90dvh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0; padding: 10px 16px calc(var(--safe-b) + 16px);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet .grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet .sub { color: var(--muted); margin: 0 0 12px; }
.sheet .foot { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.sheet .foot.one { grid-template-columns: 1fr; }

.stack { display: flex; flex-direction: column-reverse; gap: 6px; margin: 10px 0; }
.stack .it {
  padding: 12px 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line);
  display: flex; justify-content: space-between; gap: 8px;
}
.stack .it.top { border-color: var(--accent); box-shadow: 0 0 0 2px #f5b94233; }
.stack .it small { color: var(--muted); }
.stack-empty { color: var(--muted); font-style: italic; }

.gl-search { width: 100%; margin-bottom: 10px; }
.gl dt { font-weight: 700; margin-top: 12px; color: var(--accent); }
.gl dd { margin: 2px 0 0; }

.banner {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; text-align: center;
  background: #000c; animation: fade .2s ease-out; padding: 24px;
}
.banner .big { font-size: 40px; font-weight: 900; margin: 8px 0; }
.banner p { color: var(--muted); }
.menu-list .btn { justify-content: flex-start; margin-bottom: 8px; }
.muted { color: var(--muted); }

/* ---------- Mise en place ---------- */
.mini {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  margin-top: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.mini .mini-ico {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); font-size: 16px;
}
.mini.done { color: var(--text); }
.mini.done .mini-ico { background: var(--good); color: #062b19; font-weight: 900; }
.pl-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.pl { background: var(--panel-2); border-radius: 14px; padding: 10px; }
.pl .check { background: var(--panel); margin: 6px 0 0; }
.pl.other { opacity: .8; }
.pl-name { font-weight: 800; font-size: 15px; }
.status { color: var(--muted); padding: 8px 2px 2px; }
.status.ok { color: var(--good); font-weight: 600; }
.seg button:disabled { opacity: .4; }

/* ---------- Invitation ---------- */
.invite { text-align: center; border-color: var(--accent); }
.qr { width: 210px; max-width: 70%; margin: 4px auto 0; background: #fff; border-radius: 14px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; }
.code { font-size: 40px; font-weight: 900; letter-spacing: 10px; margin: 6px 0 10px; color: var(--accent); }
.code-in {
  flex: 1; min-width: 0; text-align: center; font-size: 24px; font-weight: 800; letter-spacing: 8px; text-transform: uppercase;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 12px; padding: 10px; outline: none;
}
.code-in:focus { border-color: var(--accent); }

/* ---------- Partie partagée ---------- */
.conn { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--good); margin-right: 6px; vertical-align: 1px; }
.conn.off { background: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.note.watch { background: #b48cff1f; border-color: #b48cff66; margin: 10px 0 0; }
.stack-badge { border-color: var(--accent); color: var(--accent); }
.check:disabled { opacity: .7; cursor: default; }
.dock .go:disabled { opacity: .4; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translateX(-50%); z-index: 40;
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 99px; font-size: 15px; max-width: 90vw;
  animation: fade .2s ease-out;
}

/* ---------- Livre des règles ---------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--panel-2); padding: 4px; border-radius: 14px; margin: 10px 0 12px; }
.tabs button { padding: 10px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }
.types { display: flex; flex-direction: column; gap: 8px; }
.type { display: flex; gap: 12px; background: var(--panel-2); border-radius: 14px; padding: 12px; }
.type-ico { font-size: 30px; line-height: 1; }
.type b { font-size: 17px; }
.type p { margin: 2px 0 4px; }
.type small { color: var(--accent); }
.linkish { color: var(--ph-debut); text-decoration: underline; padding: 8px 0 0; text-align: left; font-size: 15px; }
