/* =========================================================
   RedRead — main.css
   Mobile-first, app-feel design system
   ========================================================= */

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

/* ── Tokens ──────────────────────────────────────────────── */
:root {
  /* Palette — warm neutrals + single red accent */
  --color-bg:            #f7f5f1;
  --color-surface:       #ffffff;
  --color-surface-2:     #f1ede7;
  --color-surface-3:     #e7e1d8;
  --color-border:        rgba(34, 28, 22, 0.10);
  --color-border-strong: rgba(34, 28, 22, 0.18);

  --color-text:        #1c1a17;
  --color-text-muted:  #6b6760;
  --color-text-soft:   #8a857d;

  --color-primary:        #d8332a;
  --color-primary-hover:  #b62a23;
  --color-primary-soft:   rgba(216, 51, 42, 0.10);
  --color-primary-tint:   #fdecea;
  --color-on-primary:     #ffffff;

  --color-danger:  #c43c2d;
  --color-success: #2f8f5e;
  --color-warning: #b67a07;

  /* Полупрозрачные слои */
  --color-overlay: rgba(15, 13, 11, 0.55);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 72px;
  --space-12: 96px;
  --space-16: 128px;

  /* Radii — varied: tighter inside, softer containers */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-2xl: 28px;
  --radius-pill: 999px;

  /* Shadows — tinted warm */
  --shadow-sm: 0 1px 2px rgba(34, 28, 22, 0.06);
  --shadow-md: 0 6px 18px -8px rgba(34, 28, 22, 0.18), 0 2px 4px rgba(34, 28, 22, 0.04);
  --shadow-lg: 0 24px 48px -20px rgba(34, 28, 22, 0.26), 0 6px 14px -8px rgba(34, 28, 22, 0.10);
  --shadow-pop: 0 14px 30px -10px rgba(216, 51, 42, 0.40);

  /* Transitions */
  --transition-fast: 140ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 220ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 360ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --container-max: 1180px;
  --header-height: 60px;
  --bottombar-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Typography */
  --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* z-index scale */
  --z-base:    1;
  --z-sticky:  50;
  --z-header:  60;
  --z-bottombar: 65;
  --z-modal:   100;
  --z-toast:   200;
}

.theme-dark {
  --color-bg:            #14120f;
  --color-surface:       #1c1a17;
  --color-surface-2:     #25221d;
  --color-surface-3:     #322d27;
  --color-border:        rgba(255, 245, 230, 0.08);
  --color-border-strong: rgba(255, 245, 230, 0.16);

  --color-text:        #f3efe8;
  --color-text-muted:  #a39d92;
  --color-text-soft:   #7c766d;

  --color-primary:        #ef4a40;
  --color-primary-hover:  #f2645b;
  --color-primary-soft:   rgba(239, 74, 64, 0.16);
  --color-primary-tint:   #2a1411;

  --color-warning: #f6c878;
  --color-overlay: rgba(0, 0, 0, 0.6);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px -8px rgba(0, 0, 0, 0.65), 0 2px 4px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 24px 48px -20px rgba(0, 0, 0, 0.75), 0 6px 14px -8px rgba(0, 0, 0, 0.50);
  --shadow-pop: 0 14px 30px -10px rgba(239, 74, 64, 0.55);
}

/* ── Reset / base ────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
  transition: background var(--transition-base), color var(--transition-base);
  min-height: 100dvh;
  /* Stop tap highlight on mobile */
  -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }

a { color: var(--color-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary-hover); }

button { font: inherit; cursor: pointer; }

img, svg { display: block; max-width: 100%; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
p  { margin: 0; }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Container ───────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

/* ── Header ──────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: color-mix(in srgb, var(--color-bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--color-border);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--header-height);
}

.logo {
  display: inline-flex;
  align-items: baseline;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-text);
}

.logo:hover { color: var(--color-text); }
.logo__red  { color: var(--color-primary); }
.logo__dark { color: inherit; }

.main-nav {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.main-nav__link {
  position: relative;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.main-nav__link:hover { color: var(--color-text); background: var(--color-surface-2); }
.main-nav__link.is-active { color: var(--color-text); }
.main-nav__link.is-active::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  width: 18px;
  height: 3px;
  background: var(--color-primary);
  border-radius: var(--radius-pill);
}

.header-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.nav-burger {
  display: none;
  background: transparent;
  border: 1px solid var(--color-border);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 1.15rem;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.nav-burger:hover { background: var(--color-surface-2); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--color-surface);
  --btn-color: var(--color-text);
  --btn-border: var(--color-border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  color: var(--btn-color);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
              transform var(--transition-fast), box-shadow var(--transition-fast),
              border-color var(--transition-fast);
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover  { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn--primary {
  --btn-bg: var(--color-primary);
  --btn-color: var(--color-on-primary);
  --btn-border: transparent;
  box-shadow: var(--shadow-pop);
}
.btn--primary:hover  { --btn-bg: var(--color-primary-hover); }

.btn--secondary {
  --btn-bg: var(--color-surface);
  --btn-color: var(--color-text);
  --btn-border: var(--color-border-strong);
}
.btn--secondary:hover { --btn-bg: var(--color-surface-2); }

.btn--ghost {
  --btn-bg: transparent;
  --btn-color: var(--color-text-muted);
  --btn-border: transparent;
  padding: 10px 12px;
}
.btn--ghost:hover { --btn-color: var(--color-text); --btn-bg: var(--color-surface-2); }

.btn--oauth {
  --btn-bg: var(--color-surface-2);
  --btn-color: var(--color-text);
  --btn-border: transparent;
  width: 100%;
  font-weight: 600;
}
.btn--oauth:hover { --btn-bg: var(--color-surface-3); }

.btn--block { display: flex; width: 100%; }

.btn--small { padding: 9px 13px; font-size: 0.85rem; border-radius: var(--radius-sm); }

.btn--icon {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.05rem;
  border-radius: var(--radius-md);
  --btn-border: var(--color-border);
}
.btn--icon:hover { --btn-bg: var(--color-surface-2); }

/* ── Hero / Index ────────────────────────────────────────── */
.hero {
  padding: var(--space-8) 0 var(--space-9);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: -10% -10% auto auto;
  width: 60vmax;
  height: 60vmax;
  background:
    radial-gradient(closest-side, var(--color-primary-soft), transparent 70%);
  pointer-events: none;
  z-index: 0;
  filter: blur(20px);
}

.hero__inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: var(--space-9);
  align-items: start;
}

/* По умолчанию grid-items имеют min-width: auto и не сжимаются меньше
   ширины своего nowrap-контента (длинный email, названия книг). Из-за
   этого правая колонка раздувается и выталкивает левую за экран.
   min-width: 0 разрешает колонкам сжиматься нормально. */
.hero__content,
.hero__panel {
  min-width: 0;
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.hero__eyebrow::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-soft);
}

.hero__title {
  font-size: clamp(2.2rem, 5.6vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin-bottom: var(--space-5);
  text-wrap: balance;
}

.hero__title .accent { color: var(--color-primary); }

.hero__text {
  font-size: clamp(1rem, 1.6vw, 1.1rem);
  color: var(--color-text-muted);
  max-width: 56ch;
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

.hero__features {
  list-style: none;
  padding: 0;
  margin: var(--space-8) 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.feature-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}
.feature-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.feature-card__title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
  letter-spacing: -0.01em;
}

.feature-card__text {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ── Auth card ───────────────────────────────────────────── */
.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

.auth-card__title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
  letter-spacing: -0.02em;
}

.auth-card__text {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
  line-height: 1.5;
}

.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }

.form-field { display: flex; flex-direction: column; gap: 6px; }

.form-field__label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
}

.form-field__input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.form-field__input::placeholder { color: var(--color-text-soft); }
.form-field__input:focus {
  outline: none;
  background: var(--color-surface);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-soft);
}

.auth-divider {
  position: relative;
  text-align: center;
  margin: var(--space-5) 0;
  color: var(--color-text-soft);
  font-size: 0.78rem;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 32px);
  height: 1px;
  background: var(--color-border);
}
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }

.oauth-list { display: flex; flex-direction: column; gap: var(--space-2); }

.auth-footer {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.auth-footer__text { font-size: 0.88rem; color: var(--color-text-muted); }

.auth-message {
  margin-top: var(--space-3);
  font-size: 0.85rem;
  min-height: 1.1em;
}

/* ── Modal ───────────────────────────────────────────────── */
/* Глобальное правило: атрибут hidden всегда скрывает элемент,
   даже если на нём задан display:flex/grid через класс */
[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 13, 11, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal__dialog {
  position: relative;
  z-index: 1;
  background: var(--color-surface);
  border-radius: var(--radius-2xl);
  padding: var(--space-7);
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  max-height: 90vh;
  overflow: auto;
}

.modal__title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: var(--space-5);
  letter-spacing: -0.02em;
}

.modal__close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  background: var(--color-surface-2);
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.modal__close:hover { background: var(--color-surface-3); color: var(--color-text); }

/* ── Bottom tab bar (mobile) ─────────────────────────────── */
.bottom-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-bottombar);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--color-border);
  padding-bottom: var(--safe-bottom);
}

.bottom-tabs__inner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: var(--bottombar-height);
}

.bottom-tab {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-decoration: none;
  position: relative;
  transition: color var(--transition-fast);
}

.bottom-tab__icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bottom-tab.is-active { color: var(--color-primary); }
.bottom-tab.is-active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 3px;
  background: var(--color-primary);
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 920px) {
  .hero__inner { grid-template-columns: 1fr; gap: var(--space-7); }
  .hero__features { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  :root { --header-height: 56px; }

  .container { padding: 0 var(--space-4); }

  .main-nav { display: none; position: fixed; top: var(--header-height); left: 0; right: 0;
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    flex-direction: column; align-items: stretch; padding: var(--space-2); z-index: var(--z-header); }
  .main-nav.is-open { display: flex; }
  .main-nav__link { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); }
  .main-nav__link.is-active::after { display: none; }
  .main-nav__link.is-active { background: var(--color-primary-soft); color: var(--color-primary); }

  .nav-burger { display: inline-flex; }

  .hero { padding: var(--space-6) 0 calc(var(--space-9) + var(--bottombar-height)); }
  .hero__title { font-size: clamp(2rem, 8vw, 2.6rem); }
  .hero__features { grid-template-columns: 1fr; }

  .header-actions .btn--small { padding: 8px 12px; }

  /* show bottom nav on mobile */
  .bottom-tabs { display: block; }
  body { padding-bottom: calc(var(--bottombar-height) + var(--safe-bottom)); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
