:root {
  --bg: #12121e;
  --surface: #1a1a2e;
  --card: #0f3460;
  --card2: #1e2a4a;
  --accent: #e94560;
  --accent2: #f5a623;
  --text: #eaeaea;
  --muted: #7a8499;
  --success: #2ecc71;
  --error: #e74c3c;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Nav ── */
nav {
  background: var(--surface);
  display: flex;
  justify-content: space-around;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}
nav button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.65rem;
  padding: 0.55rem 0.5rem;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  transition: color 0.15s, background 0.15s;
}
nav button .nav-icon { font-size: 1.35rem; }
nav button.active,
nav button:hover { color: var(--accent); background: rgba(233,69,96,0.08); }

/* ── Pages ── */
.page { display: none; flex: 1; padding: 1.2rem 1rem 2rem; flex-direction: column; gap: 1rem; }
.page.active { display: flex; }

/* ── Typography ── */
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin-bottom: 0.6rem; }
.muted-text { color: var(--muted); font-size: 0.875rem; line-height: 1.5; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius);
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--card); color: var(--text); }
.btn-danger { background: rgba(231,76,60,0.2); color: #ff6b6b; border: 1px solid rgba(231,76,60,0.4); }
.btn-review { background: rgba(245,166,35,0.15); color: var(--accent2); border: 1px solid rgba(245,166,35,0.4); }
.btn-mastered { background: rgba(46,204,113,0.15); color: var(--success); border: 1px solid rgba(46,204,113,0.4); }
.btn-block { width: 100%; }
.btn-xl { padding: 1rem; font-size: 1.1rem; border-radius: var(--radius); }
.assess-btns { display: flex; gap: 0.8rem; }
.assess-btns .btn { font-size: 1rem; padding: 0.85rem; }

/* ── Study home ── */
.study-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.due-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
}
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}
.status-cell {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.9rem 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.status-cell .sc-num { font-size: 1.8rem; font-weight: 700; }
.status-cell .sc-label { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.sc-num.new { color: var(--muted); }
.sc-num.learning { color: var(--accent2); }
.sc-num.known { color: var(--success); }

/* ── Écrans internes de la page Étude ── */
#study-home,
#study-card-screen,
#quiz-screen,
#session-result {
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

/* ── Session progress bar ── */
.session-topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.btn-back {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem 0.3rem 0;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-back:hover { color: var(--text); }
.session-progress { margin-top: 0.2rem; }
.progress-bar-wrap { flex: 1; background: var(--card); border-radius: 99px; height: 5px; overflow: hidden; width: 100%; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.counter-label { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ── Word card ── */
.word-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.2rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
}
.word-type-badge {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--card);
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
}
.word-japanese { font-size: 5rem; line-height: 1.1; margin: 0.5rem 0; }
.word-reading { font-size: 1.2rem; color: var(--muted); margin-bottom: 0.2rem; }
.word-divider { width: 40px; height: 2px; background: var(--accent); margin: 1rem auto; border-radius: 1px; }
.word-french { font-size: 1.5rem; font-weight: 600; }
.word-info { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }

/* ── Sentence card ── */
.sentence-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow);
  min-height: 100px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sentence-loading { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.875rem; }
.sent-jp { font-size: 1.35rem; line-height: 1.7; }
.sent-reading { font-size: 0.9rem; color: var(--muted); }
.sent-fr { font-size: 1rem; color: var(--text); opacity: 0.85; }
.audio-btn {
  align-self: flex-start;
  background: rgba(233,69,96,0.15);
  border: 1px solid rgba(233,69,96,0.3);
  color: var(--accent);
  padding: 0.45rem 1rem;
  border-radius: 99px;
  font-size: 0.875rem;
  cursor: pointer;
  margin-top: 0.2rem;
  transition: background 0.15s;
}
.audio-btn:hover { background: rgba(233,69,96,0.25); }

/* ── Quiz ── */
.quiz-question-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.4rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.quiz-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.5rem; }

.mcq-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.mcq-option {
  background: var(--card2);
  border: 2px solid transparent;
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.9rem 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.mcq-option:hover { border-color: var(--accent); }
.mcq-option.correct { border-color: var(--success); background: rgba(46,204,113,0.15); }
.mcq-option.wrong { border-color: var(--error); background: rgba(231,76,60,0.12); }
.mcq-option:disabled { cursor: default; }

.feedback-box {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
}
.feedback-box.correct { background: rgba(46,204,113,0.12); color: var(--success); }
.feedback-box.wrong { background: rgba(231,76,60,0.12); color: #ff6b6b; }

/* ── Session result ── */
.result-header { text-align: center; }
.result-score { font-size: 4rem; font-weight: 800; color: var(--accent); }
.result-msg { font-size: 1.1rem; color: var(--muted); margin-top: 0.3rem; }
.recap-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.9rem;
}
.recap-row:last-child { border-bottom: none; }
.recap-mark { width: 20px; text-align: center; flex-shrink: 0; }

/* ── Scanner ── */
.scanner-jp { font-size: 1.3rem; line-height: 1.6; margin-bottom: 0.3rem; }

/* ── Phrases ── */
.phrase-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  border-left: 3px solid var(--accent);
  padding-left: 0.8rem;
}
.phrase-jp { font-size: 1.05rem; }
.phrase-fr { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.phrase-del { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 0.1rem; flex-shrink: 0; }
.phrase-del:hover { color: var(--error); }

/* ── Admin ── */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.95rem;
}
.setting-row:last-child { border-bottom: none; }
.setting-row select {
  background: var(--card);
  color: var(--text);
  border: none;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  font-size: 0.9rem;
}
.danger-card { border: 1px solid rgba(231,76,60,0.25); }
.overview-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}
.ov-cell { text-align: center; }
.ov-num { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.ov-label { font-size: 0.7rem; color: var(--muted); }
.gen-bar-wrap { background: var(--card); border-radius: 99px; height: 8px; overflow: hidden; margin: 0.5rem 0; }
.gen-bar { height: 100%; background: var(--accent2); border-radius: 99px; transition: width 0.5s; }

/* ── Loaders ── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 1rem auto;
}
.spinner-sm {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modale ── */
#word-list-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-height: 80dvh;
  display: flex; flex-direction: column;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.2rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.2rem; cursor: pointer; padding: 0.2rem;
}
.modal-word-list {
  overflow-y: auto; padding: 0.5rem 1.2rem 2rem;
}
.modal-word-row {
  display: grid;
  grid-template-columns: 2fr 2fr 3fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 1.05rem;
}
.modal-word-row:last-child { border-bottom: none; }
.mwl-jp { font-size: 1.4rem; font-weight: 600; }
.mwl-reading { font-size: 1rem; }

.status-cell.clickable { cursor: pointer; transition: opacity 0.15s; }
.status-cell.clickable:hover { opacity: 0.75; }

/* ── Selection tooltip ── */
#selection-tooltip {
  background: var(--card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ── Catégories (page Étude) ── */
.cat-study-row {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  align-items: stretch;
  gap: 0.8rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  border: none;
  color: var(--text);
  width: 100%;
  text-align: left;
  transition: opacity 0.15s;
}
.cat-study-row:active { opacity: 0.75; }
.cat-all-btn { margin-top: 0; }
.cat-color-bar { width: 4px; border-radius: 2px; flex-shrink: 0; align-self: stretch; min-height: 36px; }
.cat-arrow { color: var(--muted); font-size: 1.3rem; display: flex; align-items: center; }
.mini-progress-wrap { background: var(--card); border-radius: 99px; height: 3px; margin-top: 6px; overflow: hidden; }
.mini-progress { height: 100%; background: var(--success); border-radius: 99px; }

.cat-status-chips { display: flex; gap: 0.35rem; margin-top: 0.35rem; flex-wrap: wrap; }
.chip { font-size: 0.72rem; padding: 0.2rem 0.55rem; border-radius: 99px; font-weight: 600; cursor: default; }
.chip-new { background: rgba(150,150,150,0.12); color: var(--muted); }
.chip-learning { background: rgba(245,166,35,0.15); color: var(--accent2); }
.chip-known { background: rgba(46,204,113,0.15); color: var(--success); }
.chip[onclick] { cursor: pointer; }
.chip[onclick]:hover { opacity: 0.75; }

/* ── Admin import ── */
.preview-table { font-size: 0.82rem; }
.preview-header {
  display: grid;
  grid-template-columns: 2fr 2fr 2fr 1fr;
  gap: 0.4rem;
  color: var(--muted);
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  margin-bottom: 0.3rem;
}
.preview-row {
  display: grid;
  grid-template-columns: 2fr 2fr 2fr 1fr;
  gap: 0.4rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.color-picker { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.color-swatch.selected { border-color: #fff; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.9rem;
}
.cat-row:last-child { border-bottom: none; }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

code {
  background: var(--card);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.82rem;
  font-family: monospace;
}

/* ── Safe area (iPhone notch) ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  nav { padding-bottom: calc(0.4rem + env(safe-area-inset-bottom)); }
}
