:root {
  --bg-outer: #D5B596;
  --bg-app: #F3E4D2;
  --bg-paper: #FAF0E2;
  --bg-paper-soft: #EFE0CC;
  --ink-cocoa: #3F251C;
  --ink-muted: #725144;
  --ink-faint: #987769;
  --border-warm: #BD8A64;
  --border-soft: #DFC3A5;
  --accent-terracotta: #8F4933;
  --accent-caramel: #B87644;
  --accent-gold: #E4A83B;
  --accent-sage: #5E7550;
  --accent-lilac: #735B98;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 10%, #E5C8AA 0%, #C9A684 100%);
  color: var(--ink-cocoa);
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

#app-shell {
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  background: var(--bg-app);
  position: relative;
  display: flex;
  flex-direction: column;
  padding-bottom: 84px;
  box-shadow: 0 24px 60px rgba(48, 25, 16, 0.38);
  overflow-x: hidden;
}

@media (min-width: 500px) {
  body {
    padding: 18px 0;
  }
  #app-shell {
    min-height: 860px;
    border-radius: 34px;
    border: 5px solid #DEC1A1;
  }
}

.blog-garland-bar {
  width: 100%;
  height: 26px;
  overflow: hidden;
  pointer-events: none;
}

.garland-bulb {
  animation: warmPulse 2.5s ease-in-out infinite alternate;
}

@keyframes warmPulse {
  from { opacity: 0.72; filter: drop-shadow(0 0 2px #F5C96B); }
  to { opacity: 1; filter: drop-shadow(0 0 6px #FFE08A); }
}

.app-header {
  padding: 6px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(243, 228, 210, 0.94);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--bg-paper);
  border: 1.5px solid var(--border-warm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(63, 37, 28, 0.12);
  overflow: hidden;
  flex-shrink: 0;
}

.brand-logo-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.brand-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 25px;
  font-weight: 700;
  line-height: 1;
  margin: 0;
  color: var(--ink-cocoa);
}

.brand-subtitle {
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: var(--accent-terracotta);
  margin: 2px 0 0;
  line-height: 1;
}

.role-pill-wrap {
  display: flex;
  background: var(--bg-paper-soft);
  border: 1px solid var(--border-warm);
  border-radius: 999px;
  padding: 2px;
}

.role-pill {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.role-pill.active {
  background: var(--ink-cocoa);
  color: var(--bg-paper);
}

.screen-container {
  flex: 1;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Бумажная карточка в стиле коллажей Reels Лианы */
.paper-plaque {
  background: var(--bg-paper);
  border: 1.5px solid var(--border-warm);
  border-radius: 14px;
  padding: 13px;
  position: relative;
  box-shadow: 0 8px 20px -8px rgba(63, 37, 28, 0.22);
}

.paper-plaque::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(184, 118, 68, 0.45);
  border-radius: 10px;
  pointer-events: none;
}

/* Деревянная полка */
.wood-shelf-beam {
  height: 14px;
  border-radius: 3px 3px 6px 6px;
  background: linear-gradient(180deg, #9E6847 0%, #73442F 68%, #522E21 100%);
  box-shadow: 0 8px 14px rgba(52, 27, 17, 0.28), inset 0 1px 0 rgba(255, 238, 215, 0.32);
}

.shelf-row-books {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 12px;
  padding: 10px 8px 0;
  min-height: 146px;
}

.book-cover-btn {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 86px;
  transition: transform 0.2s ease;
  position: relative;
}

.book-cover-btn:hover {
  transform: translateY(-5px) rotate(-1deg);
}

.book-cover-art {
  width: 82px;
  height: 120px;
  border-radius: 6px 8px 8px 6px;
  border: 1px solid rgba(45, 22, 14, 0.45);
  box-shadow: -3px 5px 12px rgba(45, 22, 14, 0.32), inset 3px 0 5px rgba(255, 255, 255, 0.18);
  padding: 7px 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  color: #FFFDF7;
  position: relative;
  overflow: hidden;
}

.book-cover-art::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(255, 250, 235, 0.26);
  border-radius: 4px;
  pointer-events: none;
}

.book-cover-author {
  font-size: 7.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.86;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-cover-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 700;
  font-size: 12.5px;
  line-height: 1.06;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-cover-accent {
  font-size: 7.5px;
  color: #FFE399;
}

.book-badge-pill {
  position: absolute;
  top: -5px;
  right: 0;
  background: var(--bg-paper);
  border: 1px solid var(--border-warm);
  color: var(--ink-cocoa);
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.chips-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chips-scroll::-webkit-scrollbar {
  display: none;
}

.sub-tab-btn {
  border: 1px solid var(--border-warm);
  background: var(--bg-paper-soft);
  color: var(--ink-muted);
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.sub-tab-btn.active {
  background: var(--ink-cocoa);
  color: var(--bg-paper);
  border-color: var(--ink-cocoa);
}

.btn-primary {
  border: none;
  background: var(--ink-cocoa);
  color: var(--bg-paper);
  font-weight: 600;
  font-size: 13px;
  padding: 11px 14px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-secondary {
  border: 1px solid var(--border-warm);
  background: var(--bg-paper);
  color: var(--ink-cocoa);
  font-weight: 600;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 11px;
  cursor: pointer;
}

.tag-chip {
  border: 1px solid var(--border-warm);
  background: var(--bg-paper);
  color: var(--ink-cocoa);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tag-chip.selected {
  background: var(--ink-cocoa);
  color: var(--bg-paper);
  border-color: var(--ink-cocoa);
  font-weight: 600;
}

/* Половинки звёзд 1..5 */
.half-stars-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.star-box {
  position: relative;
  font-size: 24px;
  line-height: 1;
  color: #D7C2AA;
  user-select: none;
}

.star-fill {
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
  color: var(--accent-gold);
  pointer-events: none;
}

.star-hit-left,
.star-hit-right {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  cursor: pointer;
  z-index: 2;
}
.star-hit-left { left: 0; }
.star-hit-right { right: 0; }

/* Навигация */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: rgba(250, 240, 226, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-warm);
  display: flex;
  justify-content: space-around;
  padding: 6px 8px 8px;
  z-index: 30;
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
}

.nav-btn.active {
  background: var(--bg-paper-soft);
  color: var(--ink-cocoa);
  border: 1px solid var(--border-soft);
}

/* Модалка */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 22, 14, 0.62);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  width: 100%;
  max-width: 430px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-app);
  border-top: 2px solid var(--border-warm);
  border-radius: 24px 24px 0 0;
  padding: 16px;
}

.toast-banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-cocoa);
  color: var(--bg-paper);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  z-index: 80;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

.hidden {
  display: none !important;
}

/* Открытка 9:16 для Stories */
.story-canvas-9x16 {
  width: 256px;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  border-radius: 20px;
  background: linear-gradient(180deg, #3D231A 0%, #523023 52%, #2F1A13 100%);
  border: 2px solid #C69268;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #FAF0E2;
  box-shadow: 0 14px 28px rgba(42, 22, 14, 0.42);
}

/* ==========================================================================
   ЭКРАН КРИТИЧЕСКОЙ ОШИБКИ
   Показывается, если приложение не может авторизоваться (нет initData в
   production, нет связи с API). Вместо бесконечной загрузки пользователь
   видит понятное объяснение и кнопку повтора.
   ========================================================================== */
.fatal-error-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  background: linear-gradient(180deg, #2A1610 0%, #3F2318 60%, #24120D 100%);
}

.fatal-error-screen[hidden] {
  display: none;
}

.fatal-error-card {
  max-width: 380px;
  width: 100%;
  text-align: center;
  background: rgba(250, 240, 226, 0.06);
  border: 1px solid rgba(250, 240, 226, 0.18);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.fatal-error-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 14px;
}

.fatal-error-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 23px;
  font-weight: 700;
  color: #FAF0E2;
  margin: 0 0 12px;
}

.fatal-error-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: rgba(250, 240, 226, 0.86);
  margin: 0 0 18px;
}

.fatal-error-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}

.fatal-error-hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: rgba(250, 240, 226, 0.55);
  margin: 0;
}
