/* ═══════════════════════════════════════════════════════
   Escribir — Design System "Warm Midnight"
   Basado en The Digital Heirloom / Literary Sanctuary
   ═══════════════════════════════════════════════════════ */

:root {
  --base: #151311;
  --surface: #1d1b19;
  --surface-card: #211f1d;
  --surface-elevated: #2c2927;
  --surface-highest: #373432;
  --surface-lowest: #100e0c;
  --primary: #a78bfa;
  --primary-dim: rgba(167, 139, 250, 0.12);
  --primary-glow: rgba(167, 139, 250, 0.25);
  --primary-text: #cebdff;
  --secondary: #ffc640;
  --secondary-dim: rgba(255, 198, 64, 0.12);
  --tertiary: #ffb77d;
  --success: #4ade80;
  --error: #ef4444;
  --on-surface: #e7e1de;
  --on-surface-variant: #a8a4a0;
  --on-surface-dim: #6b6865;
  --outline: rgba(255, 255, 255, 0.06);
  --font-creative: 'Newsreader', Georgia, serif;
  --font-functional: 'Inter', -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-creative);
  background: var(--base);
  background-image: radial-gradient(circle at center, var(--surface) 0%, var(--base) 100%);
  color: var(--on-surface);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(167, 139, 250, 0.3); color: #fff; }

/* ── Typography ────────────────────────────────────── */
.font-creative { font-family: var(--font-creative); }
.font-functional { font-family: var(--font-functional); }
.headline-xl { font-family: var(--font-creative); font-size: 3.5rem; font-weight: 200; font-style: italic; letter-spacing: -0.02em; line-height: 1.1; }
.headline-lg { font-family: var(--font-creative); font-size: 2rem; font-weight: 300; font-style: italic; letter-spacing: -0.01em; }
.headline-md { font-family: var(--font-creative); font-size: 1.5rem; font-weight: 400; }
.body-lg { font-family: var(--font-creative); font-size: 1.125rem; line-height: 1.8; letter-spacing: 0.012em; }
.body-md { font-family: var(--font-creative); font-size: 1rem; line-height: 1.7; }
.label-md { font-family: var(--font-functional); font-size: 0.625rem; text-transform: uppercase; letter-spacing: 0.15em; font-weight: 600; }
.label-sm { font-family: var(--font-functional); font-size: 0.5625rem; text-transform: uppercase; letter-spacing: 0.12em; }

/* ── Cards (no borders — tonal separation) ─────────── */
.card {
  background: var(--surface-card);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  transition: background 0.3s;
}
.card:hover { background: var(--surface-elevated); }
.card-glass {
  background: rgba(167, 139, 250, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
  font-family: var(--font-functional);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--primary);
  color: #1a0a3e;
  padding: 0.875rem 1.5rem;
  border-radius: var(--radius-full);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  background: var(--surface-elevated);
  color: var(--on-surface);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-lg);
}
.btn-secondary:hover { background: var(--surface-highest); }
.btn-ghost {
  background: none;
  color: var(--on-surface-variant);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
}
.btn-ghost:hover { color: var(--primary); }
.btn-icon {
  background: var(--surface-elevated);
  color: var(--on-surface);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--surface-highest); color: var(--primary); }

/* ── Inputs ────────────────────────────────────────── */
.input-invisible {
  background: none;
  border: none;
  color: var(--on-surface);
  font-family: var(--font-creative);
  font-size: 1rem;
  outline: none;
  width: 100%;
  caret-color: var(--secondary);
}
.input-invisible::placeholder { color: var(--on-surface-dim); }
.input-underline {
  background: none;
  border: none;
  border-bottom: 1px solid var(--surface-highest);
  color: var(--on-surface);
  font-family: var(--font-creative);
  font-size: 1.125rem;
  padding: 0.75rem 0.25rem;
  outline: none;
  width: 100%;
  transition: border-color 0.3s;
}
.input-underline:focus { border-color: var(--primary); }
textarea.editor-canvas {
  background: transparent;
  border: none;
  color: var(--on-surface);
  font-family: var(--font-creative);
  font-style: italic;
  font-size: 1.25rem;
  line-height: 1.8;
  width: 100%;
  min-height: 60vh;
  resize: none;
  outline: none;
  caret-color: var(--secondary);
  scrollbar-width: none;
}
textarea.editor-canvas::-webkit-scrollbar { display: none; }
textarea.editor-canvas::placeholder { color: rgba(231, 225, 222, 0.1); }

/* ── Badges ────────────────────────────────────────── */
.badge {
  font-family: var(--font-functional);
  font-size: 0.5625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
}
.badge-primary { background: var(--primary-dim); color: var(--primary); }
.badge-secondary { background: var(--secondary-dim); color: var(--secondary); }
.badge-success { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.badge-tertiary { background: rgba(255, 183, 125, 0.12); color: var(--tertiary); }
.badge-ghost { background: var(--surface-highest); color: var(--on-surface-variant); }

/* ── Status badges ─────────────────────────────────── */
.status-idea { background: var(--surface-highest); color: var(--on-surface-variant); }
.status-outline { background: rgba(96, 165, 250, 0.12); color: #60a5fa; }
.status-borrador { background: var(--secondary-dim); color: var(--secondary); }
.status-revision { background: var(--primary-dim); color: var(--primary); }
.status-final { background: rgba(74, 222, 128, 0.12); color: var(--success); }

/* ── Navigation ────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0.5rem 1.5rem calc(0.5rem + var(--safe-bottom));
  background: rgba(29, 27, 25, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  color: var(--on-surface-dim);
  text-decoration: none;
  transition: color 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  position: relative;
}
.nav-item span.label { font-family: var(--font-functional); font-size: 0.5625rem; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 0.25rem; }
.nav-item.active { color: var(--primary); background: var(--primary-dim); border-radius: var(--radius-full); padding: 0.625rem 0.75rem; }
.nav-item:not(.active):hover { color: var(--secondary); }
.nav-badge {
  position: absolute;
  top: 0;
  right: -2px;
  background: var(--error);
  color: #fff;
  font-family: var(--font-functional);
  font-size: 0.5rem;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ── Header ────────────────────────────────────────── */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  background: var(--base);
  z-index: 50;
}
.app-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.app-logo .avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-creative);
  font-style: italic;
  font-weight: 700;
  color: #1a0a3e;
  font-size: 0.875rem;
}
.app-logo h1 {
  font-family: var(--font-creative);
  font-style: italic;
  font-size: 1.375rem;
  font-weight: 400;
  color: var(--on-surface);
}

/* ── Views & Layout ────────────────────────────────── */
.view { display: none; padding: 0 1.5rem 7rem; }
.view.active { display: block; }
.view-writing { padding: 0; }
.view-writing.active { display: flex; flex-direction: column; min-height: 100dvh; }

.section-title {
  font-family: var(--font-functional);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--on-surface-variant);
  margin-bottom: 0.75rem;
}

/* ── Progress bar ──────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--surface-highest);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: var(--secondary);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ── Fragment cards ────────────────────────────────── */
.fragment-card {
  background: var(--surface-card);
  border-radius: var(--radius-xl);
  padding: 1.25rem;
  cursor: pointer;
  transition: background 0.3s;
}
.fragment-card:hover { background: var(--surface-elevated); }
.fragment-card.selected { outline: 2px solid var(--primary); background: var(--primary-dim); }
.fragment-text {
  font-family: var(--font-creative);
  font-style: italic;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--on-surface);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fragment-meta { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.75rem; }

/* ── Chapter cards ─────────────────────────────────── */
.chapter-card {
  background: var(--surface-card);
  border-radius: var(--radius-xl);
  padding: 1.25rem;
  cursor: pointer;
  transition: background 0.3s;
  position: relative;
}
.chapter-card:hover { background: var(--surface-elevated); }
.chapter-number {
  font-family: var(--font-creative);
  font-size: 3rem;
  font-weight: 800;
  color: rgba(231, 225, 222, 0.05);
  position: absolute;
  top: -0.5rem;
  left: 0.5rem;
}

/* ── AI Companion Card ─────────────────────────────── */
.ai-card {
  background: rgba(167, 139, 250, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-xl);
  padding: 1.25rem;
}
.ai-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.8); }
}

/* ── Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 2rem;
  height: 0.25rem;
  background: var(--surface-highest);
  border-radius: 2px;
  margin: 0 auto 1rem;
}

/* ── Writing mode floating bar ─────────────────────── */
.writing-bar {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background: rgba(29, 27, 25, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-full);
  z-index: 90;
}
.writing-bar .divider {
  width: 1px;
  height: 1rem;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 0.375rem;
}

/* ── Audio player ──────────────────────────────────── */
.audio-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface-card);
  border-radius: var(--radius-lg);
}
.audio-progress {
  flex: 1;
  height: 3px;
  background: var(--surface-highest);
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
}
.audio-progress .fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.1s linear;
}
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(239, 68, 68, 0.12);
  border-radius: var(--radius-md);
  color: var(--error);
  font-family: var(--font-functional);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
  animation: pulse 1s infinite;
}

/* ── Modo Poderoso cards ───────────────────────────── */
.modo-card {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  min-width: 100px;
  flex-shrink: 0;
}
.modo-card:hover { background: var(--surface-elevated); }
.modo-card:active { transform: scale(0.96); }
.modo-card .icon { font-size: 1.75rem; margin-bottom: 0.375rem; }
.modo-card .name { font-family: var(--font-functional); font-size: 0.6875rem; font-weight: 600; }

/* ── Filter pills ──────────────────────────────────── */
.filters {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }
.filter-pill {
  font-family: var(--font-functional);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  color: var(--on-surface-variant);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.filter-pill.active { background: var(--primary); color: #1a0a3e; }
.filter-pill:not(.active):hover { color: var(--on-surface); }

/* ── Grain texture overlay ─────────────────────────── */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.03;
  z-index: 999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-highest); border-radius: 2px; }

/* ── Utility ───────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 0.75rem; }
.gap-lg { gap: 1rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-md { margin-bottom: 1rem; }
.mb-lg { margin-bottom: 1.5rem; }
.text-variant { color: var(--on-surface-variant); }
.text-dim { color: var(--on-surface-dim); }
.text-primary { color: var(--primary); }
.text-secondary { color: var(--secondary); }
.text-center { text-align: center; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Desktop ───────────────────────────────────────── */
@media (min-width: 768px) {
  .view { max-width: 720px; margin: 0 auto; }
  .headline-xl { font-size: 5rem; }
  .bottom-nav { max-width: 400px; left: 50%; transform: translateX(-50%); border-radius: var(--radius-xl); bottom: 1rem; }
  .modal-content { border-radius: var(--radius-xl); max-height: 80vh; }
  .modal-overlay { align-items: center; }
}

/* ── Loading spinner ───────────────────────────────── */
.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--surface-highest);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ───────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--on-surface-dim);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }
.empty-state p { font-family: var(--font-creative); font-style: italic; font-size: 1rem; }
