:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --border: #e6ebf2;
  --text: #0f1b3d;
  --muted: #5b6b86;
  --track: #e8edf4;
  --primary: #1f6fef;
  --primary-hover: #155ad0;
  --accent: #14956f;
  --radius: 16px;

  --n5-bg: #fde6ea; --n5-bar: #ee6b78; --n5-text: #c21d33; --n5-title: #5c0f1f;
  --n4-bg: #fdf1dd; --n4-bar: #fbb415; --n4-text: #b8650a; --n4-title: #5a3a06;
  --n3-bg: #e5f6ea; --n3-bar: #1fbb86; --n3-text: #14956f; --n3-title: #0f1b3d;
  --n2-bg: #e3eefd; --n2-bar: #2f7ff0; --n2-text: #1f6fef; --n2-title: #0f1b3d;
  --n1-bg: #efe8fb; --n1-bar: #8b4ff0; --n1-text: #7c2fe0; --n1-title: #0f1b3d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 20px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}
.page-header h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: -0.01em;
}

/* ---------- Grille des 9 widgets ---------- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.widget {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 6px 20px rgba(15, 27, 61, 0.04);
  min-height: 380px;
}

.widget-placeholder {
  display: grid;
  place-items: center;
  background: transparent;
  border: 2px dashed var(--border);
  box-shadow: none;
  color: #9aa7bc;
  font-size: 0.95rem;
}

/* ---------- Widget Grammaire ---------- */
.widget-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.widget-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #e8f1fe;
  color: var(--primary);
}
.widget-icon svg { width: 26px; height: 26px; }
.widget-icon--vocab {
  background: #fdf1dd;
  color: #b8650a;
  font-family: "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
}
a.widget-icon { transition: background 0.15s, transform 0.15s; }
a.widget-icon:hover { background: #d6e6fd; transform: translateY(-1px); }
a.widget-icon { text-decoration: none; }
a.widget-icon--vocab:hover { background: #fbe3bb; }

.widget-title { flex: 1; min-width: 0; }
.widget-title h2 { margin: 0; font-size: 1.3rem; font-weight: 700; }
.widget-title p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }

.btn-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(31, 111, 239, 0.25);
}
.btn-icon:hover { background: var(--primary-hover); }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--track); color: var(--text); }

/* Niveaux : une ligne par niveau */
.levels {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.level {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 52px 40px;
  align-items: center;
  gap: 10px;
  margin: -4px -8px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: inherit;
  text-decoration: none;
}
a.level:hover { background: #f3f6fb; }
.level-tag {
  padding: 3px 0;
  border-radius: 6px;
  text-align: center;
  font-weight: 700;
  background: var(--level-bg);
  color: var(--level-title);
}
.level-mastered { color: var(--muted); text-align: right; white-space: nowrap; }
.level-mastered strong { color: var(--text); font-weight: 600; }
.level-percent { text-align: right; font-weight: 600; color: var(--level-text); }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  min-width: 8px;
  border-radius: 999px;
  background: var(--level-bar);
  transition: width 0.4s ease;
}
.bar-fill.empty { min-width: 0; }

[data-level="N5"], [data-tone="red"] { --level-bg: var(--n5-bg); --level-bar: var(--n5-bar); --level-text: var(--n5-text); --level-title: var(--n5-title); }
[data-level="N4"], [data-tone="amber"] { --level-bg: var(--n4-bg); --level-bar: var(--n4-bar); --level-text: var(--n4-text); --level-title: var(--n4-title); }
[data-level="N3"], [data-tone="green"] { --level-bg: var(--n3-bg); --level-bar: var(--n3-bar); --level-text: var(--n3-text); --level-title: var(--n3-title); }
[data-level="N2"], [data-tone="blue"] { --level-bg: var(--n2-bg); --level-bar: var(--n2-bar); --level-text: var(--n2-text); --level-title: var(--n2-title); }
[data-level="N1"], [data-tone="purple"] { --level-bg: var(--n1-bg); --level-bar: var(--n1-bar); --level-text: var(--n1-text); --level-title: var(--n1-title); }

/* Lignes à libellé long (widget Vocabulaire) */
.levels--wide .level { grid-template-columns: 104px minmax(0, 1fr) 52px 40px; }
.levels--wide .level-tag { padding: 3px 6px; font-size: 0.78rem; white-space: nowrap; }

/* Progression totale */
.total {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfd;
}

.donut { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut circle { fill: none; stroke-width: 12; }
.donut-track { stroke: var(--track); }
.donut-value {
  stroke: #3bb77e;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}
.donut-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 700;
}

.total-stats {
  flex: 1;
  margin: 0;
  display: grid;
  gap: 8px;
}
.total-stats div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.total-stats dt { color: var(--muted); font-size: 0.85rem; }
.total-stats dd { margin: 0; font-size: 1.05rem; font-weight: 700; }
.total-stats dd.accent { color: var(--accent); }

[hidden] { display: none !important; }

/* ---------- Modale d'ajout de règle ---------- */
.rule-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(1000px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(15, 27, 61, 0.2);
}
.rule-dialog::backdrop { background: rgba(15, 27, 61, 0.4); }

.rule-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}
.dialog-header h2 { margin: 0; font-size: 1.35rem; }

.btn-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.btn-close:hover { background: var(--track); color: var(--text); }

.dialog-body {
  display: grid;
  gap: 20px;
  padding: 24px 28px;
  overflow-y: auto;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.field { display: grid; gap: 8px; }
.field-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2b2f38;
}
.field > input[type="text"],
.field > input[type="number"],
.field > select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #d9dde3;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
.field > input[type="text"]:focus,
.field > input[type="number"]:focus,
.field > select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 239, 0.12);
}
.field > input[lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif; }

.checkbox { display: flex; align-items: center; gap: 8px; color: var(--muted); }

.field-optional { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }

/* Exemples d'une règle (ajout / modification) */
.example-list { display: grid; gap: 10px; }
.example-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
  gap: 10px;
  align-items: center;
}
.example-row input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #d9dde3;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
.example-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 239, 0.12);
}
.example-row input[lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif; }
.btn-add-example { justify-self: start; margin-top: 10px; }

/* Exemples d'une règle (lecture) */
.rule-examples-view { margin-top: 16px; }
.examples-title { margin: 0 0 12px; font-size: 1.1rem; font-weight: 800; }
.examples-view { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.examples-view li { display: grid; gap: 2px; padding-left: 12px; border-left: 3px solid var(--border); }
.examples-view .example-ja { font-family: "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif; font-size: 1.05rem; }
.examples-view .example-fr { color: var(--muted); }

/* Modale compacte (vocabulaire) */
.rule-dialog.dialog-small { width: min(620px, calc(100vw - 32px)); }

.vocab-preview {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 12px;
  background: #f7f9fc;
}
.vocab-preview ul { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.vocab-preview li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.95rem; }
.preview-track {
  min-width: 104px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--level-bg);
  color: var(--level-title);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}
.preview-arrow { color: var(--muted); }
.preview-empty { color: #b0b8c6; }
/* Avertissement « doublon possible » (fenêtre d'ajout de vocabulaire) */
.duplicate-warning {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid #f5d28a;
  border-radius: 12px;
  background: #fff8e8;
  color: #6b4a06;
}
.duplicate-warning.is-blocking { border-color: #e8a93a; box-shadow: 0 0 0 3px rgba(232, 169, 58, 0.18); }
.duplicate-title { margin: 0; font-weight: 700; }
.duplicate-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 0.92rem; }
.duplicate-list strong { color: #1a1a1a; }
.duplicate-list [lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; color: #1a1a1a; }
.duplicate-reasons { display: block; color: #8a6a24; font-size: 0.8rem; }
.duplicate-more { color: #8a6a24; font-style: italic; }
.duplicate-confirm { justify-self: start; }

.preview-kanji { color: var(--muted); font-size: 0.85rem; }
.preview-kanji::before { content: "（"; }
.preview-kanji::after { content: "）"; }
.field > select:disabled { background: #f3f5f8; color: #9aa7bc; cursor: not-allowed; }
.vocab-preview [lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 28px;
  border-top: 1px solid var(--border);
}
.form-error { margin: 0 auto 0 0; color: #c21d33; font-size: 0.9rem; }

/* Bouton « + Mot de vocabulaire » en bas des fenêtres de règle */
.add-vocab-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}
.add-vocab-inline ~ .form-error { margin: 0; }
.vocab-added-note { color: var(--accent); font-size: 0.85rem; font-weight: 600; }

/* ---------- Éditeur de texte enrichi ---------- */
.rte {
  border: 1px solid #d9dde3;
  border-radius: 10px;
  background: #fff;
}
.rte:focus-within { border-color: #b9c9e4; }

.rte-toolbar,
.rte-table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  font-family: "Raleway", "Segoe UI", sans-serif;
}
.rte-toolbar {
  background: #f7f7f7;
  border-bottom: 1px solid #e3e3e3;
  border-radius: 10px 10px 0 0;
}
.rte-table-tools {
  background: #eef4fe;
  border-bottom: 1px solid #d6e2f5;
  font-size: 0.8rem;
  color: var(--muted);
}

.rte-btn {
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  font: 700 14px "Raleway", "Segoe UI", sans-serif;
  cursor: pointer;
}
.rte-btn:hover { background: #f0f4fb; border-color: #c5d3ea; }
.rte-btn.is-active { background: #e3edfd; border-color: var(--primary); color: var(--primary); }
.rte-table-tools .rte-btn { height: 30px; font-size: 12px; font-weight: 600; }
.rte-btn.rte-danger { color: #c21d33; }

.rte-sep { width: 1px; height: 24px; margin: 0 4px; background: #dcdcdc; }

.rte-font,
.rte-size {
  height: 36px;
  padding: 0 10px;
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  font: 14px "Raleway", "Segoe UI", sans-serif;
}
.rte-font { width: 190px; }
.rte-size { width: 72px; }

.rte-color {
  width: 36px;
  height: 36px;
  padding: 3px;
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.rte-color::-webkit-color-swatch-wrapper { padding: 0; }
.rte-color::-webkit-color-swatch { border: none; border-radius: 4px; }
.rte-color::-moz-color-swatch { border: none; border-radius: 4px; }

.rte-table-wrap { position: relative; }
.rte-table-picker {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 10;
  padding: 10px;
  background: #fff;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 27, 61, 0.15);
}
.rte-grid { display: grid; grid-template-columns: repeat(8, 18px); gap: 3px; }
.rte-grid span {
  width: 18px;
  height: 18px;
  border: 1px solid #d0d7e2;
  border-radius: 3px;
  cursor: pointer;
}
.rte-grid span.is-on { background: #d6e6fd; border-color: var(--primary); }
.rte-grid-label { margin-top: 8px; text-align: center; font-size: 12px; color: var(--muted); }

.rte-content {
  min-height: 280px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 18px 24px;
  outline: none;
  font-family: "Raleway", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: #1a1a1a;
}
.rte-content:empty::before {
  content: attr(data-placeholder);
  color: #7a7a7a;
  pointer-events: none;
}

/* Contenu d'une règle (éditeur et, plus tard, affichage) */
.rich-content p { margin: 0 0 0.6em; }
.rich-content ul,
.rich-content ol { margin: 0 0 0.6em; padding-left: 1.6em; }
.rich-content ul { list-style: disc; }
.rich-content ul ul { list-style: circle; }
.rich-content ul ul ul { list-style: square; }
.rich-content ul ul ul ul { list-style: disc; }
.rich-content ol { list-style: decimal; }
.rich-content ol ol { list-style: lower-alpha; }
.rich-content ol ol ol { list-style: lower-roman; }
.rich-content ul ul, .rich-content ol ol,
.rich-content ul ol, .rich-content ol ul { margin-bottom: 0; }
.rich-content table { border-collapse: collapse; margin: 0.8em 0; }
.rich-content td,
.rich-content th {
  min-width: 80px;
  padding: 6px 10px;
  border: 1px solid #c9d1dc;
  vertical-align: top;
}
.rich-content img { max-width: 100%; height: auto; border-radius: 6px; }
.rich-content hr { margin: 1em 0; border: none; border-top: 1px solid #d5dbe4; }

/* ---------- Quiz de vocabulaire ---------- */
.btn-quiz {
  height: 36px;
  padding: 0 14px;
  border: 1px solid #f3d4a4;
  border-radius: 10px;
  background: #fdf1dd;
  color: #9a5a06;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn-quiz:hover { background: #fbe3bb; }

.quiz-fieldset { margin: 0; padding: 0; border: none; }
.quiz-fieldset legend { margin-bottom: 8px; padding: 0; }
.quiz-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.quiz-option input,
.quiz-chip input { position: absolute; opacity: 0; pointer-events: none; }
.quiz-option span {
  display: grid;
  gap: 2px;
  height: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid #d9dde3;
  border-radius: 10px;
  cursor: pointer;
}
.quiz-option small { color: var(--muted); font-size: 0.78rem; }
.quiz-option input:checked + span { border-color: var(--primary); background: #eef4fe; box-shadow: 0 0 0 1px var(--primary); }
.quiz-option input:focus-visible + span,
.quiz-chip input:focus-visible + span { outline: 3px solid rgba(31, 111, 239, 0.35); }

.quiz-levels { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-chip span {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid #d9dde3;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.quiz-chip input:checked + span { border-color: var(--text); background: var(--text); color: #fff; }

.quiz-count input { max-width: 120px; }
.quiz-checks { display: grid; gap: 8px; }
.quiz-checks .checkbox { color: var(--text); }
.quiz-availability { margin: 0; color: var(--muted); font-size: 0.9rem; }

.quiz-run .dialog-header { gap: 16px; }
.quiz-progress { flex: 1; display: grid; gap: 6px; }
.quiz-progress-text { font-weight: 700; }
.quiz-progress .bar { height: 6px; }
.quiz-progress-fill { background: var(--primary); min-width: 0; }

.quiz-card-body { padding-block: 32px; }
.quiz-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  min-height: 240px;
  align-content: center;
  padding: 28px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fafbfd;
  text-align: center;
}
.quiz-card-mode { color: var(--muted); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.quiz-question { margin: 0; font-size: 2.2rem; font-weight: 800; line-height: 1.25; color: var(--text); }
.quiz-question[lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; font-size: 2.6rem; font-weight: 700; }
.quiz-answer { display: grid; gap: 4px; padding-top: 14px; border-top: 1px dashed #d5dbe4; }
.quiz-answer-main { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.quiz-answer-secondary { font-size: 1.05rem; color: var(--muted); }
.quiz-answer [lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; }
.quiz-reveal { font-weight: 600; }

/* Quiz de traduction : contenu de la règle au survol de son nom. */
.rule-peek-trigger { cursor: help; text-decoration: underline dotted; text-underline-offset: 4px; }
.rule-peek {
  position: fixed;
  inset: auto;
  margin: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: 50vh;
  overflow-y: auto;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(15, 27, 61, 0.18);
  font-size: 0.92rem;
  line-height: 1.6;
  text-align: left;
}
kbd {
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font: inherit;
  font-size: 0.7rem;
  opacity: 0.6;
}

.quiz-rating { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 16px 28px 22px; }
.quiz-rate {
  padding: 14px 10px;
  border: none;
  border-radius: 12px;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.quiz-rate:hover { filter: brightness(1.07); }
.quiz-rate:active { transform: translateY(1px); }
.quiz-rate[data-rate="non"] { background: var(--mastery-non); }
.quiz-rate[data-rate="difficile"] { background: var(--mastery-difficile); }
.quiz-rate[data-rate="maitrise"] { background: var(--mastery-maitrise); }

.quiz-summary { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.quiz-summary li { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; font-size: 1.05rem; }
.quiz-summary strong { font-size: 1.3rem; }
.quiz-summary-total { padding-top: 10px; border-top: 1px solid var(--border); }
.quiz-summary-note { margin: 16px 0 0; font-size: 0.85rem; }
.quiz-list-link { margin-right: auto; color: var(--text); font-weight: 600; text-decoration: none; }

/* Quiz de grammaire : deux modes, et la fiche complète dans la réponse. */
.btn-quiz--grammar { border-color: #c9dbf8; background: #e8f1fe; color: var(--primary); }
.btn-quiz--grammar:hover { background: #d6e6fd; }
.quiz-options--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grammar-quiz-dialog { width: min(760px, calc(100vw - 32px)); }
.quiz-card-badges { justify-content: center; margin: 0; }
.quiz-question--rule { font-size: 1.7rem; }
.quiz-question--rule[lang="ja"] { font-size: 1.7rem; }
.grammar-quiz-dialog .quiz-answer { width: 100%; justify-items: center; }
.quiz-rule-content {
  width: 100%;
  max-height: 38vh;
  overflow-y: auto;
  margin-top: 10px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 0.92rem;
  line-height: 1.6;
  text-align: left;
}

@media (max-width: 560px) {
  .quiz-options, .quiz-options--two, .quiz-rating { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Widget Kana ---------- */
/* Le titre est un lien étiré sur tout le widget ; le bouton reste cliquable au-dessus. */
.widget--link { position: relative; display: flex; flex-direction: column; transition: border-color 0.15s, box-shadow 0.15s; }
.widget--link:hover { border-color: #c5d3ea; box-shadow: 0 8px 24px rgba(15, 27, 61, 0.08); }
.widget-link { color: inherit; text-decoration: none; }
.widget-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.widget-link:focus-visible { outline: none; }
.widget--link:has(.widget-link:focus-visible) { outline: 3px solid rgba(31, 111, 239, 0.35); }

.widget-icon--kana {
  background: #e5f6ea;
  color: #14956f;
  font-family: "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.kana-daily {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfd;
}
.kana-daily-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.kana-daily-char {
  font-family: "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 5.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}
.kana-daily-answer { margin: 0; color: var(--muted); font-size: 1.05rem; }
.kana-daily-answer strong { color: var(--accent); font-size: 1.4rem; }
.kana-daily-btn { position: relative; z-index: 1; font-weight: 600; }

/* ---------- Widget Traductions ---------- */
.widget--translations { display: flex; flex-direction: column; }
.widget-icon--translations {
  background: #f3ecfd;
  color: #7a3fd1;
  font-family: "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
}
.translations-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 20px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfd;
  text-align: center;
}
.translations-stats { margin: 0; color: var(--muted); line-height: 1.5; }
.translations-stats strong { color: var(--text); }
.btn-quiz--translations {
  height: 48px;
  padding: 0 36px;
  border-color: #dccbf7;
  background: #f3ecfd;
  color: #7a3fd1;
  font-size: 1.1rem;
}
.btn-quiz--translations:hover { background: #e8dbfb; }
.quiz-question--sentence { font-size: 1.6rem; }
.quiz-question--sentence[lang="ja"] { font-size: 1.8rem; }
.quiz-answer-main--sentence { font-size: 1.3rem; }

/* ---------- Page « Kana » ---------- */
.kana-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.kana-controls .filter-toggle { height: 34px; }

.kana-script { margin-top: 32px; }
.kana-script-title {
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--n3-bar);
  font-size: 1.5rem;
  font-weight: 800;
}
.kana-script[data-script="katakana"] .kana-script-title { border-bottom-color: var(--n2-bar); }
.kana-script-title [lang="ja"] { margin-left: 10px; color: var(--muted); font-family: "Noto Sans JP", sans-serif; font-weight: 400; }

.kana-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  align-items: start;
}
.kana-block { margin: 0; overflow-x: auto; }
.kana-block figcaption {
  margin-bottom: 10px;
  color: #5a5a5a;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.kana-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 4px;
  table-layout: fixed;
}
.kana-table th { color: #9a9a9a; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.kana-table td {
  height: 64px;
  padding: 4px;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  background: #fff;
  text-align: center;
  vertical-align: middle;
}
.kana-table td.kana-empty { border: none; background: transparent; }
.kana-char {
  display: block;
  font-family: "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 1.6rem;
  line-height: 1.2;
  color: #1a1a1a;
}
.kana-table--yoon .kana-char { font-size: 1.35rem; }
.kana-romaji { display: block; color: #8a8a8a; font-size: 0.8rem; }
.hide-romaji .kana-romaji { visibility: hidden; }

/* Couleur de maîtrise des cases (quiz de kana) */
.kana-table td[data-mastery="non"] { border-color: var(--mastery-non); background: #fdecec; box-shadow: inset 0 0 0 1px var(--mastery-non); }
.kana-table td[data-mastery="difficile"] { border-color: var(--mastery-difficile); background: #fef3e0; box-shadow: inset 0 0 0 1px var(--mastery-difficile); }
.kana-table td[data-mastery="maitrise"] { border-color: var(--mastery-maitrise); background: #e6f6ee; box-shadow: inset 0 0 0 1px var(--mastery-maitrise); }

.kana-legend { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 16px; color: var(--muted); font-size: 0.9rem; }
.kana-legend-item { display: inline-flex; align-items: center; gap: 8px; }
.kana-legend-item strong { color: var(--text); }

/* Quiz de kana */
.btn-quiz--kana { position: relative; z-index: 1; border-color: #b9e3cc; background: #e5f6ea; color: #14956f; }
.btn-quiz--kana:hover { background: #d3efdd; }
.quiz-question--kana { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; font-size: 4.5rem !important; }
.quiz-answer--kana { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; font-size: 3.5rem; }

/* ---------- Page « Grammaire » (liste des règles) ---------- */
.rules-page { background: #f6f6f6; font-family: "Raleway", "Noto Sans JP", "Segoe UI", sans-serif; }
.rules-page .page { max-width: 1200px; }

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.back-link:hover { color: var(--primary); }

.rules-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.rules-header h1 { margin: 0; font-size: 2rem; font-weight: 800; }
.rules-header p { margin: 4px 0 0; }

.level-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.rules-header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.export-pdf-link {
  display: inline-block;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}
.export-pdf-link:hover { background: #dfe5ee; }
.export-pdf-link.is-disabled { opacity: 0.5; pointer-events: none; }
.level-tab {
  padding: 6px 14px;
  border: 1px solid #e3e3e3;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
}
.level-tab:hover { border-color: #c5d3ea; }
.level-tab[aria-current="page"] { background: var(--text); border-color: var(--text); color: #fff; }

.level-section { margin-top: 36px; }
.level-title {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--level-bar);
  font-size: 1.5rem;
  font-weight: 800;
}
.level-title a { color: var(--level-text); text-decoration: none; }
.level-title a:hover { text-decoration: underline; }
.level-count { color: var(--muted); font-size: 0.95rem; font-weight: 600; }

.type-section { margin-top: 28px; }
.type-title {
  margin: 0 0 14px;
  color: #5a5a5a;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.rule-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border: 1px solid #e3e3e3;
  border-radius: 14px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.rule-card { position: relative; }
.rule-card:hover { border-color: #d0d0d0; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05); }
.rule-card:has(.rule-link:focus-visible) { outline: 3px solid rgba(31, 111, 239, 0.35); }

/* Le lien du titre couvre toute la carte ; la case à cocher reste cliquable au-dessus. */
.rule-link { color: inherit; text-decoration: none; outline: none; }
.rule-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.rule-card .rule-check { position: relative; z-index: 1; }
.rule-card.is-mastered { border-color: #bfe5d4; background: #f7fcf9; }
.rule-card-body { flex: 1; min-width: 0; }
/* Règle sans exemple : petit rond rouge dans le coin. */
.no-examples-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1; /* au-dessus du lien de la carte, pour afficher l'info-bulle */
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e5484d;
}

.rule-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 800;
}
.badge-level { background: var(--level-bg); color: var(--level-text); }
.badge-type { background: #efefef; color: #555; }
.badge-mastery-non { background: #fde6e7; color: #c8262b; }
.badge-mastery-difficile { background: #fdf0d9; color: #a86203; }

.rule-title { margin: 0; font-size: 1.15rem; font-weight: 800; color: #1a1a1a; }
.rule-subtitle {
  margin: 6px 0 0;
  color: #666;
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 0.95rem;
}

.rule-check {
  appearance: none;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid #cfcfcf;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.rule-check:hover { border-color: #9aa7bc; }
.rule-check:checked { background: var(--accent); border-color: var(--accent); }
.rule-check:checked::after {
  content: "";
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.rule-check:focus-visible { outline: 3px solid rgba(31, 111, 239, 0.35); outline-offset: 2px; }

/* ---------- Page « Vocabulaire » ---------- */
/* Recherche + groupe Export sur la même ligne, puis Filtres et Maîtrise en dessous */
.vocab-search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.vocab-search-row .search-input { flex: 1 1 280px; width: auto; margin-top: 0; }
.vocab-search-row .toolbar-group { flex: 0 0 auto; }
.vocab-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
.toolbar-group {
  flex: 1 1 auto;
  padding: 10px 14px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
}
.toolbar-group-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.toolbar-group-body { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar-group-body > .vocab-filter,
.toolbar-group-body > .filter-toggle,
.toolbar-group-body > button { height: 38px; }
.toolbar-group-body > button { font-weight: 600; white-space: nowrap; }
/* Barre de recherche (pages Grammaire et Vocabulaire) */
.search-input {
  width: 100%;
  margin-top: 16px;
  padding: 12px 16px;
  border: 1px solid #e3e3e3;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 239, 0.12); }
.search-count { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }

.vocab-filter {
  padding: 0 14px;
  border: 1px solid #e3e3e3;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
}
.vocab-count { margin: 12px 0 8px; color: var(--muted); font-size: 0.9rem; }
.filter-toggle {
  padding: 0 14px;
  border: 1px solid #e3e3e3;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.filter-toggle:hover { border-color: #b9c9e4; }
.filter-toggle[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }

/* Puces de filtre par maîtrise (page Vocabulaire) */
.mastery-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mastery-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid #e3e3e3;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.mastery-chip:hover { border-color: #b9c9e4; }
.mastery-chip[aria-pressed="true"] { border-color: var(--text); background: #eef1f6; box-shadow: inset 0 0 0 1px var(--text); }
.mastery-chip-count { color: var(--muted); font-weight: 700; }
.mastery-square--chip { width: 16px; height: 16px; font-size: 10px; border-radius: 4px; }
.mastery-chip-reset {
  border: none;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.mastery-chip-reset:hover { text-decoration: underline; }

.vocab-table-wrap {
  overflow-x: auto;
  border: 1px solid #e3e3e3;
  border-radius: 14px;
  background: #fff;
}
.vocab-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.vocab-table th {
  position: sticky;
  top: 0;
  padding: 12px 14px;
  background: #fafafa;
  border-bottom: 1px solid #e3e3e3;
  color: #5a5a5a;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.vocab-table td {
  padding: 8px 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.vocab-table tbody tr:last-child td { border-bottom: none; }
.vocab-table tbody tr:hover { background: #fafcff; }
.vocab-table [lang="ja"] { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; }
.vocab-table .cell-fr { font-weight: 600; color: #1a1a1a; }
.vocab-table .cell-kanji { color: #555; }
.vocab-table .cell-ja,
.vocab-table .cell-kanji { min-width: 10em; }
.vocab-table .col-mastery { width: 80px; text-align: center; }

/* Carré de maîtrise : gris (jamais évalué), rouge, orange, vert */
:root { --mastery-none: #e3e6eb; --mastery-non: #e5484d; --mastery-difficile: #f59e0b; --mastery-maitrise: #22a06b; }
/* Aspect de case à cocher : vide et bordée (jamais évalué), puis remplie de la couleur
   avec un symbole : ✕ non maîtrisé, ! difficile, ✓ maîtrisé. */
.mastery-square {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  box-sizing: border-box;
  border: 2px solid #cfd5de;
  border-radius: 6px;
  background: #fff;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
}
.mastery-square[data-mastery="non"] { border-color: var(--mastery-non); background: var(--mastery-non); }
.mastery-square[data-mastery="difficile"] { border-color: var(--mastery-difficile); background: var(--mastery-difficile); }
.mastery-square[data-mastery="maitrise"] { border-color: var(--mastery-maitrise); background: var(--mastery-maitrise); }
.mastery-square[data-mastery="non"]::after { content: "✕"; }
.mastery-square[data-mastery="difficile"]::after { content: "!"; }
.mastery-square[data-mastery="maitrise"]::after { content: "✓"; }

/* Petite pastille après le kanji : couleur seule, sans symbole. */
.mastery-square--small { width: 12px; height: 12px; margin-left: 8px; border-width: 1.5px; border-radius: 3px; }
.mastery-square--small::after { content: none !important; }
.vocab-table .col-level { width: 92px; }
.vocab-table .col-anki { width: 60px; text-align: center; }
.vocab-table .col-anki .rule-check { margin: 0 auto; }
.rule-check.anki-check:checked { background: var(--primary); border-color: var(--primary); }
.vocab-table .col-actions { width: 1%; white-space: nowrap; text-align: right; }

.level-select {
  width: 72px;
  padding: 5px 8px;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.level-select[data-level="N5"],
.level-select[data-level="N4"],
.level-select[data-level="N3"],
.level-select[data-level="N2"],
.level-select[data-level="N1"] {
  border-color: transparent;
  background: var(--level-bg);
  color: var(--level-text);
}
.level-select:disabled { background: #f5f5f5; color: #c0c0c0; cursor: not-allowed; }

.btn-small {
  padding: 6px 12px;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-small + .btn-small { margin-left: 6px; }
.btn-small:hover { border-color: #b9c9e4; background: #f3f7fd; }
.btn-small-danger { color: #b3162c; }
.btn-small-danger:hover { border-color: #f3b7c1; background: #fdf0f2; }

.edit-note { margin: 0; font-size: 0.85rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Page « Règle » (détail / édition) ---------- */
.detail-page { max-width: 960px; }

.btn-danger {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  background: #fde6ea;
  color: #b3162c;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: #fbd0d8; }
.detail-page .btn-primary,
.detail-page .btn-secondary,
.confirm-dialog .btn-secondary { font-weight: 600; }

.detail-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}
.detail-heading { flex: 1; min-width: 260px; }
.detail-title { margin: 0; font-size: 2rem; font-weight: 800; color: #1a1a1a; }
.detail-subtitle {
  margin: 6px 0 0;
  color: #666;
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 1.1rem;
}

.detail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.mastered-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 6px;
  font-weight: 600;
  cursor: pointer;
}

.detail-content {
  padding: 28px 32px;
  border: 1px solid #e3e3e3;
  border-radius: 14px;
  background: #fff;
  font-size: 15px;
  line-height: 1.7;
  color: #1a1a1a;
  overflow-x: auto;
}

.detail-form {
  display: grid;
  gap: 20px;
  padding: 28px 32px;
  border: 1px solid #e3e3e3;
  border-radius: 14px;
  background: #fff;
}
.detail-form-title { margin: 0; font-size: 1.5rem; font-weight: 800; }
.detail-form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.detail-form .rte-content { max-height: none; }

.confirm-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 24px 28px;
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(15, 27, 61, 0.2);
}
.confirm-dialog::backdrop { background: rgba(15, 27, 61, 0.4); }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 1.3rem; }
.confirm-dialog p { margin: 0; color: var(--muted); line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; }
.backup-actions { display: flex; gap: 8px; }
.backup-actions .btn-secondary { font-weight: 600; }
.backup-actions .btn-secondary:hover { background: #dfe5ee; }
.backup-actions .btn-secondary:disabled { opacity: 0.6; cursor: wait; }
#restore-error { margin-top: 12px; color: #c21d33; }

.empty-state {
  margin: 20px 0 0;
  padding: 24px;
  border: 2px dashed #e0e0e0;
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .dashboard { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .dashboard { grid-template-columns: minmax(0, 1fr); }
  .widget { min-height: 240px; }
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .example-row { grid-template-columns: minmax(0, 1fr) 36px; }
  .example-row .example-fr { grid-row: 2; }
  .rule-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-content, .detail-form { padding: 20px 18px; }
  .detail-title { font-size: 1.6rem; }
  .dialog-header, .dialog-body, .dialog-actions { padding-left: 18px; padding-right: 18px; }
}

/* ---------- Kanji (widget, fenêtre d'ajout, quiz et page) ---------- */
.widget-icon--kanji {
  background: #fde6ea;
  color: #c21d33;
  font-family: "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
}
a.widget-icon--kanji:hover { background: #fbd3da; }
.btn-quiz--kanji { border-color: #f6c2cb; background: #fde6ea; color: #c21d33; }
.btn-quiz--kanji:hover { background: #fbd3da; }

.kanji-input { font-family: "Noto Sans JP", "Yu Gothic", sans-serif; font-size: 1.4rem; }

/* Zone « Stroke Order » : coller, déposer ou choisir des images */
.stroke-zone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 2px dashed #d5dbe4;
  border-radius: 12px;
  background: #fafbfd;
}
.stroke-zone:focus { outline: none; border-color: var(--primary); }
.stroke-zone.is-dragover { border-color: var(--primary); background: #eef4fe; }
.stroke-hint { flex: 1; min-width: 200px; margin: 0; color: var(--muted); font-size: 0.88rem; }
.stroke-zone.has-images .stroke-hint { flex-basis: 100%; }
.stroke-list { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; margin: 0; padding: 0; list-style: none; }
.stroke-list[hidden] { display: none; }
.stroke-item { position: relative; }
.stroke-item img {
  display: block;
  max-width: 100%;
  max-height: 160px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.stroke-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.stroke-remove:hover { background: #b3162c; }

/* Quiz : kanji en grand, Stroke Order sous la réponse */
.quiz-question.quiz-question--kanji { font-size: 5rem; line-height: 1.1; }
.quiz-answer-main.quiz-answer-kanji { font-size: 3.5rem; line-height: 1.1; }
.quiz-strokes { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.quiz-strokes img { max-width: 100%; max-height: 180px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* Page « Kanji » */
.kanji-table .cell-kanji-char { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.rules-page .page--wide { max-width: 1600px; }
.kanji-table .cell-ja { min-width: 0; }
.kanji-table .cell-reading { min-width: 8em; color: #555; }
.kanji-table .reading { display: inline-block; margin: 2px 10px 2px 0; white-space: nowrap; }
.kanji-table .reading:last-child { margin-right: 0; }
.kanji-table .col-strokes { width: 1%; white-space: nowrap; }
.kanji-table .cell-empty { color: #b0b8c4; }
.stroke-thumb {
  position: relative;
  display: block;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: zoom-in;
}
.stroke-thumb img { display: block; height: 44px; max-width: 120px; object-fit: contain; border-radius: 6px; }
.stroke-thumb:hover { border-color: var(--primary); }
.stroke-thumb-count {
  position: absolute;
  right: -6px;
  bottom: -6px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}
.stroke-viewer { display: grid; justify-items: center; gap: 12px; }
/* Fenêtre Stroke Order : presque toute la largeur de l'écran, image agrandie pour la remplir */
.rule-dialog.stroke-dialog { width: min(1600px, calc(100vw - 32px)); }
.stroke-viewer img {
  width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* ---------- Bandeau « Nouvelle version disponible » (js/pwa.js) ---------- */
.update-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 14px;
  background: var(--text);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 27, 61, 0.3);
  transform: translateX(-50%);
}
.update-reload {
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.update-reload:hover { background: var(--primary-hover); }
.update-dismiss {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.update-dismiss:hover { background: rgba(255, 255, 255, 0.12); }
@media print { .update-banner { display: none; } }

/* ---------- Synchronisation (js/sync.js) ---------- */
.backup-actions { flex-wrap: wrap; align-items: center; }
.sync-panel { position: relative; }
.sync-signin { font-weight: 600; }
.sync-signin:hover { background: #dfe5ee; }
.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.sync-chip:hover { border-color: #b9c9e4; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa7bc; }
.sync-chip[data-phase="synced"] .sync-dot { background: var(--mastery-maitrise); }
.sync-chip[data-phase="syncing"] .sync-dot { background: var(--primary); animation: sync-pulse 1s ease-in-out infinite; }
.sync-chip[data-phase="offline"] .sync-dot,
.sync-chip[data-phase="choice"] .sync-dot { background: var(--mastery-difficile); }
.sync-chip[data-phase="error"] .sync-dot { background: var(--mastery-non); }
@keyframes sync-pulse { 50% { opacity: 0.3; } }
.sync-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  min-width: 240px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(15, 27, 61, 0.12);
}
.sync-menu[hidden] { display: none; }
.sync-menu .btn-small { width: 100%; text-align: left; }
.sync-menu .btn-small + .btn-small { margin-left: 0; }
.sync-account { margin: 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.sync-message { margin: 0; color: #b3162c; font-size: 0.85rem; }
.sync-panel > .sync-message { position: absolute; top: calc(100% + 6px); right: 0; width: max-content; max-width: 280px; }

.sync-choice-dialog { width: min(520px, calc(100vw - 32px)); }
.sync-choice-list { margin: 14px 0; padding-left: 20px; color: var(--text); line-height: 1.7; }
.sync-choice-date { color: var(--muted); font-size: 0.85rem; }
.confirm-dialog .sync-choice-warning { margin-top: 4px; color: #b3162c; font-size: 0.9rem; }
.sync-choice-actions { flex-wrap: wrap; }
/* Téléphone : le panneau est à gauche, son menu s'ouvre donc vers la droite. */
@media (max-width: 560px) {
  .sync-menu, .sync-panel > .sync-message { left: 0; right: auto; }
}

/* ---------- Téléphone : consultation et révision ----------
   Tout ce bloc ne s'applique qu'aux écrans de 700 px de large ou moins : le PC n'est pas concerné. */
.filters-toggle, .title-short { display: none; } /* bouton « Filtres » et titre court : téléphone uniquement */

@media (max-width: 700px) {
  .page { padding: 20px 16px 32px; }

  /* En-têtes compacts : titre court sur une ligne, actions groupées */
  .page-header h1 { font-size: 1.45rem; }
  .rules-header { gap: 12px; }
  .rules-header h1 { font-size: 1.6rem; }
  .title-full { display: none; }
  .title-short { display: inline; }
  .rules-header-actions { gap: 8px; }
  .level-tab { display: inline-flex; align-items: center; min-height: 40px; }

  /* Recherche toujours visible, filtres derrière le bouton « Filtres » */
  .filters-toggle {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    min-height: 48px;
    padding: 0 16px;
    border: 1px solid #e3e3e3;
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
  }
  .filters-toggle[aria-expanded="true"] { border-color: var(--text); background: #eef1f6; }
  .vocab-search-row { flex-wrap: nowrap; gap: 8px; }
  .vocab-search-row .search-input { flex: 1 1 auto; min-width: 0; }
  .filters-collapsible:not(.filters-open) .vocab-search-row .toolbar-group,
  .filters-collapsible:not(.filters-open) .vocab-toolbar { display: none; }
  .filters-open .vocab-search-row { flex-wrap: wrap; }
  .filters-open .vocab-search-row .toolbar-group { flex: 1 1 100%; }
  .toolbar-group { flex: 1 1 100%; }
  .toolbar-group-body > .vocab-filter { flex: 1 1 140px; }
  .mastery-chip { min-height: 40px; }

  /* Listes Vocabulaire et Kanji : chaque ligne devient une carte */
  .vocab-table-wrap { overflow: visible; }
  .vocab-table, .vocab-table tbody { display: block; }
  .vocab-table thead { display: none; }
  .vocab-table tr {
    display: grid;
    column-gap: 12px;
    row-gap: 2px;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
  }
  .vocab-table tbody tr:last-child { border-bottom: none; }
  .vocab-table td { display: block; min-width: 0 !important; width: auto !important; padding: 0; border: none; }
  .vocab-table .col-actions, .vocab-table .col-anki { display: none; }
  .vocab-table .level-select { width: auto; min-height: 36px; }

  /* Carte de vocabulaire : maîtrise | question / réponse / kanji | niveaux */
  .vocab-table:not(.kanji-table) tr {
    grid-template-columns: 26px minmax(0, 1fr) auto;
    grid-template-areas:
      "mastery question vocab-level"
      "mastery answer kanji-level"
      "mastery kanji kanji-level";
  }
  .vocab-table:not(.kanji-table) .col-mastery { grid-area: mastery; align-self: start; padding-top: 2px; }
  .vocab-table:not(.kanji-table) td:nth-child(5) { grid-area: vocab-level; justify-self: end; }
  .vocab-table:not(.kanji-table) td:nth-child(6) { grid-area: kanji-level; justify-self: end; align-self: start; }
  .vocab-table:not(.kanji-table) td:nth-child(6) .level-select:disabled { display: none; }
  /* Consultation : seuls les niveaux renseignés sont affichés (pastilles de couleur). */
  .vocab-table:not(.kanji-table) .level-select[data-level=""] { display: none; }
  .vocab-table[data-direction="fr-ja"] .cell-fr { grid-area: question; }
  .vocab-table[data-direction="fr-ja"] .cell-ja { grid-area: answer; }
  .vocab-table[data-direction="ja-fr"] .cell-ja { grid-area: question; font-weight: 700; color: var(--text); }
  .vocab-table[data-direction="ja-fr"] .cell-fr { grid-area: answer; font-weight: 400; color: #555; }
  .vocab-table .cell-kanji { grid-area: kanji; font-size: 0.9rem; }
  .vocab-table .cell-kanji:empty { display: none; }
  .vocab-table .cell-fr, .vocab-table[data-direction="ja-fr"] .cell-ja { font-size: 1.05rem; }

  /* Carte de kanji : kanji en grand | sens, lecture, lectures kun / on | niveau ; Stroke Order dessous */
  .kanji-table tr {
    grid-template-columns: 64px minmax(0, 1fr) auto;
    grid-template-areas:
      "char fr mastery"
      "char ja level"
      "char kun kun"
      "char on on"
      "strokes strokes strokes";
  }
  .kanji-table .cell-kanji-char { grid-area: char; align-self: start; font-size: 2.6rem; line-height: 1.1; text-align: center; }
  .kanji-table .cell-fr { grid-area: fr; font-size: 1.05rem; }
  .kanji-table .cell-ja { grid-area: ja; }
  .kanji-table .cell-kun { grid-area: kun; }
  .kanji-table .cell-on { grid-area: on; }
  .kanji-table .col-mastery { grid-area: mastery; justify-self: end; }
  .kanji-table .col-level { grid-area: level; justify-self: end; }
  .kanji-table .col-strokes { grid-area: strokes; margin-top: 8px; }
  .kanji-table .col-strokes:has(.cell-empty) { display: none; }
  .kanji-table .cell-ja:empty, .kanji-table .cell-reading:empty { display: none; }
  .kanji-table .cell-reading { min-width: 0; font-size: 0.9rem; }
  .kanji-table .cell-reading::before {
    display: inline-block;
    min-width: 40px;
    color: #c0002a;
    font-family: "Raleway", sans-serif;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .kanji-table .cell-kun::before { content: "Kun"; }
  .kanji-table .cell-on::before { content: "On"; }
  .kanji-table .reading { margin: 1px 8px 1px 0; }
  .stroke-thumb { width: 100%; }
  .stroke-thumb img { width: 100%; height: auto; max-width: none; max-height: 90px; }
}

/* Écran tactile : les raccourcis clavier des quiz ne servent à rien */
@media (hover: none) and (pointer: coarse) {
  .quiz-reveal kbd, .quiz-rate kbd { display: none; }
}
