/* `hidden` attribute must always hide, even on elements with display set via class */
[hidden] { display: none !important; }

/* Respect the OS "reduce motion" setting: collapse animations/transitions to a
   near-instant tick (not 0s, so transitionend/animationend handlers still fire)
   and disable smooth scrolling. Applies app-wide so new UI inherits it. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============ Tokens ============ */
:root {
  /* Drive native UI (scrollbars, form controls) from the in-app theme rather
     than the OS, so dark mode gets dark scrollbars everywhere — and the chosen
     theme wins even when the OS preference is the opposite. */
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --bg-elev: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-soft: #f5f3ff;
  --accent: #4f46e5;
  --danger: #ef4444;
  --success: #16a34a;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow: 0 4px 14px rgba(15,23,42,.07);
  --shadow-lg: 0 24px 48px -12px rgba(15,23,42,.18);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --max-w: 1180px;
  --grad: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-soft: #11141b;
  --bg-elev: #161a23;
  --border: #232a38;
  --border-strong: #2c3445;
  --text: #f1f5f9;
  --text-soft: #cbd5e1;
  --text-mute: #64748b;
  --primary: #a78bfa;
  --primary-hover: #c4b5fd;
  --primary-soft: #4c1d95;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 6px 20px rgba(0,0,0,.4);
  --shadow-lg: 0 24px 48px -12px rgba(0,0,0,.55);
}

/* ============ Reset ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; }
img, svg { display: block; max-width: 100%; }

/* ============ Brand ============ */
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('fonts/manrope-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand.small { font-size: 14px; }
.brand-mark-bg { fill: var(--primary); }
.brand-img { color: var(--primary); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--grad);
  color: white;
  border-color: transparent;
  box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, var(--shadow-sm);
}
.btn-primary:hover { filter: brightness(1.05); background: var(--grad); }

.btn-ghost { border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-soft); border-color: var(--border-strong); }

.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { padding: 8px; }

/* Theme icon toggling — needs `.icon-btn` prefix so specificity beats the
   global `svg { display: block; }` reset and any future button-svg rules. */
.icon-btn .icon-moon { display: none; }
html[data-theme="dark"] .icon-btn .icon-sun { display: none; }
html[data-theme="dark"] .icon-btn .icon-moon { display: block; }

/* ============ Utilities ============ */
.muted { color: var(--text-soft); }
.grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.view[hidden] { display: none !important; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: toastIn .2s ease-out;
}
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--success); color: white; }
@keyframes toastIn {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============ Page transitions (rise + fade) ============ */
/* Shared motion for navigation. The app shell (styles/app.css) drives in-app swaps
   via View Transitions + a .kp-enter fallback; standalone document pages fade their
   <main> in on load via body.page-enter below. ~260ms ease-out matches clRise/modal.
   The global prefers-reduced-motion block at the top collapses these to an instant. */
@keyframes kpRise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes kpFadeDown {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}
body.page-enter main {
  animation: kpRise .28s cubic-bezier(.2, .7, .3, 1) both;
}

/* ============ Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease-out;
}
@keyframes modalIn {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg-soft); color: var(--text); }
.modal-card h2 { margin-bottom: 8px; font-size: 20px; }
.modal-card p { margin-bottom: 20px; }

.waitlist-form {
  display: flex;
  gap: 8px;
}
.waitlist-form input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.waitlist-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.waitlist-thanks {
  margin-top: 12px;
  color: var(--success);
  font-weight: 500;
}

/* ============ Auth modal ============ */
.auth-card { max-width: 420px; }
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-form input {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.auth-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.auth-thanks {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}
.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(220, 38, 38, 0.08);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 13px;
}

/* ============ Upgrade modal ============ */
.upgrade-card { max-width: 560px; }
.upgrade-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}
.upgrade-option {
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.upgrade-option h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.upgrade-option p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  flex: 1;
}
.upgrade-foot {
  margin-top: 14px;
  font-size: 12px;
  text-align: center;
}
@media (max-width: 560px) {
  .upgrade-options { grid-template-columns: 1fr; }
}

/* ============ Magic-link confirm page ============ */
.signin-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-soft);
}
.signin-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.signin-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  margin-bottom: 18px;
}
.signin-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
}
.signin-lede {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
}
.signin-foot {
  margin-top: 16px;
  font-size: 12px;
  line-height: 1.5;
}
.signin-error {
  margin-top: 16px;
  text-align: left;
}

/* ============ Forms (shared) ============ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
}
.field input, .field select, .field textarea {
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint { font-size: 12px; color: var(--text-mute); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Range input */
.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.range-row input[type="range"] {
  flex: 1;
}
.range-row .range-val {
  min-width: 48px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 13px;
  color: var(--text-soft);
  text-align: right;
}
