/* ==========================================================================
   CIVIC WEB — "NEON RÉPUBLIQUE"
   Glassmorphism + tricolor aurora glow on obsidian void.
   Mobile-first, responsive. Theme via [data-theme] on <html>.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Dark (default signature) */
  --blue: #4D7CFF;
  --blue-soft: #9DBBFF;
  --red: #FF4D6D;
  --gold: #FFC53D;
  --green: #17E08F;
  --violet: #A78BFA;
  --cyan: #22D3EE;

  --bg: #05060A;
  --bg-top: #070912;
  --surface: #0E1420;
  --ink: #EAF1FF;
  --ink-soft: #8B99C4;
  --border: rgba(77, 124, 255, .30);
  --track: rgba(77, 124, 255, .16);

  /* Derived / glass */
  --surface-trans: rgba(14, 20, 32, .60);
  --surface-2: rgba(14, 20, 32, .86);
  --glow: .55;
  --shadow: 0 18px 48px rgba(0, 0, 0, .55);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, .40);

  --radius: 20px;
  --radius-sm: 14px;
  --radius-lg: 28px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --font-head: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --ease: cubic-bezier(.22, 1, .36, 1);
}

[data-theme="light"] {
  --blue: #2F5BFF;
  --blue-soft: #6D8CFF;
  --red: #FF3B5C;
  --gold: #FFB020;
  --green: #00C979;
  --violet: #8B5CF6;
  --cyan: #12C2E9;

  --bg: #EEF2FF;
  --bg-top: #DCE4FF;
  --surface: rgba(255, 255, 255, .90);
  --ink: #0B1230;
  --ink-soft: #5A6B9E;
  --border: rgba(47, 91, 255, .28);
  --track: rgba(47, 91, 255, .12);

  --surface-trans: rgba(255, 255, 255, .68);
  --surface-2: rgba(255, 255, 255, .92);
  --glow: .16;
  --shadow: 0 18px 48px rgba(47, 91, 255, .18);
  --shadow-soft: 0 8px 24px rgba(47, 91, 255, .12);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--blue-soft); text-decoration: none; }
h1, h2, h3, h4 { font-family: var(--font-head); letter-spacing: -.01em; line-height: 1.15; }

/* ---------- Aurora background ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: linear-gradient(180deg, var(--bg-top), var(--bg) 60%);
}.bg::before, .bg::after, .bg .blob3 {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: var(--glow);
  will-change: transform;
}
.bg::before {           /* blue */
  width: 60vmax; height: 60vmax;
  top: -22vmax; left: -18vmax;
  background: radial-gradient(circle, var(--blue) 0%, transparent 68%);
  animation: drift1 26s var(--ease) infinite alternate;
}
.bg::after {            /* red */
  width: 52vmax; height: 52vmax;
  top: 8vmax; right: -22vmax;
  background: radial-gradient(circle, var(--red) 0%, transparent 68%);
  animation: drift2 32s var(--ease) infinite alternate;
}
.bg .blob3 {            /* violet */
  width: 58vmax; height: 58vmax;
  bottom: -26vmax; left: 4vmax;
  background: radial-gradient(circle, var(--violet) 0%, transparent 68%);
  animation: drift3 38s var(--ease) infinite alternate;
}
@keyframes drift1 { to { transform: translate3d(6vmax, 5vmax, 0) scale(1.12); } }
@keyframes drift2 { to { transform: translate3d(-7vmax, 7vmax, 0) scale(1.08); } }
@keyframes drift3 { to { transform: translate3d(5vmax, -6vmax, 0) scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .bg::before, .bg::after, .bg .blob3 { animation: none; } }

/* ---------- Layout shell ---------- */
.app {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-t)) 16px calc(96px + var(--safe-b));
  min-height: 100vh;
  position: relative;
}
.screen { animation: fade-up .38s var(--ease); }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Glass components ---------- */
.glass {
  background: var(--surface-trans);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
}
.card {
  background: var(--surface-trans);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 44px;
}
.topbar .title { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-trans);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 1.15rem;
  transition: transform .18s var(--ease), background .18s var(--ease);
  flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.93); }
.icon-btn:hover { background: var(--surface-2); }

.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-trans);
  font-weight: 600;
  transition: transform .18s var(--ease);
}
.back-btn:active { transform: scale(.95); }

/* ---------- Hero (home) ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px;
  margin-bottom: 18px;
  background: var(--surface-trans);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 120% at 100% 0%, rgba(77,124,255,.18), transparent 55%);
  pointer-events: none;
}
.hero .greet { font-size: .92rem; color: var(--ink-soft); font-weight: 600; }
.hero h1 { font-size: 1.55rem; margin: 2px 0 6px; }
.hero .sub { color: var(--ink-soft); font-size: .9rem; }

/* Circular progress */
.circle {
  position: relative;
  width: 104px; height: 104px;
  flex: 0 0 auto;
}
.circle svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.circle .track { stroke: var(--track); }
.circle .val { stroke: url(#grad); stroke-linecap: round; transition: stroke-dashoffset .8s var(--ease); }
.circle .pct {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.4rem;
}

/* ---------- Section ---------- */
.section-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.12rem;
  margin: 22px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title .sub { font-size: .8rem; color: var(--ink-soft); font-weight: 500; }

/* ---------- Tile grid ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  position: relative;
  text-align: left;
  padding: 18px 16px;
  min-height: 116px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-trans);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.tile:active { transform: scale(.97); }.tile .ic {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.25rem;
  margin-bottom: 10px;
}
.tile .lab { font-family: var(--font-head); font-weight: 700; font-size: 1rem; }
.tile .hint { font-size: .78rem; color: var(--ink-soft); margin-top: 2px; }
.tile .glowbar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; opacity: .9; }

.tile.blue   .ic { background: rgba(77,124,255,.16);  color: var(--blue); }
.tile.blue   .glowbar { background: var(--blue); }
.tile.red    .ic { background: rgba(255,77,109,.16);  color: var(--red); }
.tile.red    .glowbar { background: var(--red); }
.tile.gold   .ic { background: rgba(255,197,61,.16);  color: var(--gold); }
.tile.gold   .glowbar { background: var(--gold); }
.tile.green  .ic { background: rgba(23,224,143,.16);  color: var(--green); }
.tile.green  .glowbar { background: var(--green); }
.tile.violet .ic { background: rgba(167,139,250,.16); color: var(--violet); }
.tile.violet .glowbar { background: var(--violet); }
.tile.cyan   .ic { background: rgba(34,211,238,.16);  color: var(--cyan); }
.tile.cyan   .glowbar { background: var(--cyan); }

/* Compact mode grid (launcher) */
.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.mode {
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-trans);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
  text-align: left;
  min-height: 96px;
  display: flex; flex-direction: column; gap: 4px;
  transition: transform .18s var(--ease);
}
.mode:active { transform: scale(.97); }
.mode .em { font-size: 1.4rem; }
.mode .lab { font-family: var(--font-head); font-weight: 700; }
.mode .hint { font-size: .78rem; color: var(--ink-soft); }
.mode.big { grid-column: 1 / -1; }

.cat-list { display: grid; gap: 10px; }
.cat {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-trans);
  text-align: left;
  min-height: 56px;
  transition: transform .18s var(--ease);
}
.cat:active { transform: scale(.98); }
.cat .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.cat .nm { flex: 1; font-weight: 600; }
.cat .cnt { font-size: .78rem; color: var(--ink-soft); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border-radius: 14px;
  font-family: var(--font-head); font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface-trans);
  transition: transform .16s var(--ease), filter .16s var(--ease);
}
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(135deg, var(--blue), var(--violet)); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger  { background: linear-gradient(135deg, var(--red), var(--gold)); color: #fff; border-color: transparent; }
.btn.ghost   { background: transparent; }
.btn.block   { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row .btn { flex: 1; }

/* ---------- Quiz ---------- */
.quiz-head { margin-bottom: 14px; }
.quiz-head .meta { display: flex; align-items: center; justify-content: space-between; font-size: .82rem; color: var(--ink-soft); margin-bottom: 8px; font-weight: 600; }
.progress { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .35s var(--ease); }

.qcard { padding: 22px; margin-bottom: 16px; }
.qcard .cat-tag {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: 4px 10px; border-radius: 99px;
  background: rgba(77,124,255,.16); color: var(--blue-soft);
  margin-bottom: 12px;
}
.qcard .qtext { font-family: var(--font-head); font-size: 1.16rem; font-weight: 600; line-height: 1.35; }

.opts { display: grid; gap: 10px; margin-top: 4px; }
.opt {
  display: flex; align-items: center; gap: 12px;
  text-align: left;
  padding: 15px 16px;
  min-height: 56px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-trans);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform .16s var(--ease), background .2s, border-color .2s;
  line-height: 1.35;
}
.opt .key {
  width: 28px; height: 28px; flex: 0 0 auto;
  border-radius: 9px; display: grid; place-items: center;
  background: var(--track); font-weight: 700; font-size: .82rem;
  font-family: var(--font-head);
}
.opt:not(.locked):active { transform: scale(.98); }
.opt.correct { border-color: var(--green); background: rgba(23,224,143,.12); box-shadow: 0 0 0 1px var(--green) inset; }
.opt.correct .key { background: var(--green); color: #04231a; }
.opt.wrong { border-color: var(--red); background: rgba(255,77,109,.12); box-shadow: 0 0 0 1px var(--red) inset; }
.opt.wrong .key { background: var(--red); color: #fff; }
.opt.locked { cursor: default; }
.opt .mark { margin-left: auto; font-weight: 700; }

.vf { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.vf .btn { min-height: 96px; font-size: 1.25rem; flex-direction: column; gap: 6px; }
.vf .btn .em { font-size: 1.6rem; }
.vf .btn.vrai { }
.vf .btn.faux { }
.vf .btn.correct { background: rgba(23,224,143,.16); border-color: var(--green); }
.vf .btn.wrong   { background: rgba(255,77,109,.16); border-color: var(--red); }

.answer-reveal {
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: rgba(23,224,143,.08);
  animation: fade-up .3s var(--ease);
}
.answer-reveal .lbl { font-size: .74rem; font-weight: 700; letter-spacing: .04em; color: var(--green); margin-bottom: 6px; text-transform: uppercase; }
.answer-reveal .txt { font-size: 1rem; }

.feedback { margin-top: 14px; font-weight: 700; text-align: center; font-family: var(--font-head); }
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--red); }

/* ---------- Result ---------- */
.result-hero { text-align: center; padding: 30px 20px; margin-bottom: 16px; }
.result-hero .big { font-family: var(--font-head); font-weight: 700; font-size: 3.4rem; line-height: 1; }
.result-hero .verdict { font-family: var(--font-head); font-weight: 700; font-size: 1.25rem; margin-top: 10px; }
.result-hero .verdict.pass { color: var(--green); }
.result-hero .verdict.fail { color: var(--red); }
.result-hero .note { color: var(--ink-soft); margin-top: 6px; font-size: .9rem; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { text-align: center; padding: 14px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-trans); }
.stat .n { font-family: var(--font-head); font-weight: 700; font-size: 1.35rem; }
.stat .l { font-size: .72rem; color: var(--ink-soft); }
.stat.ok .n { color: var(--green); }
.stat.no .n { color: var(--red); }

/* ---------- Flashcards ---------- */
.flash-tools { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.select {
  appearance: none;
  min-height: 44px; padding: 0 36px 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-trans)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%238B99C4' stroke-width='1.6'/></svg>")
    no-repeat right 12px center;
  color: var(--ink);
  font-weight: 600;
  flex: 1;
  min-width: 150px;
}
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-trans); font-weight: 600;
}
.toggle.on { border-color: var(--cyan); color: var(--cyan); background: rgba(34,211,238,.10); }

.flip-wrap { perspective: 1400px; margin: 8px 0 18px; }
.flip {
  position: relative;
  width: 100%;
  min-height: 300px;
  transform-style: preserve-3d;
  transition: transform .55s var(--ease);
  cursor: pointer;
}
.flip.flipped { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-trans);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 26px; text-align: center; gap: 12px;
}
.face .tag { font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--blue-soft); }
.face .ftext { font-family: var(--font-head); font-size: 1.2rem; font-weight: 600; line-height: 1.35; }
.face .hu { position: absolute; bottom: 14px; left: 0; right: 0; font-size: .74rem; color: var(--ink-soft); }
.face.back { transform: rotateY(180deg); }
.face.back .ftext { font-weight: 500; }
.face.back .tag { color: var(--green); }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding: 8px 0 8px; }
.timeline::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; transform: translateX(-50%);
  background: linear-gradient(180deg, transparent, var(--border) 6%, var(--border) 94%, transparent);
}
.trow { position: relative; display: grid; grid-template-columns: 1fr 44px 1fr; align-items: center; margin: 10px 0; }
.trow .node {
  grid-column: 2;
  width: 16px; height: 16px; border-radius: 50%;
  justify-self: center;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 2px currentColor, 0 0 16px currentColor;
  background: currentColor;
}
.trow .desc { grid-column: 1; text-align: right; padding-right: 12px; }
.trow .yr   { grid-column: 3; text-align: left; padding-left: 12px; }
.trow .yr .y { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; }
.trow .yr .p { font-size: .74rem; color: var(--ink-soft); }
.trow button.evt { text-align: inherit; width: 100%; }
.trow .desc .t { font-family: var(--font-head); font-weight: 700; font-size: .96rem; }
.trow .desc .d { font-size: .8rem; color: var(--ink-soft); margin-top: 2px; }
.trow .figs { font-size: .72rem; color: var(--ink-soft); margin-top: 4px; }
.era-head { text-align: center; margin: 22px 0 8px; }
.era-head span {
  display: inline-block; padding: 4px 14px; border-radius: 99px;
  border: 1px solid currentColor; font-family: var(--font-head);
  font-weight: 700; font-size: .8rem; letter-spacing: .03em;
}
/* era colors */
.era-Antiquité { color: var(--gold); }
.era-MoyenÂge, .era-Moyen\ \Âge { color: var(--violet); }
.era-Renaissance { color: var(--cyan); }
.era-AncienRégime, .era-Ancien\ \Régime { color: var(--blue); }
.era-RévolutionEmpire, .era-Révolution\ \&\ Empire { color: var(--red); }
.era-XIXesiècle, .era-XIXe\ siècle { color: var(--green); }
.era-XXesiècle, .era-XXe\ siècle { color: var(--blue-soft); }
.era-VeRépublique, .era-Ve\ République { color: var(--ink); }
.era { --c: var(--blue); }

/* ---------- Detail (history) ---------- */
.detail-hero { padding: 22px; margin-bottom: 16px; }
.detail-hero .era-tag { font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.detail-hero h2 { font-size: 1.45rem; margin: 8px 0; }
.detail-hero .meta { color: var(--ink-soft); font-size: .88rem; }
.detail-hero .figs { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: .76rem; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--border); background: var(--track); font-weight: 600; }
.para { margin-bottom: 14px; color: var(--ink); opacity: .92; }
.para:first-letter { font-family: var(--font-head); font-weight: 700; }

/* ---------- Progress ---------- */
.score-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-trans);
  margin-bottom: 10px;
}
.score-row .pct {
  width: 56px; height: 56px; flex: 0 0 auto; border-radius: 16px;
  display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 1.05rem;
}
.score-row .pct.pass { background: rgba(23,224,143,.14); color: var(--green); }
.score-row .pct.fail { background: rgba(255,77,109,.14); color: var(--red); }
.score-row .info { flex: 1; }
.score-row .info .d { font-weight: 700; }
.score-row .info .s { font-size: .78rem; color: var(--ink-soft); }

.mastery { margin-bottom: 14px; }
.mastery .top { display: flex; justify-content: space-between; font-size: .86rem; font-weight: 600; margin-bottom: 6px; }
.mastery .top .v { color: var(--ink-soft); }
.mbar { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.mbar > i { display: block; height: 100%; border-radius: 99px; transition: width .6s var(--ease); }

/* ---------- Empty / misc ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty .em { font-size: 2.4rem; margin-bottom: 10px; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--blue); animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 6px 10px calc(6px + var(--safe-b));
  display: flex; gap: 4px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.nav-inner { max-width: 760px; margin: 0 auto; width: 100%; display: flex; gap: 4px; }
.nav a {
  flex: 1; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 12px; color: var(--ink-soft); font-size: .68rem; font-weight: 700;
  transition: color .18s, background .18s;
}
.nav a .em { font-size: 1.15rem; line-height: 1; }
.nav a.active { color: var(--blue-soft); background: rgba(77,124,255,.12); }
[data-theme="light"] .nav a.active { color: var(--blue); }

/* Version badge */
.ver-badge {
  position: fixed; top: calc(10px + var(--safe-t)); right: 12px; z-index: 30;
  font-family: var(--font-head); font-size: .68rem; font-weight: 700;
  padding: 4px 10px; border-radius: 99px;
  background: rgba(14,20,32,.78); color: #EAF1FF;
  border: 1px solid var(--border);
  pointer-events: none;
}
[data-theme="light"] .ver-badge { background: rgba(11,18,48,.82); color: #fff; }

/* ---------- Responsive ---------- */
@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .hero h1 { font-size: 1.8rem; }
}
@media (max-width: 380px) {
  .tiles, .modes, .vf { grid-template-columns: 1fr; }
  .trow .desc .d { display: none; }
}

/* ==========================================================================
   MOTION LAYER — ambient canvas, reveal, tilt, ripple, confetti
   ========================================================================== */
#bgfx {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: -1; pointer-events: none; display: block;
}
[data-theme="light"] .bg { opacity: .55; }
[data-theme="light"] #bgfx { opacity: .9; }

/* scroll reveal (cascading cards) */
.reveal {
  opacity: 0; transform: translateY(16px) scale(.985);
  transition: opacity .58s var(--ease), transform .58s var(--ease);
}
.reveal.in { opacity: 1; transform: none; }

/* card / tile tilt + pointer shine */
.card.tilt, .tile.tilt {
  transform: perspective(900px) rotateX(var(--rx, 0)) rotateY(var(--ry, 0));
  transition: transform .18s ease, border-color .2s, box-shadow .25s;
  will-change: transform;
}
.card.tilt::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 0;
  background: radial-gradient(320px 200px at var(--mx, 50%) var(--my, 0%), rgba(77,124,255,.16), transparent 62%);
  opacity: 0; transition: opacity .25s;
}
.card.tilt:hover::after { opacity: 1; }
.card.tilt:hover, .tile.tilt:hover {
  transform: perspective(900px) rotateX(var(--rx, 0)) rotateY(var(--ry, 0)) translateY(-6px) scale(1.012);
}
.tile { transition: transform .2s var(--ease), box-shadow .25s, border-color .2s; }
.tile:hover { transform: translateY(-4px) scale(1.015); box-shadow: var(--shadow-soft); }

/* ripple */
.btn, .tile, .mode, .cat, .opt, .toggle, .icon-btn { position: relative; overflow: hidden; }
.ripple {
  position: absolute; border-radius: 50%; transform: scale(0); pointer-events: none; z-index: 1;
  background: rgba(255,255,255,.35);
  animation: rip .6s ease-out forwards;
}
[data-theme="light"] .ripple { background: rgba(47,91,255,.22); }
@keyframes rip { to { transform: scale(2.4); opacity: 0; } }

/* livelier micro-interactions */
.btn { transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .25s, filter .2s; }
.opt { transition: transform .16s cubic-bezier(.34,1.56,.64,1), background .16s, border-color .16s; }
.opt:not(.locked):hover { transform: translateX(4px); }
.mode, .cat { transition: transform .18s cubic-bezier(.34,1.56,.64,1), border-color .2s, background .2s; }
.mode:hover, .cat:hover { transform: translateY(-3px); }
.toggle:hover { transform: translateY(-1px); }

/* entrance animations */
.hero h1, .hero .greet, .hero .sub { animation: rise .6s var(--ease) both; }
.hero .sub { animation-delay: .07s; }
.hero .circle { animation: rise .6s .12s var(--ease) both; }
.section-title { animation: rise .5s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.opt.correct, .opt.wrong { animation: pop .32s cubic-bezier(.34,1.56,.64,1); }
.vf .btn.correct, .vf .btn.wrong { animation: pop .32s cubic-bezier(.34,1.56,.64,1); }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.035); } 100% { transform: scale(1); } }
.face { transition: transform .55s var(--ease); }
.answer-reveal, .feedback { animation: rise .35s var(--ease) both; }
.result-hero .big { animation: pop .5s var(--ease) both; }
.score-row, .stat, .mastery { transition: transform .18s var(--ease), border-color .2s; }
.score-row:hover, .stat:hover { transform: translateY(-2px); }

/* streak flame flourish */
.streak-flame {
  position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 80;
  pointer-events: none; font-size: 3.4rem; opacity: 0; animation: flame 1s ease-out;
}
@keyframes flame {
  0% { opacity: 0; transform: translateX(-50%) scale(.5); }
  30% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1 !important; transform: none !important; }
  #bgfx { display: none; }
  .hero h1, .hero .greet, .hero .sub, .hero .circle, .section-title,
  .opt.correct, .opt.wrong, .result-hero .big, .answer-reveal, .feedback { animation: none; }
  .card.tilt, .tile.tilt { transform: none !important; }
}
