/* tabarra — cliente messenger. Tema pergamino RO, tipografía pixel monoespaciada.
   Sin dependencias: 0 fuentes vendorizadas (Galmuri11 si el sistema la tiene,
   si no monospace). El log es claro por defecto; hay tema oscuro por clase. */

:root {
  --mono: "Galmuri11", ui-monospace, "SF Mono", "Menlo", monospace;
  --ink: #241a33;
  --paper: #f3e6c4;
  --paper-2: #e2cd9b;
  --bar: #d9c085;
  --bar-2: #e9d7a8;
  --log-bg: #fbf3dd;      /* pergamino claro del log */
  --log-ink: #2c2036;     /* texto de sistema/hora */
  --sys: #7a6a52;
  --quest: #8a6d1e;
  --pink: #ff5d8f;
  --border: #241a33;
  --shadow: 4px 4px 0 rgba(36,26,20,.45);

  /* Colores de usuario (índice de paleta → --uN). Variante CLARA: afinada para
     contraste AA (≥4.5:1) sobre --log-bg claro (#fbf3dd) y sobre el crema de
     paneles. El tema oscuro las reemplaza por variante DARK dentro del log.
     El hex de paleta es sólo la IDENTIDAD (índice estable); lo pintado es --uN.
     Ver themedColor() en api.js y el porqué del split claro/oscuro:
     un único color no puede pasar 4.5:1 contra fondo casi-blanco Y casi-negro. */
  --u0:#d32822;  --u1:#b25219;  --u2:#876903;  --u3:#61760d;
  --u4:#2b7d16;  --u5:#167d57;  --u6:#12797d;  --u7:#1b74a7;
  --u8:#3f64dd;  --u9:#6f5ad6;  --u10:#aa36cd; --u11:#be2da1;
  --u12:#ce2463; --u13:#a25a36; --u14:#57708e; --u15:#726d67;
}

/* Tema oscuro del log (toggle en ajustes). */
.log-dark {
  --log-bg: #201a2b;
  --log-ink: #d8cfe6;
  --sys: #9a8fb0;
  --quest: #d9b34a;
}

/* Variante DARK de los colores de usuario: ≥4.5:1 sobre --log-bg oscuro.
   Se acota a los contenedores que REALMENTE se oscurecen con el tema (el log, la
   preview de quirk y la pestaña activa); el resto de la UI sigue en crema aunque
   el tema esté oscuro, así que allí se mantiene la variante clara del :root.
   .color-preview.dark tiene fondo oscuro fijo, por eso va sin prefijo de tema. */
.log-dark .log,
.log-dark .quirk-preview,
.log-dark .win-tab.on,
.color-preview.dark {
  --u0:#e35752;  --u1:#d9631f;  --u2:#ae8604;  --u3:#84a112;
  --u4:#359b1b;  --u5:#1b986a;  --u6:#16989c;  --u7:#218ecc;
  --u8:#6482e4;  --u9:#8877dd;  --u10:#bb60d7; --u11:#d651bb;
  --u12:#e15287; --u13:#c27148; --u14:#6e88a6; --u15:#8a857e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* gana a display:flex de .auth/.app */

html, body {
  margin: 0; height: 100%;
  background: #cbb98a;
  color: var(--ink);
  font: 600 13px/1.4 var(--mono);
  -webkit-font-smoothing: none;
  font-smooth: never;
}

button, input, select, textarea { font-family: var(--mono); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 999; max-width: 90vw;
  padding: 8px 14px; border: 2px solid var(--border); border-radius: 10px;
  background: var(--paper); box-shadow: var(--shadow);
  font-weight: 700; font-size: 12px;
}

/* ─────────────────── AUTH ─────────────────── */

.auth {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 94vw);
  border: 2px solid var(--border); border-radius: 14px;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: var(--shadow);
  padding: 22px;
}
.auth-card h1 { margin: 0 0 2px; font-size: 26px; letter-spacing: 1px; }
.auth-card .tagline { margin: 0 0 18px; color: var(--sys); font-size: 12px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tabs button {
  flex: 1; cursor: pointer; padding: 8px; border: 2px solid var(--border);
  border-radius: 8px; background: var(--paper); color: var(--ink); font-weight: 700;
}
.auth-tabs button.on { background: var(--pink); color: #fff; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 9px 10px; border: 2px solid var(--border); border-radius: 8px;
  background: rgba(255,247,234,.95); color: var(--ink); outline: none; font-weight: 600;
}
.hint { font-size: 10px; color: var(--sys); margin-top: 4px; min-height: 12px; }
.hint.bad { color: #c0392b; }
.hint.good { color: #2e8b57; }

.palette-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch {
  aspect-ratio: 1; border: 2px solid var(--border); border-radius: 7px; cursor: pointer;
  padding: 0; position: relative;
}
.swatch.on { outline: 3px solid var(--ink); outline-offset: 1px; }
.swatch.on::after {
  content: "✓"; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: #fff; text-shadow: 0 0 3px #000; font-size: 13px;
}

.color-previews { display: flex; gap: 8px; margin: 10px 0 4px; }
.color-preview {
  flex: 1; border: 2px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.color-preview.light { background: #fbf3dd; }
.color-preview.dark  { background: #201a2b; }

.btn {
  cursor: pointer; padding: 10px 14px; border: 2px solid var(--border); border-radius: 9px;
  background: var(--pink); color: #fff; font-weight: 700; box-shadow: 2px 2px 0 rgba(36,26,51,.35);
}
.btn:active { transform: translate(2px,2px); box-shadow: none; }
.btn.wide { width: 100%; }
.btn.ghost { background: var(--paper); color: var(--ink); }
.btn.sm { padding: 5px 9px; font-size: 11px; }

/* ─────────────────── APP SHELL ─────────────────── */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(180deg, var(--bar-2), var(--bar));
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 800; font-size: 15px; letter-spacing: 1px; }
.topbar .me-handle { font-weight: 800; }
.topbar .spacer { flex: 1; }
.topbar .mood-pick {
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  border: 2px solid var(--border); border-radius: 8px; background: var(--paper);
  padding: 4px 8px; font-weight: 700; font-size: 12px;
}
.topbar .mood-ico { font-size: 15px; }

.workspace { flex: 1; display: flex; min-height: 0; }

/* ─────────────────── CHUMROLL ─────────────────── */

.chumroll {
  width: 230px; flex: 0 0 230px; overflow-y: auto; overscroll-behavior: contain;
  border-right: 2px solid var(--border);
  background: linear-gradient(180deg, #efe1bb, #e2cd9b);
  padding: 8px;
}
.chum-search { display: flex; gap: 4px; margin-bottom: 8px; }
.chum-search input {
  flex: 1; min-width: 0; padding: 6px 8px; border: 2px solid var(--border); border-radius: 7px;
  background: rgba(255,247,234,.95); outline: none;
}
.chum-section-title {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  color: var(--sys); margin: 10px 2px 4px;
}
.chum-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 7px; margin-bottom: 3px;
  border: 2px solid var(--border); border-radius: 8px; background: rgba(255,247,234,.9);
  cursor: pointer;
}
.chum-item:hover { background: #fff;}
.chum-mood { font-size: 15px; line-height: 1; }
.chum-handle { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chum-badge {
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--pink);
  color: #fff; font-size: 10px; font-weight: 800; display: inline-flex; align-items: center;
  justify-content: center;
}
.chum-actions { display: flex; gap: 3px; }
.chum-actions button {
  cursor: pointer; border: 2px solid var(--border); border-radius: 6px; background: var(--paper);
  color: var(--ink); font-size: 10px; font-weight: 700; padding: 2px 5px;
}
.chum-actions button.ok { background: #b6e3b0; }
.chum-actions button.no { background: #ffd7e2; }
.chum-empty { color: var(--sys); font-size: 11px; padding: 6px; font-style: italic; }

/* ─────────────────── WINDOWS AREA ─────────────────── */

.windows { flex: 1; position: relative; overflow: hidden; }

/* ─── EL ESPACIO (canvas de sala) ─── */
/* El canvas es el fondo de #windows; la ventana de chat flota encima (z>8).
   object-fit: contain mantiene la proporción 960×640 y escala a ancho completo
   en móvil. image-rendering pixelated para el pixel-art. */
.room-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; z-index: 1; background: #1a1420;
  image-rendering: pixelated; touch-action: none;
}
.room-name {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 3;
  padding: 3px 12px; border: 2px solid var(--border); border-radius: 9px;
  background: rgba(251,243,221,.92); font-weight: 800; font-size: 13px;
  color: var(--ink); pointer-events: none; text-transform: lowercase;
}

.win {
  position: absolute; z-index: 8; width: min(380px, 92%);
  display: flex; flex-direction: column;
  border: 2px solid var(--border); border-radius: 10px; overflow: hidden;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: var(--shadow);
}
.win.focused { z-index: 20; }
.win-bar {
  display: flex; align-items: center; gap: 6px; cursor: move; user-select: none;
  padding: 5px 7px; border-bottom: 2px solid #3a2a14;
  background: linear-gradient(180deg, var(--bar-2), var(--bar));
}
.win-title { font-weight: 800; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-sub { font-weight: 600; font-size: 10px; color: var(--sys); margin-left: 4px; }
.win-bar .grow { flex: 1; min-width: 0; overflow: hidden; }
.win-btn {
  cursor: pointer; border: 2px solid var(--border); border-radius: 6px; background: var(--paper);
  color: var(--ink); width: 22px; height: 20px; line-height: 1; font-weight: 800; padding: 0;
}
.win-btn.close { background: #ffd7e2; }
.win-btn:active { transform: translate(1px,1px); }

/* Pestañas de conversaciones dentro de una ventana. */
.win-tabs { display: flex; gap: 3px; padding: 4px 5px 0; flex-wrap: wrap; background: var(--bar); }
.win-tab {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  border: 2px solid var(--border); border-bottom: none; border-radius: 7px 7px 0 0;
  background: var(--paper-2); padding: 3px 8px; font-size: 11px; font-weight: 700;
}
.win-tab.on { background: var(--log-bg); }
.win-tab .tab-badge {
  min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--pink);
  color: #fff; font-size: 9px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center;
}
.win-tab .tab-x { border: none; background: none; cursor: pointer; font-weight: 800; padding: 0 0 0 2px; color: var(--sys); }

.log {
  height: 260px; overflow-y: auto; overflow-x: hidden; padding: 7px 9px;
  background: var(--log-bg); color: var(--log-ink); overscroll-behavior: contain;
}
.line { margin: 0 0 2px; word-break: break-word; white-space: pre-wrap; display: flex; }
.line .time { color: var(--sys); font-size: 10px; margin-right: 6px; flex: 0 0 auto; padding-top: 1px; }
.line .body { flex: 1; min-width: 0; }
.line .ini { font-weight: 800; }
.line.sys .body { color: var(--sys); font-style: italic; }
.line.quest .body { color: var(--quest); font-weight: 800; }
.line.banner .body { color: var(--sys); font-style: italic; font-weight: 700; }

.typing {
  min-height: 15px; padding: 1px 9px 3px; font-size: 10px; font-style: italic; color: var(--sys);
  background: var(--log-bg);
}

.win-form { display: flex; gap: 6px; padding: 6px 8px; border-top: 2px solid #3a2a14; background: linear-gradient(180deg, #ecdcb2, var(--paper-2)); }
.win-form input {
  flex: 1; min-width: 0; padding: 8px 9px; border: 2px solid var(--border); border-radius: 8px;
  background: rgba(255,247,234,.97); color: var(--ink); outline: none; font-weight: 600;
}
.win-form button {
  cursor: pointer; padding: 0 12px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--pink); color: #fff; font-weight: 700; box-shadow: 2px 2px 0 rgba(36,26,51,.35);
}
.win-form button:active { transform: translate(2px,2px); box-shadow: none; }

.win.min .win-tabs, .win.min .log, .win.min .typing, .win.min .win-form { display: none; }

/* ─────────────────── TASKBAR (ventanas minimizadas) ─────────────────── */
.taskbar {
  display: flex; gap: 6px; padding: 6px 10px; border-top: 2px solid var(--border);
  background: var(--bar); overflow-x: auto; flex-wrap: wrap;
}
.task-chip {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  border: 2px solid var(--border); border-radius: 8px; background: var(--paper); padding: 4px 8px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}

/* ─────────────────── MODAL (quirk editor, humor, memos, ajustes) ─────────────────── */
.modal-back {
  position: fixed; inset: 0; z-index: 500; background: rgba(20,14,28,.5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: min(520px, 96vw); max-height: 90vh; overflow-y: auto;
  border: 2px solid var(--border); border-radius: 14px;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: var(--shadow); padding: 18px;
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal .row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.modal label { font-size: 11px; font-weight: 700; }
.modal input[type=text], .modal select, .modal textarea {
  padding: 7px 9px; border: 2px solid var(--border); border-radius: 8px;
  background: rgba(255,247,234,.95); color: var(--ink); outline: none; font-weight: 600;
}
.modal .close-x { float: right; }
.quirk-rule { border: 2px dashed var(--border); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.quirk-preview { border: 2px solid var(--border); border-radius: 8px; padding: 10px; background: var(--log-bg); margin-top: 6px; min-height: 20px; }

.mood-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mood-opt {
  cursor: pointer; border: 2px solid var(--border); border-radius: 10px; background: var(--paper);
  padding: 10px 6px; text-align: center; font-size: 11px; font-weight: 700;
}
.mood-opt.on { background: var(--pink); color: #fff; }
.mood-opt .big { display: block; font-size: 24px; margin-bottom: 3px; }

/* ─────────────────── AJUSTES (M6) ─────────────────── */
.settings-modal { width: min(380px, 96vw); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 2px; border-bottom: 2px dashed var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-label { font-weight: 800; font-size: 12px; }
.settings-seg { display: flex; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn {
  cursor: pointer; border: none; background: var(--paper); color: var(--ink);
  padding: 6px 12px; font-weight: 700; font-size: 11px;
}
.seg-btn.on { background: var(--pink); color: #fff; }
.settings-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; cursor: pointer; }
.settings-logout { justify-content: stretch; }
.settings-logout .s-logout { width: 100%; }

/* ─────────────────── ONBOARDING (M6): cartelito de bienvenida ─────────────────── */
.onboarding-card {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 6;
  width: min(300px, 90%);
  border: 2px solid var(--border); border-radius: 12px;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow: var(--shadow); padding: 14px 16px;
}
.onboarding-card h3 { margin: 0 0 8px; font-size: 14px; }
.onboarding-card ul { margin: 0 0 10px; padding-left: 18px; font-size: 12px; line-height: 1.6; }
.onboarding-card .ob-dismiss { width: 100%; }

/* ─────────────────── AVATAR PICKER (customizador, M4) ─────────────────── */
.avatar-picker { width: min(420px, 96vw); }
.ap-preview-wrap {
  display: flex; justify-content: center; margin: 4px 0 14px;
  padding: 14px; border: 2px solid var(--border); border-radius: 12px;
  background: var(--log-bg);
}
.ap-preview {
  width: 128px; height: 128px; image-rendering: pixelated;
  filter: drop-shadow(0 3px 0 rgba(36,26,20,.25));
}
.ap-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.ap-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 2px solid var(--border); border-radius: 9px; background: rgba(255,247,234,.9);
  padding: 8px 10px;
}
.ap-label { font-weight: 800; font-size: 12px; text-transform: lowercase; }
.ap-stepper { display: flex; align-items: center; gap: 8px; }
.ap-val { min-width: 74px; text-align: center; font-weight: 700; font-size: 12px; text-transform: lowercase; }
.ap-arrow {
  cursor: pointer; width: 34px; height: 34px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--paper); color: var(--ink); font-weight: 800; font-size: 15px; padding: 0;
  box-shadow: 2px 2px 0 rgba(36,26,51,.3);
}
.ap-arrow:active { transform: translate(2px,2px); box-shadow: none; }
.ap-actions { margin-top: 10px; }
.ap-actions .spacer { flex: 1; }
.ap-actions .surprise { font-size: 12px; }

/* ─────────────────── MÓVIL: customizador a pantalla completa ─────────────────── */
@media (max-width: 720px) {
  .avatar-picker-back { padding: 0; align-items: stretch; justify-content: stretch; }
  .avatar-picker {
    width: 100%; max-width: none; height: 100%; max-height: none;
    border-radius: 0; border: none; display: flex; flex-direction: column;
  }
  /* float:right no pinta nada dentro de un flex container (el modal pasa a
     serlo en móvil): sin esto, .close-x se estira a lo ancho como cualquier
     flex item normal, un botón "✕" del tamaño de una barra entera. */
  .avatar-picker .close-x { align-self: flex-end; flex: 0 0 auto; }
  .ap-preview-wrap { flex: 0 0 auto; }
  .ap-rows { flex: 1; overflow-y: auto; }
  .ap-row { padding: 14px 12px; }
  .ap-arrow { width: 46px; height: 46px; font-size: 18px; }
  .ap-val { min-width: 84px; font-size: 13px; }
  .ap-actions { flex: 0 0 auto; }
  .ap-actions .surprise, .ap-actions .save { padding: 14px 16px; font-size: 13px; }
}

/* ─────────────────── MÓVIL: ventanas a pantalla completa ─────────────────── */
@media (max-width: 720px) {
  .workspace { flex-direction: column; }
  .chumroll {
    width: 100%; flex: 0 0 auto; max-height: 40vh; border-right: none; border-bottom: 2px solid var(--border);
  }
  .chumroll.hidden-mobile { display: none; }
  .win {
    left: 0 !important; top: 0 !important; right: 0; bottom: 0;
    width: 100%; height: 100%; border-radius: 0; border: none;
    z-index: 30;
  }
  .win.min { display: none; }
  .win-bar { cursor: default; }
  .log { height: auto; flex: 1; }
  .taskbar { position: sticky; bottom: 0; }
  .mobile-only { display: inline-flex !important; }
}
.mobile-only { display: none; }

/* ─────────────────── handle clicable en el log + menú contextual ─────────────────── */
.ini-clickable { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.handle-menu {
  position: fixed; z-index: 600; border: 2px solid var(--border); border-radius: 8px;
  background: var(--paper); box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column;
}
.handle-menu button {
  cursor: pointer; border: none; background: none; text-align: left; padding: 6px 10px;
  font-size: 12px; font-weight: 700; color: var(--ink); border-radius: 6px; white-space: nowrap;
}
.handle-menu button:hover { background: #ffd7e2; }

/* ─────────────────── panel de miembros del memo ─────────────────── */
.members-panel { width: min(420px, 96vw); }
.mp-row { cursor: default; }
.mp-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--sys); flex: 0 0 auto;
}
.mp-dot.on { background: #5c9e2e; }
.mp-invite { margin-top: 10px; }
.mp-invite-select {
  flex: 1; min-width: 0; padding: 7px 9px; border: 2px solid var(--border); border-radius: 8px;
  background: rgba(255,247,234,.95); color: var(--ink); font-weight: 600;
}

/* ─────────────────── crear memo (modal) ─────────────────── */
.memo-create .field { margin-bottom: 12px; }
.memo-create .invite-grid {
  display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto;
  border: 2px solid var(--border); border-radius: 8px; padding: 6px; background: rgba(255,247,234,.7);
}
.memo-create .invite-row { display: flex; align-items: center; gap: 8px; padding: 3px 4px; }
.memo-create .invite-row label { font-weight: 600; flex: 1; cursor: pointer; }
.toggle-row { display: flex; align-items: center; gap: 8px; }
.toggle-row .hint { font-size: 11px; color: var(--sys); font-weight: 500; }

/* ─────────────────── búsqueda de gente + badges pendientes ─────────────────── */
.chum-status-tag {
  font-size: 9px; font-weight: 800; padding: 1px 6px; border-radius: 8px; margin-left: 4px;
  background: var(--paper-2); color: var(--sys); text-transform: uppercase;
}
.chum-status-tag.pending { background: #ffe6a8; color: #7a5a00; }
.chum-status-tag.accepted { background: #b6e3b0; color: #1f5c14; }
.chum-status-tag.blocked { background: #ffd7e2; color: #8a1f3a; }
.chum-section-title .count-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 15px; height: 15px;
  padding: 0 4px; border-radius: 8px; background: var(--pink); color: #fff; font-size: 9px;
  font-weight: 800; margin-left: 5px;
}
.chums-toggle { position: relative; }
.chums-toggle .toggle-badge {
  position: absolute; top: -5px; right: -5px; min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 8px; background: var(--pink); color: #fff; font-size: 9px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
