/* ---- Thème ---- */
:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f1f6;
  --text: #1c1e26;
  --muted: #6b7080;
  --border: #e2e4ec;
  --primary: #5b6cff;
  --primary-ink: #ffffff;
  --good: #17b26a;
  --accent: #ff7a59;
  --shadow: 0 6px 24px rgba(20, 22, 40, 0.08);
  --radius: 16px;
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222d;
  --text: #eceef5;
  --muted: #9aa0b0;
  --border: #262b38;
  --primary: #6d7dff;
  --primary-ink: #ffffff;
  --good: #35d08a;
  --accent: #ff8a6a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
/* Un élément avec l'attribut hidden doit toujours rester masqué,
   même si sa classe (.modal, .field) définit un display. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ---- Barre du haut ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.browser-warning {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.browser-warning strong { color: var(--accent); }
.browser-warning .close-warning {
  margin-left: auto;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}
.browser-warning .close-warning:hover { color: var(--text); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo { font-size: 22px; }
.brand-name { letter-spacing: 0.3px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  transition: transform .1s ease, background .2s ease;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn.help-hint { animation: help-hint-pulse 2.6s ease-in-out infinite; }
@keyframes help-hint-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(91, 108, 255, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(91, 108, 255, 0); }
}
.lang-select {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  height: 38px;
  padding: 0 8px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.btn-premium {
  border: 1px solid #d4af37;
  background: transparent;
  color: #b8860b;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  transition: transform .1s ease, background .2s ease;
}
.btn-premium:hover { background: rgba(212, 175, 55, 0.12); transform: translateY(-1px); }
:root[data-theme="dark"] .btn-premium { color: #e0b84c; }

/* ---- Layout ---- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 12px; }
.panel-right .panel-title:not(:first-child) { margin-top: 20px; }
.panel-title-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 20px; }
.panel-title-row.panel-title-row-first { margin-top: 0; }
.panel-title-row .panel-title { margin: 0; }
.panel-title-actions { display: flex; gap: 12px; }
.link-btn {
  background: none; border: none; padding: 0;
  font-size: 12px; color: var(--muted); cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { color: var(--accent); }

/* ---- Champs ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.field span { color: var(--muted); font-size: 13px; }
select, input[type="text"], input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
select:focus, input:focus { border-color: var(--primary); }

.btn {
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s ease, opacity .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); margin-top: 8px; }
.btn-send { background: var(--primary); color: var(--primary-ink); padding: 10px 16px; }

.hint { margin-top: auto; font-size: 12px; color: var(--muted); padding-top: 12px; }

/* ---- Transcription ---- */
.panel-center { padding: 0; overflow: hidden; }
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.empty-state { margin: auto; text-align: center; color: var(--muted); max-width: 340px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }

.bubble {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 15px;
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.bubble.tutor { align-self: flex-start; background: var(--panel-2); color: var(--text); border-bottom-left-radius: 4px; }
.bubble .speak-again { margin-left: 8px; cursor: pointer; opacity: .6; font-size: 13px; }
.bubble .speak-again.looking-up { opacity: .3; cursor: wait; }
.bubble-translation { margin-top: 6px; font-size: 13px; font-style: italic; color: var(--muted); }

.clickable-word {
  cursor: pointer;
  border-radius: 4px;
  transition: background-color .15s ease, color .15s ease;
}
.clickable-word:hover { background: var(--primary); color: var(--primary-ink); }
.clickable-word.looking-up { opacity: .5; cursor: wait; }
.clickable-word.word-added { color: var(--good); font-weight: 600; }

/* ---- Zone micro ---- */
.mic-zone {
  border-top: 1px solid var(--border);
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--panel);
}
.waveform { display: flex; align-items: center; gap: 4px; height: 28px; }
.waveform span {
  width: 4px; height: 8px;
  background: var(--border);
  border-radius: 4px;
}
.waveform.active span { background: var(--primary); animation: wave 1s ease-in-out infinite; }
.waveform.active span:nth-child(2){animation-delay:.1s}
.waveform.active span:nth-child(3){animation-delay:.2s}
.waveform.active span:nth-child(4){animation-delay:.3s}
.waveform.active span:nth-child(5){animation-delay:.4s}
.waveform.active span:nth-child(6){animation-delay:.5s}
.waveform.active span:nth-child(7){animation-delay:.4s}
.waveform.active span:nth-child(8){animation-delay:.3s}
.waveform.active span:nth-child(9){animation-delay:.2s}
.waveform.active span:nth-child(10){animation-delay:.1s}
.waveform.speaking span { background: var(--accent); animation: wave .7s ease-in-out infinite; }
@keyframes wave { 0%,100%{ height: 8px; } 50%{ height: 26px; } }

.mic-row { display: flex; align-items: center; gap: 14px; }
.accent-toggle {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  width: 30px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  opacity: .6;
  transition: opacity .15s ease, background .15s ease;
}
.accent-toggle:hover { opacity: 1; }
.accent-toggle.active { opacity: 1; background: var(--border); }
.accent-keyboard {
  display: grid;
  grid-template-columns: repeat(7, 30px);
  grid-auto-rows: 30px;
  gap: 4px;
}
.accent-keyboard.hidden { display: none; }
.accent-key {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .15s ease, transform .1s ease;
}
.accent-key:hover { background: var(--border); }
.accent-key:active { transform: scale(.92); }

.mic-btn {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .2s ease;
}
.mic-btn:hover:not(:disabled) { transform: scale(1.05); }
.mic-btn:disabled { opacity: .5; cursor: not-allowed; }
.mic-btn.listening { background: var(--accent); animation: pulse 1.3s infinite; }
@keyframes pulse { 0%{ box-shadow: 0 0 0 0 rgba(255,122,89,.5);} 70%{ box-shadow: 0 0 0 18px rgba(255,122,89,0);} 100%{ box-shadow: 0 0 0 0 rgba(255,122,89,0);} }

.status-line { font-size: 13px; color: var(--muted); min-height: 18px; }
.text-form { display: flex; gap: 8px; width: 100%; max-width: 520px; }
.text-form input { flex: 1; }

/* ---- Corrections ---- */
/* Corrections : une seule visible à la fois (défilement pour les
   autres), pour laisser le plus de place possible au vocabulaire. */
.corrections {
  max-height: 170px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}
.vocab { flex: 1; overflow-y: auto; }
.correction-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--panel-2);
  font-size: 14px;
  animation: pop .18s ease;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
.correction-card .row, .bubble .row { margin-bottom: 6px; }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: block; }
.correction-card .said { color: var(--text); }
.correction-card .better { color: var(--text); }
.correction-card .why { color: var(--text); }
.err-word { color: var(--accent); text-decoration: line-through; }
.fix-word { color: var(--good); font-weight: 700; }

.vocab-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  margin-bottom: 6px;
  font-size: 14px;
}
.vocab-main { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.vocab-item .word { font-weight: 600; }
.vocab-item .tr { color: var(--muted); flex-shrink: 0; }
.vocab-tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
}

.vocab-stats { margin: -4px 0 8px; }

/* ---- Révision (flashcards) ---- */
.review-progress { font-size: 12px; color: var(--muted); margin-bottom: 12px; text-align: center; }
.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 28px 20px;
  min-height: 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  text-align: center;
}
.review-word-row { display: flex; align-items: center; justify-content: center; gap: 6px; }
.review-word { font-size: 22px; font-weight: 700; }
.review-listen-btn { font-size: 15px; width: 30px; height: 30px; }
.review-answer { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.review-translation { font-size: 16px; color: var(--text); }
.review-example { font-size: 13px; color: var(--muted); font-style: italic; margin: 4px 0 0; }
.review-example-translation { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.review-actions { margin-top: 18px; display: flex; gap: 10px; justify-content: center; }
.review-actions .btn { flex: 1; max-width: 180px; }
.review-empty { text-align: center; color: var(--muted); padding: 20px 0; }
.review-done { text-align: center; padding: 20px 0; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal-card {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 22px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-subhead { margin: 18px 0 6px; font-size: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.summary-row { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 14px; }
.summary-tag { color: var(--muted); }
.summary-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
.summary-list li { font-size: 14px; }
.summary-checkbox { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 14px; color: var(--muted); cursor: pointer; }
.modal-actions { margin-top: 16px; display: flex; justify-content: flex-end; }
.modal-card-wide { max-width: 560px; }
.help-body { max-height: 60vh; overflow-y: auto; font-size: 14px; line-height: 1.5; }
.help-body h3 { margin: 18px 0 6px; font-size: 14px; }
.help-body h3:first-child { margin-top: 0; }
.help-body p { margin: 0 0 10px; color: var(--muted); }
.help-body strong { color: var(--text); }
.auth-error { color: var(--accent); margin: 0 0 12px; }
.auth-success { color: var(--good); margin: 0 0 12px; }
.legacy-note { background: var(--panel-2); border-radius: 10px; padding: 12px; margin: 0 0 16px; line-height: 1.5; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  /* Sur mobile, on abandonne la grille à 3 colonnes (fragile sur petit
     écran, en particulier avec les unités vh de Safari iOS) pour une
     simple colonne qui suit l'ordre naturel du HTML : réglages, puis
     conversation, puis corrections/vocabulaire. La page défile
     normalement plutôt que d'essayer de tout faire tenir sur un écran. */
  html, body { height: auto; }
  body { overflow-x: hidden; }
  .layout {
    display: flex;
    flex-direction: column;
    flex: none;
    min-height: 0;
    padding: 12px;
    gap: 12px;
  }
  .panel { padding: 16px; }
  .panel-left, .panel-right { flex: none; }
  .panel-center {
    flex: none;
    height: 70vh;
    height: 70dvh;   /* tient compte de la barre d'adresse mobile */
  }
  .panel-title-row { flex-wrap: wrap; row-gap: 6px; }
}
