/* === Variables (hereda del global) === */
:root {
  --navy:   #0f1729;
  --navy2:  #1a2a4a;
  --navy3:  #0d1424;
  --gold:   #c9a227;
  --gold2:  #e8c04a;
  --white:  #ffffff;
  --gray:   #64748b;
  --light:  #f1f5f9;
  --border: rgba(255,255,255,0.08);
  --font:   'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--navy3);
  color: var(--white);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* === Botón volver móvil === */
.mobile-back-btn {
  display: none;
  color: rgba(255,255,255,0.7);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.3rem 0.5rem;
  text-decoration: none;
  flex-shrink: 0;
}
.mobile-back-btn:hover { color: #fff; }

/* === Topbar === */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  padding-top: max(0.85rem, env(safe-area-inset-top));
  background: var(--navy);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nexus-avatar {
  width: 36px;
  height: 36px;
  background: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.nexus-info .name {
  font-weight: 700;
  font-size: 0.95rem;
}

.nexus-info .status {
  font-size: 0.72rem;
  color: #4ade80;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.nexus-info .status::before {
  content: '●';
  font-size: 0.5rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--white);
  font-size: 0.9rem;
  font-weight: 700;
}

.logo-link span { color: var(--gold); }

.btn-reset {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  color: rgba(255,255,255,0.6);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-reset:hover {
  background: rgba(255,255,255,0.12);
  color: var(--white);
}

.btn-upgrade {
  background: var(--gold);
  border: 1px solid var(--gold);
  color: #0f1729;
  border-radius: 8px;
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  letter-spacing: 0.01em;
}

.btn-upgrade:hover {
  background: #e8c04a;
  border-color: #e8c04a;
}

.btn-manage {
  background: rgba(201,162,39,0.12);
  border: 1px solid rgba(201,162,39,0.4);
  color: var(--gold);
  border-radius: 8px;
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-manage:hover {
  background: rgba(201,162,39,0.2);
}

/* === Layout principal === */
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  width: 240px;
  background: var(--navy);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 0.5rem;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  margin-bottom: 0.5rem;
  padding: 0 0.25rem;
}

.sidebar-progress-wrap {
  padding: 0 0.25rem;
  margin-bottom: 0.75rem;
}
.sidebar-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}
.sidebar-progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.22,1,0.36,1);
}
.sidebar-progress-text {
  font-size: 0.67rem;
  color: rgba(255,255,255,0.28);
  font-weight: 500;
}

.module-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  color: rgba(255,255,255,0.5);
  cursor: default;
  transition: all 0.2s;
  border: 1.5px solid transparent;
}

.module-item.active {
  background: rgba(201,162,39,0.12);
  border-color: rgba(201,162,39,0.3);
  color: var(--gold2);
}

.module-item.done {
  color: rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.04);
}

.module-item.done[data-practice-wired]:hover {
  background: rgba(74,222,128,0.08);
  border-color: rgba(74,222,128,0.25);
  color: rgba(255,255,255,0.9);
}

.module-item.done[data-practice-wired]:hover .module-badge {
  background: rgba(74,222,128,0.25);
}

.module-item.done .mod-check { color: #4ade80; }

.module-badge {
  width: 22px;
  height: 22px;
  background: rgba(255,255,255,0.08);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
}

.module-item.active .module-badge {
  background: var(--gold);
  color: var(--navy);
}

.module-item.done .module-badge {
  background: #4ade80;
  color: var(--navy);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

.sidebar-disclaimer {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.25);
  line-height: 1.5;
  padding: 0 0.25rem;
  margin-top: auto;
}

/* === Module progress strip === */
.mod-progress-strip {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.4rem 1.5rem;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}
.mod-progress-label {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.38);
  white-space: nowrap;
  min-width: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.mod-progress-label strong {
  color: var(--gold);
  font-weight: 700;
}
.mod-progress-track {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.mod-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold2));
  border-radius: 2px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
}
.mod-progress-fill.done { background: linear-gradient(90deg, #4ade80, #86efac); }

/* Evaluación: barra indeterminate, oscila suavemente sin implicar % exacto */
@keyframes eval-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.mod-progress-fill.eval-indeterminate {
  width: 30% !important;
  transition: none;
  position: relative;
  overflow: hidden;
  background: linear-gradient(90deg, rgba(201,162,39,0.3), var(--gold), rgba(201,162,39,0.3));
}
.mod-progress-fill.eval-indeterminate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: eval-sweep 1.8s ease-in-out infinite;
}
.mod-progress-pct {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.25);
  white-space: nowrap;
  font-weight: 600;
  min-width: 28px;
  text-align: right;
}

/* === Área del chat === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* === Burbujas de mensaje === */
.msg {
  display: flex;
  gap: 0.75rem;
  max-width: 760px;
  width: 100%;
  animation: fadeSlide 0.25s ease;
  position: relative;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  margin-top: 2px;
}

.msg.nexus .msg-avatar {
  background: none;
}

.msg.user .msg-avatar {
  background: rgba(255,255,255,0.12);
}

.msg-bubble {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1.1rem;
  font-size: 0.9rem;
  line-height: 1.65;
  color: rgba(255,255,255,0.88);
  flex: 1;
  max-width: 100%;
  word-wrap: break-word;
}

.msg.user .msg-bubble {
  background: rgba(201,162,39,0.15);
  border-color: rgba(201,162,39,0.25);
  color: #e8c04a;
  border-radius: 14px 4px 14px 14px;
  flex: 0 1 auto;
  max-width: 75%;
}

.msg.nexus .msg-bubble {
  border-radius: 4px 14px 14px 14px;
}

/* === Bloques educativos === */
.edu-block {
  margin: 0.75rem 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}

.edu-block-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* === Copy button inside edu-blocks === */
.edu-copy-btn {
  margin-left: auto;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.55);
  border-radius: 5px;
  padding: 0.1rem 0.4rem;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  text-transform: none;
  letter-spacing: 0;
}
.edu-copy-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

.edu-block-body {
  padding: 0.85rem;
  font-size: 0.875rem;
  line-height: 1.7;
  white-space: pre-wrap;
}

.edu-block.teoria .edu-block-header  { background: rgba(59,130,246,0.2); color: #93c5fd; }
.edu-block.teoria .edu-block-body    { background: rgba(59,130,246,0.06); }
.edu-block.formula .edu-block-header { background: rgba(168,85,247,0.2); color: #d8b4fe; }
.edu-block.formula .edu-block-body   { background: rgba(168,85,247,0.06); font-family: 'Courier New', monospace; }
.edu-block.ejercicio .edu-block-header { background: rgba(234,179,8,0.2); color: #fde047; }
.edu-block.ejercicio .edu-block-body   { background: rgba(234,179,8,0.06); }
.edu-block.correccion .edu-block-header { background: rgba(34,197,94,0.2); color: #86efac; }
.edu-block.correccion .edu-block-body   { background: rgba(34,197,94,0.06); }
.edu-block.perfil .edu-block-header { background: rgba(201,162,39,0.25); color: var(--gold2); }
.edu-block.perfil .edu-block-body   { background: rgba(201,162,39,0.07); }

/* === Copy button on Nexus messages === */
.msg-copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.35);
  border-radius: 6px;
  padding: 0.22rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s, background 0.18s, color 0.18s;
  font-family: var(--font);
  white-space: nowrap;
  z-index: 2;
}
.msg.nexus:hover .msg-copy-btn {
  opacity: 1;
}
.msg-copy-btn:hover {
  background: rgba(255,255,255,0.13);
  color: rgba(255,255,255,0.75);
}
.msg-copy-btn.copied {
  color: #4ade80;
  border-color: rgba(74,222,128,0.35);
  background: rgba(74,222,128,0.08);
  opacity: 1;
}

/* === Feedback buttons on Nexus messages === */
.msg-feedback {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.4rem;
  opacity: 0;
  transition: opacity 0.18s;
  padding-left: 0.1rem;
}
.msg.nexus:hover .msg-feedback,
.msg-feedback.voted {
  opacity: 1;
}
.msg-fb-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: rgba(255,255,255,0.3);
  font-size: 0.72rem;
  padding: 0.18rem 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  line-height: 1.4;
}
.msg-fb-btn:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.65); }
.msg-fb-btn.good  { color: #4ade80; border-color: rgba(74,222,128,0.4); background: rgba(74,222,128,0.08); opacity: 1 !important; }
.msg-fb-btn.bad   { color: #f87171; border-color: rgba(248,113,113,0.4); background: rgba(248,113,113,0.08); opacity: 1 !important; }
.msg-fb-btn.faded { opacity: 0.2 !important; cursor: default; }
.msg-fb-label { font-size: 0.65rem; color: rgba(255,255,255,0.2); margin-left: 0.15rem; }
.msg.nexus:hover .msg-fb-label { color: rgba(255,255,255,0.35); }

/* === MC Options (tipo test) === */
.mc-question-num {
  font-size: 0.68rem;
  font-weight: 700;
  color: #c9a227;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 10px;
}

.mc-options {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 14px;
}

.mc-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  background: rgba(255,255,255,0.03);
  border: 1.5px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.855rem;
  color: rgba(255,255,255,0.75);
  text-align: left;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
  line-height: 1.45;
}

.mc-option-btn:hover:not(.mc-disabled) {
  background: rgba(201,162,39,0.09);
  border-color: rgba(201,162,39,0.38);
  color: rgba(255,255,255,0.95);
  transform: translateX(3px);
}

.mc-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(201,162,39,0.10);
  border: 1.5px solid rgba(201,162,39,0.25);
  color: #c9a227;
  font-size: 0.78rem;
  font-weight: 800;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.mc-option-btn:hover:not(.mc-disabled) .mc-letter {
  background: rgba(201,162,39,0.18);
  border-color: rgba(201,162,39,0.55);
}

/* Seleccionado */
.mc-option-btn.mc-selected {
  background: rgba(201,162,39,0.13);
  border-color: #c9a227;
  color: #fff;
  transform: none;
}
.mc-option-btn.mc-selected .mc-letter {
  background: #c9a227;
  border-color: #c9a227;
  color: #0f1729;
}
.mc-option-btn.mc-selected::after {
  content: '✓';
  margin-left: auto;
  color: #c9a227;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  padding-left: 8px;
}

/* Texto de la opción */
.mc-text {
  flex: 1;
  min-width: 0;
}

/* No seleccionados tras confirmar */
.mc-option-btn.mc-disabled:not(.mc-selected) {
  opacity: 0.28;
  cursor: default;
  transform: none;
  pointer-events: none;
}

/* === PWA install banner === */
.pwa-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--navy2, #1a2a4a);
  border-top: 1px solid rgba(201,162,39,0.3);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  z-index: 500;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.25);
}
.pwa-banner.visible { transform: translateY(0); }
.pwa-banner-icon {
  width: 38px; height: 38px; border-radius: 9px; object-fit: cover; flex-shrink: 0;
}
.pwa-banner-text { flex: 1; min-width: 0; }
.pwa-banner-title { font-size: 0.85rem; font-weight: 700; color: #fff; }
.pwa-banner-sub   { font-size: 0.72rem; color: rgba(255,255,255,0.5); margin-top: 0.1rem; }
.pwa-banner-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.pwa-btn-install  { background: var(--gold, #c9a227); color: var(--navy, #0f1729); border: none; border-radius: 8px; font-weight: 700; font-size: 0.8rem; padding: 0.45rem 1rem; cursor: pointer; font-family: var(--font); white-space: nowrap; }
.pwa-btn-dismiss  { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); color: rgba(255,255,255,0.45); border-radius: 8px; font-size: 0.8rem; padding: 0.45rem 0.75rem; cursor: pointer; font-family: var(--font); }
.pwa-btn-dismiss:hover { color: rgba(255,255,255,0.7); }
@media (max-width: 480px) {
  .pwa-banner { flex-wrap: wrap; gap: 0.6rem; }
  .pwa-banner-actions { width: 100%; }
  .pwa-btn-install { flex: 1; }
}

/* === Typing indicator === */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 0;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* === Input area === */
.input-area {
  padding: 1rem 1rem 1.25rem;
  /* iOS safe area: home indicator on newer iPhones */
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  background: var(--navy);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  max-width: 760px;
  margin: 0 auto;
}

.input-wrapper {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  transition: border-color 0.2s;
  display: flex;
  align-items: flex-end;
}

.input-wrapper:focus-within {
  border-color: rgba(201,162,39,0.5);
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--white);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#user-input::placeholder { color: rgba(255,255,255,0.3); }

#send-btn {
  width: 44px;
  height: 44px;
  background: var(--gold);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  font-size: 1.1rem;
}

#send-btn:hover:not(:disabled) {
  background: var(--gold2);
  transform: translateY(-1px);
}

#send-btn:disabled {
  background: rgba(201,162,39,0.3);
  cursor: not-allowed;
  transform: none;
}

#send-btn.stop-mode {
  background: rgba(239,68,68,0.85);
  font-size: 0.8rem;
}
#send-btn.stop-mode:hover {
  background: #dc2626;
  transform: none;
}

.stop-note {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.3);
  margin-top: 0.5rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.input-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  gap: 0.5rem;
}

.input-hint {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.2);
}

.char-counter {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

/* === Token / context bar === */
.token-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.68rem;
  color: rgba(255,255,255,0.25);
  max-width: 760px;
  margin: 0.4rem auto 0;
}

.ctx-bar-wrap {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}

.ctx-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gold2);
  border-radius: 2px;
  transition: width 0.6s ease, background 0.4s;
}

#token-count { white-space: nowrap; }

/* === Welcome screen === */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  gap: 1rem;
}

.welcome-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--gold), var(--gold2));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.welcome h2 {
  font-size: 1.4rem;
  font-weight: 800;
}

.welcome p {
  color: rgba(255,255,255,0.55);
  max-width: 400px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.welcome-btn {
  background: var(--gold);
  color: var(--navy);
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
  margin-top: 0.5rem;
}

.welcome-btn:hover {
  background: var(--gold2);
  transform: translateY(-1px);
}

/* === Onboarding stepper === */
.onboarding-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin: 0.25rem 0 0.5rem;
  max-width: 480px;
  width: 100%;
}

.ob-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
  gap: 0.5rem;
}

.ob-step-icon {
  width: 38px;
  height: 38px;
  background: var(--navy, #0f1729);
  border: 1.5px solid rgba(201,162,39,0.4);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 900;
  color: #c9a227;
  flex-shrink: 0;
}

.ob-step-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  line-height: 1.3;
}

.ob-step-sub {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.38);
  line-height: 1.45;
}

.ob-connector {
  flex-shrink: 0;
  width: 28px;
  height: 1.5px;
  background: rgba(201,162,39,0.25);
  margin-top: 20px;
}

@media (max-width: 480px) {
  .onboarding-steps {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    max-width: 300px;
  }
  .ob-step {
    flex-direction: row;
    text-align: left;
    gap: 0.75rem;
  }
  .ob-step-body { flex: 1; }
  .ob-connector {
    width: 1.5px;
    height: 16px;
    margin-top: 0;
    margin-left: 20px;
  }
}

/* === Quick-start chips === */
.quick-starts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  margin-top: 1.25rem;
  max-width: 480px;
}

.qs-label {
  width: 100%;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.28);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  margin-bottom: 0.1rem;
}

.qs-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
  border-radius: 20px;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.18s;
  white-space: nowrap;
}

.qs-btn:hover {
  background: rgba(201,162,39,0.12);
  border-color: rgba(201,162,39,0.3);
  color: var(--gold2);
  transform: translateY(-1px);
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #dc2626;
  color: white;
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  animation: fadeSlide 0.25s ease;
  z-index: 9999;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.toast--success {
  background: #0f1729;
  border: 1.5px solid var(--gold);
  color: white;
}
.toast--error {
  background: #dc2626;
}

/* === KaTeX: fórmulas matemáticas === */
.katex-content .katex-display {
  margin: 0.75rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.katex-content .katex {
  font-size: 1.05em;
  color: rgba(255,255,255,0.92);
}
.edu-block.formula .edu-block-body {
  font-family: var(--font);
  font-size: 0.9rem;
}
.edu-block.formula .katex-display > .katex {
  background: rgba(168,85,247,0.08);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border-left: 3px solid rgba(168,85,247,0.4);
}

/* === Responsive === */
/* === Mobile drawer overlay === */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.drawer-overlay.open { display: block; }

.sidebar-drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100dvh;
  width: 280px;
  background: var(--navy);
  z-index: 201;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 0.5rem;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.22,1,0.36,1);
  overflow-y: auto;
}
.sidebar-drawer.open { transform: translateX(0); }

.drawer-close {
  align-self: flex-end;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
  font-family: var(--font);
}
.drawer-close:hover { background: rgba(255,255,255,0.12); color: white; }

/* Mobile progress pill shown in topbar */
.mobile-progress-pill {
  display: none;
  align-items: center;
  gap: 0.45rem;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 0.3rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: background 0.2s;
}
.mobile-progress-pill:hover { background: rgba(255,255,255,0.12); }
.mobile-progress-pill .pill-bar {
  width: 36px; height: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}
.mobile-progress-pill .pill-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  width: 0%;
  transition: width 0.6s ease;
}

/* === Scroll to bottom button === */
.scroll-to-bottom {
  position: absolute;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gold);
  color: var(--navy);
  border: none;
  border-radius: 20px;
  padding: 0.45rem 1.1rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 0.2s, transform 0.2s;
  animation: fadeSlide 0.2s ease;
}
.scroll-to-bottom:hover { background: var(--gold2); transform: translateX(-50%) translateY(-1px); }

/* === Module completion celebration toast === */
.celebrate-toast {
  position: fixed;
  bottom: 6.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: linear-gradient(135deg, #1a2a4a, #0f1f3d);
  border: 1px solid rgba(201,162,39,0.4);
  color: white;
  padding: 0.85rem 1.4rem;
  border-radius: 14px;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(201,162,39,0.2);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.celebrate-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.celebrate-toast .cel-icon { font-size: 1.5rem; flex-shrink: 0; }
.celebrate-toast strong { display: block; color: var(--gold2); font-size: 0.9rem; }
.celebrate-toast span { color: rgba(255,255,255,0.55); font-size: 0.8rem; }

/* Badge pulse animation on module completion */
@keyframes badgePulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.4); }
  65%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}
.module-badge.badge-pulse { animation: badgePulse 0.7s cubic-bezier(0.36, 0.07, 0.19, 0.97); }

/* === Custom confirm modal === */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.2s;
}
.confirm-overlay.visible { opacity: 1; }
.confirm-box {
  background: var(--navy);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  transform: scale(0.95);
  transition: transform 0.2s;
}
.confirm-overlay.visible .confirm-box { transform: scale(1); }
.confirm-icon { font-size: 2rem; margin-bottom: 1rem; }
.confirm-msg {
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}
.confirm-btns { display: flex; gap: 0.75rem; }
.confirm-cancel, .confirm-ok {
  flex: 1;
  padding: 0.7rem;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.18s;
}
.confirm-cancel {
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.6);
  border: 1px solid rgba(255,255,255,0.1);
}
.confirm-cancel:hover { background: rgba(255,255,255,0.12); color: white; }
.confirm-ok {
  background: #ef4444;
  color: white;
}
.confirm-ok:hover { background: #dc2626; }

/* === Retry on stream failure === */
.retry-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 10px;
  margin: 0.25rem 1rem 0.5rem;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}
.retry-msg {
  flex: 1;
  font-size: 0.82rem;
  color: #fca5a5;
}
.btn-retry {
  background: rgba(239,68,68,0.15);
  color: #fca5a5;
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 7px;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.18s;
  white-space: nowrap;
}
.btn-retry:hover {
  background: rgba(239,68,68,0.28);
  color: white;
}

@media (max-width: 640px) {
  .sidebar { display: none; }
  .topbar { padding: 0.75rem 1rem; padding-top: max(0.75rem, env(safe-area-inset-top)); }
  .logo-link { display: none !important; }
  .messages { padding: 1rem 0.75rem; }
  .msg.user .msg-bubble { max-width: 88%; }
  .mobile-progress-pill { display: flex; }
  /* Topbar overflow fix: hide secondary buttons and text labels on mobile */
  .btn-hide-mobile { display: none !important; }
  .btn-label { display: none; }
  #user-greeting { display: none !important; }
  #streak-badge { display: none !important; }
  #export-btn { display: none !important; }
  #reset-btn { display: none !important; }
  .btn-reset { font-size: 0.78rem; padding: 0.35rem 0.6rem; }
  .topbar-right { gap: 0.4rem; }
  /* Salir del topbar-right ocultado en móvil, sustituido por flecha izquierda */
  #logout-btn { display: none !important; }
  .mobile-back-btn { display: flex; }
}

/* ── Sesión bloqueada por disrupción ─────────────────────────────── */
.session-blocked-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.35);
  border-radius: 12px;
  padding: 0.9rem 1.25rem;
  margin: 1rem 0;
  font-size: 0.88rem;
  color: #fca5a5;
  flex-wrap: wrap;
}
.session-blocked-btn {
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
  white-space: nowrap;
}
.session-blocked-btn:hover { background: #dc2626; }

/* ── Confirm modal (Nueva sesión / reset) ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 26, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.confirm-overlay.visible { opacity: 1; }

.confirm-box {
  background: #0f1a2e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 2rem 1.75rem 1.5rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.confirm-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(139,26,26,0.15);
  border: 1px solid rgba(139,26,26,0.4);
  color: #e05050;
  font-size: 1.2rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}
.confirm-msg {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.7);
  line-height: 1.6;
  margin: 0 0 1.5rem;
}
.confirm-btns {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}
.confirm-cancel {
  flex: 1;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.confirm-cancel:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}
.confirm-ok {
  flex: 1;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: none;
  background: #8b1a1a;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.confirm-ok:hover { background: #a82020; }
