/* ==========================================================================
   Last Asylum — mini-site
   Thèmes : [data-theme="light"|"dark"] posé sur <html> par theme.js
   ========================================================================== */

:root {
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --radius: 14px;
  --radius-sm: 8px;
  --gap: clamp(0.75rem, 2vw, 1.25rem);
  --max: 1200px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f1e8;
  --bg-grad: radial-gradient(1200px 500px at 50% -200px, #e9dfc9 0%, transparent 70%);
  --surface: #fffdf8;
  --surface-2: #efe8d9;
  --border: #ddd2bc;
  --text: #1d2230;
  --text-muted: #5c6070;
  --accent: #9a6a10;
  --accent-strong: #7a5208;
  --accent-contrast: #fffdf8;
  --focus: #2f64d6;
  --shadow: 0 1px 2px rgb(60 45 20 / .08), 0 6px 20px rgb(60 45 20 / .08);
  --overlay: rgb(20 18 14 / .92);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10141f;
  --bg-grad: radial-gradient(1200px 500px at 50% -200px, #232c44 0%, transparent 70%);
  --surface: #181e2d;
  --surface-2: #222a3d;
  --border: #2e3850;
  --text: #e8e6e1;
  --text-muted: #a2a8b8;
  --accent: #e3b454;
  --accent-strong: #f0c874;
  --accent-contrast: #1a1406;
  --focus: #8fb3ff;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
  --overlay: rgb(5 7 12 / .95);
}

/* Couleurs par catégorie (pastilles) */
[data-cat="heros"]      { --cat: #c2412d; }
[data-cat="equipement"] { --cat: #b7791f; }
[data-cat="corbeau"]    { --cat: #7b4bc4; }
[data-cat="troupes"]    { --cat: #2b6cb0; }
[data-cat="ralliement"] { --cat: #2f855a; }
[data-cat="guides"]     { --cat: #0f8b8d; }

/* --- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font: 16px/1.55 var(--font-body);
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  transition: background-color .25s var(--ease), color .25s var(--ease);
}

img { max-width: 100%; display: block; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 .5em; }

.container { width: min(100% - 2 * var(--gap), var(--max)); margin-inline: auto; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: .5rem; top: -3rem; z-index: 100;
  padding: .5rem .8rem; background: var(--accent); color: var(--accent-contrast);
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: .5rem; }

/* --- Header / footer ---------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .container {
  display: flex; align-items: center; gap: 1rem; min-height: 60px;
}
.brand {
  display: flex; align-items: center; gap: .55rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem;
  color: var(--text); text-decoration: none; letter-spacing: .01em;
}
.brand svg { width: 28px; height: 28px; color: var(--accent); }
.brand .brand-inner { fill: var(--bg); }
.site-nav { display: flex; gap: .25rem; margin-left: auto; }
.site-nav a {
  padding: .4rem .7rem; border-radius: var(--radius-sm);
  color: var(--text-muted); text-decoration: none; font-weight: 500;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--accent); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: border-color .2s, transform .2s var(--ease);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 20px; height: 20px; }

/* Icône du thème affiché : soleil en clair, lune en sombre */
#theme-toggle .i-sun, #theme-toggle .i-moon { display: none; }
[data-theme="light"] #theme-toggle .i-sun,
[data-theme="dark"] #theme-toggle .i-moon { display: block; }

main { flex: 1; padding-block: clamp(1.5rem, 4vw, 3rem); }

/* Toujours visible, comme le header */
.site-footer {
  position: sticky; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-block: .6rem calc(.6rem + env(safe-area-inset-bottom));
  color: var(--text-muted); font-size: .85rem;
}

/* --- Accueil ------------------------------------------------------------- */

.hero { text-align: center; margin-bottom: clamp(2rem, 5vw, 3.5rem); }
.hero h1 { font-size: clamp(2rem, 6vw, 3.25rem); }
.hero p { color: var(--text-muted); max-width: 42rem; margin: 0 auto; font-size: 1.1rem; }
.eyebrow {
  display: inline-block; margin-bottom: .75rem;
  font-size: .8rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent);
}

.sections {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.section-card {
  position: relative; display: flex; flex-direction: column; gap: .4rem;
  padding: 1.4rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
  transition: transform .25s var(--ease), border-color .2s;
}
a.section-card:hover { transform: translateY(-3px); border-color: var(--accent); color: var(--text); }
.section-card h2 { font-size: 1.35rem; margin: 0; }
.section-card p { margin: 0; color: var(--text-muted); }
.section-card .meta { margin-top: auto; padding-top: .6rem; font-weight: 600; color: var(--accent); font-size: .9rem; }
.section-card.is-soon { opacity: .6; border-style: dashed; box-shadow: none; }

/* --- Page fiches -------------------------------------------------------- */

.page-head { display: flex; flex-wrap: wrap; align-items: end; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); margin: 0; }
.page-head p { margin: .25rem 0 0; color: var(--text-muted); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  margin-bottom: 1.5rem;
}
.search {
  flex: 1 1 220px; max-width: 340px;
  padding: .6rem .9rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.search::placeholder { color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .4rem .85rem; font: inherit; font-size: .92rem; font-weight: 500;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.chip::before {
  content: ""; width: .6rem; height: .6rem; border-radius: 50%;
  background: var(--cat, var(--accent));
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.fiche-grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
  list-style: none; padding: 0; margin: 0;
}
.fiche-card {
  display: flex; flex-direction: column; width: 100%; height: 100%;
  padding: 0; font: inherit; text-align: left; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: zoom-in;
  transition: transform .25s var(--ease), border-color .2s;
}
.fiche-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.fiche-card .thumb {
  aspect-ratio: 480 / 330; overflow: hidden; background: var(--surface-2);
}
.fiche-card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.fiche-card .body { display: flex; flex-direction: column; gap: .3rem; padding: .8rem .95rem 1rem; }
.fiche-card .num {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted);
}
.fiche-card .num::before {
  content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: var(--cat);
}
.fiche-card h2 { font-family: var(--font-body); font-size: 1rem; font-weight: 650; margin: 0; }
.fiche-card p { margin: 0; font-size: .88rem; color: var(--text-muted); }

.empty { padding: 2rem; text-align: center; color: var(--text-muted); }

/* --- Visionneuse -------------------------------------------------------- */

.viewer {
  width: 100vw; max-width: none; height: 100dvh; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: var(--overlay); color: #f1efe9;
}
.viewer::backdrop { background: transparent; }
.viewer[open] { display: grid; grid-template-rows: auto 1fr; }
.viewer-bar {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem max(.75rem, env(safe-area-inset-left));
}
.viewer-title { flex: 1; min-width: 0; margin: 0; font: 600 1rem/1.3 var(--font-body); }
.viewer-title small { display: block; font-weight: 400; opacity: .7; font-size: .8rem; }
.viewer .icon-btn { background: rgb(255 255 255 / .08); border-color: rgb(255 255 255 / .18); color: inherit; }
.viewer .icon-btn:hover { border-color: rgb(255 255 255 / .6); }
.viewer-stage {
  position: relative; overflow: auto; overscroll-behavior: contain;
  display: grid; place-items: start center; padding: 0 .5rem 1rem;
  touch-action: pan-y pinch-zoom;
}
.viewer-stage img {
  width: auto; max-width: min(100%, 1080px); height: auto;
  border-radius: var(--radius-sm); box-shadow: 0 10px 40px rgb(0 0 0 / .5);
}
.viewer-nav {
  position: fixed; top: 50%; translate: 0 -50%;
  width: 48px; height: 48px;
}
.viewer-nav.prev { left: .6rem; }
.viewer-nav.next { right: .6rem; }
@media (max-width: 700px) {
  .viewer-nav { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* Mode « ajusté à l'écran » (par défaut) ; clic sur l'image = taille réelle */
.viewer-stage.is-fit { place-items: center; }
.viewer-stage.is-fit img { max-height: calc(100dvh - 76px); cursor: zoom-in; }
.viewer-stage:not(.is-fit) img { cursor: zoom-out; }

.brand, .site-nav a { white-space: nowrap; }
@media (max-width: 440px) {
  .site-header .container { gap: .5rem; }
  .brand { font-size: 0; }          /* logo seul ; le texte reste lu par les lecteurs d'écran */
  .site-nav a { padding-inline: .5rem; }
}

/* --- Page 404 ----------------------------------------------------------- */

[data-theme="light"] .theme-dark-only,
[data-theme="dark"] .theme-light-only { display: none; }

.not-found-img {
  width: 100%; max-width: 960px; height: auto; margin: 0 auto 1.5rem;
  border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.not-found p { font-size: 1.05rem; }

/* --- Crédits ------------------------------------------------------------ */

.handle { font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
.fiche-card .credit { margin-top: auto; padding-top: .35rem; font-size: .85rem; }
.fiche-card .credit strong { color: var(--accent); font-weight: 600; }
.fiche-card .body { flex: 1; }

.footer-grid { display: flex; align-items: center; justify-content: space-between; gap: 1rem; line-height: 1.4; }
.footer-grid p:last-child { white-space: nowrap; }
.footer-grid p { margin: 0; }

/* --- Page crédits ------------------------------------------------------- */

.narrow { max-width: 760px; }
.section-title { font-size: 1.3rem; margin: 2rem 0 .75rem; }
.credit-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.credit-item {
  padding: 1rem 1.2rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.credit-item p { margin: 0; }
.credit-item .credit-name { font-weight: 650; font-size: 1.05rem; margin-bottom: .3rem; }
.credit-works summary { cursor: pointer; color: var(--text-muted); }
.credit-works ul { margin: .5rem 0 0; padding-left: 1.2rem; columns: 2 280px; column-gap: 1.5rem; }
.credit-works li { break-inside: avoid; padding: .1rem 0; }
.credit-note { margin-top: 1rem; color: var(--text-muted); font-size: .9rem; }

.brand-tag { color: var(--accent); font-family: var(--font-body); font-size: .85em; font-weight: 600; }
/* Le tag d'alliance est sensible à la casse : [Sno] ≠ [SNO] (autre alliance) */
.alliance-tag, .brand-tag { text-transform: none; }
.credit-item.is-unknown { border-style: dashed; box-shadow: none; }
.credit-item.is-unknown .credit-name { color: var(--text-muted); font-style: italic; }
