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

  :root, [data-theme="light"] {
    --primary:    #1a6fc4;
    --primary-dk: #1557a0;
    --primary-text: #ffffff;
    --accent:     #e8a020;
    --bg:         #f0f2f5;
    --surface:    #ffffff;
    --surface2:   #f8f9fb;
    --border:     rgba(0,0,0,0.08);
    --text:       #1a1a2e;
    --muted:      #6b7280;
    --green:      #1d9e75;
    --red:        #c0392b;
    --radius:     10px;
    --navbar-h:   52px;
  }
  [data-theme="dark"] {
    --primary:    #3b82f6;
    --primary-dk: #2563eb;
    --primary-text: #ffffff;
    --primary-on-surface: #93c5fd;          /* azul más claro como texto sobre el fondo oscuro */
    --nav-chip-bg: rgba(0,0,0,0.18);        /* ⚙ y pomodoro: velo oscuro (el blanco restaba contraste) */
    --nav-chip-border: rgba(0,0,0,0.15);
    --accent:     #f59e0b;
    --bg:         #0f172a;
    --surface:    #1e293b;
    --surface2:   #334155;
    --border:     rgba(255,255,255,0.08);
    --text:       #f1f5f9;
    --muted:      #94a3b8;
    --green:      #22c55e;
    --red:        #ef4444;
    color-scheme: dark;
  }
  [data-theme="mint"] {
    --primary:    #1abc9c;
    --primary-dk: #148f77;
    --primary-text: #06302a;  /* el menta es claro: con blanco encima no se leía (2,4:1) */
    --primary-on-surface: #0e7a64;  /* el menta como texto sobre fondo claro (respuestas rápidas) */
    --accent:     #f39c12;
    --bg:         #f6fdfc;
    --surface:    #ffffff;
    --surface2:   #edfaf7;
    --border:     rgba(0,0,0,0.06);
    --text:       #2f4f4f;
    --muted:      #7f8c8d;
    --green:      #27ae60;
    --red:        #e74c3c;
  }
  [data-theme="barbie"] {
    --primary:    #ff4081;
    --primary-dk: #c2185b;
    --primary-text: #ffffff;
    --primary-on-surface: #c2185b;          /* rosa oscuro como texto sobre fondo claro */
    --nav-chip-bg: rgba(0,0,0,0.18);        /* ⚙ y pomodoro: velo oscuro (el blanco restaba contraste) */
    --nav-chip-border: rgba(0,0,0,0.15);
    --accent:     #ff80ab;
    --bg:         #fff0f6;
    --surface:    #ffffff;
    --surface2:   #ffe4f0;
    --border:     rgba(255,64,129,0.12);
    --text:       #5f1027;
    --muted:      #c2748a;
    --green:      #e91e8c;
    --red:        #ad1457;
  }
  [data-theme="dracula"] {
    --primary:    #bd93f9;
    --primary-dk: #9d74d9;
    --primary-text: #282a36;  /* el lila es claro: con blanco encima no se leía (2,4:1) */
    --accent:     #ffb86c;
    --bg:         #282a36;
    --surface:    #44475a;
    --surface2:   #383a4a;
    --border:     rgba(255,255,255,0.1);
    --text:       #f8f8f2;
    --muted:      #b0b8dc;  /* antes #6272a4: sobre la superficie #44475a se quedaba en 1,9:1 */
    --green:      #50fa7b;
    --red:        #ff5555;
    color-scheme: dark;
  }
  /* Cyberpunk "neón nocturno": base cian, magenta de acento, barra oscura (ver ajustes más abajo).
     Antes el primario era amarillo #f0e040 y pintaba la barra entera: más señal de obra que Night City. */
  [data-theme="cyberpunk"] {
    --primary:    #00fff9;
    --primary-dk: #00c8c3;
    --primary-text: #041014;
    --accent:     #ff2a6d;
    --bg:         #0d0f12;
    --surface:    #161920;
    --surface2:   #1e2130;
    --border:     rgba(0,255,249,0.18);
    --text:       #e0e0e0;
    --muted:      #6b7280;
    --green:      #39ff14;
    --red:        #ff003c;
    color-scheme: dark;
  }

  body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; background: var(--bg); color: var(--text); height: 100dvh; display: flex; flex-direction: column; transition: background 0.2s, color 0.2s; }

  /* NAVBAR */
  nav { background: var(--primary); height: var(--navbar-h); display: flex; align-items: center; padding: 0 16px; gap: 10px; flex-shrink: 0; border-bottom: 1px solid var(--border); }
  .nav-brand { color: var(--primary-text); font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
  .nav-brand span { background: rgba(255,255,255,0.2); border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 500; }
  .nav-badges { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
  /* Chips de la barra: fondo oscuro translúcido + texto blanco, legible sobre cualquier color de barra. Antes eran
     texto claro (amarillo/cian) sobre un velo blanco: en las barras claras (mint, barbie, light...) no se leían. */
  .badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,0.32); color: #ffffff; }
  .badge.topic { font-weight: 600; }
  .badge.mode  { font-style: italic; }
  /* Botón de ajustes: en la barra, blanco sobre el color del tema. En la pantalla de inicio flota sobre el fondo
     de la página, que en los temas claros es casi blanco: ahí toma los colores del tema. */
  #settings-btn { background: var(--nav-chip-bg, rgba(255,255,255,0.15)); border: 1px solid var(--nav-chip-border, rgba(255,255,255,0.2)); color: var(--primary-text); border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer; line-height: 1; }
  body:has(#login-overlay:not(.hidden)) #settings-btn { background: var(--surface); border-color: var(--border); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
  .nav-controls { display: flex; align-items: center; gap: 6px; }
  #settings-dropdown { display: none; flex-direction: column; gap: 10px; position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-width: 200px; z-index: 999; box-shadow: 0 8px 24px rgba(0,0,0,0.15); }
  #toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; z-index: 9999; opacity: 0; transition: opacity 0.3s; pointer-events: none; white-space: nowrap; }
  #toast.show { opacity: 1; }
  #settings-dropdown.open { display: flex; }
  .sd-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
  .sd-select { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 13px; background: var(--surface2); color: var(--text); cursor: pointer; -webkit-appearance: auto; }
  @media (max-width: 600px) { .sd-select { font-size: 16px; padding: 8px; } .sd-action { padding: 10px 8px; font-size: 14px; } }
  .sd-section { display: flex; flex-direction: column; gap: 4px; }
  .sd-divider { border: none; border-top: 1px solid var(--border); margin: 2px 0; }
  .sd-action { background: transparent; border: none; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; text-align: left; padding: 7px 8px; border-radius: 6px; transition: background 0.15s; width: 100%; }
  .sd-action:hover { background: var(--surface2); }
  .sd-danger { color: var(--muted); font-weight: 400; }
  .cs-wrap { position: relative; }
  .cs-trigger { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 13px; cursor: pointer; outline: none; display: flex; align-items: center; gap: 5px; white-space: nowrap; width: 100%; justify-content: space-between; }
  .cs-trigger:hover { background: var(--border); }
  .cs-label { overflow: hidden; text-overflow: ellipsis; }
  .cs-arrow { font-size: 9px; opacity: 0.75; }
  .cs-list { display: none; position: absolute; top: calc(100% + 4px); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; z-index: 200; min-width: 130px; list-style: none; padding: 4px 0; box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
  .cs-wrap.open .cs-list { display: block; }
  .cs-item { padding: 7px 12px; font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap; }
  .cs-item:hover, .cs-item.cs-active { background: var(--primary); color: var(--primary-text); }

  /* MESSAGES */
  #messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 16px; }

  .msg-row { display: flex; gap: 10px; align-items: flex-start; }
  .msg-row.user { flex-direction: row-reverse; }

  .avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; }
  .avatar.bot { background: var(--primary); color: var(--primary-text); }
  /* --accent suele ser un color claro (naranja, amarillo, rosa): texto oscuro por defecto; cada tema lo cambia si hace falta. */
  .avatar.user { background: var(--accent); color: var(--accent-text, #111111); }

  .bubble { max-width: 75%; padding: 10px 14px; border-radius: var(--radius); line-height: 1.6; font-size: 14px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
  .msg-row.bot  .bubble { background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 3px; }
  .msg-row.user .bubble { background: var(--primary); color: var(--primary-text); border-top-right-radius: 3px; }

  .typing .bubble { background: var(--surface); border: 1px solid var(--border); }
  .typing span { display: inline-block; width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: bounce 1.2s infinite; margin: 0 2px; }
  .typing span:nth-child(2) { animation-delay: 0.2s; }
  .typing span:nth-child(3) { animation-delay: 0.4s; }
  @keyframes bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-5px)} }

  /* Fondo rosa fijo → texto rojo oscuro fijo (con var(--red) de dracula, #ff5555, se quedaba en 2,6:1). */
  .msg-row.error .bubble { background: #fee2e2; border: 1px solid #fca5a5; color: #b91c1c; }

  .bubble.streaming::after { content: '▋'; animation: blink 0.7s step-end infinite; color: var(--primary); margin-left: 1px; }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

  /* FOOTER */
  footer { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 8px; flex-shrink: 0; }
  textarea { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 10px 12px; font-size: 14px; resize: none; outline: none; min-height: 42px; max-height: 120px; font-family: inherit; transition: border 0.15s; }
  textarea:focus { border-color: var(--primary); }
  /* Pista fija encima de la caja de escribir: que se sepa que existen los comandos /help, /ls… */
  #cmd-hint { background: var(--surface); border-top: 1px solid var(--border); color: var(--muted);
              font-size: 11px; padding: 4px 16px; flex-shrink: 0; }
  #cmd-hint code { font-family: monospace; color: var(--text); }
  /* Botón </> del editor: vive en la caja de escribir, así que lleva sus colores (como el textarea).
     Antes copiaba los de la barra de arriba (blanco translúcido) y en los temas claros era blanco sobre blanco. */
  #code-mode-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--text);
                   border-radius: 6px; padding: 6px 10px; font-size: 13px; cursor: pointer;
                   font-family: monospace; white-space: nowrap; flex-shrink: 0; }
  #code-mode-btn:hover { border-color: var(--primary); }
  .btn-send { background: var(--primary); color: var(--primary-text); border: none; border-radius: var(--radius); padding: 0 20px; font-weight: 600; cursor: pointer; font-size: 14px; transition: background 0.15s; white-space: nowrap; }
  .btn-send:hover { background: var(--primary-dk); }
  .btn-send:disabled { background: var(--surface2); color: var(--muted); cursor: not-allowed; border: 1px solid var(--border); }

  #quick-replies { background: var(--surface); border-top: 1px solid var(--border); padding: 8px 16px; display: none; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
  .qr-btn { background: var(--surface2); border: 1px solid var(--border); border-radius: 999px; color: var(--primary-on-surface, var(--primary)); font-size: 12px; padding: 6px 14px; cursor: pointer; font-family: inherit; transition: background 0.15s, color 0.15s; }
  .qr-btn:hover { background: var(--primary); color: var(--primary-text); }

  .site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--muted); flex-shrink: 0; }
  .site-footer-links { display: flex; gap: 12px; }
  .site-footer-links a { color: var(--muted); text-decoration: none; transition: color 0.15s; }
  .site-footer-links a:hover { color: var(--primary); }

  /* Cyberpunk: barra casi negra con borde magenta que brilla; lo que va encima, en cian. */
  [data-theme="cyberpunk"] nav { background: #0a0c10; border-bottom: 2px solid var(--accent);
                                 box-shadow: 0 0 14px rgba(255,42,109,0.55); }
  [data-theme="cyberpunk"] .nav-brand { color: var(--primary); text-shadow: 0 0 8px rgba(0,255,249,0.6); }
  [data-theme="cyberpunk"] #settings-btn,
  [data-theme="cyberpunk"] #pomodoro { color: var(--primary); background: rgba(0,255,249,0.08);
                                       border-color: rgba(0,255,249,0.35); }
  [data-theme="cyberpunk"] .badge       { color: var(--primary); background: rgba(0,255,249,0.1); }
  [data-theme="cyberpunk"] .badge.topic { color: var(--accent); background: rgba(255,42,109,0.12); }
  [data-theme="cyberpunk"] .badge.mode  { color: #e0e0e0; }
  [data-theme="cyberpunk"] select       { border-color: rgba(0,255,249,0.25); }
  /* Mensajes: el del tutor con filo cian, el tuyo con filo magenta (en vez de un bloque de color). */
  [data-theme="cyberpunk"] .msg-row.bot  .bubble { border-color: rgba(0,255,249,0.35); }
  [data-theme="cyberpunk"] .msg-row.user .bubble { background: rgba(255,42,109,0.12); color: var(--text);
                                                   border: 1px solid var(--accent); }
  [data-theme="cyberpunk"] .btn-send { box-shadow: 0 0 10px rgba(0,255,249,0.45); }
  [data-theme="cyberpunk"] #pomodoro.pomo-break { color: #000; }  /* texto negro sobre verde neón */

  [data-theme="harvard"] {
    --primary:    #a51c30;
    --primary-dk: #8b1525;
    --primary-text: #ffffff;
    --accent:     #c9a84c;
    --bg:         #f8f4f4;
    --surface:    #ffffff;
    --surface2:   #fdf0f0;
    --border:     rgba(165,28,48,0.12);
    --text:       #1a0508;
    --muted:      #8a6670;
    --green:      #2e7d32;
    --red:        #c62828;
  }
  [data-theme="oldschool"] {
    --primary:    #111111;
    --primary-dk: #000000;
    --primary-text: #ffffff;
    --accent:     #555555;
    --accent-text: #ffffff;  /* su acento es gris oscuro: aquí el texto blanco sí se lee */
    --bg:         #f2efe8;
    --surface:    #faf8f3;
    --surface2:   #ebe8e0;
    --border:     rgba(0,0,0,0.14);
    --text:       #111111;
    --muted:      #777777;
    --green:      #333333;
    --red:        #222222;
  }

  /* ── RESPONSIVE ─────────────────────────────────── */

  /* Tablet (≤768px): bubbles más anchos */
  @media (max-width: 768px) {
    .bubble { max-width: 85%; }
  }

  /* Móvil (≤600px): estructura navbar en 2 filas — aplica en portrait y landscape */
  @media (max-width: 600px) {
    nav { height: auto; flex-wrap: wrap; padding: 8px 12px; row-gap: 4px; }
    .nav-brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .nav-controls { margin-left: auto; flex-shrink: 0; }
    .nav-badges { order: 3; flex: 0 0 100%; padding-bottom: 2px; }
    .bubble { max-width: 92%; }
    #messages { padding: 14px 10px; gap: 12px; }
    footer { padding: 10px 10px; }
    .site-footer { justify-content: center; gap: 12px; flex-wrap: wrap; }
    #settings-dropdown { right: 0; left: auto; min-width: 0; width: calc(100vw - 24px); max-width: 280px; }
  }

  /* Móvil portrait (≤600px): tamaños visuales solo en vertical */
  @media (max-width: 600px) and (orientation: portrait) {
    .nav-brand { font-size: 17px; font-weight: 700; }
    .badge { font-size: 12px; padding: 3px 10px; }
    .site-footer { font-size: 13px; padding: 10px 16px; }
  }

  /* Móvil landscape (altura ≤ 500px): navbar compacta, badges ocultos */
  @media (orientation: landscape) and (max-height: 500px) {
    nav { height: 40px; padding: 0 12px; flex-wrap: nowrap; }
    .nav-badges { display: none; }
    #messages { padding: 10px 12px; }
    #settings-dropdown { max-height: calc(100vh - 60px); overflow-y: auto; }
  }

  /* ── POMODORO ────────────────────────────────────── */
  /* Pastilla en la barra de arriba (junto a ⚙), con el mismo estilo que ⚙: no tapa el chat.
     El progreso es una línea fina bajo la barra (#pomo-progress). */
  #pomodoro {
    display: flex; align-items: center; gap: 2px;
    background: var(--nav-chip-bg, rgba(255,255,255,0.15));
    border: 1px solid var(--nav-chip-border, rgba(255,255,255,0.2));
    border-radius: 999px; padding: 2px 4px 2px 10px; color: var(--primary-text);
  }
  #pomo-time  { font-size: 13px; font-weight: 700; margin-right: 2px;
                font-variant-numeric: tabular-nums; letter-spacing: -0.3px; }
  #pomodoro button { background: none; border: none; color: inherit; cursor: pointer;
                     font-size: 14px; padding: 3px 5px; line-height: 1; }
  #pomodoro button:hover { opacity: 0.65; }
  #pomo-progress { height: 3px; background: var(--border); flex-shrink: 0; }
  #pomo-bar { height: 100%; width: 0; background: var(--primary); transition: width 0.8s linear; }
  #pomo-progress.pomo-break #pomo-bar { background: var(--green); }
  #pomo-progress.pomo-done  #pomo-bar { background: var(--red); }
  #pomodoro.pomo-break { background: var(--green); border-color: var(--green); color: #fff; }
  #pomodoro.pomo-done  { background: var(--red); border-color: var(--red); color: #fff;
                         animation: pomo-pulse 0.8s ease-in-out 4; }
  @keyframes pomo-pulse {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.12); }
  }
  [data-theme="cyberpunk"] #pomo-time {
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 6px var(--primary);
    letter-spacing: 1px;
  }
  [data-theme="oldschool"] #pomo-time {
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    font-size: 11px;
  }

  /* LOGIN */
  #login-overlay {
    position: fixed; inset: 0; background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
  }
  #login-overlay.hidden { display: none; }
  .login-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 52px 44px; width: 380px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.14); text-align: center;
    display: flex; flex-direction: column; gap: 0;
  }
  .login-box h2 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
  .login-box p  { font-size: 14px; color: var(--muted); margin-bottom: 28px; line-height: 1.5; }
  .login-box input {
    width: 100%; padding: 13px 14px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--surface2);
    color: var(--text); font-size: 14px; outline: none;
    transition: border 0.15s; font-family: inherit; margin-bottom: 14px;
  }
  .login-box input:focus { border-color: var(--primary); }
  .login-box .btn-primary {
    width: 100%; padding: 13px; background: var(--primary);
    color: var(--primary-text); border: none; border-radius: var(--radius);
    font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.15s;
    margin-bottom: 16px;
  }
  .login-box .btn-primary:hover { background: var(--primary-dk); }
  .login-box .btn-guest {
    background: none; border: none; color: var(--muted);
    font-size: 13px; cursor: pointer; text-decoration: underline;
    font-family: inherit; padding: 4px 0;
  }
  .login-box .btn-guest:hover { color: var(--text); }
  /* Tarjetas de curso: cada curso con su color, fijo en todos los temas (es su identidad).
     Un curso sin color asignado usa el del tema. */
  .login-box .course-card {
    width: 100%; padding: 13px; border: none; border-radius: var(--radius);
    background: var(--course-color, var(--primary)); color: var(--course-text, var(--primary-text));
    font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: filter 0.15s;
  }
  .login-box .course-card:hover { filter: brightness(0.88); }
  .login-box .course-card[data-course="cs50"]     { --course-color: #a51c30; --course-text: #fff; } /* carmesí Harvard */
  .login-box .course-card[data-course="mouredev"] { --course-color: #1a6fc4; --course-text: #fff; }
  .course-chip {
    font-size: 11px; font-weight: 600; padding: 2px 8px;
    border-radius: 999px; background: rgba(255, 255, 255, 0.25);
  }
  .login-error { color: var(--red); font-size: 12px; display: none; margin-bottom: 10px; }
