:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1c1d29;
  --muted: #6b6f85;
  --border: #e3e5ee;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --again: #dc2626;
  --hard: #d97706;
  --good: #16a34a;
  --easy: #2563eb;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11121a;
    --surface: #1b1d29;
    --text: #eceef7;
    --muted: #9a9eb5;
    --border: #2c2f40;
    --primary: #818cf8;
    --primary-text: #11121a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
h1 { font-size: 1.45rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.6rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .6rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a {
  text-decoration: none; color: var(--muted); padding: .4rem .65rem; border-radius: 999px; font-size: .92rem;
}
.topbar nav a.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 1.25rem max(1rem, env(safe-area-inset-left)) 3rem; }

.banner { background: #fef3c7; color: #78350f; text-align: center; padding: .5rem 1rem; font-size: .9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 12px; padding: .65rem 1.1rem;
  background: var(--primary); color: var(--primary-text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  min-height: 44px; transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1.5px var(--primary); }
.btn.big { width: 100%; padding: .9rem; font-size: 1.05rem; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: .88rem; text-decoration: underline; cursor: pointer; padding: .5rem 0; }
.link.danger { color: var(--again); }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }

.hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.themes { list-style: none; padding: 0; margin: 0; display: grid; gap: .7rem; }
.theme {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
}
.theme-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.theme-info strong { overflow-wrap: anywhere; }
.theme-info .muted { font-size: .85rem; }
.pills { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .3rem; }
.pill { font-size: .75rem; padding: .15rem .55rem; border-radius: 999px; background: var(--border); color: var(--text); }
.pill.due { background: color-mix(in srgb, var(--hard) 18%, transparent); color: var(--hard); }
.pill.new { background: color-mix(in srgb, var(--easy) 16%, transparent); color: var(--easy); }
.empty, .footnote { text-align: center; }
.footnote { font-size: .8rem; margin-top: 2rem; }

.review { display: flex; flex-direction: column; gap: 1rem; }
.review-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .9rem; }
.back { text-decoration: none; color: var(--muted); font-size: 1.2rem; padding: .25rem .5rem; }
.counter { font-variant-numeric: tabular-nums; color: var(--muted); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 1.5rem 1.25rem; min-height: 46dvh;
  display: flex; flex-direction: column; justify-content: center; gap: 1.25rem;
  box-shadow: 0 8px 30px rgba(20, 20, 50, .06); cursor: pointer;
}
.card-meta { display: flex; gap: .4rem; justify-content: center; }
.question, .answer { white-space: pre-wrap; overflow-wrap: anywhere; text-align: center; }
.question { font-size: 1.35rem; font-weight: 600; }
.answer { font-size: 1.15rem; padding-top: 1.25rem; border-top: 1px dashed var(--border); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.grade {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  border: 0; border-radius: 12px; padding: .65rem .25rem; min-height: 56px;
  font: inherit; font-weight: 600; font-size: .88rem; color: #fff; cursor: pointer;
}
.grade small { font-weight: 400; opacity: .9; font-size: .75rem; }
.grade:active { transform: scale(.96); }
.g0 { background: var(--again); } .g1 { background: var(--hard); }
.g2 { background: var(--good); } .g3 { background: var(--easy); }
.report { align-self: center; }

.done { text-align: center; padding: 3rem 0; display: flex; flex-direction: column; align-items: center; gap: .75rem; }

.form { display: flex; flex-direction: column; gap: 1rem; }
.form label, .panel label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .92rem; }
input, select, textarea {
  font: inherit; font-size: 16px; /* évite le zoom auto sur iOS */
  color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px; padding: .7rem .8rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.panel p { margin: .25rem 0 .75rem; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 12px;
  font-size: .92rem; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 20; max-width: calc(100% - 2rem);
}
