/* Layout concept: one column sheet. Striped tiger band and title on top, a sticky tab bar, then one panel per tab. Counters are large tap targets built for use mid-reading. */
:root {
  --bg: #e8ebee;
  --surface: #f7f8f9;
  --surface-2: #dde2e8;
  --ink: #18202c;
  --ink-soft: #4a5668;
  --line: #c3cbd5;
  --accent: #b8541a;
  --accent-ink: #ffffff;
  --jade: #2f7d62;
  --blue: #2f5d9e;
  --warn: #8f6208;
  --danger: #b3261e;
  --f-display: 'Shippori Mincho', 'Hiragino Mincho ProN', Georgia, serif;
  --f-body: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Segoe UI', system-ui, sans-serif;
  --f-num: 'DM Mono', ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10151d;
    --surface: #182030;
    --surface-2: #212b3d;
    --ink: #e6eaf0;
    --ink-soft: #9aa7ba;
    --line: #2c384d;
    --accent: #e8863f;
    --accent-ink: #1a0f05;
    --jade: #5cc2a0;
    --blue: #7fa6e6;
    --warn: #e3b04b;
    --danger: #f0766c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10151d;
  --surface: #182030;
  --surface-2: #212b3d;
  --ink: #e6eaf0;
  --ink-soft: #9aa7ba;
  --line: #2c384d;
  --accent: #e8863f;
  --accent-ink: #1a0f05;
  --jade: #5cc2a0;
  --blue: #7fa6e6;
  --warn: #e3b04b;
  --danger: #f0766c;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--f-body);
  padding-block: 0 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--bg);
}
.wrap { max-width: 880px; margin: 0 auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

/* header */
.stripe {
  height: 8px;
  background: repeating-linear-gradient(105deg, var(--accent) 0 12px, var(--ink) 12px 17px);
}
.head { padding-top: 18px; display: grid; gap: 14px; }
.title-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
h1 {
  font: 800 clamp(1.3rem, 4.5vw, 1.7rem)/1.1 var(--f-display);
  letter-spacing: 0.01em;
  text-wrap: balance;
}
.eyebrow { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-soft); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--ink-soft); }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--jade); display: inline-block; }
.status[data-s="pending"] i { background: var(--warn); }
.status[data-s="local"] i { background: var(--blue); }
.status[data-s="error"] i { background: var(--danger); }
.status[hidden] { display: none; }
.book-title { margin-top: 4px; color: var(--accent); font: 700 1rem/1.3 var(--f-display); }
.title-row { align-items: flex-end; }
.title-row .tome { flex: 0 1 auto; }
@media (max-width: 560px) { .title-row .tome { flex: 1 1 100%; } }
.who { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 18px; align-items: end; }
@media (max-width: 560px) { .who { grid-template-columns: minmax(0, 1fr); } }
.fld { display: grid; gap: 4px; min-width: 0; }
.fld[hidden] { display: none; }
.fld > span, .lbl { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
input[type="text"], select, textarea, input[type="number"] {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 84px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button {
  border: 0; background: transparent; padding: 9px 0; min-width: 40px; flex: 1;
  font-family: var(--f-num); border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* tabs */
.tabs-wrap {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: var(--bg);
  margin-top: 16px;
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 500;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font: 700 0.72rem/20px var(--f-num);
  text-align: center;
}
.badge.over { background: var(--danger); color: var(--accent-ink); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

main { padding-top: 22px; display: grid; gap: 26px; }

/* sections */
.grp { display: grid; gap: 12px; }
.grp-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
h2 { font: 800 1.15rem/1.2 var(--f-display); }
.sub { color: var(--ink-soft); font-size: 0.86rem; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 14px; min-width: 0; }

/* counters */
.counter { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px 10px; display: grid; gap: 8px; --tone: var(--accent); }
.counter[data-tone="jade"] { --tone: var(--jade); }
.counter[data-tone="blue"] { --tone: var(--blue); }
.counter[data-tone="warn"] { --tone: var(--warn); }
.counter[data-tone="soft"] { --tone: var(--ink-soft); }
.counter[data-low="1"] { --tone: var(--danger); }
.c-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
h3 { font-size: 1.1rem; font-weight: 700; }
.c-full { border: 1px solid var(--line); background: transparent; border-radius: 5px; padding: 2px 8px; font-size: 0.74rem; color: var(--ink-soft); }
.c-body { display: grid; grid-template-columns: 46px minmax(0, 1fr) 46px; gap: 8px; align-items: center; }
.step { height: 46px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; font-size: 1.5rem; line-height: 1; }
.step:active { background: var(--tone, var(--accent)); color: var(--accent-ink); }
.c-val {
  font: 500 2.1rem/1 var(--f-num);
  text-align: center;
  border: 0; border-bottom: 1px dashed var(--line); border-radius: 0; background: transparent; padding: 4px 0;
  appearance: textfield; -moz-appearance: textfield;
}
.c-val::-webkit-outer-spin-button, .c-val::-webkit-inner-spin-button, .c-max input::-webkit-outer-spin-button, .c-max input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--tone); }
.c-max { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.78rem; color: var(--ink-soft); }
.c-max input { width: 64px; text-align: center; padding: 4px 6px; font-family: var(--f-num); appearance: textfield; -moz-appearance: textfield; }

.hint { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; border: 1px solid var(--accent); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.hint p { flex: 1 1 260px; font-size: 0.9rem; }
.hint.warn { border-color: var(--danger); }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 9px 14px; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger[data-confirm="1"] { background: var(--danger); color: var(--surface); }
.btn.sm { padding: 5px 10px; font-size: 0.82rem; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* misc */
.x { border: 0; background: transparent; color: var(--ink-soft); padding: 6px 8px; border-radius: 6px; font-size: 1.1rem; line-height: 1; }
.x[data-confirm="1"] { background: var(--danger); color: var(--surface); font-size: 0.8rem; }
.empty { color: var(--ink-soft); padding: 14px 0 4px; font-size: 0.92rem; }
.pill { display: inline-block; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; color: var(--ink-soft); }
.pill.on { background: var(--jade); border-color: var(--jade); color: var(--surface); font-weight: 700; }

/* feuille perso : une ligne par compteur */
.crows { display: grid; gap: 10px; width: 100%; max-width: 480px; margin-inline: auto; }
.crow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 68px; padding: 0 12px 0 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.crow h3 { font-size: 1.1rem; min-width: 0; overflow-wrap: anywhere; }
.crow .c-body { flex: 0 0 160px; grid-template-columns: 36px minmax(0, 1fr) 36px; }
.crow .step { height: 36px; font-size: 1.2rem; }
.crow .c-val { border: 0; background: transparent; padding: 0; font-size: 1.3rem; }

/* cartes : disciplines et inventaire */
.dcards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.dwrap { position: relative; min-width: 0; display: grid; }
.dcard {
  display: grid; place-items: center; width: 100%; min-height: 76px; padding: 10px 30px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  font: 700 0.76rem/1.25 var(--f-display); text-align: center;
}
button.dcard { cursor: pointer; }
button.dcard:hover { border-color: var(--accent); }
.dcard .nm { overflow-wrap: anywhere; }
.dcard.acq { background: transparent; color: var(--ink-soft); }
.dcard.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 2px var(--accent); }
.dinfo {
  position: absolute; top: 6px; right: 6px; z-index: 1;
  width: 22px; height: 22px; padding: 0; display: grid; place-items: center;
  border: 1.5px solid var(--ink-soft); border-radius: 50%; background: var(--surface); color: var(--ink-soft);
  font: italic 700 0.8rem/1 var(--f-display); cursor: pointer;
}
.dinfo::after { content: ""; position: absolute; inset: -9px; }
.dinfo[aria-expanded="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.dcard.add { background: transparent; border: 2px dashed var(--accent); color: var(--accent); cursor: pointer; }
.dcard.add .plus { font: 400 2.4rem/1 var(--f-num); }
.dtip {
  position: fixed; z-index: 60; left: 0; top: 0;
  width: min(340px, calc(100vw - 16px)); padding: 10px 12px;
  background: var(--ink); color: var(--bg); border-radius: 8px;
  font: 400 0.86rem/1.45 var(--f-body); white-space: pre-line; overflow-wrap: anywhere;
  visibility: hidden; opacity: 0; pointer-events: none; transition: opacity 0.12s;
}
.dwrap.tip-open .dtip { visibility: visible; opacity: 1; }

/* carte d'objet : nom, effet, compteur éventuel */
/* Inventaire : 4 colonnes max, toutes les cartes de même taille */
.dcards.inv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 500px) { .dcards.inv { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 720px) { .dcards.inv { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.inv .icard, .inv .dcard.add { height: 96px; min-height: 0; }
.icard {
  display: grid; gap: 4px; align-content: center; justify-items: center; width: 100%; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; text-align: center;
}
.icard:hover { border-color: var(--accent); }
.ibody {
  display: grid; gap: 2px; justify-items: stretch; width: 100%; min-width: 0; padding: 0 20px;
  border: 0; background: transparent; color: inherit; font: inherit; text-align: center;
}
div.ibody { cursor: default; }
.ibody .nm, .ibody .ef { display: block; min-width: 0; min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ibody .nm { font: 700 0.76rem/1.3 var(--f-display); }
.ibody .ef { font: 400 0.74rem/1.3 var(--f-body); color: var(--ink-soft); }
.icount { display: grid; grid-template-columns: 30px minmax(0, 1fr) 30px; gap: 4px; align-items: center; width: 100%; height: 30px; }
.icount .step { height: 30px; font-size: 1.1rem; }
.icount .c-val { font-size: 1.2rem; padding: 2px 0; }
.ichk { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ichk input { width: 18px; height: 18px; accent-color: var(--accent); }

/* fenêtre de choix */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 12, 18, 0.6); }
.modal[hidden] { display: none; }
.mpanel {
  width: min(560px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 14px;
}
.mpanel form { display: grid; gap: 14px; }
.mpanel:focus { outline: none; }
.mh { font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.mpanel .btns { justify-content: center; }
.mdesc { color: var(--ink-soft); font-size: 0.92rem; white-space: pre-line; }
.mmsg { min-height: 1.4em; color: var(--danger); font-size: 0.9rem; }

/* cards */
.cards { display: grid; gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--surface); display: grid; gap: 8px; min-width: 0; }
.card-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.card h3 { font: 800 1.05rem/1.2 var(--f-display); overflow-wrap: anywhere; }
.card .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.card .foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 0.85rem; }
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.meta { font-size: 0.8rem; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }

/* combats : tableau, colonnes fixes (aucun décalage d'une ligne à l'autre) */
.ftable { display: grid; }
.ftable > * + * { border-top: 1px solid var(--line); }
.frow { display: grid; grid-template-columns: minmax(0, 1fr) 2.4rem; align-items: center; }
.fmain {
  display: grid; grid-template-columns: 1.7rem 4.4rem minmax(0, 1fr); column-gap: 0.6rem; align-items: baseline; align-content: center;
  width: 100%; min-height: 46px; padding: 6px 0; border: 0; background: transparent; color: inherit; text-align: left; font: inherit;
}
.fmain:hover .fname { color: var(--accent); }
.fno { font: 500 0.85rem/1.3 var(--f-num); color: var(--ink-soft); text-align: right; }
.fref { font: 500 0.85rem/1.3 var(--f-num); white-space: nowrap; text-align: right; }
.fn { display: flex; gap: 0.35em; min-width: 0; padding-left: 0.6rem; white-space: nowrap; line-height: 1.3; }
.fname { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.fres { flex: none; color: var(--ink-soft); }
.ficell { display: grid; place-items: center end; height: 100%; }
.frow .dinfo { position: relative; top: auto; right: auto; }
.fadd { cursor: pointer; }
.fadd .plus { font: 400 1.4rem/1.3 var(--f-num); color: var(--accent); text-align: right; }
.fadd .fn { color: var(--accent); font-weight: 700; }
.fchks { display: flex; gap: 20px; }
.f2 { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 12px; }

/* journal : deux colonnes (livre.§, texte) + le « i » */
.jmain { grid-template-columns: 4.4rem minmax(0, 1fr); }
.jtxt { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.jmain:hover .jtxt { color: var(--accent); }
.jtable .frow, .jtable > .fadd { padding-inline: 8px; }
.jtable .frow.imp { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.jtable .frow.imp .jtxt { font-weight: 700; }
.jtable .frow.imp .fref { color: var(--accent); font-weight: 700; }

/* sauvegarde : 9 emplacements, puis trois lignes d'actions */
.slots { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.slot {
  position: relative; display: grid; align-content: center; justify-items: center; gap: 2px;
  height: 96px; min-width: 0; padding: 8px 6px; text-align: center; color: inherit; font: inherit; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.slot:hover { border-color: var(--accent); }
.slot .sn { position: absolute; top: 6px; left: 8px; font: 500 0.72rem/1 var(--f-num); color: var(--ink-soft); }
.slot .nm, .slot .ef { display: block; max-width: 100%; min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .nm { font: 700 0.8rem/1.3 var(--f-display); }
.slot .ef { font: 400 0.74rem/1.3 var(--f-body); color: var(--ink-soft); }
.slot.empty .nm { font-weight: 400; font-style: italic; color: var(--ink-soft); }
.slot.empty .ef { display: none; }
.slot.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 2px var(--accent); }
.slot.sel .sn, .slot.sel .nm, .slot.sel .ef { color: inherit; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.srows { display: grid; margin-top: 8px; }
.srows > * + * { border-top: 1px solid var(--line); }
.srow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 14px 0; }
.stx { display: grid; gap: 2px; min-width: 0; flex: 1 1 240px; }
.stx b { font-weight: 700; }
.stx span { color: var(--ink-soft); font-size: 0.86rem; }

/* fenêtre du journal : le texte occupe toute la hauteur, boutons en bas */
.mpanel.tall { width: min(560px, 100%); height: min(560px, calc(100vh - 32px)); height: min(560px, calc(100dvh - 32px)); grid-template-rows: auto minmax(0, 1fr); }
.mpanel.tall form { display: flex; flex-direction: column; min-height: 0; }
.mpanel.tall .fgrow { flex: 1 1 auto; min-height: 7rem; grid-template-rows: auto minmax(0, 1fr); }
.mpanel.tall .fgrow textarea { height: 100%; min-height: 84px; resize: none; }
.mpanel.tall form .btns { margin-top: auto; }
.rules { margin: 0; padding-left: 1.2rem; display: grid; gap: 8px; }
.mpanel.wide { width: min(880px, 100%); }
.fgrid { display: grid; gap: 18px; align-items: start; }
.rules-panel { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 8px; align-content: start; font-size: 0.92rem; }
.rules-panel h3 { font: 800 1rem/1.2 var(--f-display); }
.rules-panel h4 { margin: 6px 0 0; font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.fgrow textarea { min-height: 11em; }
@media (min-width: 720px) {
  /* hauteur stable : le détail occupe tout l'espace libre, les boutons sont collés en bas */
  .mpanel.wide { height: min(700px, calc(100vh - 32px)); height: min(700px, calc(100dvh - 32px)); grid-template-rows: auto minmax(0, 1fr); }
  .fgrid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 22px; align-items: stretch; min-height: 0; }
  .fgrid form { display: flex; flex-direction: column; min-height: 0; }
  .fgrow { flex: 1 1 auto; min-height: 7rem; grid-template-rows: auto minmax(0, 1fr); }
  .fgrow textarea { height: 100%; min-height: 84px; resize: none; }
  .fgrid form .btns { margin-top: auto; }
  .rules-panel { border-top: 0; border-left: 1px solid var(--line); padding: 0 0 0 22px; min-height: 0; overflow-y: auto; }
}

pre.out { margin: 0; max-height: 200px; overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 10px; font: 0.8rem/1.4 var(--f-num); white-space: pre-wrap; overflow-wrap: anywhere; }

#toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; font-size: 0.88rem; z-index: 40;
  max-width: calc(100vw - 32px);
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
