/* ==========================================================================
   Lexicon — modern theme
   Self-contained design system: variables, cinematic backdrop, glass surfaces,
   cards, forms, modals. No external framework dependency.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 26px;
  --radius-pill: 999px;

  --ease: cubic-bezier(.22, 1, .36, 1);
}

/* ---------- Light theme (default) ---------- */
:root,
:root[data-theme="light"] {
  --bg: #f2f3fb;
  --bg-2: #e9ebf8;
  --surface: #ffffff;
  --surface-2: #f7f8fd;
  --glass: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(20, 20, 40, 0.08);
  --text: #191a23;
  --text-muted: #6b6d84;
  --text-faint: #9698ab;
  --border: rgba(20, 20, 40, 0.08);
  --accent: #6d5bf6;
  --accent-2: #ec4899;
  --accent-soft: rgba(109, 91, 246, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --shadow: 0 10px 30px -10px rgba(24, 20, 60, 0.18);
  --shadow-lg: 0 24px 60px -15px rgba(24, 20, 60, 0.28);
  --scrollbar: rgba(20, 20, 40, 0.18);
  --blob-1: #a78bfa;
  --blob-2: #f0abfc;
  --blob-3: #93c5fd;
  color-scheme: light;
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
  --bg: #0b0c14;
  --bg-2: #12131e;
  --surface: #171923;
  --surface-2: #1d202c;
  --glass: rgba(23, 25, 35, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text: #f1f1f6;
  --text-muted: #a3a5b8;
  --text-faint: #6c6e82;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #8b7bfa;
  --accent-2: #f472b6;
  --accent-soft: rgba(139, 123, 250, 0.18);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #34d399;
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 60px -15px rgba(0, 0, 0, 0.6);
  --scrollbar: rgba(255, 255, 255, 0.16);
  --blob-1: #4c3b9e;
  --blob-2: #7c2d6e;
  --blob-3: #1e3a6e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s var(--ease), color .4s var(--ease);
  opacity: 0;
  animation: pageIn .5s var(--ease) forwards;
}
@keyframes pageIn { to { opacity: 1; } }

::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Cinematic animated backdrop ---------- */
.cine-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(120% 120% at 10% 0%, var(--bg-2), var(--bg) 60%);
}
.cine-bg span {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .55;
  will-change: transform;
}
.cine-bg span:nth-child(1) {
  width: 42vw; height: 42vw; left: -10%; top: -12%;
  background: var(--blob-1);
  animation: float1 26s ease-in-out infinite;
}
.cine-bg span:nth-child(2) {
  width: 36vw; height: 36vw; right: -8%; top: 10%;
  background: var(--blob-2);
  animation: float2 32s ease-in-out infinite;
}
.cine-bg span:nth-child(3) {
  width: 40vw; height: 40vw; left: 20%; bottom: -18%;
  background: var(--blob-3);
  animation: float3 30s ease-in-out infinite;
}
@keyframes float1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(8%, 10%) scale(1.12); }
}
@keyframes float2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-10%, 8%) scale(0.92); }
}
@keyframes float3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(6%, -8%) scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
  .cine-bg span { animation: none; }
  body { animation: none; opacity: 1; }
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  --size: 42px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), background .3s;
  box-shadow: var(--shadow);
}
.theme-toggle:hover { transform: translateY(-2px) rotate(12deg); }
.theme-toggle:active { transform: translateY(0) scale(.94); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* ---------- Icon helpers ---------- */
.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; }
.icon svg { width: 100%; height: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  border: none;
  border-radius: var(--radius-pill);
  padding: .8rem 1.6rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), opacity .2s var(--ease), background .2s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px -8px var(--accent-soft), var(--shadow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 16px 30px -8px var(--accent-soft), var(--shadow); }
.btn-ghost {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }
.btn-danger-ghost { color: var(--danger); background: var(--danger-soft); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); transform: translateY(-1px); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.active { color: #f6b93b; }
.icon-btn.active svg { fill: #f6b93b; }

/* ---------- Inputs ---------- */
.field { margin-bottom: 1.1rem; text-align: left; }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
  letter-spacing: .01em;
}
.input, textarea.input {
  width: 100%;
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.input:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: var(--surface);
}
.input-hint { font-size: .78rem; color: var(--text-faint); margin-top: .35rem; }
.input-with-icon { position: relative; }
.input-with-icon .input { padding-right: 2.6rem; }
.input-with-icon .icon-slot {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
}

/* ---------- Alert banner ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  margin-bottom: 1rem;
  animation: alertIn .3s var(--ease);
}
@keyframes alertIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: rgba(16, 185, 129, .12); color: var(--success); }

/* ---------- Progress bar ---------- */
.progress-track {
  width: 100%;
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--border);
  overflow: hidden;
  margin: 1rem 0;
}
.progress-fill {
  height: 100%;
  width: 15%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s linear;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 1.1em; height: 1.1em;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Glass surface ---------- */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(8, 8, 16, .5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s var(--ease);
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateY(24px) scale(.96);
  opacity: 0;
  transition: transform .32s var(--ease), opacity .28s var(--ease);
}
.modal-backdrop.open .modal-box { transform: translateY(0) scale(1); opacity: 1; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.4rem 1.5rem 0.6rem;
}
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-body { padding: .6rem 1.5rem 0; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: .6rem;
  padding: 1.2rem 1.5rem 1.5rem;
}
.voice-row { display: flex; align-items: center; gap: .4rem; margin-top: .5rem; }
.voice-row .icon-btn { background: var(--surface-2); }
.voice-row .icon-btn.recording { color: var(--danger); background: var(--danger-soft); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 var(--danger-soft);} 50%{ box-shadow: 0 0 0 8px transparent; } }

/* ---------- Confirm dialog (small variant) ---------- */
.confirm-box { max-width: 360px; text-align: center; padding: 2rem 1.6rem 1.6rem; }
.confirm-box .confirm-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--danger-soft); color: var(--danger);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem;
}
.confirm-box .confirm-icon svg { width: 24px; height: 24px; }
.confirm-box p { color: var(--text-muted); margin: .4rem 0 1.4rem; font-size: .92rem; }
.confirm-actions { display: flex; gap: .6rem; }
.confirm-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; top: 1.2rem; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: .5rem;
  width: min(92vw, 380px);
}
.toast {
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: .87rem;
  font-weight: 500;
  display: flex; align-items: center; gap: .5rem;
  animation: toastIn .35s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.96); } to { opacity: 1; transform: none; } }
.toast.error { color: var(--danger); }
.toast.success { color: var(--success); }
