/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg: #0a0714;
  --surface: #110f27;
  --surface2: #1a1739;
  --border: #2a2460;
  --primary: #c9a9f5;
  --primary-dark: #7c52a8;
  --gold: #f5e6c8;
  --gold-dim: #c9a87a;
  --text: #e8e0f5;
  --text-muted: #9084c0;
  --error: #ff8080;
  --header-h: 60px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Lato', Georgia, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
}

.hidden { display: none !important; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Login Screen ─────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, #1c0a40 0%, #0a0714 70%);
}

.login-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}

.login-inner h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.9rem;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 6px;
}

#login-form {
  width: 100%;
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.field-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.field-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: 'Lato', sans-serif;
  transition: border-color 0.2s;
}

.field-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.field-group input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.optional { color: var(--muted); font-weight: 300; }

.field-hint {
  font-size: .75rem;
  color: var(--text-muted);
  opacity: .6;
  line-height: 1.4;
}

.login-error {
  color: var(--error);
  font-size: 0.85rem;
  text-align: center;
  padding: 8px 12px;
  background: rgba(255, 128, 128, 0.08);
  border-radius: 8px;
  border: 1px solid rgba(255, 128, 128, 0.2);
}

#btn-login {
  width: 100%;
  background: linear-gradient(135deg, #4a1f8a, #9b6dcc);
  color: var(--gold);
  border: none;
  padding: 14px;
  font-size: 1rem;
  font-family: 'Playfair Display', Georgia, serif;
  letter-spacing: 1px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(155, 109, 204, 0.35);
  margin-top: 4px;
}

#btn-login:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(155, 109, 204, 0.55);
}

#btn-login:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Landing ──────────────────────────────────────────────────────────────── */
#landing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, #1c0a40 0%, #0a0714 70%);
}

.landing-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
  max-width: 500px;
}

.gem-large {
  font-size: 72px;
  display: block;
  margin-bottom: 24px;
  animation: gem-pulse 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(201, 169, 245, 0.6));
}

@keyframes gem-pulse {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.08) translateY(-4px); }
}

#landing h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.6rem;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.landing-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 28px;
}

.landing-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.8;
  margin-bottom: 36px;
}

#btn-start {
  background: linear-gradient(135deg, #4a1f8a, #9b6dcc);
  color: var(--gold);
  border: none;
  padding: 16px 52px;
  font-size: 1.05rem;
  font-family: 'Playfair Display', Georgia, serif;
  letter-spacing: 1px;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 24px rgba(155, 109, 204, 0.45);
  margin-bottom: 16px;
}

#btn-start:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(155, 109, 204, 0.65);
}

#btn-start:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.landing-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ── Chat Layout ──────────────────────────────────────────────────────────── */
#chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  flex-shrink: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-gem { font-size: 1.3rem; }

.header-title {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  font-size: 1rem;
  white-space: nowrap;
}

.header-center {
  flex: 1;
  padding: 0 8px;
}

.progress-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  border-radius: 2px;
  width: 0%;
  transition: width 0.6s ease;
}

.header-right { flex-shrink: 0; }

#pilar-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Message Bubbles ──────────────────────────────────────────────────────── */
.msg {
  display: flex;
  gap: 12px;
  animation: msg-in 0.35s ease;
  max-width: 82%;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.ai { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.sys { align-self: center; max-width: 90%; }

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.msg-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  line-height: 1.75;
  font-size: 0.94rem;
}

.msg.ai .msg-bubble {
  border-radius: 4px 16px 16px 16px;
  border-left: 3px solid var(--primary);
}

.msg.user .msg-bubble {
  background: rgba(124, 82, 168, 0.15);
  border-color: rgba(201, 169, 245, 0.25);
  border-radius: 16px 4px 16px 16px;
  font-style: italic;
  color: var(--text-muted);
}

.msg.sys .msg-bubble {
  background: rgba(255, 128, 128, 0.08);
  border-color: rgba(255, 128, 128, 0.25);
  color: var(--error);
  text-align: center;
  font-size: 0.85rem;
}

/* Markdown inside AI bubbles */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  margin: 18px 0 8px;
}
.msg-bubble h1:first-child,
.msg-bubble h2:first-child,
.msg-bubble h3:first-child { margin-top: 0; }
.msg-bubble h1 { font-size: 1.25rem; }
.msg-bubble h2 { font-size: 1.08rem; }
.msg-bubble h3 { font-size: 0.97rem; color: var(--primary); }

.msg-bubble p { margin-bottom: 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble ul, .msg-bubble ol {
  margin: 8px 0 10px 20px;
  line-height: 1.9;
}
.msg-bubble li { margin-bottom: 4px; }

.msg-bubble strong { color: var(--primary); font-weight: 700; }
.msg-bubble em { color: var(--gold-dim); }

.msg-bubble blockquote {
  border-left: 3px solid var(--primary);
  padding: 8px 14px;
  margin: 12px 0;
  background: rgba(201, 169, 245, 0.05);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-style: italic;
}

.msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.msg-bubble code {
  background: rgba(201, 169, 245, 0.12);
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.87em;
}

/* ── Input Area ───────────────────────────────────────────────────────────── */
#input-area {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Loading */
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.loading-wrap p {
  font-size: 0.82rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.dots {
  display: flex;
  gap: 6px;
}

.dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: dot-bounce 1.3s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.55); opacity: 0.35; }
  40% { transform: scale(1); opacity: 1; }
}

/* Continuar button */
.btn-continuar {
  display: block;
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #3a1870, #7c52a8);
  color: var(--gold);
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-family: 'Playfair Display', Georgia, serif;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 2px 14px rgba(124, 82, 168, 0.4);
}

.btn-continuar:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 22px rgba(124, 82, 168, 0.6);
}

/* Response input */
.input-group {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-group textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-family: 'Lato', sans-serif;
  font-size: 0.94rem;
  resize: none;
  line-height: 1.6;
  transition: border-color 0.2s;
  min-height: 56px;
  max-height: 160px;
}

.input-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.input-group textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

#btn-send {
  background: linear-gradient(135deg, #3a1870, #7c52a8);
  color: var(--gold);
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s ease;
  align-self: flex-end;
}

#btn-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124, 82, 168, 0.55);
}

/* Done state */
.done-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 4px 0;
}

.done-title {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  font-size: 1.1rem;
  text-align: center;
}

.btn-pdf {
  display: inline-block;
  padding: 14px 40px;
  background: linear-gradient(135deg, #4a1f8a, #9b6dcc);
  color: var(--gold);
  text-decoration: none;
  border-radius: 50px;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1rem;
  box-shadow: 0 4px 22px rgba(155, 109, 204, 0.45);
  transition: all 0.3s ease;
  letter-spacing: 0.5px;
}

.btn-pdf:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(155, 109, 204, 0.65);
}

.btn-restart {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 22px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s;
}

.btn-restart:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #landing h1 { font-size: 2rem; }
  .gem-large { font-size: 56px; }
  .msg { max-width: 94%; }
  #messages { padding: 18px 14px; }
  header { padding: 0 14px; }
  #input-area { padding: 12px 14px 16px; }
}

.required { color: #e05c7a; margin-left: 2px; font-weight: bold; }
