:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e2e2df;
  --accent: #2f5d50;
  --accent-soft: #e6efec;
  --known: #2f7d4f;
  --review: #b8862c;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2123;
    --text: #ececec;
    --muted: #9b9b9b;
    --border: #333537;
    --accent: #7fc9b3;
    --accent-soft: #22332e;
    --known: #5fbf82;
    --review: #d9a545;
  }
}

/* Choix explicite de l'utilisateur (bouton) — l'emporte sur le système dans les deux sens. */
:root[data-theme="light"] {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e2e2df;
  --accent: #2f5d50;
  --accent-soft: #e6efec;
  --known: #2f7d4f;
  --review: #b8862c;
}

:root[data-theme="dark"] {
  --bg: #17181a;
  --surface: #1f2123;
  --text: #ececec;
  --muted: #9b9b9b;
  --border: #333537;
  --accent: #7fc9b3;
  --accent-soft: #22332e;
  --known: #5fbf82;
  --review: #d9a545;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
}

header h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
}

nav.tabs {
  display: flex;
  gap: 0.3rem;
}

nav.tabs button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
}

nav.tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.2rem 1.5rem 3rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
  align-items: center;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 180px;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

select, .toolbar select {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.lang-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.lang-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
}

.lang-chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-weight: 600;
}

tbody td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover {
  background: var(--accent-soft);
}

tbody tr:last-child td {
  border-bottom: none;
}

.cat-badge {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  white-space: nowrap;
}

.word-cell .word {
  font-weight: 600;
}

.word-cell .ipa, .word-cell .approx {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.play-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.95rem;
  padding: 0 0.2rem;
}

.play-btn.no-voice {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* --- Fiche mot --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.2rem;
  font-size: 1.4rem;
}

.card .cat-badge {
  margin-bottom: 0.8rem;
}

.trans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.trans-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
}

.trans-item .lang-name {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.trans-item .word {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0.15rem 0;
}

.trans-item .ipa {
  color: var(--muted);
  font-size: 0.82rem;
}

.trans-item .approx {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: italic;
}

.alt-item {
  margin-top: 0.5rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
}

.alt-item .alt-word {
  font-weight: 600;
  color: var(--accent);
  display: block;
}

.alt-item .ipa, .alt-item .approx {
  font-size: 0.78rem;
}

.alt-item .alt-note {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-style: italic;
  margin-top: 0.1rem;
}

.related {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.related h3 {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.related-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.related-list button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
}

.related-list button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Flashcards --- */
.flash-setup {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1.2rem;
}

.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: pointer;
}

.flashcard .prompt-lang {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.flashcard .prompt-word {
  font-size: 1.8rem;
  font-weight: 700;
}

.flashcard .answer {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
  width: 100%;
}

.flashcard .answer .word {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.flashcard .answer .ipa, .flashcard .answer .approx {
  color: var(--muted);
  font-size: 0.85rem;
}

.flash-actions {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.2rem;
}

.flash-actions button {
  padding: 0.6rem 1.3rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.flash-actions .btn-known {
  border-color: var(--known);
  color: var(--known);
}

.flash-actions .btn-review {
  border-color: var(--review);
  color: var(--review);
}

.flash-progress {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.8rem;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.status-dot.known { background: var(--known); }
.status-dot.review { background: var(--review); }
.status-dot.new { background: var(--muted); opacity: 0.4; }

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.extra-toggle {
  border: 1px dashed var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
}

.extra-toggle:disabled {
  opacity: 0.6;
  cursor: default;
  border-style: solid;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.hidden { display: none !important; }

@media (max-width: 700px) {
  #word-table th.col-category,
  #word-table td.col-category {
    display: none;
  }
}
