/* ---------- Tokens ---------- */
:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --text: #1d1f24;
  --muted: #6b6f78;
  --border: #e2dccf;
  --accent: #2a4bd7;       /* bleu */
  --accent-soft: #e3e8fb;
  --right: #1f8a55;
  --right-soft: #dff3e8;
  --wrong: #d23a3a;        /* rouge */
  --wrong-soft: #fbe3e1;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(40 30 10 / 0.08);
  --radius: 20px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --surface: #1f2229;
    --surface-2: #2a2e37;
    --text: #eceef2;
    --muted: #9aa0ab;
    --border: #323743;
    --accent: #8ea2ff;
    --accent-soft: #273056;
    --right: #4cc98a;
    --right-soft: #1c3a2c;
    --wrong: #ff7a72;
    --wrong-soft: #452523;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
button { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  max-width: 640px;
  margin: 0 auto;
}

.brand { font-size: 22px; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  text-decoration: none;
  font-weight: 600;
  color: var(--accent);
}
.back span[aria-hidden] { font-size: 26px; line-height: 1; margin-top: -3px; }

.lang {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}
.lang button {
  border: 0;
  background: transparent;
  min-width: 44px;
  min-height: 36px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.lang button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

/* ---------- Home ---------- */
.home {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 40px;
}
.home h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 8vw, 40px);
  font-weight: 600;
}
.tagline { color: var(--muted); margin: 6px 0 24px; }

.set-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }

.set-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.15s ease;
}
.set-item:active { transform: scale(0.98); }

.set-body { flex: 1; min-width: 0; }
.set-sub {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.set-title { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 2px 0 6px; }
.set-desc { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.set-count {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.chevron { font-size: 30px; color: var(--muted); }

/* ---------- Study ---------- */
.study-page { display: flex; flex-direction: column; }

.study {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px 16px;
}

.study-head h1 {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
}

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 12px 0 16px;
  font-size: 14px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  cursor: pointer;
  font-weight: 600;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.2s;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.seg-label { color: var(--muted); margin-right: 4px; }
.seg button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 36px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.seg button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.session { flex: 1; display: flex; flex-direction: column; }

.progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.bar { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.3s ease; }
.counter { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Card + flip */
.card-stage {
  flex: 1;
  display: flex;
  min-height: 300px;
  max-height: 460px;
  perspective: 1400px;
}

.card {
  flex: 1;
  position: relative;
  cursor: pointer;
  border-radius: var(--radius);
  user-select: none;
  -webkit-user-select: none;
}
.card.enter { animation: card-in 0.28s ease-out; }

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.3, 0.7, 0.3, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.instant .card-inner { transition: none; }

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 22px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: auto;
}
.face-a { transform: rotateY(180deg); border-top: 4px solid var(--accent); }

.face-label {
  position: absolute;
  top: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.face-main {
  font-family: var(--serif);
  font-size: clamp(34px, 10vw, 48px);
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.face-a .face-main { font-size: clamp(28px, 8.5vw, 40px); color: var(--accent); }
.face-tr { font-size: 18px; font-weight: 600; }
.face-other { font-size: 15px; color: var(--muted); }
.face-note {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 8px 12px;
  max-width: 34ch;
}

.hint { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0; min-height: 1.5em; }

/* Answer buttons */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.act {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 64px;
  border-radius: 18px;
  border: 2px solid transparent;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s;
}
.act:active:not(:disabled) { transform: scale(0.96); }
.act:disabled { opacity: 0.4; cursor: not-allowed; }
.act-icon { font-size: 24px; line-height: 1; }
.act-wrong { background: var(--wrong-soft); color: var(--wrong); border-color: var(--wrong); }
.act-right { background: var(--right-soft); color: var(--right); border-color: var(--right); }

/* Summary */
.summary { text-align: center; padding: 24px 0; }
.summary-badge { font-size: 56px; }
.summary h2 { font-family: var(--serif); font-size: 30px; margin-top: 8px; outline: none; }
.summary-score { color: var(--muted); font-size: 17px; margin: 8px 0 24px; }
.summary h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }

.missed-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  text-align: left;
  display: grid;
  gap: 8px;
}
.missed-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--wrong);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
}
.missed-list strong { font-family: var(--serif); font-size: 18px; }
.missed-list span { color: var(--muted); font-size: 14px; }

.summary-actions { display: grid; gap: 10px; }
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- Larger screens ---------- */
@media (min-width: 640px) {
  .study-head { text-align: center; }
  .options { justify-content: center; }
  .study-head h1 { font-size: 30px; }
  .summary-actions { grid-template-columns: 1fr 1fr; }
  .summary-actions .btn-ghost { grid-column: 1 / -1; }
}

@media (hover: hover) {
  .set-item:hover { transform: translateY(-2px); }
  .act:hover:not(:disabled) { filter: brightness(0.97); }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner { transition: none; }
  .card.enter { animation: none; }
  .set-item, .act { transition: none; }
}
