:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #efe8db;
  --text: #1f1b16;
  --muted: #6b6259;
  --accent: #8a1c2b;
  --accent-2: #c79a2e;
  --border: #ddd3c2;
  --ok: #1e8449;
  --ko: #b03a2e;
  --shadow: 0 2px 10px rgba(40, 25, 10, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f; --surface: #1f1b17; --surface-2: #2a241e; --text: #efe8dc; --muted: #a99d8f;
    --accent: #d9576a; --accent-2: #e2b850; --border: #3a3129; --ok: #4cc27a; --ko: #e5675a;
    --shadow: 0 2px 10px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #15120f; --surface: #1f1b17; --surface-2: #2a241e; --text: #efe8dc; --muted: #a99d8f;
  --accent: #d9576a; --accent-2: #e2b850; --border: #3a3129; --ok: #4cc27a; --ko: #e5675a;
  --shadow: 0 2px 10px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55; font-size: 16px;
}
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: Georgia, "Times New Roman", serif; line-height: 1.2; }
h1 { font-size: 1.9rem; margin: .2em 0 .4em; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; margin-top: 1.4em; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: .92em; }
blockquote { border-left: 4px solid var(--accent-2); margin: 1em 0; padding: .4em 1em; background: var(--surface-2); border-radius: 0 8px 8px 0; font-style: italic; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--accent); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; box-shadow: var(--shadow);
}
.topbar .logo { font-family: Georgia, serif; font-weight: bold; font-size: 1.2rem; color: #fff; text-decoration: none; white-space: nowrap; }
.topbar .xp { margin-left: auto; font-size: .9rem; background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.topbar button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 8px; padding: 4px 9px; cursor: pointer; font-size: 1rem; }
.layout { display: flex; max-width: 1200px; margin: 0 auto; }
nav.side {
  width: 230px; flex-shrink: 0; padding: 16px 10px; position: sticky; top: 52px; align-self: flex-start;
  max-height: calc(100vh - 52px); overflow-y: auto;
}
nav.side a {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px;
}
nav.side a:hover { background: var(--surface-2); }
nav.side a.active { background: var(--accent); color: #fff; }
nav.side .sep { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 12px 4px; }
main { flex: 1; min-width: 0; padding: 20px 20px 60px; }
#menuBtn { display: none; }

@media (max-width: 820px) {
  #menuBtn { display: inline-block; }
  nav.side {
    position: fixed; left: 0; top: 52px; bottom: 0; background: var(--surface); z-index: 9; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow); max-height: none;
  }
  nav.side.open { transform: none; }
  main { padding: 16px; }
  h1 { font-size: 1.5rem; }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tile { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); transition: transform .12s; position: relative; }
.tile:hover { transform: translateY(-2px); border-color: var(--accent-2); }
.tile .ico { font-size: 1.8rem; }
.tile h3 { margin: .3em 0 .2em; font-size: 1.05rem; }
.tile p { margin: 0; color: var(--muted); font-size: .9rem; }
.tile .badge { position: absolute; top: 10px; right: 10px; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok); color: #fff; }
.btn { display: inline-block; background: var(--accent); color: #fff; border: none; padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 1rem; text-decoration: none; font-family: inherit; }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 6px 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.encadre { background: var(--surface-2); border-left: 4px solid var(--accent-2); border-radius: 0 10px 10px 0; padding: 4px 16px; margin: 1em 0; }
.encadre.important { border-left-color: var(--accent); }
.encadre h4 { margin: .7em 0 .3em; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { border-bottom: 1px solid var(--border); padding: 7px 8px; text-align: left; vertical-align: top; }
.table th { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
input[type=search], input[type=text], select {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1rem; font-family: inherit; max-width: 100%;
}
input[type=search] { width: 100%; }
.chip { display: inline-block; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .85rem; margin: 2px; color: var(--text); }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* swatch */
.swatch { display: inline-flex; width: 46px; height: 22px; border-radius: 5px; overflow: hidden; border: 1px solid rgba(0,0,0,.25); vertical-align: middle; }
.swatch span { flex: 1; }
.swatch.velours { box-shadow: inset 0 0 6px rgba(0,0,0,.45); }
.swatch.satin { background-image: linear-gradient(120deg, rgba(255,255,255,.35), rgba(255,255,255,0) 40%, rgba(255,255,255,.25) 70%, rgba(255,255,255,0)); }

/* insignes */
.insigne-card { display: flex; gap: 12px; align-items: flex-start; }
.insigne-card .emo { font-size: 1.9rem; width: 46px; text-align: center; flex-shrink: 0; }
.insigne-card h4 { margin: 0 0 .2em; font-family: inherit; font-size: 1rem; }
.insigne-card p { margin: 0; font-size: .9rem; }
.cat-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; border: 1px solid rgba(0,0,0,.2); }

/* quiz */
.quiz-q { font-size: 1.15rem; font-weight: 600; margin-bottom: 12px; }
.choices { display: grid; gap: 8px; }
.choice { text-align: left; background: var(--surface); border: 2px solid var(--border); padding: 11px 14px; border-radius: 10px; cursor: pointer; font-size: 1rem; color: var(--text); font-family: inherit; }
.choice:hover:not(:disabled) { border-color: var(--accent-2); }
.choice.good { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--surface)); }
.choice.bad { border-color: var(--ko); background: color-mix(in srgb, var(--ko) 15%, var(--surface)); }
.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); }
.big-emoji { font-size: 3.2rem; text-align: center; }

/* flashcards */
.flashcard { perspective: 1000px; height: 260px; cursor: pointer; margin: 0 auto 16px; max-width: 520px; }
.flashcard .inner { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.flashcard.flipped .inner { transform: rotateY(180deg); }
.flashcard .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; text-align: center; border: 1px solid var(--border); box-shadow: var(--shadow); background: var(--surface); }
.flashcard .back { transform: rotateY(180deg); background: var(--surface-2); }
.flashcard .face .big { font-size: 3rem; }
.flashcard .face .title { font-size: 1.25rem; font-weight: 600; margin-top: 8px; }
.leitner { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.leitner div { text-align: center; font-size: .8rem; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; min-width: 60px; }
.leitner b { display: block; font-size: 1.2rem; }

/* timeline */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 0; bottom: 0; width: 3px; background: var(--accent-2); border-radius: 3px; }
.tl-item { position: relative; margin-bottom: 18px; }
.tl-item::before { content: ""; position: absolute; left: -24px; top: 6px; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.tl-item .date { font-weight: bold; color: var(--accent); font-size: .9rem; }
.tl-item h4 { margin: .1em 0 .2em; }
.tl-item p { margin: 0; }

/* atelier */
.atelier { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1000px) { .atelier { grid-template-columns: 1fr; } }
.atelier label { display: block; font-size: .85rem; color: var(--muted); margin-top: 10px; margin-bottom: 3px; }
.atelier select, .atelier input[type=text] { width: 100%; }
.svg-wrap svg { width: 100%; height: auto; display: block; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; max-height: 220px; overflow-y: auto; padding: 6px; background: var(--surface-2); border-radius: 10px; }
.palette button { font-size: 1.4rem; width: 42px; height: 42px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.palette button:hover { border-color: var(--accent); }
.lecture { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; font-size: .95rem; }
.lecture li { margin-bottom: 4px; }

.hero { background: linear-gradient(135deg, var(--accent), #4a0f18); color: #fff; border-radius: 16px; padding: 26px; margin-bottom: 18px; box-shadow: var(--shadow); }
.hero h1 { color: #fff; margin-top: 0; }
.hero p { opacity: .92; max-width: 640px; }
.hero .btn { background: var(--accent-2); color: #1f1b16; font-weight: 600; }
.stat { text-align: center; }
.stat b { display: block; font-size: 1.8rem; font-family: Georgia, serif; color: var(--accent); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); }
.hidden { display: none !important; }
footer.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }
@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 10px 12px; }
  .topbar .logo { font-size: 1rem; }
  .topbar .xp { overflow: hidden; text-overflow: ellipsis; min-width: 0; font-size: .8rem; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card.stat b { font-size: 1.4rem; }
}
.grid > * { min-width: 0; }
.insigne-card > div { min-width: 0; overflow-wrap: anywhere; }
