/* Cahiers du BIA — reading and revision site. */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --raised: #f2efea;
  --text: #23201c;
  --muted: #6d675f;
  --faint: #9a938a;
  --line: #e2ddd5;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --good: #1a7f4b;
  --good-soft: #e3f5ea;
  --bad: #c02b32;
  --bad-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.06);
  --radius: 10px;
  --sidebar-w: 300px;
  --topbar-h: 56px;
  --measure: 68ch;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1b1e24;
  --raised: #232830;
  --text: #e6e3de;
  --muted: #a6a49f;
  --faint: #7d7b76;
  --line: #2e343d;
  --accent: #6aa4ff;
  --accent-soft: #1d2a3f;
  --good: #57c98a;
  --good-soft: #16301f;
  --bad: #ef7c81;
  --bad-soft: #331a1c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
        "Times New Roman", serif;
  -webkit-text-size-adjust: 100%;
}

.skip {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .6rem 1rem;
}
.skip:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 .9rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: .95rem; letter-spacing: .01em;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.brand b { color: var(--accent); }

.icon {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--muted); cursor: pointer;
}
.icon:hover { background: var(--raised); color: var(--text); }
.icon svg {
  width: 19px; height: 19px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#theme .moon { display: none; }
html[data-theme="dark"] #theme .sun { display: none; }
html[data-theme="dark"] #theme .moon { display: block; }

.search {
  position: relative; flex: 1 1 auto; max-width: 460px; margin-left: auto;
}
.search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; fill: none; stroke: var(--faint);
  stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
#q {
  width: 100%; height: 36px;
  padding: 0 2.2rem 0 2rem;
  font: 14px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text); background: var(--raised);
  border: 1px solid transparent; border-radius: 8px;
}
#q:focus {
  outline: none; background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#qhint {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--faint); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px;
}
#q:focus ~ #qhint { display: none; }

.modes { display: flex; gap: .15rem; flex: none; }
.mode {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: .84rem; text-decoration: none;
  color: var(--muted); padding: .42rem .7rem; border-radius: 7px;
}
.mode:hover { background: var(--raised); color: var(--text); }
.mode.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* --------------------------------------------------------------- layout */

.shell { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky; top: var(--topbar-h);
  width: var(--sidebar-w); flex: none;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem .6rem 3rem;
  border-right: 1px solid var(--line);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: .875rem;
}

.cat { margin-bottom: .15rem; }
.cat > summary {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .55rem; border-radius: 8px;
  cursor: pointer; list-style: none; color: var(--text);
  font-weight: 600; font-size: .83rem;
}
.cat > summary::-webkit-details-marker { display: none; }
.cat > summary:hover { background: var(--raised); }
.cat .chev {
  width: 14px; height: 14px; flex: none; stroke: var(--faint);
  fill: none; stroke-width: 2.2; stroke-linecap: round;
  stroke-linejoin: round; transition: transform .15s ease;
}
.cat[open] .chev { transform: rotate(90deg); }
.cat .count {
  margin-left: auto; font-size: .72rem; color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.cat ul { list-style: none; margin: .1rem 0 .5rem; padding: 0 0 0 1.55rem; }
.cat li a {
  display: flex; align-items: center; gap: .5rem;
  padding: .34rem .5rem; border-radius: 7px;
  color: var(--muted); text-decoration: none; line-height: 1.35;
}
.cat li a:hover { background: var(--raised); color: var(--text); }
.cat li a.on {
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--line);
}
a.done .dot { background: var(--good); }

.scrim { display: none; }

.main {
  flex: 1 1 auto; min-width: 0;
  padding: 2.2rem clamp(1rem, 4vw, 3.5rem) 6rem;
  outline: none;
}
.wrap { max-width: var(--measure); margin: 0 auto; }

/* ------------------------------------------------------------- article */

.eyebrow {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: .75rem; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 .5rem;
}
h1 {
  font-size: clamp(1.8rem, 3.6vw, 2.5rem); line-height: 1.15;
  margin: 0 0 .5rem; letter-spacing: -.015em; font-weight: 600;
}
.byline {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: .8rem; color: var(--faint);
  display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center;
  padding-bottom: 1.2rem; margin-bottom: 1.8rem;
  border-bottom: 1px solid var(--line);
}
.byline a { color: var(--faint); }

article h2, article h3, article h4 {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.25; scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
article h2 {
  font-size: 1.32rem; font-weight: 650; margin: 2.6rem 0 .8rem;
  padding-bottom: .35rem; border-bottom: 1px solid var(--line);
  letter-spacing: -.01em;
}
article h3 { font-size: 1.08rem; font-weight: 650; margin: 2rem 0 .6rem; }
article h4 {
  font-size: .93rem; font-weight: 650; margin: 1.5rem 0 .45rem;
  color: var(--muted); letter-spacing: .01em;
}
article p { margin: 0 0 1.05rem; }
article ul { margin: 0 0 1.2rem; padding-left: 1.25rem; }
article li { margin: .3rem 0; }
article li::marker { color: var(--faint); }
.indent-1 { padding-left: 1.5rem; }
.indent-2 { padding-left: 3rem; }
.indent-3 { padding-left: 4.5rem; }
article strong { font-weight: 650; }
article a { color: var(--accent); text-underline-offset: 2px; }
article hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

figure {
  margin: 1.8rem 0; text-align: center;
}
figure img {
  max-width: 100%; height: auto; border-radius: var(--radius);
  background: #fff; cursor: zoom-in; box-shadow: var(--shadow);
}
figcaption {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: .8rem; color: var(--faint); margin-top: .6rem;
}

.twrap { overflow-x: auto; margin: 1.6rem 0; }
table {
  border-collapse: collapse; width: 100%; font-size: .88rem;
  font-family: system-ui, -apple-system, sans-serif;
}
th, td {
  border: 1px solid var(--line); padding: .5rem .65rem;
  text-align: left; vertical-align: top;
}
th, tr:first-child td { background: var(--raised); font-weight: 600; }
td img { max-width: 220px; height: auto; border-radius: 6px; cursor: zoom-in; }

/* ------------------------------------------------------------ page nav */

.pagenav {
  display: flex; gap: 1rem; margin-top: 4rem;
  padding-top: 1.5rem; border-top: 1px solid var(--line);
  font-family: system-ui, -apple-system, sans-serif;
}
.pagenav a {
  flex: 1 1 0; min-width: 0; text-decoration: none;
  padding: .85rem 1rem; border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text); background: var(--surface);
}
.pagenav a:hover { border-color: var(--accent); }
.pagenav .dir { font-size: .72rem; color: var(--faint); display: block; }
.pagenav .ttl {
  font-size: .9rem; font-weight: 600;
  display: block; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.pagenav .next { text-align: right; }

.readbtn {
  display: inline-flex; align-items: center; gap: .5rem;
  font-family: system-ui, -apple-system, sans-serif; font-size: .84rem;
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.readbtn:hover { border-color: var(--accent); }
.readbtn.on {
  background: var(--good-soft); border-color: var(--good); color: var(--good);
  font-weight: 600;
}

/* ---------------------------------------------------------------- quiz */

.quizbox {
  margin: 3rem 0 0; padding: 1.4rem 1.5rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-family: system-ui, -apple-system, sans-serif;
}
.quizbox h2 {
  font-size: 1rem; margin: 0 0 1rem; border: 0; padding: 0;
  display: flex; align-items: center; gap: .55rem;
}
.qtag {
  font-size: .68rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; padding: .18rem .45rem; border-radius: 4px;
  background: var(--raised); color: var(--faint);
}
.qtag.src { background: var(--accent-soft); color: var(--accent); }
.qtag.gen { background: var(--raised); color: var(--faint); }
.qtext .qtag { vertical-align: middle; margin-left: .3rem; }
.q { margin-bottom: 1.6rem; }
.q:last-child { margin-bottom: 0; }
.qtext { font-weight: 600; margin: 0 0 .7rem; font-size: .95rem; }
.choices { display: grid; gap: .4rem; }
.choice {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .6rem .8rem; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; background: var(--bg);
  font-size: .9rem; text-align: left; color: var(--text);
  transition: background .12s, border-color .12s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .key {
  flex: none; width: 20px; height: 20px; border-radius: 5px;
  display: grid; place-items: center; font-size: .7rem; font-weight: 700;
  background: var(--raised); color: var(--muted);
}
.choice.right {
  background: var(--good-soft); border-color: var(--good); color: var(--good);
  font-weight: 600;
}
.choice.right .key { background: var(--good); color: #fff; }
.choice.wrong {
  background: var(--bad-soft); border-color: var(--bad); color: var(--bad);
}
.choice.wrong .key { background: var(--bad); color: #fff; }
.choice:disabled { cursor: default; }
.why {
  margin: .7rem 0 0; padding: .6rem .8rem; font-size: .86rem;
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 6px 6px 0; color: var(--text);
}
.why b { color: var(--accent); }

/* --------------------------------------------------------- quiz runner */

.runner { max-width: 40rem; margin: 0 auto;
  font-family: system-ui, -apple-system, sans-serif; }
.pickers { display: grid; gap: .6rem; margin: 1.6rem 0 2rem; }
.picker {
  display: flex; align-items: center; gap: .8rem; width: 100%;
  padding: .9rem 1.1rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
  cursor: pointer; color: var(--text); font-size: .95rem; text-align: left;
}
.picker:hover { border-color: var(--accent); }
.picker .n {
  margin-left: auto; font-size: .8rem; color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.bar {
  height: 5px; background: var(--raised); border-radius: 99px;
  overflow: hidden; margin: 1rem 0 2rem;
}
.bar > i { display: block; height: 100%; background: var(--accent); }
.runhead {
  display: flex; align-items: center; gap: 1rem;
  font-size: .82rem; color: var(--muted);
}
.runhead .score { margin-left: auto; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: .6rem; margin-top: 1.6rem; }
.btn {
  font: 600 .88rem system-ui, -apple-system, sans-serif;
  padding: .6rem 1.1rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface); color: var(--text);
  border-color: var(--line); }
.btn.ghost:hover { border-color: var(--accent); }

.result { text-align: center; padding: 2rem 0; }
.result .big {
  font-size: 3.2rem; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.result .sub { color: var(--muted); font-size: .9rem; }

/* -------------------------------------------------------------- search */

.hits { max-width: 46rem; margin: 0 auto;
  font-family: system-ui, -apple-system, sans-serif; }
.hit {
  display: block; padding: .9rem 1rem; margin-bottom: .5rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; color: var(--text);
}
.hit:hover { border-color: var(--accent); }
.hit .t { font-weight: 650; font-size: .95rem; }
.hit .c { font-size: .74rem; color: var(--accent); }
.hit .s { font-size: .84rem; color: var(--muted); margin-top: .3rem; }
mark { background: #ffe9a8; color: inherit; border-radius: 3px; padding: 0 2px; }
html[data-theme="dark"] mark { background: #5c4a12; color: #ffe9a8; }

/* --------------------------------------------------------------- stats */

.stats { max-width: 46rem; margin: 0 auto;
  font-family: system-ui, -apple-system, sans-serif; }
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .8rem; margin: 1.5rem 0 2.5rem;
}
.tile {
  padding: 1rem 1.1rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
.tile .v {
  font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.tile .k { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.row {
  display: flex; align-items: center; gap: .9rem; padding: .6rem 0;
  border-bottom: 1px solid var(--line); font-size: .88rem;
}
.row .nm { flex: 1 1 auto; min-width: 0; }
.row .track {
  flex: 0 0 130px; height: 6px; border-radius: 99px;
  background: var(--raised); overflow: hidden;
}
.row .track > i { display: block; height: 100%; background: var(--good); }
.row .pc {
  flex: 0 0 3.2rem; text-align: right; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.empty { color: var(--muted); text-align: center; padding: 3rem 1rem;
  font-family: system-ui, -apple-system, sans-serif; }

/* ------------------------------------------------------------ lightbox */

.lightbox {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.85); display: grid; place-items: center;
  padding: 2rem; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%; max-height: 86vh; border-radius: 6px; background: #fff;
}
.lb-cap { color: #ddd; font: .85rem system-ui, sans-serif; margin: .8rem 0 0;
  text-align: center; }
.lb-close {
  position: absolute; top: 1rem; right: 1.4rem; font-size: 2rem;
  background: none; border: 0; color: #fff; cursor: pointer; line-height: 1;
}

/* -------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  .modes .mode { padding: .42rem .55rem; font-size: .8rem; }
  .brand { display: none; }
}

@media (max-width: 780px) {
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 35;
    background: var(--surface); box-shadow: var(--shadow);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim {
    display: block; position: fixed; inset: var(--topbar-h) 0 0; z-index: 30;
    background: rgba(0,0,0,.35);
  }
  #qhint { display: none; }
  .main { padding: 1.5rem 1.1rem 5rem; }
  .pagenav { flex-direction: column; }
}

@media (min-width: 781px) { #menu { display: none; } }

@media print {
  .topbar, .sidebar, .pagenav, .quizbox { display: none; }
  .main { padding: 0; }
}
