:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1f2328;
  --muted: #6b6f76;
  --border: #e2dfd6;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --owned: #15803d;
  --owned-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --weak: #b91c1c;
  --weak-bg: #fee2e2;
  --resist-bg: #dbeafe;
  --immune-bg: #c7d2fe;
  --absorb-bg: #e9d5ff;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2127;
    --surface-2: #272b33;
    --text: #e7e9ee;
    --muted: #9aa0aa;
    --border: #333843;
    --accent: #6d95f5;
    --accent-text: #0d1220;
    --owned: #4ade80;
    --owned-bg: #143222;
    --warn: #fbbf24;
    --warn-bg: #3a2c0b;
    --weak: #f87171;
    --weak-bg: #3b1616;
    --resist-bg: #172a4a;
    --immune-bg: #252c5a;
    --absorb-bg: #34204d;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: 1.2rem 0 .8rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .7rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.wrap { max-width: 1150px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.count { font-size: .9rem; font-weight: 400; }
.ja { font-family: var(--font); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- En-tête / pied ---------- */
header.site { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
header.site .wrap { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; padding-top: .6rem; padding-bottom: .6rem; }
.brand { font-weight: 900; font-size: 1.25rem; letter-spacing: .04em; color: var(--text); }
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }
header nav { display: flex; gap: .3rem; }
header nav a { padding: .35rem .7rem; border-radius: 8px; color: var(--text); }
header nav a.active, header nav a:hover { background: var(--surface-2); text-decoration: none; }
.quick-search { margin-left: auto; }
.quick-search input { width: 240px; max-width: 100%; }
footer.site { margin-top: 3rem; padding: 1.2rem 0 2rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }

/* ---------- Formulaires ---------- */
input, select, button, .button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .4rem .7rem;
}
button, .button { cursor: pointer; background: var(--surface-2); display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button[type=submit] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1 1 240px; }
.reset { font-size: .9rem; }

.own-btn { white-space: nowrap; font-size: .85rem; padding: .25rem .6rem; }
.own-btn.small { font-size: .75rem; padding: .1rem .45rem; }
.own-btn.is-owned { background: var(--owned-bg); color: var(--owned); border-color: var(--owned); }

/* ---------- Cartes / grilles ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1rem; display: block; color: inherit; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.cols > .card { margin-bottom: 0; }
.cols { margin-bottom: 1rem; }

.hero { padding: 1rem 0 .5rem; }
.hero h1 { font-size: 2rem; margin-bottom: .2rem; }
.hero .ja { color: var(--muted); margin: 0; }
.lede { max-width: 60ch; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; color: inherit; display: flex; flex-direction: column; }
.stat-card:hover { border-color: var(--accent); text-decoration: none; }
.stat-card strong { font-size: 2rem; line-height: 1.1; }
.stat-card small { color: var(--muted); margin-top: .3rem; }

.family-list, .link-list, .chip-list, .page-cards { list-style: none; padding: 0; margin: 0; }
.family-list li, .chip-list li { margin: .35rem 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.link-list li { margin: .35rem 0; }
.family-list.in-row { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; }
.info-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 0 1.5rem; }
.page-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .8rem; }
.page-cards .card { height: 100%; margin: 0; display: flex; flex-direction: column; gap: .25rem; }
.page-cards .card:hover { border-color: var(--accent); text-decoration: none; }
.result-list { list-style: none; padding: 0; margin: 0; }
.result-list li { padding: .4rem 0; border-top: 1px solid var(--border); }
.result-list li:first-child { border-top: 0; }
.result-list .chip { vertical-align: middle; }
.chip-row.plain { list-style: none; padding: 0; margin: 0; }
.more { margin-top: .6rem; }
.more summary { cursor: pointer; color: var(--accent); margin-bottom: .4rem; }

/* ---------- Badges / chips ---------- */
.badge, .tag {
  display: inline-flex; align-items: center; gap: .3em; font-size: .8rem;
  padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge.fam { border-color: var(--fam); background: color-mix(in srgb, var(--fam) 14%, var(--surface)); color: var(--text); }
.badge.fam .ja { color: var(--muted); }
.badge.rank { font-weight: 700; }
.badge.muted { color: var(--muted); }
.badge.status-complete { color: var(--owned); border-color: var(--owned); }
.badge.status-stub { color: var(--warn); border-color: var(--warn); }
.tag.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.badges { display: flex; flex-wrap: wrap; gap: .4rem; }

.chip {
  display: inline-flex; align-items: center; gap: .35em; padding: .15rem .55rem;
  border-radius: 8px; border: 1px solid var(--border); border-left: 4px solid var(--fam, var(--border));
  background: var(--surface);
}
.chip .ja { color: var(--muted); font-size: .85em; }
.chip .ico { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; margin: -.1rem 0 -.1rem -.25rem; flex-shrink: 0; }
.chip .fam-ico { width: 20px; height: 20px; border-radius: 4px; }
.ico-badge { width: 16px; height: 16px; border-radius: 3px; }
.ico-list { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; vertical-align: middle; margin-right: .5rem; }
.name-cell, .nowrap { white-space: nowrap; }
.name-line { display: flex; align-items: center; }
.sub { display: block; line-height: 1.3; }
.phone-only, .menu-btn { display: none; }
.portrait { width: 128px; height: 128px; border-radius: 18px; object-fit: cover; border: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.head-main { flex: 1 1 300px; }
.chip .rank { font-size: .75em; font-weight: 700; background: var(--surface-2); border-radius: 4px; padding: 0 .3em; }
.chip.is-owned { background: var(--owned-bg); border-color: var(--owned); border-left-color: var(--owned); }
.chip.is-stub { border-style: dashed; border-left-style: solid; }
.chip.family { font-style: italic; background: color-mix(in srgb, var(--fam) 10%, var(--surface)); }

/* ---------- Liste des monstres ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.monster-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.monster-table th, .monster-table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; }
.monster-table th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.monster-table tr.is-owned td:first-child { box-shadow: inset 4px 0 var(--owned); }
.monster-table th.num { text-align: right; }
.monster-table td.num { text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 2rem !important; }

/* ---------- Fiche monstre ---------- */
.crumbs { margin: 1rem 0 0; font-size: .9rem; color: var(--muted); }
.monster-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 1rem; }
.monster-head h1 { margin-top: .4rem; }
.head-actions { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.names { display: flex; gap: 1.2rem; flex-wrap: wrap; margin: 0 0 .7rem; }
.names div { display: flex; gap: .4rem; }
.names dt { font-weight: 700; color: var(--muted); font-size: .8rem; padding-top: .15rem; }
.names dd { margin: 0; }
.notice { background: var(--warn-bg); color: var(--text); border: 1px solid var(--warn); border-radius: var(--radius); padding: .7rem 1rem; }

.recipe { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; margin: .5rem 0; background: var(--surface); }
.recipe.is-uncertain { border-style: dashed; }
.recipe-parents { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.plus, .arrow { color: var(--muted); font-weight: 700; }
.recipe-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .45rem; font-size: .85rem; }
.recipe-meta .note { color: var(--muted); }
.recipe-meta .src { margin-left: auto; font-size: .8rem; }

.stats { max-width: 560px; }
.stats th { text-align: left; font-weight: 600; padding: .25rem .6rem .25rem 0; width: 90px; }
.stats td { padding: .25rem .4rem; }
.bar-cell { width: 60%; }
.bar { display: block; height: 10px; border-radius: 5px; background: var(--accent); min-width: 2px; }

table.list th, table.list td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list th { font-size: .8rem; color: var(--muted); }
table.list th.num { text-align: right; }

table.resist { max-width: 560px; }
table.resist th, table.resist td { padding: .3rem .6rem; border-bottom: 1px solid var(--border); text-align: left; font-size: .9rem; }
table.resist thead th { font-size: .8rem; color: var(--muted); }
.r-weak { background: var(--weak-bg); color: var(--weak); font-weight: 600; }
.r-resist { background: var(--resist-bg); }
.r-immune { background: var(--immune-bg); font-weight: 600; }
.r-absorb { background: var(--absorb-bg); font-weight: 600; }
.r-normal, .r-none { color: var(--muted); }
td.changed { box-shadow: inset 3px 0 var(--accent); }

/* ---------- Arbre ---------- */
.tree-toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: .6rem; }
.legend { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .85rem; color: var(--muted); }
.tree { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; overflow-x: auto; }
.tree ul { list-style: none; margin: 0; padding-left: 1.4rem; border-left: 1px dashed var(--border); }
.tree ul.tree-root { padding-left: 0; border-left: 0; }
.tree li { margin: .3rem 0; }
.tree summary { cursor: pointer; display: list-item; }
.tree summary > * { vertical-align: middle; }
.tree .recipe-node > details > summary { font-size: .9rem; color: var(--muted); }
.tree .recipe-node > details > summary strong { color: var(--text); }
.tree .tag { margin-left: .3rem; }
.leaf-info { font-size: .85rem; }

.segmented { display: inline-flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.tag.cond { background: var(--resist-bg); border-color: var(--accent); }

/* ---------- Schéma de synthèse (arbre généalogique) ---------- */
.diagram-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); gap: 1rem; }
.diagram-card { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); overflow: hidden; }
.diagram-card figcaption { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .55rem .8rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.diagram-card .recipe-meta { margin-top: 0; flex: 1; }
.diagram-box { overflow-x: auto; padding: 1rem .5rem; }
#tree-schema { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }

.sd { --line: color-mix(in srgb, var(--muted) 55%, transparent); --gap: 22px; display: flex; justify-content: center; min-width: max-content; }
.sd ul { display: flex; justify-content: center; list-style: none; margin: 0; padding: var(--gap) 0 0; position: relative; }
.sd > ul { padding-top: 0; }
.sd li { display: flex; flex-direction: column; align-items: center; position: relative; padding: var(--gap) 6px 0; }
.sd > ul > li { padding-top: 0; }
/* traits horizontaux et verticaux entre parents */
.sd li::before, .sd li::after { content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: var(--gap); border-top: 2px solid var(--line); }
.sd li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.sd li:only-child::before, .sd li:only-child::after { display: none; }
.sd li:only-child { padding-top: 0; }
.sd li:first-child::before, .sd li:last-child::after { border: 0 none; }
.sd li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 8px 0 0; }
.sd li:first-child::after { border-radius: 8px 0 0 0; }
.sd > ul > li::before, .sd > ul > li::after { display: none; }
/* trait vertical sous la carte enfant */
.sd ul ul::before { content: ''; position: absolute; top: 0; left: 50%; height: var(--gap); border-left: 2px solid var(--line); }

.sd-card {
  width: 128px; display: flex; flex-direction: column; align-items: center; gap: .15rem; text-align: center;
  padding: .45rem .35rem .4rem; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--border); border-top: 4px solid var(--fam, var(--border));
  font-size: .85rem; line-height: 1.25; position: relative;
}
.sd-card.is-owned { background: var(--owned-bg); border-color: var(--owned); }
.sd-card.is-stub { border-style: dashed; border-top-style: solid; }
.sd-ico { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; }
.sd-ico-fam { width: 36px; height: 36px; border-radius: 8px; margin: 10px 0; }
.sd-ico-empty { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.sd-name { font-weight: 700; word-break: break-word; }
.sd-ja { color: var(--muted); font-size: .75rem; }
.sd-rank { font-size: .7rem; font-weight: 700; background: var(--surface-2); border-radius: 4px; padding: 0 .35em; }
.sd-note { font-size: .72rem; color: var(--muted); }
.sd-family { font-style: italic; background: color-mix(in srgb, var(--fam) 10%, var(--surface)); }
.sd-free { border-style: dashed; font-style: italic; }
.pair { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .3rem; color: var(--muted); }
.tag.skill-attack { border-color: var(--weak); }
.tag.skill-heal { border-color: var(--owned); }
.tag.skill-support { border-color: var(--accent); }
.tag.skill-passive { color: var(--muted); }
.sd-how { font-size: .7rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: .2rem; margin-top: .15rem; width: 100%; }
.sd-cond { color: var(--accent); font-weight: 600; }
.sd-warn { color: var(--warn); font-weight: 600; }
.sd-controls { display: flex; align-items: center; gap: .2rem; margin-top: .1rem; }
.sd-btn { font-size: .85rem; font-weight: 700; line-height: 1; min-width: 1.6rem; padding: .2rem .4rem; border-radius: 6px; }
.sd-count { font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Objets ---------- */
.ico-empty { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--surface-2); font-size: .8rem; }
.portrait-item { width: 96px; height: 96px; object-fit: contain; padding: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.mat { display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; }
.stats-acc { max-width: 480px; }
tr:target { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Encyclopédie et zones ---------- */
.tabs { display: flex; gap: .3rem; margin: 1rem 0 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs a { padding: .45rem .9rem; border-radius: 8px 8px 0 0; color: var(--text); border: 1px solid transparent; border-bottom: 0; }
.tabs a.active { background: var(--surface); border-color: var(--border); font-weight: 600; }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .4rem; }
.region-title { margin-top: 1.6rem; }
.zone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.zone-card { display: flex; flex-direction: column; gap: .3rem; margin: 0; }
.zone-card:hover { border-color: var(--accent); text-decoration: none; }
.zone-icons { display: flex; flex-wrap: wrap; gap: 2px; }
.zone-icons img { width: 26px; height: 26px; border-radius: 5px; }

.rank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.rank-grid .card { margin: 0; }
.rank-list { margin: 0; padding-left: 1.6rem; }
.rank-list li { margin: .3rem 0; }
.rank-list .num { float: right; font-weight: 700; }

/* ---------- Collection ---------- */
.progress { height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; margin: .4rem 0; }
.progress span { display: block; height: 100%; background: var(--owned); }
.synth-item { border-top: 1px solid var(--border); padding-top: .4rem; }
.synth-item h3 { text-transform: none; letter-spacing: 0; color: var(--text); }

/* ---------- Pages d'infos ---------- */
.page-layout { display: grid; grid-template-columns: minmax(0, 820px) minmax(0, 1fr); gap: 1.5rem; align-items: start; margin-top: .5rem; }
.page-layout .prose { grid-column: 1; grid-row: 1; }
.toc { grid-column: 2; grid-row: 1; position: sticky; top: 75px; max-height: calc(100vh - 95px); overflow-y: auto; font-size: .9rem; }
.toc summary { font-weight: 700; cursor: pointer; }
.toc ul { list-style: none; margin: .5rem 0 0; padding: 0; border-left: 2px solid var(--border); }
.toc a { display: block; padding: .2rem .8rem; color: var(--muted); }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc-3 a { padding-left: 1.6rem; font-size: .85rem; }
.prose { max-width: 820px; }
.prose h2, .prose h3, section[id] { scroll-margin-top: 75px; }
.page-sources { margin-top: 2rem; padding-top: .8rem; border-top: 1px solid var(--border); }
.prose h1 { margin-top: .3rem; }
.prose h2 { margin-top: 1.5rem; }
.prose table { margin: .8rem 0; }
.prose th, .prose td { border: 1px solid var(--border); padding: .35rem .6rem; text-align: left; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 0 0 1rem; padding: .4rem .9rem; border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--muted); }

/* En-tête de tableau toujours visible : impossible dans un bloc qui défile en largeur */
@media (min-width: 1001px) {
  .sticky-head { overflow: visible; }
  .sticky-head .monster-table { overflow: clip; }
  .sticky-head thead th { position: sticky; top: 56px; z-index: 5; }
}

@media (max-width: 1000px) {
  .page-layout { grid-template-columns: minmax(0, 1fr); gap: .8rem; }
  .page-layout .prose { grid-row: auto; }
  .toc { grid-column: 1; grid-row: auto; position: static; max-height: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem 1rem; }
  .toc a { padding-top: .35rem; padding-bottom: .35rem; }
}

@media (max-width: 960px) {
  .menu-btn { display: block; margin-left: auto; }
  header nav, .quick-search { display: none; width: 100%; }
  header.site.is-open nav { display: grid; grid-template-columns: 1fr 1fr; }
  header.site.is-open .quick-search { display: block; margin-left: 0; }
  header.site .wrap { gap: .6rem; }
  .quick-search input { width: 100%; }
}

@media (max-width: 960px) {
  .opt { display: none; }
  .phone-only { display: block; }
  .name-cell { white-space: normal; min-width: 165px; }
}

@media (max-width: 640px) {
  .card { padding: .8rem .9rem; }
  .tabs { gap: 0; }
  .tabs a { padding: .45rem .5rem; font-size: .9rem; }
  .monster-table th, .monster-table td { padding: .45rem .5rem; }
  h1 { font-size: 1.4rem; }
}
