/**
 * MisparBit v2.1 — Beit Midrash Digital (Pizarra CSS)
 * Warm palette for the personal study space.
 */

/* ============================================================
   PIZARRA CUSTOM PROPERTIES
   ============================================================ */
:root {
  --mb-piz-bg:        var(--mb-bg-soft, #F2F4F7);
  --mb-piz-card:      var(--mb-bg-card, #FFFFFF);
  --mb-piz-gold:      var(--mb-indigo-mid, #2c4969);
  --mb-piz-gold-dark: var(--mb-indigo, #1b3045);
  --mb-piz-text:      var(--mb-text, #1A1B2E);
  --mb-piz-border:    var(--mb-border, #D8E4EE);
  --mb-piz-muted:     var(--mb-text-muted, #6B7280);
}

/* ============================================================
   1. FAB — FLOATING ACTION BUTTON (Pizarra Trigger)
   ============================================================ */
/* Badge counter para el botón Pizarra en la Toolbar */
.mb-pizarra-fab-target {
  position: relative; /* Necesario para el badge absoluto */
}

.mb-pizarra-fab-target::after {
  content: attr(data-count);
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: var(--mb-danger, #ef4444);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  border-radius: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  line-height: 1;
}
.mb-pizarra-fab-target[data-count="0"]::after {
  display: none;
}

/* Pulse animation */
@keyframes mb-fab-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.4); }
  50%  { box-shadow: 0 0 0 8px rgba(14, 165, 233, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); }
}
.mb-pizarra-fab-target.mb-fab-pulse {
  animation: mb-fab-pulse 0.6s ease 3;
}

/* ============================================================
   2. TOAST NOTIFICATION SYSTEM
   ============================================================ */
.mb-toast {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 9999;
  padding: 12px 20px;
  border-radius: 10px;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  transform: translateX(110%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
  max-width: 340px;
}
.mb-toast-visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.mb-toast-ok   { background: linear-gradient(135deg, #22c55e, #16a34a); }
.mb-toast-warn { background: linear-gradient(135deg, #f59e0b, #d97706); }
.mb-toast-err  { background: linear-gradient(135deg, #ef4444, #dc2626); }

/* ============================================================
   3. NOTA DOT — Indicator in verse margin
   ============================================================ */
.mb-nota-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mb-text-muted, #94a3b8);
  vertical-align: middle;
  margin-left: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.mb-nota-dot:hover {
  transform: scale(1.6);
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.3);
}

/* Category colors */
.mb-nota-dot[data-categoria="general"] { background: #94a3b8; }
.mb-nota-dot[data-categoria="pshat"]   { background: #22c55e; }
.mb-nota-dot[data-categoria="remez"]   { background: #3b82f6; }
.mb-nota-dot[data-categoria="drash"]   { background: #f59e0b; }
.mb-nota-dot[data-categoria="sod"]     { background: #8b5cf6; }

.mb-nota-dot[data-categoria="pshat"]:hover   { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3); }
.mb-nota-dot[data-categoria="remez"]:hover   { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3); }
.mb-nota-dot[data-categoria="drash"]:hover   { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3); }
.mb-nota-dot[data-categoria="sod"]:hover     { box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3); }

/* ============================================================
   4. NOTA TRIGGER — Edit icon on verse hover
   ============================================================ */
.mb-nota-trigger {
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  font-size: 0.85rem;
  margin-left: 4px;
  transition: opacity 0.2s ease;
  vertical-align: middle;
  display: inline-block;
  min-width: 44px;
  min-height: 44px;
  line-height: 44px;
  text-align: center;
  flex-shrink: 0;
  color: var(--mb-piz-muted);
}
.mb-nota-trigger:hover {
  color: var(--mb-piz-gold);
}

/* ============================================================
   5. NOTA TOOLTIP — Hover preview of note text
   ============================================================ */
.mb-nota-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--mb-piz-bg);
  color: var(--mb-piz-text);
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--mb-piz-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  max-width: 260px;
  white-space: pre-wrap;
  z-index: 1300;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.mb-nota-dot:hover .mb-nota-tooltip {
  opacity: 1;
}

/* ============================================================
   6. NOTA EDITOR — Inline textarea (parchment style)
   ============================================================ */
.mb-nota-editor {
  background: var(--mb-piz-bg);
  border: 1px solid var(--mb-piz-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  padding: 12px;
  direction: ltr;
  animation: mb-nota-editor-in 0.25s ease;
}
@keyframes mb-nota-editor-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mb-nota-editor__select {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 10px;
  border: 1px solid var(--mb-piz-border);
  border-radius: 6px;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  font-size: 0.82rem;
  background: #fff;
  color: var(--mb-piz-text);
  cursor: pointer;
}

.mb-nota-editor__textarea {
  width: 100%;
  min-height: 80px;
  max-height: 200px;
  resize: vertical;
  border: 1px solid var(--mb-piz-border);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  font-size: 0.9rem;
  color: var(--mb-piz-text);
  background: #fff;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s;
}
.mb-nota-editor__textarea:focus {
  border-color: var(--mb-piz-gold);
}
.mb-nota-editor__textarea::placeholder {
  color: var(--mb-piz-muted);
  font-style: italic;
}

.mb-nota-editor__actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}
.mb-nota-editor__btn {
  padding: 6px 16px;
  border-radius: 6px;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  min-height: 44px;
}
.mb-nota-editor__btn:active { transform: scale(0.97); }

.mb-nota-editor__btn--save {
  background: linear-gradient(135deg, var(--mb-piz-gold), var(--mb-piz-gold-dark));
  color: #fff;
}
.mb-nota-editor__btn--save:hover { filter: brightness(1.1); }

.mb-nota-editor__btn--cancel {
  background: transparent;
  color: var(--mb-piz-muted);
  border: 1px solid var(--mb-piz-border);
}
.mb-nota-editor__btn--cancel:hover { background: var(--mb-piz-bg); }

/* ============================================================
   7. HAPAX BADGE
   ============================================================ */
.mb-hapax-badge {
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 0.72rem;
  color: var(--mb-piz-gold);
  line-height: 1;
  pointer-events: auto;
  cursor: help;
  z-index: 5;
  animation: mb-hapax-shimmer 4s ease-in-out infinite;
}
@keyframes mb-hapax-shimmer {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* ============================================================
   8. PIZARRA PANEL — Free floating window
   ============================================================ */
.mb-pizarra-panel {
  position: fixed;
  top: 10vh;
  left: 10vw;
  width: 80vw;
  max-height: calc(100vh - 12vh);  /* Never overflow below viewport */
  min-width: min(500px, 94vw);
  min-height: 250px;
  background: var(--mb-piz-bg);
  z-index: 1250;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  transform: scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  border: 1px solid var(--mb-piz-border);
  border-radius: 12px;
  overflow: hidden;
}

/* Resize handle (bottom-right corner, custom) */
.mb-piz-resize-handle {
  position: absolute;
  bottom: 0; right: 0;
  width: 28px; height: 28px; /* A-08: aumentado a 28px para mejor target táctil */
  cursor: nwse-resize;
  z-index: 10;
  opacity: 0.4;
  transition: opacity 0.2s;
  background:
    linear-gradient(135deg, transparent 50%, var(--mb-piz-muted) 50%, var(--mb-piz-muted) 56%, transparent 56%),
    linear-gradient(135deg, transparent 62%, var(--mb-piz-muted) 62%, var(--mb-piz-muted) 68%, transparent 68%),
    linear-gradient(135deg, transparent 74%, var(--mb-piz-muted) 74%, var(--mb-piz-muted) 80%, transparent 80%);
  border-bottom-right-radius: 12px;
}
.mb-piz-resize-handle:hover { opacity: 0.8; }
.mb-pizarra-panel.mb-pizarra-abierta {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Modos Avanzados de UI Flotante */
.mb-pizarra-panel.mb-pizarra-ghost {
  opacity: 0.15;
  box-shadow: none;
  backdrop-filter: none;
}
.mb-pizarra-panel.mb-pizarra-ghost .mb-piz-toolbox,
.mb-pizarra-panel.mb-pizarra-ghost .mb-piz-alphabet,
.mb-pizarra-panel.mb-pizarra-ghost .mb-piz-tarjetas-container,
.mb-pizarra-panel.mb-pizarra-ghost .mb-piz-colores {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.mb-pizarra-panel.mb-pizarra-ghost:hover {
  opacity: 1;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.mb-pizarra-panel.mb-pizarra-ghost:hover .mb-piz-toolbox,
.mb-pizarra-panel.mb-pizarra-ghost:hover .mb-piz-alphabet,
.mb-pizarra-panel.mb-pizarra-ghost:hover .mb-piz-tarjetas-container,
.mb-pizarra-panel.mb-pizarra-ghost:hover .mb-piz-colores {
  opacity: 1;
  pointer-events: auto;
}

.mb-pizarra-panel.mb-pizarra-minimizada {
  height: 44px !important;
  min-height: 44px !important;
  min-width: 280px !important;
  width: auto !important;
  resize: none !important;
  border-radius: 22px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0,0,0,0.06);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Header becomes the pill strip */
.mb-pizarra-minimizada .mb-piz-header {
  border-radius: 22px;
  padding: 0 6px 0 16px;
  min-height: 44px;
  border-bottom: none;
  gap: 6px;
}

/* Hide non-essential header items when minimized */
.mb-pizarra-minimizada .mb-piz-view-tabs,
.mb-pizarra-minimizada #mb-piz-cuota,
.mb-pizarra-minimizada .mb-piz-tool,
.mb-pizarra-minimizada #mb-piz-btn-ghost {
  display: none !important;
}

/* Compact the title */
.mb-pizarra-minimizada .mb-piz-title {
  font-size: 0.82rem;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact sigma badge */
.mb-pizarra-minimizada .mb-piz-sigma {
  font-size: 0.7rem;
  padding: 2px 8px;
}

/* Tighten control buttons */
.mb-pizarra-minimizada .mb-piz-header-right {
  gap: 4px !important;
}

.mb-pizarra-minimizada .mb-piz-close {
  width: 26px;
  height: 26px;
  min-width: 26px;
  min-height: 26px;
  font-size: 0.75rem;
}

/* Hide everything below the header */
.mb-pizarra-minimizada .mb-piz-toolbox,
.mb-pizarra-minimizada .mb-piz-alphabet,
.mb-pizarra-minimizada .mb-piz-tarjetas-container,
.mb-pizarra-minimizada .mb-piz-colores {
  display: none !important;
}

/* Header — horizontal strip at top of panel */
.mb-piz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 120px 10px 20px; /* padding-right reserva espacio para window-ctrl */
  border-bottom: 1px solid var(--mb-piz-border);
  background: linear-gradient(135deg, var(--mb-piz-gold), var(--mb-piz-gold-dark));
  color: #fff;
  flex-shrink: 0;
  min-height: 44px;
  cursor: grab;
  position: relative; /* necesario para el hijo position:absolute */
  overflow: hidden;   /* clips el header-right si es demasiado ancho */
}
.mb-piz-header:active {
  cursor: grabbing;
}

/* Controles de ventana: siempre visibles en la esquina superior derecha,
   independientemente del ancho del panel. Igual que el chrome de un OS. */
.mb-piz-window-ctrl {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px 0 24px;
  /* Desvanecimiento hacia la derecha: oculta el overflow del header-right de forma elegante */
  background: linear-gradient(to right, transparent, var(--mb-piz-gold-dark) 28%);
  z-index: 5;
}
/* En modo minimizado el div ya hereda visibilidad — no hay que hacer nada extra */
.mb-pizarra-minimizada .mb-piz-window-ctrl {
  padding: 0 8px 0 16px;
}

.mb-piz-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 0;    /* puede encoger — cede espacio al header-right */
  min-width: 0;   /* permite que los hijos hagan overflow:hidden ellipsis */
  overflow: hidden;
}
.mb-piz-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0; /* NUNCA encoge — los botones — y ✕ siempre visibles */
}
.mb-piz-icon  { font-size: 1.1rem; }
.mb-piz-title { font-size: 0.95rem; font-weight: 700; margin: 0; letter-spacing: 0.02em; color: #f1f5f9; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.mb-piz-sigma {
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 10px;
  border-radius: 100px;
  white-space: nowrap;
}
.mb-piz-close {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  min-width: 36px; min-height: 36px;
}
.mb-piz-close:hover { background: rgba(255, 255, 255, 0.3); }
.mb-piz-btn--active {
  background: rgba(255, 255, 255, 0.35) !important;
  border-color: rgba(255, 255, 255, 0.6) !important;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2) inset;
}

/* View Tabs (Board vs Grid) */
.mb-piz-view-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.mb-piz-tab {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
}
.mb-piz-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}
.mb-piz-tab--active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.mb-piz-tarjetas-container {
  flex: 1;
  min-height: 0;          /* FIX CRÍTICO: sin esto flex:1 ignora max-height del padre y no scrollea */
  overflow-y: auto;
  overflow-x: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.mb-piz-tarjetas-container::-webkit-scrollbar { height: 8px; width: 8px; }
.mb-piz-tarjetas-container::-webkit-scrollbar-thumb { background: var(--mb-piz-border); border-radius: 4px; }

/* Empty state */
.mb-piz-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--mb-piz-muted);
}
.mb-piz-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}
.mb-piz-empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--mb-piz-text);
  margin: 0 0 8px;
}
.mb-piz-empty-hint {
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0;
}

/* Bottom actions */
.mb-piz-acciones {
  padding: 12px 16px;
  border-top: 1px solid var(--mb-piz-border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.mb-piz-btn-guardar,
.mb-piz-btn-mis-estudios {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-height: 44px;
}
.mb-piz-btn-guardar {
  background: linear-gradient(135deg, var(--mb-piz-gold), var(--mb-piz-gold-dark));
  color: #fff;
}
.mb-piz-btn-guardar:hover { filter: brightness(1.1); }
.mb-piz-btn-mis-estudios {
  background: #fff;
  color: var(--mb-piz-text);
  border: 1px solid var(--mb-piz-border);
}
.mb-piz-btn-mis-estudios:hover { background: var(--mb-piz-bg); }

/* ============================================================
   9. PIZARRA CARD — Word study card
   ============================================================ */
.mb-piz-card {
  background: var(--mb-piz-card);
  border: 1px solid var(--mb-piz-border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.15s;
  animation: mb-card-in 0.3s ease;
}
@keyframes mb-card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes mb-card-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

.mb-piz-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.mb-piz-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.mb-piz-card__heb {
  font-family: 'SBL Hebrew', 'Ezra SIL', 'Frank Ruehl Libre', serif;
  font-size: 1.6rem;
  color: var(--mb-piz-text);
  direction: rtl;
  line-height: 1.2;
}
.mb-piz-card__remove {
  background: none;
  border: none;
  color: var(--mb-piz-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mb-piz-card__remove:hover {
  color: var(--mb-danger, #ef4444);
  background: rgba(239, 68, 68, 0.08);
}

.mb-piz-card__translit {
  font-size: 0.82rem;
  color: var(--mb-piz-muted);
  font-style: italic;
  margin-bottom: 6px;
}
.mb-piz-card__gema {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--mb-piz-gold-dark);
  background: rgba(0, 94, 184, 0.1);
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 6px;
}
.mb-piz-card__ref {
  font-size: 0.75rem;
  color: var(--mb-piz-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.mb-piz-card__trad {
  font-size: 0.8rem;
  color: var(--mb-piz-muted);
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--mb-piz-border);
}

/* ============================================================
   10. SHARED GEMATRIA STATE
   ============================================================ */
.mb-gema-compartida {
  border-color: var(--mb-piz-gold) !important;
  box-shadow: 0 0 0 2px rgba(0, 94, 184, 0.2), 0 4px 16px rgba(0, 94, 184, 0.1) !important;
}

@keyframes mb-gema-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(0, 94, 184, 0.2), 0 4px 16px rgba(0, 94, 184, 0.1); }
  50%      { box-shadow: 0 0 0 4px rgba(0, 94, 184, 0.35), 0 4px 24px rgba(0, 94, 184, 0.2); }
}
.mb-gema-compartida.mb-gema-pulse-anim {
  animation: mb-gema-pulse 0.6s ease 3;
}

/* Tag theme group header in panel */
.mb-piz-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mb-piz-muted);
  padding: 4px 0;
  margin-top: 4px;
}

/* ============================================================
   RESPONSIVE — Mobile Bottom Sheet (≤768px)
   La Pizarra se convierte en un sheet modal desde abajo.
   Desktop INTACTO.
   ============================================================ */
@media (max-width: 768px) {
  .mb-pizarra-panel {
    /* Bottom sheet que ocupa 65dvh: en 740px empieza en y≈259, dejando espacio
       suficiente para el toolbar arriba y el contenido del panel abajo.
       La protección contra ghost-click (stopPropagation + 350ms pointer-events:none)
       impide que tocar el botón chalkboard dispare botones del panel. */
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    min-width: unset !important;
    height: 65dvh !important;
    max-height: 65dvh !important;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.25);
    z-index: 2000 !important;
    touch-action: pan-y;
    transform: none !important;
    transition: opacity 0.22s ease !important;
  }
  /* Asegurar que el estado abierto tampoco use transform */
  .mb-pizarra-panel.mb-pizarra-abierta {
    transform: none !important;
    opacity: 1 !important;
  }

  /* ══════════════════════════════════════════════════════════
     PIZARRA HEADER — MOBILE (3 filas, UX de alto nivel)
     Fila 1: [🕯️ ESTUDI3 ──────────────────────] [🧊][—][✕]
     Fila 2: [  📝 Tablero  |  🔢 Bustrófedon  ]   ← ancho completo
     Fila 3: [zoom──────────────] Σ [💾][📚]
     ══════════════════════════════════════════════════════════ */
  .mb-piz-header {
    padding: 6px 8px 4px;
    min-height: auto;
    gap: 4px;
    flex-wrap: wrap;
    overflow: visible;
    align-content: flex-start;
    /* padding-right reducido: window-ctrl es inline en fila 1 */
    padding-right: 6px;
  }
  .mb-piz-header::-webkit-scrollbar { display: none; }

  /* ── FILA 1: icon + título [grow] + window-ctrl ─────────────
     header-left es flex-wrap:wrap para que view-tabs (fila 2)
     ocupe su propia línea abajo de icono+titulo+ctrl           */
  .mb-piz-header-left {
    flex: 0 0 100%;             /* Ocupa todo el ancho → wrap interno */
    display: flex;
    flex-wrap: wrap;            /* Permite que view-tabs salte a fila 2 */
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: visible;
  }

  /* Fila 1: icon */
  .mb-piz-icon { font-size: 0.82rem; flex-shrink: 0; }

  /* Fila 1: título crece para empujar window-ctrl a la derecha */
  .mb-piz-title {
    flex: 1 1 auto;             /* FIX: crece → window-ctrl queda a la derecha */
    font-size: 0.78rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0;
  }

  /* Window-ctrl: INLINE en móvil, al extremo derecho de fila 1 */
  .mb-piz-window-ctrl {
    position: static !important;    /* FIX: no absolute → no overlapping tabs */
    background: none !important;    /* FIX: sin gradiente */
    padding: 0 !important;
    margin-left: auto;              /* Empuja al extremo derecho */
    flex-shrink: 0;
    gap: 2px;
    z-index: auto;
  }
  /* Ocultar modo cristal en móvil (no relevante en táctil) */
  #mb-piz-btn-ghost { display: none !important; }

  /* ── FILA 2: view-tabs a ancho completo (segmented control) ── */
  .mb-piz-view-tabs {
    flex: 0 0 100%;             /* FIX: fila propia, ancho completo */
    display: flex;
    gap: 0;
    padding: 2px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
  }
  .mb-piz-view-tabs::-webkit-scrollbar { display: none; }
  .mb-piz-tab {
    flex: 1;                    /* Ambas tabs: mismo ancho */
    padding: 4px 6px;
    font-size: 0.66rem;
    white-space: nowrap;
    text-align: center;
    border-radius: 6px;
  }

  /* ── FILA 3 (header-right): zoom + Σ + Guardar + Mis Estudios */
  .mb-piz-header-right {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    gap: 5px;
    justify-content: flex-start;
    padding: 0;
  }

  /* Zoom: visible y compacto */
  .mb-piz-zoom-wrap {
    display: flex !important;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 60px;
  }
  .mb-piz-zoom-wrap label {
    font-size: 0.6rem;
    font-weight: 700;
    color: rgba(255,255,255,0.9);
    white-space: nowrap;
    min-width: 28px;
  }
  .mb-piz-zoom-slider {
    flex: 1 1 auto;
    min-width: 40px;
    height: 4px;
    accent-color: rgba(255,255,255,0.9);
  }

  /* Sigma total */
  .mb-piz-sigma { font-size: 0.6rem; padding: 2px 5px; flex-shrink: 0; }

  /* Ocultar cuota en móvil */
  .mb-piz-cuota { display: none !important; }

  /* Guardar / Estudios: botones de acción compactos en Fila 3 */
  .mb-piz-action-btn {
    font-size: 0.62rem !important;
    padding: 4px 8px !important;
    flex-shrink: 0;
    border-radius: 8px !important;
    background: rgba(255,255,255,0.15) !important;
    color: #fff !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
    white-space: nowrap;
    letter-spacing: 0.01em;
    font-weight: 600;
  }
  .mb-piz-header-right .mb-piz-tool:not(.mb-piz-action-btn) { display: none; }


  /* ── TOOLBOX: layout 2-por-fila para 360px ──────────────────── */
  /* IMPORTANTE: la regla base .mb-piz-toolbox (flex-wrap:nowrap) está DESPUÉS
     en el archivo → gana la cascada CSS. Los !important aquí son el fix correcto
     ya que no podemos reordenar el archivo sin riesgo. */
  .mb-piz-toolbox {
    padding: 6px 8px !important;
    gap: 5px !important;
    flex-wrap: wrap !important;       /* FIX CRÍTICO: !important para ganar sobre regla base línea 985 */
    overflow-x: hidden !important;    /* FIX CRÍTICO: base tiene overflow-x:auto */
    overflow-y: visible !important;
    justify-content: flex-start !important;
    align-content: flex-start !important;
  }
  .mb-piz-toolbox::-webkit-scrollbar { display: none !important; }

  /* Botones del TOOLBOX: 2 por fila exactamente */
  .mb-piz-toolbox .mb-piz-tool {
    flex: 0 0 calc(50% - 3px) !important;  /* 2 exactos por fila, inmune a la cascada */
    padding: 8px 6px !important;
    font-size: 0.76rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-sizing: border-box;
  }
  /* Emoji en toolbox: tamaño controlado (evita "letra inicial muy grande") */
  .mb-piz-toolbox .mb-piz-tool::first-letter {
    font-size: 0.9rem !important;
  }

  /* Tarjetas container: scroll habilitado en móvil */
  .mb-piz-tarjetas-container {
    padding: 6px 8px;
    padding-bottom: 80px;                /* Evitar que el teclado lo tape */
    min-height: 0 !important;           /* Flexbox scroll fix */
    overflow-y: auto !important;        /* Scroll vertical forzado en táctil */
    -webkit-overflow-scrolling: touch;  /* iOS momentum scroll */
    touch-action: pan-y !important;     /* FIX: capturar swipe vertical explícitamente */
    overscroll-behavior: contain;       /* Evitar scroll-chaining al panel padre */
  }

  /* Cards: más compactas */
  .mb-piz-card { padding: 10px; }
  .mb-piz-card__heb { font-size: 1.3rem; }
  .mb-piz-card__gema { font-size: 0.78rem; padding: 2px 8px; }
  .mb-piz-card__ref { font-size: 0.68rem; }
  .mb-piz-line { padding: 8px 10px; }
  .mb-piz-line__heb { font-size: 1.3rem; }

  /* Ocultar handle de resize en táctil */
  .mb-piz-resize-handle { display: none !important; }

  /* Colores strip compacta */
  .mb-piz-colores { padding: 4px 8px 6px; gap: 6px; }

  /* Footer compacto */
  .mb-piz-footer { padding: 6px 8px 10px; }
  .mb-piz-acciones { gap: 6px; }
  .mb-piz-btn-guardar,
  .mb-piz-btn-mis-estudios {
    font-size: 0.78rem;
    padding: 8px 10px;
    min-height: 48px;             /* WCAG 2.5.8: was 40px */
  }

  /* Window controls: WCAG 48px enforcement */
  .mb-piz-close {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    font-size: 1rem;
  }
  .mb-piz-window-ctrl {
    gap: 4px;
    padding: 0 8px 0 16px;
  }
}

/* Zoom control in header */
.mb-piz-zoom-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0 2px;
}
.mb-piz-zoom-wrap label {
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
  cursor: default;
}
.mb-piz-zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 60px;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.25);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}
.mb-piz-zoom-slider:hover {
  background: rgba(255,255,255,0.4);
}
.mb-piz-zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  cursor: pointer;
}
.mb-piz-zoom-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  border: none;
  cursor: pointer;
}

/* ============================================================
   NOTA TRIGGER — Show on verse hover (book-reader integration)
   ============================================================ */
.mb-verse:hover .mb-nota-trigger {
  opacity: 1;
  pointer-events: auto;
}/* ============================================================
   PIN BUTTON — Add complete verse to Pizarra (verse hover)
   ============================================================ */
.mb-piz-verso-pin {
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  font-size: 0.82rem;
  margin-left: 2px;
  transition: opacity 0.2s ease, transform 0.15s ease;
  vertical-align: middle;
  display: inline-block;
  user-select: none;
}
.mb-verse:hover .mb-piz-verso-pin {
  opacity: 1;
  pointer-events: auto;
}
.mb-piz-verso-pin:hover {
  transform: scale(1.3) rotate(-15deg);
}
/* ============================================================
   TARJETAS: tipos verso_completo y nota_texto
   ============================================================ */
.mb-piz-card--verso {
  border-left: 3px solid var(--mb-indigo);
  background: linear-gradient(135deg, #f0f4ff, #fff);
}
.mb-piz-card__verso-heb {
  font-family: 'SBL Hebrew', 'Ezra SIL', 'Frank Rühl Libre', 'Times New Roman', serif;
  font-size: 1.25rem;
  line-height: 1.6;
  color: var(--mb-text);
  direction: rtl;
  padding: 6px 0;
  word-break: break-word;
  max-height: 80px;
  overflow-y: auto;
}
.mb-piz-card--nota {
  border-left: 3px solid #f59e0b;
  background: linear-gradient(135deg, #fffbeb, #fff);
}
.mb-piz-card__nota-text {
  font-size: 0.9rem;
  color: var(--mb-text);
  line-height: 1.5;
  padding: 4px 0;
  font-style: italic;
}
.mb-piz-card__badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(99,102,241,0.1);
  color: var(--mb-indigo);
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 4px;
  white-space: nowrap;
  align-self: center;
}
.mb-piz-card--nota .mb-piz-card__badge {
  background: rgba(245,158,11,0.12);
  color: #d97706;
}

/* ============================================================
   11. TOOLBOX STRIP
   ============================================================ */
.mb-piz-toolbox {
  display: flex;
  gap: 5px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--mb-piz-border);
  background: var(--mb-bg-soft);
  flex-wrap: nowrap;
  overflow-x: auto;
  flex-shrink: 0;
}
.mb-piz-toolbox::-webkit-scrollbar { height: 0; }
.mb-piz-tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 20px;
  border: 1px solid var(--mb-piz-border);
  background: var(--mb-piz-card);
  color: var(--mb-piz-text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
}
.mb-piz-tool:hover {
  background: var(--mb-indigo-light, #e0e7ff);
  border-color: var(--mb-indigo);
  color: var(--mb-indigo);
  transform: translateY(-1px);
}
.mb-piz-tool--boustro {
  border-color: var(--mb-violet, #7c3aed);
  color: var(--mb-violet, #7c3aed);
}
.mb-piz-tool--boustro:hover {
  background: var(--mb-violet-light, #ede9fe);
  border-color: var(--mb-violet, #7c3aed);
  color: var(--mb-violet, #7c3aed);
}

/* ============================================================
   12. FOOTER (Cuota + Acciones)
   ============================================================ */
.mb-piz-footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--mb-piz-border);
  background: var(--mb-bg-soft);
}
.mb-piz-cuota {
  margin-bottom: 8px;
}

/* ============================================================
   13. TARJETA BUSTRÓFEDON
   ============================================================ */
.mb-piz-card--boustro {
  border-color: var(--mb-violet, #7c3aed);
  background: linear-gradient(135deg, #faf5ff, #fff);
}
.mb-piz-card--boustro .mb-piz-card__heb {
  color: var(--mb-violet, #7c3aed);
  direction: ltr; /* invertido visualmente */
}
.mb-piz-boustro-inv {
  display: inline-block;
  transform: scaleX(-1);
  font-size: 0.7rem;
  color: var(--mb-violet, #7c3aed);
  margin-left: 4px;
  vertical-align: middle;
}

/* ============================================================
   MODO RESALTADO — Cursor y estado del lector
   ============================================================ */
body[data-piz-mode="highlight"] .mb-word {
  cursor: crosshair !important;
  transition: border-bottom 0.12s ease;
}
body[data-piz-mode="highlight"] .mb-word:hover {
  border-bottom: 2px dashed rgba(217, 119, 6, 0.7);
  padding-bottom: 1px;
}
.mb-piz-tool--active {
  background: var(--mb-indigo) !important;
  color: #fff !important;
  border-color: var(--mb-indigo) !important;
}
.mb-piz-tool--hl.mb-piz-tool--active {
  background: #d97706 !important;
  border-color: #d97706 !important;
  color: #fff !important;
  animation: mb-hl-pulse 1.5s ease infinite;
}
@keyframes mb-hl-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217,119,6,0.35); }
  50%       { box-shadow: 0 0 0 5px rgba(217,119,6,0); }
}

/* Selector de colores */
.mb-piz-colores {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 8px;
  background: var(--mb-bg-soft);
  border-bottom: 1px solid var(--mb-piz-border);
}
.mb-piz-color-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.mb-piz-color-btn:hover { transform: scale(1.25); border-color: rgba(0,0,0,0.2); }
.mb-piz-color-btn--active {
  border-color: var(--mb-text) !important;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.15);
  transform: scale(1.15);
}
.mb-piz-color-btn--erase {
  background: var(--mb-bg-card) !important;
  border: 2px dashed var(--mb-border) !important;
  color: var(--mb-danger);
}
.mb-piz-color-btn--erase:hover { border-color: var(--mb-danger) !important; background: #fee2e2 !important; }
.mb-word { transition: background 0.2s ease, border-radius 0.2s ease; }

/* ============================================================
   TABLERO LINEAL — Board layout
   ============================================================ */
.mb-piz-board {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 8px;
  width: 100%;
}

/* Cada línea del tablero */
.mb-piz-line {
  position: relative;
  padding: 12px 16px;
  background: var(--mb-piz-card);
  border: 1px solid var(--mb-piz-border);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  box-sizing: border-box;
}

/* Texto hebreo principal — normalizado para el Tablero */
.mb-piz-line__heb {
  display: block;
  direction: rtl;
  font-family: 'SBL Hebrew', 'Frank Rühl Libre', 'Noto Serif Hebrew', serif;
  font-size: 1.6rem;
  line-height: 1.6;
  color: var(--mb-text);
  margin: 6px 0;
  word-break: break-word;
}


/* Referencia (libro cap:verso) — 3 partes */
.mb-piz-line__ref {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 3px;
}
.mb-piz-line__ref-heb {
  font-family: 'SBL Hebrew', 'Frank Rühl Libre', serif;
  font-size: 0.82rem;
  color: var(--mb-text-muted);
  direction: rtl;
}
.mb-piz-line__ref-esp {
  font-size: 0.7rem;
  color: var(--mb-text-muted);
  font-style: italic;
}
.mb-piz-line__ref-esp::before { content: '·'; margin-right: 4px; color: #cbd5e1; }
.mb-piz-line__ref-cv {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--mb-indigo, #4f46e5);
  font-family: 'SFMono-Regular', 'Courier New', monospace;
  letter-spacing: 0.03em;
}
.mb-piz-line__ref-cv::before { content: '·'; margin-right: 4px; color: #cbd5e1; font-weight: 400; }

/* Traducción — siempre visible para evitar saltos en la UI */
.mb-piz-line__trad {
  font-size: 0.8rem;
  color: var(--mb-text-muted);
  font-style: italic;
  line-height: 1.4;
  margin-top: 4px;
}

/* Controles (invertir + borrar) — aparecen al hover */
.mb-piz-line__ctrl {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  flex-direction: row;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.mb-piz-line:hover .mb-piz-line__ctrl {
  opacity: 1;
  pointer-events: all;
}
/* Touch devices: mostrar controles siempre (no existe :hover táctil)
   Cubre: controles de línea, nota-trigger, verso-pin, card remove */
@media (hover: none) and (pointer: coarse) {
  /* Controles de línea del tablero */
  .mb-piz-line__ctrl {
    opacity: 1;
    pointer-events: all;
  }

  /* Trigger de nota (✏️) — siempre visible en táctil */
  .mb-nota-trigger {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Pin de verso (📌) — siempre visible en táctil */
  .mb-piz-verso-pin {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Nota dot: escala permanente para mayor superficie táctil */
  .mb-nota-dot {
    transform: scale(1.2);
  }
}

/* Botón base de línea */
.mb-piz-line__btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--mb-border);
  background: #f1f5f9;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: #334155;
}
.mb-piz-line__btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.mb-piz-line__btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Botón invertir */
.mb-piz-line__inv:hover {
  background: #e0e7ff;
  border-color: var(--mb-indigo, #4f46e5);
  color: var(--mb-indigo, #4f46e5);
}
.mb-piz-line__inv--on {
  background: var(--mb-indigo, #4f46e5) !important;
  border-color: var(--mb-indigo, #4f46e5) !important;
  color: #fff !important;
}

/* Botón borrar */
.mb-piz-line__del:hover {
  background: #fee2e2;
  border-color: #ef4444;
  color: #ef4444;
}

/* Línea invertida — texto en violeta */
.mb-piz-line--boustro .mb-piz-line__heb {
  color: var(--mb-violet, #7c3aed);
}

/* Línea de nota */
.mb-piz-line--nota {
  background: rgba(245, 158, 11, 0.04);
  padding-right: 100px;
}
.mb-piz-line--nota .mb-piz-line__ctrl {
  left: auto;
  right: 6px;
}
.mb-piz-line__nota {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.mb-piz-line__nota-icon { font-size: 0.9rem; flex-shrink: 0; margin-top: 2px; }
.mb-piz-line__nota-txt  { 
  font-size: 0.88rem; 
  line-height: 1.5; 
  color: var(--mb-text); 
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 6px;
  background: transparent;
  transition: all 0.2s ease;
  cursor: text;
}
.mb-piz-line__nota-txt:hover {
  background: rgba(255, 255, 255, 0.4);
  border-color: rgba(0, 0, 0, 0.05);
}
.mb-piz-line__nota-txt:focus {
  background: #fff;
  border-color: var(--mb-border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  outline: none;
}

/* Botón Deshacer */
.mb-piz-tool--undo {
  color: var(--mb-text-muted) !important;
  border-style: dashed !important;
}
.mb-piz-tool--undo:hover {
  border-color: var(--mb-indigo) !important;
  color: var(--mb-indigo) !important;
  border-style: solid !important;
}

/* ============================================================
   GRID DE ANÁLISIS BUSTRÓFEDON
   ============================================================ */
.mb-piz-tool--analisis {
  background: linear-gradient(135deg, #1e3a5f, #2d5a8e) !important;
  color: #fff !important;
  border-color: #2d5a8e !important;
}
.mb-piz-tool--analisis:hover,
.mb-piz-tool--analisis.mb-piz-tool--active {
  background: linear-gradient(135deg, #d97706, #b45309) !important;
  border-color: #b45309 !important;
}

.mb-piz-grid-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--mb-bg-card);
  border: 1px solid var(--mb-piz-border);
  border-radius: 8px;
  overflow: hidden;
  margin: 8px 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.mb-piz-grid-hint {
  font-size: 0.72rem;
  color: var(--mb-text-muted);
  background: var(--mb-bg-soft);
  padding: 6px 10px;
  border-bottom: 1px solid var(--mb-piz-border);
  text-align: center;
}

.mb-piz-grid-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 380px;
}

.mb-piz-grid {
  border-collapse: collapse;
  direction: rtl;
  font-family: 'SBL Hebrew', 'Frank Rühl Libre', 'Noto Serif Hebrew', serif;
  margin: 0 auto;
}

/* Encabezado de columnas */
.mb-piz-grid__ref-th {
  position: sticky;
  right: 0;
  background: var(--mb-bg-card);
  z-index: 10;
  border: none;
  font-size: 0.7rem;
  color: var(--mb-text-muted);
  padding: 4px 12px;
  white-space: nowrap;
  text-align: right;
}

.mb-piz-grid__num {
  min-width: 26px;
  width: 26px;
  text-align: center;
  font-size: 0.65rem;
  color: var(--mb-text-muted);
  background: transparent;
  border: 1px solid rgba(185, 28, 28, 0.2);
  padding: 3px 1px;
  cursor: pointer;
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  user-select: none;
  transition: background 0.12s;
  position: relative;
  z-index: 1;
}
.mb-piz-grid__num:hover { background: rgba(0,0,0,0.05); }
.mb-piz-grid__num--sel {
  border-left: 1px solid #1a1a1a;
  border-right: 1px solid #1a1a1a;
  border-top: 1px solid #1a1a1a;
  background: transparent !important;
  color: #1a1a1a !important;
  font-weight: 700;
}

/* Celda de referencia */
.mb-piz-grid__ref-td {
  position: sticky;
  right: 0;
  background: var(--mb-bg-card);
  z-index: 9;
  border: none;
  padding: 4px 12px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mb-piz-grid__ref-lbl {
  font-size: 0.8rem;
  color: var(--mb-text);
  font-family: 'SFMono-Regular', 'Courier New', monospace;
  direction: ltr;
  font-weight: 600;
}

/* Botón de dirección por verso */
.mb-piz-grid__dir {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: 1px solid var(--mb-piz-border);
  background: var(--mb-bg-soft);
  font-size: 0.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--mb-text-muted);
  flex-shrink: 0;
}
.mb-piz-grid__dir:hover { background: var(--mb-indigo-light, #e0e7ff); border-color: var(--mb-indigo); color: var(--mb-indigo); }
.mb-piz-grid__dir--on   { background: var(--mb-indigo); border-color: var(--mb-indigo); color: #fff; }

/* Celda de letra */
.mb-piz-grid__cell {
  min-width: 26px; width: 26px;
  height: 38px;
  text-align: center;
  vertical-align: middle;
  font-size: 1.5rem;
  line-height: 1;
  border: 1px solid rgba(185, 28, 28, 0.2); /* Reddish subtle border */
  cursor: pointer;
  user-select: none;
  color: var(--mb-text);
  position: relative;
  z-index: 0;
}

/* Efecto Hover Celeste en toda la columna */
.mb-piz-grid__cell:hover::after,
.mb-piz-grid__num:hover::after {
  content: "";
  position: absolute;
  background-color: rgba(14, 165, 233, 0.15); /* Celeste (Sky-500) */
  left: 0;
  top: -5000px;
  height: 10000px;
  width: 100%;
  z-index: -1;
  pointer-events: none;
}

.mb-piz-grid__cell:hover { background: transparent; }

/* Letras insertadas manualmente */
.mb-piz-grid__cell--inserted,
.mb-piz-inserted-char {
  color: #ea580c !important; /* Naranja rojizo para destacar */
  font-weight: 700;
  background: rgba(234, 88, 12, 0.05); /* Fondo muy sutil */
}
.mb-piz-inserted-char {
  padding: 0 1px;
}

/* Efectos Drag & Drop */
.mb-piz-drop-left {
  border-left: 2px solid var(--mb-indigo) !important;
  background: rgba(79, 70, 229, 0.1) !important;
}
.mb-piz-drop-right {
  border-right: 2px solid var(--mb-indigo) !important;
  background: rgba(79, 70, 229, 0.1) !important;
}
.mb-piz-drag-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 32px;
  font-family: 'SBL Hebrew', 'Frank Rühl Libre', serif;
  font-size: 1.4rem;
  color: var(--mb-text);
  background: var(--mb-bg-card);
  border: 1px solid var(--mb-piz-border);
  border-radius: 4px;
  cursor: grab;
  user-select: none;
  transition: all 0.15s;
}
.mb-piz-drag-letter:hover {
  background: var(--mb-indigo);
  color: #fff;
  border-color: var(--mb-indigo);
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.mb-piz-drag-letter:active { cursor: grabbing; }

/* Solid box highlight for selected column like Foto 2 */
.mb-piz-grid__cell--sel {
  border-left: 1px solid var(--mb-indigo);
  border-right: 1px solid var(--mb-indigo);
  background: rgba(79, 70, 229, 0.05) !important;
  font-weight: 700;
}
.mb-piz-grid tr:first-of-type .mb-piz-grid__cell--sel {
  border-top: 1px solid var(--mb-indigo);
}
.mb-piz-grid tr:last-of-type .mb-piz-grid__cell--sel {
  border-bottom: 1px solid var(--mb-indigo);
}

.mb-piz-grid__cell--empty { background: transparent; cursor: default; }

/* Fila invertida (LTR) */
.mb-piz-grid__row--inv .mb-piz-grid__cell { color: #7c3aed; }

/* Panel de nombre extraído */
.mb-piz-grid-nombre {
  padding: 10px 14px;
  background: var(--mb-bg-card);
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--mb-piz-border);
  flex-wrap: wrap;
}
.mb-piz-grid-nombre__label {
  font-size: 0.7rem;
  color: var(--mb-text-muted);
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
  white-space: nowrap;
}
.mb-piz-grid-nombre__heb {
  font-family: 'SBL Hebrew', 'Frank Rühl Libre', serif;
  font-size: 1.8rem;
  color: var(--mb-indigo);
  letter-spacing: 0.1em;
  direction: rtl;
}
.mb-piz-grid-nombre__detail {
  font-size: 0.68rem;
  color: var(--mb-text-muted);
  font-family: var(--mb-font-ui, 'Inter', sans-serif);
}
.mb-piz-grid-nombre--hint {
  background: var(--mb-bg-soft);
  font-size: 0.75rem;
  color: #a16207;
  justify-content: center;
  font-style: italic;
}

/* ============================================================
   UI-8: PREVENCIÓN DE CLS EN TARJETAS DE PIZARRA
   ============================================================ */
#mb-pizarra-tarjetas {
  min-height: 250px;
}
