/* ============================================================
   Karakoto — UX responsive (refonte)
   ============================================================
   Trois modes de layout :

   1. "wide" (>= 1280px) — desktop + tablette paysage
      → sidebar toujours visible, 3 panneaux empilés avec resizers
      → accordéon FR/JP utilisable mais facultatif

   2. "compact" (< 1280px) — mobile + tablette portrait
      → sidebar masquée par défaut, ouverte via burger + overlay
      → accordéon FR/JP par défaut : chacun ~4 lignes, repli rapide
      → resizers masqués (plus utiles en accordéon)
      → l'analyse (Kuromoji) prend le reste de l'écran

   3. Accordéon
      → chaque .karakoto-pane a un .karakoto-pane-header cliquable
      → classe .collapsed masque .karakoto-pane-body
      → hauteur par défaut calculée pour ~4 lignes de texte
   ============================================================ */

/* ===== EN-TÊTES DES PANNEAUX (toutes tailles) ===== */
.karakoto-pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 14px;
  background: #edf2f7;
  border: none;
  border-bottom: 1px solid #e2e8f0;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #4a5568;
  transition: background 0.15s;
  flex-shrink: 0;
  text-align: left;
}
.karakoto-pane-header:hover {
  background: #e2e8f0;
}
.karakoto-pane-header:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: -2px;
}
.karakoto-pane-chevron {
  font-size: 0.95rem;
  transition: transform 0.2s;
  color: #6366f1;
  width: 16px;
  display: inline-block;
  text-align: center;
}
.karakoto-pane-title {
  color: #6366f1;
}
.karakoto-pane-subtitle {
  margin-left: auto;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
  color: #718096;
}
.karakoto-pane-status {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: #718096;
}
.karakoto-pane-status.success { color: #38a169; }
.karakoto-pane-status.error   { color: #c53030; }

.karakoto-pane-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
}
.karakoto-pane.collapsed .karakoto-pane-body {
  max-height: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  flex: 0 0 0 !important;
}

/* ============================================================
   RÈGLES UNIVERSELLES (toutes tailles d'écran)
   Objectif : FR + JP combinés = MAX 30% de la hauteur, Analyse = 70%+
   ============================================================ */

.editor-panels.three-pane {
  display: flex !important;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  /* Défilement vertical de l'ensemble : chaque section prend la hauteur de son
     contenu (plus d'espace vide sous l'analyse). */
  overflow-y: auto;
  overflow-x: hidden;
}

/* ============================================================
   SYSTÈME DE CARTES — marges et largeurs UNIFIÉES pour les 3 panneaux
   Chaque panneau : bordure fine, fond blanc, même padding horizontal
   ============================================================ */

/* Conteneur principal : padding minimal pour maximiser l'espace utile */
html body #editorPanels.three-pane,
html body .main-container #editorPanels,
html body .main-container.two-pane #editorPanels,
html body .editor-panels.three-pane {
  /* 8px de respiration en haut pour que le cadre FR ne colle pas à la barre
     de menu (le dégagement du header fixe de 40px est fourni par
     .content-container, y compris en mode replié — voir plus bas). */
  padding: 8px 4px 4px 4px !important;
  gap: 4px !important;
  background: #cbd5e0 !important;
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Le header (.main-header) est en position:fixed (40px) à toutes les tailles.
   .content-container réserve déjà 40px, mais styles.css les retire quand la
   sidebar est repliée (.collapsed) — état par défaut sur mobile — ce qui
   faisait passer le cadre FR SOUS la barre de menu (header rogné). On rétablit
   le dégagement dans tous les cas. */
html body .main-container.collapsed .content-container {
  padding-top: 40px !important;
}

/* Les 2 panneaux FR et JP : carte blanc cassé avec bordure contrastée */
html body #editorPanels .french-input-section,
html body #editorPanels .input-section.read-only,
html body .french-input-section,
html body .input-section.read-only {
  flex: 0 0 auto !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  background: #fafbfc !important; /* blanc cassé très légèrement grisé */
  border: 1px solid #94a3b8 !important; /* bordure gris moyen bien visible */
  border-radius: 8px !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08) !important;
}

/* FR : hauteur pour ~5 lignes de texte + header fin */
html body .french-input-section {
  height: auto !important;
  flex: 0 1 auto !important;
  min-height: 0 !important;
  max-height: 26vh !important; /* ~5 lignes de 24px + header 32px */
}

/* JP : hauteur proportionnelle au contenu, plafonnée aussi à 5 lignes */
html body .input-section.read-only {
  height: auto !important;
  flex: 0 1 auto !important;
  min-height: 0 !important;
  max-height: 26vh !important;
}

/* Zone d'analyse : carte blanc cassé bordée, contraste avec fond gris */
html body .content-area,
html body #editorPanels .content-area,
html body .main-container .content-area,
html body .main-container.two-pane .content-area,
html body .main-container.two-pane #editorPanels .content-area {
  /* Hauteur = contenu COMPLET (on voit tout d'un coup, pas de scroll interne) :
     la zone est un bloc à hauteur automatique ; c'est l'ensemble des panneaux
     (#editorPanels, overflow-y:auto) qui défile si besoin. display:block évite
     les bugs de calcul de hauteur du flex imbriqué (qui faisaient déborder les
     cartes sur les sections voisines). */
  flex: 0 0 auto !important;
  max-height: none !important;
  min-height: 0 !important;
  height: auto !important;
  display: block !important;
  overflow: visible !important;
  background: #fafbfc !important; /* même blanc cassé que FR/JP */
  border: 1px solid #94a3b8 !important; /* bordure gris moyen contrastée */
  border-radius: 8px !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08) !important;
}
body .content-area .content-scroll-area {
  padding: 8px !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  background: transparent !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  margin: 0 !important;
}
/* Barre de lecture : confinée à la largeur de la carte */
body .content-area .play-control-bar {
  background: #e2e8f0 !important;
  border-bottom: 1px solid #94a3b8 !important;
  border-radius: 8px 8px 0 0 !important;
  padding: 6px 10px !important;
  flex-shrink: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  overflow-x: auto !important;
}

/* En-têtes de panneau : fins, gris moyen, peu de padding */
body .karakoto-pane-header {
  background: #e2e8f0 !important;
  border-bottom: 1px solid #94a3b8 !important;
  border-radius: 8px 8px 0 0 !important;
  padding: 4px 10px !important; /* très fin */
  flex-shrink: 0 !important;
  color: #334155 !important;
  font-size: 0.72rem !important;
  min-height: 0 !important;
}
body .karakoto-pane-header:hover {
  background: #cbd5e0 !important;
}
body .karakoto-pane-title {
  font-size: 0.72rem !important;
}
body .karakoto-pane-title {
  color: #4c1d95 !important; /* violet plus profond sur gris */
}
body .karakoto-pane-chevron {
  color: #6d28d9 !important;
}

/* Corps du panneau : padding uniforme, scroll interne */
body .karakoto-pane-body {
  padding: 10px 12px !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: auto !important;
  display: flex !important;
  flex-direction: column !important;
}

/* ============================================================
   PANNEAU FR : textarea pleine largeur + bouton Traduire dans le header
   ============================================================ */

/* Body du panneau FR : simple, textarea remplit tout */
html body .french-input-section .karakoto-pane-body {
  display: flex !important;
  flex-direction: column !important;
  padding: 10px 12px !important;
}

/* Textarea FR : pleine largeur, grand */
html body #frenchInput {
  width: 100% !important;
  box-sizing: border-box !important;
  min-height: 80px !important;
  height: 100% !important;
  max-height: 100% !important;
  resize: none !important;
  padding: 10px 12px !important;
  font-size: 1rem !important;
  line-height: 1.5 !important;
  border: 1px solid #94a3b8 !important;
  border-radius: 8px !important;
  margin: 0 !important;
  background: #fff !important;
  color: #1a202c !important;
  display: block !important;
  font-family: system-ui, -apple-system, sans-serif !important;
  flex: 1 1 auto !important;
}
html body #frenchInput:focus {
  outline: none !important;
  border-color: #6d28d9 !important;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.18) !important;
}

/* Header du panneau FR : titre repliable à gauche + bouton Traduire à droite. */
html body .karakoto-pane-header--with-action {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}
html body .karakoto-pane-toggle {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  cursor: pointer !important;
  flex-shrink: 1 !important;
  min-width: 0 !important;
  padding: 4px 0 !important;
  user-select: none !important;
}
html body .karakoto-pane-toggle:hover .karakoto-pane-title {
  color: #7c3aed !important;
}
html body .karakoto-pane-toggle:focus-visible {
  outline: 2px solid #6d28d9 !important;
  outline-offset: 2px !important;
  border-radius: 4px !important;
}

/* Hauteur d'en-tête UNIFORME pour tous les panneaux repliables → ils ont la
   même taille une fois repliés (le bouton FR→JP ne rend pas l'en-tête FR plus
   haut). */
html body .karakoto-pane > .karakoto-pane-header {
  min-height: 40px !important;
  display: flex !important;
  align-items: center !important;
  box-sizing: border-box !important;
}

/* Bouton Traduire FR → JP : dans l'en-tête, poussé à droite. */
html body .karakoto-translate-editor-btn--header,
html body #karakotoTranslateEditorBtn.karakoto-translate-editor-btn--header {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  flex-shrink: 0 !important;
  margin: 0 0 0 auto !important; /* pousse le bouton à droite */
  padding: 6px 12px !important;
  min-height: 30px !important;
  height: auto !important;
  width: auto !important;
  max-width: none !important;
  min-width: 0 !important;
  font-size: 0.8rem !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  border-radius: 6px !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  white-space: nowrap !important;
}
html body .karakoto-translate-editor-btn--header svg {
  width: 15px !important;
  height: 15px !important;
  flex-shrink: 0 !important;
}
html body .karakoto-translate-editor-btn--header span {
  display: inline !important;
  font-size: 0.8rem !important;
  white-space: nowrap !important;
}

/* Pied du cadre FR : statut de traduction seul (sous le textarea). */
html body .french-input-footer {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-shrink: 0 !important;
  margin-top: 4px !important;
  width: 100% !important;
}
html body .french-input-footer .karakoto-pane-status {
  margin: 0 !important;
  flex: 1 1 auto !important;
  text-align: left !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

/* Textarea JP (si textarea simple hors EasyMDE) */
body .input-section.read-only .input-group {
  padding: 0 !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: auto !important;
}
body #textInput {
  width: 100% !important;
  min-height: 40px !important; /* 1 ligne minimum, s'agrandit avec le contenu */
  padding: 10px 12px !important;
  font-size: 1rem !important;
  line-height: 1.6 !important;
  border: none !important;
  background: transparent !important;
  color: #1a202c !important;
  resize: none !important;
  height: auto !important;
}

/* Panneau Rōmaji (4ᵉ section) : sortie texte simple, lecture seule */
html body .romaji-output {
  width: 100% !important;
  min-height: 40px !important;
  padding: 10px 12px !important;
  font-size: 0.95rem !important;
  line-height: 1.7 !important;
  letter-spacing: 0.01em !important;
  color: #1a202c !important;
  background: transparent !important;
  box-sizing: border-box !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow: auto !important;
}
html body .romaji-output:empty::before {
  content: attr(data-placeholder);
  color: #a0aec0 !important;
  font-style: italic !important;
}

/* EasyMDE CodeMirror dans JP : s'adapte à la carte */
body .input-section.read-only .EasyMDEContainer,
body .input-section.read-only .CodeMirror {
  background: transparent !important;
  border: none !important;
}
body .input-section.read-only .CodeMirror {
  min-height: 40px !important;
  height: auto !important;
}

/* Les body (contenu du panneau) sont scrollables en interne si besoin */
body .karakoto-pane .karakoto-pane-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* Textarea FR : hauteur contrainte */
body #frenchInput {
  width: 100%;
  box-sizing: border-box;
  min-height: 60px !important;
  max-height: 100% !important;
  height: auto !important;
  resize: none !important;
  flex: 1 1 auto;
}

/* EasyMDE / CodeMirror JP : hauteur contrainte stricte */
body .input-section.read-only .EasyMDEContainer,
body .input-section.read-only .CodeMirror,
body .input-section.read-only .CodeMirror-scroll,
body .input-section.read-only #textInput {
  min-height: 0 !important;
  max-height: 100% !important;
  height: auto !important;
}
body .input-section.read-only .karakoto-pane-body {
  min-height: 0 !important;
}

/* Panneau repliée : juste le header */
body .karakoto-pane.collapsed {
  max-height: 42px !important;
  flex: 0 0 auto !important;
}

/* Zone d'ANALYSE : prend ce qui reste (>= 70% typiquement) */
body .content-area {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}
body .content-area .content-scroll-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Bouton burger : TOUJOURS visible (même en desktop) pour qu'il y
   ait toujours un moyen d'accéder au menu, peu importe la taille */
html body .karakoto-burger-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 6px !important;
  margin-right: 6px !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  color: #334155 !important;
}
html body .karakoto-burger-btn:hover {
  background: rgba(0, 0, 0, 0.06) !important;
  border-radius: 6px !important;
}
html body .karakoto-burger-btn svg {
  width: 22px !important;
  height: 22px !important;
}
/* Masque le vieux bouton Fudoki de pliage desktop */
html body #folderToolbarCollapseBtn {
  display: none !important;
}

/* ===== SIDEBAR : masquée par défaut sur TOUTES les tailles ===== */
/* Comportement universel : sidebar en colonne qui pousse le contenu.
   L'app reste TOUJOURS visible à droite — pas d'overlay qui cache.
   Le burger ouvre/ferme la colonne du menu. */

html body .main-container {
  display: flex !important;
  flex-direction: row !important;
}

/* Sidebar en colonne flex, cachée par défaut (display:none), pousse
   le contenu main quand elle est affichée. Pas de position:fixed,
   pas d'overlay. */
html body #sidebarStack,
html body .main-container #sidebarStack,
html body .main-container:not(.collapsed) #sidebarStack,
html body .main-container.collapsed #sidebarStack {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  height: calc(100vh - 40px) !important; /* compense le header fixe (40px) */
  margin-top: 40px !important;
  padding-top: 8px !important;
  background: #fafbfc !important;
  z-index: 10 !important;
  transition: width 0.2s ease !important;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08) !important;
  overflow-y: auto !important;
  display: none !important; /* cachée par défaut */
  transform: none !important;
  flex-shrink: 0 !important;
}

/* Ouverte : colonne visible. Largeur adaptative mobile/desktop. */
html body.karakoto-sidebar-open #sidebarStack,
html body.karakoto-sidebar-open .main-container #sidebarStack,
html body.karakoto-sidebar-open .main-container:not(.collapsed) #sidebarStack,
html body.karakoto-sidebar-open .main-container.collapsed #sidebarStack {
  display: flex !important;
}

/* Overlay : JAMAIS affiché. Pas d'overlay qui cache l'app. */
html body .sidebar-overlay,
html body .main-container .sidebar-overlay,
html body .main-container:not(.collapsed) .sidebar-overlay,
html body.karakoto-sidebar-open .sidebar-overlay {
  display: none !important;
  pointer-events: none !important;
}

/* Content main : prend tout l'espace restant, jamais caché. */
html body .content-main {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  min-height: 100vh !important;
  width: auto !important;
}

/* Largeur sidebar : adaptative — compact 240px, desktop 320px */
@media (max-width: 1279px) {
  html body #sidebarStack,
  html body .main-container #sidebarStack,
  html body .main-container:not(.collapsed) #sidebarStack,
  html body .main-container.collapsed #sidebarStack {
    width: 240px !important;
    max-width: 240px !important;
    flex: 0 0 240px !important;
  }
}
@media (min-width: 1280px) {
  html body #sidebarStack,
  html body .main-container #sidebarStack,
  html body .main-container:not(.collapsed) #sidebarStack,
  html body .main-container.collapsed #sidebarStack {
    width: 320px !important;
    max-width: 320px !important;
    flex: 0 0 320px !important;
  }
}

/* Contenu sidebar : visible quand ouverte (toutes tailles) */
html body.karakoto-sidebar-open #sidebarStack .folder-management,
html body.karakoto-sidebar-open #sidebarStack .list-panel,
html body.karakoto-sidebar-open #sidebarStack .sidebar-scroll {
  transform: translateX(0) !important;
  opacity: 1 !important;
  display: block !important;
  visibility: visible !important;
}

/* ===== MODE COMPACT (< 1280px) : autres ajustements ===== */
@media (max-width: 1279px) {
  /* Resizers masqués en mode compact (accordéon au lieu de drag) */
  #panelResizer,
  #panelResizerTop {
    display: none !important;
  }
  /* (sidebar/overlay règles universelles plus haut, pas répétées ici) */

  /* --------------------------------------------
     Mode compact : tailles définies dans la section universelle
     (FR 32vh/220px, JP 26vh/160px, Analyse prend le reste)
     -------------------------------------------- */

  /* Resizers masqués en mode compact (accordéon au lieu de drag) */
  #panelResizer,
  #panelResizerTop {
    display: none !important;
  }

  /* Badge label JP : masqué (le header accordéon suffit) */
  body.karakoto-compact .jp-pane-label {
    display: none;
  }

  /* Modale Bibliothèque pleine largeur */
  .karakoto-library-panel {
    width: 96vw !important;
    max-height: 92vh !important;
  }
}

/* ===== Très petits écrans (téléphone portrait strict) ===== */
@media (max-width: 480px) {
  .karakoto-pane-header {
    padding: 8px 10px;
    font-size: 0.72rem;
  }
  .karakoto-pane-subtitle {
    display: none;
  }
  body .french-input-section {
    min-height: 190px !important;
    max-height: 28vh !important;
  }
  body .input-section.read-only {
    min-height: 140px !important;
    max-height: 22vh !important;
  }
  .karakoto-burger-btn {
    padding: 8px;
  }
  .karakoto-burger-btn svg {
    width: 24px;
    height: 24px;
  }
}

/* ===== Animations subtiles ===== */
.karakoto-pane {
  transition: flex 0.2s ease, min-height 0.2s ease;
}

/* ===== Toast de synchro moins intrusif sur mobile ===== */
@media (max-width: 1279px) {
  #syncProgressToast.sync-progress-toast {
    bottom: 20px !important;
    left: auto !important;
    right: 16px !important;
    transform: none !important;
    min-width: 0 !important;
    max-width: 60vw !important;
    padding: 8px 14px !important;
    border-radius: 24px !important;
    font-size: 0.85rem !important;
    box-shadow: 0 4px 14px rgba(0,0,0,0.12) !important;
  }
  #syncProgressToast .sync-progress-content {
    gap: 8px !important;
  }
}

/* ===== Force hide sync toast sur mobile après 2s via animation ===== */
@media (max-width: 1279px) {
  /* On ajoute une animation qui masque le toast après 2.5s.
     Même si le JS oublie de retirer .show, il devient invisible. */
  #syncProgressToast.sync-progress-toast.show {
    animation: karakoto-toast-fade 2.8s ease-out forwards !important;
  }
}
@keyframes karakoto-toast-fade {
  0%, 70% { opacity: 1; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}

/* ============================================================
   Karakoto — Aération des tuiles (token pills) dans la carte Analyse
   ============================================================ */

/* Espacement entre les pills horizontalement + entre lignes */
html body .content-area .line-container {
  gap: 6px !important;
  row-gap: 16px !important; /* espace entre lignes (pour laisser de la place aux gloses FR) */
  padding: 8px 4px !important;
  align-items: flex-start !important;
}

/* Chaque pill : padding interne + margin vertical pour la glose FR au-dessus */
html body .content-area .token-pill {
  padding: 6px 10px !important;
  margin: 8px 0 4px 0 !important; /* 8px en haut pour la gloss FR qui overlay */
  border-radius: 4px !important;
  min-width: 40px !important;
}

/* Glose FR en overlay au-dessus de chaque pill (ou groupe) : plus visible et aérée */
html body .content-area .fr-gloss,
html body .content-area .token-fr-gloss {
  font-size: 11px !important;
  padding: 1px 4px !important;
  line-height: 1.3 !important;
  white-space: nowrap !important;
}

/* Scroll-area : padding latéral plus généreux pour que les pills ne touchent pas les bords */
html body .content-area .content-scroll-area {
  padding: 12px 10px !important;
}

/* Au-dessus de chaque pill, on laisse ~14px d'espace visuel pour la gloss */
html body .content-area .line-container {
  padding-top: 18px !important;
}

/* ============================================================
   Karakoto — Surlignage temps réel de la pill en cours de lecture
   ============================================================ */
html body .content-area .token-pill.karakoto-playing {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%) !important;
  box-shadow: 0 0 0 3px #f59e0b, 0 2px 8px rgba(245, 158, 11, 0.35) !important;
  border-radius: 6px !important;
  transform: scale(1.05) !important;
  z-index: 5 !important;
  position: relative !important;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s !important;
}
html body .content-area .token-pill.karakoto-playing .token-kanji,
html body .content-area .token-pill.karakoto-playing .token-kana {
  color: #92400e !important;
  font-weight: 700 !important;
}

/* ============================================================
   Panneau de détail d'un mot — décomposition caractère par caractère
   ============================================================ */
.karakoto-decomp {
  margin-top: 6px;
}
.karakoto-decomp-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.karakoto-decomp-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: rgba(99, 102, 241, 0.07);
  border: 1px solid rgba(99, 102, 241, 0.14);
  border-radius: 8px;
}
.karakoto-decomp-char {
  font-size: 1.4rem;
  font-weight: 700;
  min-width: 1.5em;
  text-align: center;
  color: #1a202c;
  line-height: 1;
}
.karakoto-decomp-type {
  font-size: 0.7rem;
  color: #6366f1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.karakoto-decomp-sound {
  font-size: 0.95rem;
  color: #1a202c;
  text-align: right;
  white-space: nowrap;
}
.karakoto-decomp-sound em {
  color: #667eea;
  font-style: italic;
  margin-left: 2px;
}
:root[data-theme="dark"] .karakoto-decomp-char,
:root[data-theme="dark"] .karakoto-decomp-sound {
  color: #e2e8f0;
}

/* ============================================================
   Bulle de détail d'un mot : modale centrée + backdrop, clic = ferme
   ============================================================ */
#karakotoDetailBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 99998;
  display: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#karakotoDetailBackdrop.show {
  display: block;
}
.token-details.karakoto-detail-modal {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: min(92vw, 460px) !important;
  max-width: min(92vw, 460px) !important;
  min-width: 0 !important;
  max-height: 82vh !important;
  overflow-y: auto !important;
  z-index: 99999 !important;
  margin: 0 !important;
  padding: 18px 16px 16px !important;
  border-radius: 16px !important;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4) !important;
  font-size: 14px !important;
  cursor: pointer;
}
/* Le bouton lecture ▶ de la bulle : positionné en haut, ne ferme pas */
.token-details.karakoto-detail-modal .play-token-btn {
  cursor: pointer;
}

/* ============================================================
   Bulle de détail : traduction du mot par Claude (remplace JMdict)
   ============================================================ */
.token-details .translation-loading {
  color: #a0aec0;
  font-style: italic;
  font-size: 0.85em;
}
.token-details .translation-senses {
  margin-top: 6px;
}
.token-details .translation-senses .sense-line {
  font-size: 0.9em;
  color: #4a5568;
  line-height: 1.55;
}
.token-details .translation-note {
  margin-top: 6px;
  font-size: 0.85em;
  color: #718096;
  font-style: italic;
}
:root[data-theme="dark"] .token-details .translation-senses .sense-line { color: #cbd5e0; }
:root[data-theme="dark"] .token-details .translation-note { color: #a0aec0; }

/* ============================================================
   Analyse pédagogique v2 (bandeau registre/naturalité, blocs de phrase,
   gloses grammaticales, décomposition morphologique)
   ============================================================ */
.karakoto-analysis-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 6px 4px 10px;
}
.karakoto-chip {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #ede9fe;
  color: #5b21b6;
  white-space: nowrap;
}
.karakoto-chip--nat { background: #dcfce7; color: #166534; }
.karakoto-banner-note {
  flex: 1 1 100%;
  font-size: 0.78rem;
  color: #64748b;
  font-style: italic;
  line-height: 1.4;
}
.karakoto-sentence-block { margin: 0 0 14px; }
.karakoto-sentence-fr {
  font-size: 0.92rem;
  color: #334155;
  font-weight: 600;
  margin: 2px 4px 8px;
  line-height: 1.45;
}
.karakoto-sentence-structure {
  margin: 6px 4px 0;
  padding: 7px 10px;
  background: rgba(99, 102, 241, 0.06);
  border-left: 3px solid #a5b4fc;
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.5;
}
.karakoto-struct-label {
  display: inline-block;
  font-weight: 700;
  color: #6366f1;
  margin-right: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.68rem;
}
/* Glose grammaticale (particule) : style distinct du sens lexical */
.token-fr-gloss.is-grammar {
  color: #9333ea !important;
  font-style: italic !important;
}
/* Décomposition morphologique dans le détail d'un mot */
.karakoto-morph-list { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.karakoto-morph-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 3px 8px;
  background: rgba(148, 163, 184, 0.12);
  border-radius: 6px;
}
.karakoto-morph-surface { font-weight: 700; color: #1a202c; }
.karakoto-morph-note { font-size: 0.85em; color: #475569; }
:root[data-theme="dark"] .karakoto-sentence-fr { color: #e2e8f0; }
:root[data-theme="dark"] .karakoto-morph-surface { color: #e2e8f0; }
:root[data-theme="dark"] .karakoto-morph-note { color: #cbd5e0; }
