/* Ada — feuille de style unique. Pensée d'abord pour l'iPhone et l'iPad. */

:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --ink: #1f2a2a;
  --muted: #6b716c;
  --line: #e2d9c7;
  --brand: #2f7f86;
  --accent: var(--brand);
  --right: #2f8a4c;
  --right-bg: #e3f3e6;
  --wrong: #c0463a;
  --wrong-bg: #fbe6e2;
  --hard: #b7791f;
  --shadow: 0 1px 2px rgb(60 45 20 / 6%), 0 6px 20px rgb(60 45 20 / 7%);
  --radius: 18px;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --read: "Iowan Old Style", "Charter", "Palatino", Georgia, serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16201f;
    --surface: #1e2a29;
    --surface-2: #263433;
    --ink: #ece6da;
    --muted: #9aa49f;
    --line: #314140;
    --brand: #5fb3ba;
    --right: #6cc58a;
    --right-bg: #1f3a2a;
    --wrong: #ef8a7e;
    --wrong-bg: #42261f;
    --hard: #e0a84a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--ui);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; margin: 0.4rem 0 0.6rem; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.page { max-width: 760px; margin: 0 auto; padding: 0 16px calc(48px + env(safe-area-inset-bottom)); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.flash { background: var(--surface); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); }
.link-quiet { color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; padding: 8px; }

/* ——— Barre du haut ——— */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  max-width: 760px; margin: 0 auto;
}
.topbar nav { display: flex; align-items: center; gap: 14px; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; display: block; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 15%)); }
.brand-mark.big { width: 84px; height: 84px; margin: 0 auto; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background 0.3s; }
.sync-dot[data-state="ok"] { background: var(--right); }
.sync-dot[data-state="syncing"] { background: var(--brand); animation: pulse 1s infinite alternate; }
.sync-dot[data-state="offline"], .sync-dot[data-state="error"] { background: var(--hard); }
@keyframes pulse { to { opacity: 0.3; } }

/* ——— Accueil ——— */
.hello { margin: 12px 0 18px; }
.hello h1 { font-size: 2.2rem; margin-bottom: 0; }
.hello p { margin: 4px 0 0; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px; min-height: 168px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none;
  border-top: 4px solid var(--accent);
  transition: transform 0.12s;
}
.tile:active { transform: scale(0.97); }
.tile-icon { font-size: 1.9rem; }
.tile-title { font-weight: 650; font-size: 1.05rem; line-height: 1.2; }
.tile-due { font-weight: 600; color: var(--muted); font-size: 0.92rem; margin-top: auto; }
.tile-due.is-due { color: var(--accent); }
.tile-foot { color: var(--muted); font-size: 0.82rem; }
.tile-mix { --accent: var(--brand); background: linear-gradient(160deg, var(--surface), color-mix(in srgb, var(--brand) 10%, var(--surface))); }
.meter { display: block; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.4s; }

/* ——— Domaine et sommaire ——— */
.domain-head { margin: 8px 0 14px; }
.domain-icon { font-size: 2.4rem; }
.domain-head h1 { margin: 2px 0 4px; }
.domain-head p { margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 8px; }
.next-lesson { margin: 4px 0 18px; color: var(--muted); }
.next-lesson:empty { display: none; }

.overview-domain { margin: 26px 0; }
.overview-domain > h2 { font-size: 1.35rem; margin-bottom: 10px; }
.overview-domain > h2 a { color: var(--ink); text-decoration: none; }

.chapter {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 6px; margin: 12px 0; border-left: 4px solid var(--accent);
}
.chapter.is-pending { opacity: 0.6; box-shadow: none; border-left-color: var(--line); padding-bottom: 14px; }
.chapter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.chapter-head h3 { margin: 0; font-size: 1.08rem; }
.num { color: var(--accent); font-variant-numeric: tabular-nums; }
.chapter.is-pending .num { color: var(--muted); }
.chapter-summary { margin: 6px 0 4px; color: var(--muted); font-size: 0.92rem; }
.chip { flex-shrink: 0; font-size: 0.78rem; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 2px 9px; border-radius: 99px; }
.chip-quiet { color: var(--muted); background: var(--surface-2); }

.lessons { list-style: none; margin: 8px 0 0; padding: 0; }
.lessons li + li { border-top: 1px solid var(--line); }
.lessons a { display: flex; align-items: center; gap: 12px; padding: 11px 0; color: var(--ink); text-decoration: none; }
.lessons .code { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.2em; font-size: 0.92rem; }
.lessons .lesson-title { flex: 1; }
.lessons .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0; }
.lessons a.is-read .check { background: var(--accent); border-color: var(--accent); }
.lessons a.is-read .check::after { content: "✓"; color: white; font-size: 13px; display: grid; place-items: center; height: 100%; font-weight: 700; }

/* ——— Boutons ——— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-block { width: 100%; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 0.9rem; border-radius: 10px; }
.badge { background: rgb(255 255 255 / 25%); border-radius: 99px; padding: 0 8px; font-size: 0.85rem; }

/* ——— Leçon ——— */
.crumbs { font-size: 0.88rem; color: var(--muted); margin-top: 6px; }
.crumbs a { color: var(--muted); }
.lesson h1 { font-size: 1.75rem; margin-top: 8px; }
.prose { font-family: var(--read); font-size: 1.12rem; line-height: 1.65; }
.prose h2 { font-family: var(--ui); font-size: 1.2rem; margin: 2rem 0 0.5rem; scroll-margin-top: 70px; }
.prose h3 { font-family: var(--ui); font-size: 1.02rem; margin: 1.4rem 0 0.3rem; }
.prose p, .prose ul, .prose ol { margin: 0.6rem 0; }
.prose li { margin: 0.25rem 0; }
.prose strong { font-weight: 650; }
.prose blockquote {
  margin: 1.2rem 0; padding: 12px 16px; border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border-left: 4px solid var(--accent);
  font-family: var(--ui); font-size: 1rem;
}
.prose blockquote p { margin: 0.3rem 0; }
.prose table { border-collapse: collapse; width: 100%; font-family: var(--ui); font-size: 0.95rem; margin: 1rem 0; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; white-space: nowrap; }
.prose th { color: var(--muted); font-weight: 600; }
.prose code { font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.prose svg { max-width: 100%; }
.prose .figure { text-align: center; margin: 1.2rem 0; }
.prose .figure svg { max-height: 150px; }
.figure-row { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin: 1rem 0; }
.figure-row figure { margin: 0; text-align: center; width: 120px; font-family: var(--ui); font-size: 0.85rem; color: var(--muted); }
.figure-row svg { height: 56px; width: 110px; }

.sources { font-size: 0.85rem; color: var(--muted); margin-top: 2rem; }
.challenge { margin: 2rem 0 0; padding: 14px 18px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); border: 2px dashed var(--accent); }
.challenge h2 { font-size: 1.05rem; margin: 0 0 6px; }
.challenge p { margin: 0.3rem 0; }
.lesson-end { margin: 2.4rem 0 1rem; text-align: center; }
.lesson-end .done { color: var(--right); font-weight: 600; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; font-size: 0.92rem; }
.pager a { color: var(--muted); text-decoration: none; max-width: 48%; }
.pager .next { text-align: right; margin-left: auto; }

/* ——— Widgets (portée, clavier, résistance) ——— */
.widget { margin: 1.2rem 0; padding: 14px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); text-align: center; font-family: var(--ui); }
.widget-caption { margin: 8px 0 0; font-size: 1rem; min-height: 1.5em; }
svg.staff { width: 100%; max-width: 420px; height: auto; display: block; margin: 0 auto 6px; overflow: visible; }
.staff-line { stroke: var(--ink); stroke-width: 1; }
.stem { stroke: var(--ink); stroke-width: 1.3; }
.note { fill: var(--ink); }
.note.is-hl { fill: var(--accent); }
.clef, .accidental { fill: var(--ink); font-family: "Bravura", "Noto Music", "Apple Symbols", "Segoe UI Symbol", serif; }
.staff-label { font-size: 12px; fill: var(--muted); font-family: var(--ui); }
svg.piano { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; touch-action: manipulation; }
.key { cursor: pointer; transition: fill 0.1s; }
.key.white { fill: #fffefb; stroke: #9b958a; stroke-width: 1; }
.key.black { fill: #23201c; stroke: #23201c; }
.key.is-hl { fill: var(--accent); }
.key.is-pressed { fill: color-mix(in srgb, var(--accent) 45%, #fff); }
.key.is-right { fill: var(--right); }
.key.is-wrong { fill: var(--wrong); }
.key-label { font-size: 10px; fill: #6b665c; pointer-events: none; font-family: var(--ui); }
.key-label.on-black { fill: #fff; }
svg.resistor { width: 100%; max-width: 320px; height: auto; display: block; margin: 0 auto; }
.resistor-body { fill: #d9c49a; stroke: #a8916a; }
.lead { stroke: #8f8f8f; stroke-width: 3; }
.band { cursor: pointer; }
.swatch { display: inline-block; width: 1em; height: 1em; border-radius: 4px; vertical-align: -0.12em; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 20%); }

/* ——— Séance ——— */
.page-review { max-width: 640px; }
.review { display: flex; flex-direction: column; min-height: calc(100dvh - 70px); }
.review-head { display: flex; align-items: center; gap: 12px; padding: 4px 0 8px; }
.review-head .close { text-decoration: none; color: var(--muted); font-size: 1.2rem; padding: 6px 8px 6px 0; }
.review-title { flex: 1; font-weight: 600; }
.review-count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.progress { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.stage { flex: 1; display: flex; flex-direction: column; }

.card-meta { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 20px; min-height: 180px;
  display: flex; flex-direction: column; justify-content: center;
}
.card .prose { font-size: 1.2rem; }
.card .prose p:first-child { margin-top: 0; }
.card .prose p:last-child { margin-bottom: 0; }
.card hr { border: 0; border-top: 1px dashed var(--line); margin: 16px 0; }
.card-back { color: var(--ink); }
.card svg.figure-inline { display: block; height: 70px; width: 140px; margin: 0 auto; }
.cloze { display: inline-block; min-width: 3em; padding: 0 8px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 650; text-align: center; }
.cloze.is-revealed { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.prompt p { margin: 0.4rem 0; }
.q-big { font-size: 1.2rem; }
.prompt svg { margin: 8px auto; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 12px; }
.feedback p { margin: 0.3rem 0; }
.feedback.is-right { background: var(--right-bg); }
.feedback.is-wrong { background: var(--wrong-bg); }
.feedback .verdict { font-weight: 700; }
.feedback.is-right .verdict { color: var(--right); }
.feedback.is-wrong .verdict { color: var(--wrong); }
.feedback svg.piano { max-width: 360px; margin-top: 6px; }

.answer-bar { margin-top: auto; padding: 18px 0 calc(8px + env(safe-area-inset-bottom)); position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 18px); }
.ratings { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }
.rating { min-height: 58px; border-radius: 14px; border: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 650; color: white; }
.rating small { font-weight: 500; opacity: 0.85; font-size: 0.78rem; }
.rating.again { background: var(--wrong); }
.rating.hard { background: var(--hard); }
.rating.good { background: var(--right); }
.rating.easy { background: var(--brand); }
.reread { display: block; margin: 8px auto 0; font-size: 0.92rem; }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.choices.is-many { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
.choice { min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 1.05rem; cursor: pointer; padding: 4px 6px; }
.choice.is-right { background: var(--right); color: white; border-color: var(--right); }
.choice.is-wrong { background: var(--wrong); color: white; border-color: var(--wrong); }
.number-input { display: flex; gap: 8px; align-items: center; }
.number-input input { flex: 1; min-width: 0; min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; font-size: 1.25rem; color: var(--ink); }
.number-input .unit { font-weight: 600; color: var(--muted); }
.piano-input { background: var(--surface); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }

.empty { text-align: center; margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 30px 0; }
.empty h2 { margin: 0; }
.empty p { margin: 0; }
.big-emoji { font-size: 3rem; }

.sheet { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 35%); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.2s; }
.sheet-panel { background: var(--bg); width: 100%; max-width: 680px; max-height: 80dvh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); animation: rise 0.25s; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); } }

/* ——— Connexion ——— */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login h1 { margin-top: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
.stack input[type=email], .stack input[type=password] { min-height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; font-size: 1rem; color: var(--ink); }
