/* ============================================================================
   Мир Волшебной страны — стили. Палитра в духе цветных стран:
   жёлтая — север, голубая — восток, фиолетовая — запад, розовая — юг,
   изумрудный город — центр. Общий фон — тёплый пергамент сказочной книги.
   ============================================================================ */
:root {
  --bg:           #fdf7e8;
  --bg-soft:      #f6ecd0;
  --paper:        #fffaef;
  --ink:          #2b2017;
  --ink-soft:     #5d4a36;
  --accent:       #2e9e6a;          /* изумрудный */
  --accent-dark:  #1d6f4b;
  --accent-soft:  #d8efe2;
  --gold:         #c89318;
  --gold-soft:    #f3dc99;
  --rose:         #d96b9e;
  --blue:         #4a90c8;
  --violet:       #8a64c4;
  --yellow:       #e6c041;
  --shadow:       0 6px 20px rgba(45, 31, 15, .12);
  --shadow-card:  0 2px 6px rgba(45, 31, 15, .10);
  --radius:       14px;
}

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

/* HTML-атрибут hidden должен прятать даже элементы с display: flex */
[hidden] { display: none !important; }
body {
  font-family: "Georgia", "Times New Roman", serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

/* ====== Шапка ============================================================== */
.site-header {
  background: linear-gradient(180deg, #2a8a5e 0%, #1d6f4b 100%);
  color: #fff;
  padding: 18px 24px 0;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 100;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  user-select: none;
}
.brand-emoji {
  font-size: 48px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
}
.brand h1 {
  margin: 0;
  font-size: 28px;
  font-family: "Georgia", serif;
  letter-spacing: .3px;
  color: #fff8e0;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 14px;
  font-style: italic;
  color: #d2efd9;
  font-family: "Georgia", serif;
}

/* Режимы (взрослый/детский) */
.mode-switch {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
}
.mode-label { color: #d2efd9; }
.mode-btn {
  background: rgba(255,255,255,.10);
  color: #fff;
  border: 1px solid rgba(255,255,255,.20);
  padding: 6px 12px;
  border-radius: 18px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.mode-btn.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #2b2017;
  font-weight: 700;
}
.mode-btn:hover { background: rgba(255,255,255,.20); }
.mode-btn.active:hover { background: #d9a322; }

/* Поиск */
.search-row { padding: 14px 0 6px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 24px;
  padding: 6px 14px;
  box-shadow: var(--shadow-card);
}
.search-ico { font-size: 16px; }
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  padding: 4px 0;
  color: var(--ink);
}
.search-clear {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 18px;
}

/* Табы */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 14px;
  border-top: 1px solid rgba(255,255,255,.15);
  padding-top: 10px;
  padding-bottom: 10px;
}
.tab {
  background: transparent;
  color: #d2efd9;
  border: none;
  padding: 8px 14px;
  border-radius: 10px 10px 0 0;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  position: relative;
  bottom: -10px;
}
.tab:hover { background: rgba(255,255,255,.10); color: #fff; }
.tab.active {
  background: var(--bg);
  color: var(--accent-dark);
  font-weight: 700;
}

/* ====== Контейнер ========================================================== */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
}

/* ====== Общие карточки ===================================================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease;
  border: 1px solid rgba(45, 31, 15, .06);
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(45, 31, 15, .15);
}
.card-image {
  aspect-ratio: 3 / 4;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-image .vk-img {
  width: 100%; height: 100%; object-fit: cover;
}
.card-body {
  padding: 12px 14px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.card-title {
  margin: 0;
  font-size: 16px;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.3;
}
.card-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 4px;
}
.card-tags {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 12px;
}
.card-tag {
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 2px 8px;
  border-radius: 10px;
}
.card-tag.evil {
  background: #f7d6d6; color: #8c2222;
}
.card-tag.neutral {
  background: #ebe1c8; color: #6b5727;
}

/* ====== Главная ============================================================ */
.hero {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  border-left: 6px solid var(--gold);
}
.hero h2 {
  margin: 0 0 6px;
  font-size: 26px;
  color: var(--accent-dark);
}
.hero p {
  margin: 0;
  font-size: 16px;
  color: var(--ink-soft);
}
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.stat-cell {
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.stat-num {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent-dark);
  font-family: "Georgia", serif;
}
.stat-lbl {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.section {
  margin: 32px 0 0;
}
.section h3 {
  margin: 0 0 14px;
  font-size: 20px;
  color: var(--accent-dark);
  border-bottom: 2px dashed var(--gold-soft);
  padding-bottom: 6px;
}

/* ====== Drawer ============================================================= */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(45, 31, 15, .35);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  animation: fadein .15s ease;
}
@keyframes fadein { from {opacity:0} to {opacity:1} }
.drawer-card {
  width: min(640px, 100%);
  height: 100%;
  background: var(--paper);
  box-shadow: -6px 0 30px rgba(0,0,0,.25);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: slidein .2s ease;
}
@keyframes slidein {
  from { transform: translateX(40px); opacity: 0 }
  to   { transform: translateX(0);    opacity: 1 }
}
.drawer-bar {
  position: sticky; top: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bg-soft);
  z-index: 1;
}
.drawer-back, .drawer-close {
  background: transparent;
  border: 1px solid var(--bg-soft);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
}
.drawer-back:hover, .drawer-close:hover { background: var(--bg-soft); }
.drawer-crumbs {
  flex: 1;
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-body { padding: 18px 22px 36px; }

.drawer-body h2 {
  margin: 0 0 4px;
  font-size: 24px;
  color: var(--accent-dark);
}
.drawer-body .drawer-sub {
  color: var(--ink-soft);
  font-size: 14px;
  font-style: italic;
  margin-bottom: 14px;
}
.drawer-body .drawer-img {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 14px;
  cursor: zoom-in;
  background: var(--bg-soft);
}
.drawer-body p { margin: 8px 0; }
.drawer-body .field {
  margin: 12px 0;
}
.drawer-body .field-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gold);
  margin-bottom: 6px;
}
.drawer-body .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-soft);
  color: var(--ink);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s ease, border-color .12s ease;
}
.chip:hover { background: var(--accent-soft); border-color: var(--accent); }
.chip-book   { background: #fff2cc; }
.chip-char   { background: #e6dcf3; }
.chip-place  { background: #d3eef9; }
.chip-animal { background: #d8efe2; }
.chip-world  { background: #f9e1d2; }
.chip .chip-role {
  font-size: 11px;
  color: var(--ink-soft);
  font-style: italic;
}

/* ====== Лайтбокс =========================================================== */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox-figure {
  margin: 0;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.lightbox-figure img {
  max-width: 95vw;
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.lightbox-figure figcaption {
  color: #fff;
  font-style: italic;
  text-align: center;
  max-width: 80%;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: rgba(255,255,255,.1);
  color: #fff;
  border: none;
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255,255,255,.25); }

/* ====== Карта (схема Волшебной страны) ===================================== */
.map-wrap {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-card);
}
.map-svg {
  width: 100%;
  max-width: 700px;
  display: block;
  margin: 0 auto;
}
.map-svg .region { cursor: pointer; transition: opacity .15s; }
.map-svg .region:hover { opacity: .8; }
.map-svg text {
  font-family: "Georgia", serif;
  fill: #2b2017;
  text-anchor: middle;
  pointer-events: none;
  font-weight: 700;
  /* font-size задаётся атрибутом на каждом <text> в app.js — в SVG user units */
}
.map-svg .city-dot { fill: var(--accent-dark); }
.map-legend {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
  color: var(--ink-soft);
  justify-content: center;
}
.map-legend .sw {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 4px;
}

/* ====== Книги — детальная карточка ========================================= */
.book-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 13px;
}
.book-meta div b { display: block; font-size: 11px; color: var(--ink-soft); text-transform: uppercase; }

/* ====== Поисковая выдача =================================================== */
.search-results {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-card);
}
.search-group {
  margin-bottom: 18px;
}
.search-group h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.search-results .chips { display: flex; flex-wrap: wrap; gap: 6px; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
  font-style: italic;
}

/* ====== Картинки =========================================================== */
.vk-img {
  display: block;
  background: var(--bg-soft);
}
.vk-img-fallback { object-fit: contain; }

/* ====== Подвал ============================================================= */
.site-footer {
  background: #1d6f4b;
  color: #d2efd9;
  text-align: center;
  padding: 18px 12px;
  margin-top: 60px;
  font-size: 13px;
  font-style: italic;
}

/* ====== Режим «для детей» ================================================== */
body[data-mode="kid"] {
  font-size: 17px;
}
body[data-mode="kid"] .card-title { font-size: 17px; }
body[data-mode="kid"] .drawer-body h2 { font-size: 26px; }
body[data-mode="kid"] .drawer-body p { font-size: 17px; }
body[data-mode="kid"] .kid-hide { display: none !important; }
body[data-mode="adult"] .kid-only { display: none !important; }

/* ====== Нижняя навигация (мобильная) ======================================= */
/* На десктопе скрыта — навигация живёт в шапке (.tabs). На телефоне это
   основной навигатор в нативном стиле: фиксирован снизу, с учётом «чёлки». */
.bottom-nav { display: none; }

@media (max-width: 720px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 150;
    background: var(--paper);
    border-top: 1px solid rgba(45, 31, 15, .10);
    box-shadow: 0 -4px 16px rgba(45, 31, 15, .12);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .bottom-nav::-webkit-scrollbar { display: none; }
  .bnav-item {
    flex: 1 0 auto;
    min-width: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: transparent;
    border: none;
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    color: var(--ink-soft);
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color .12s ease, background .12s ease;
  }
  .bnav-ico { font-size: 22px; line-height: 1; filter: grayscale(.25); opacity: .8; }
  .bnav-lbl { font-size: 10.5px; font-weight: 600; white-space: nowrap; }
  .bnav-item.active {
    color: var(--accent-dark);
    background: var(--accent-soft);
  }
  .bnav-item.active .bnav-ico { filter: none; opacity: 1; }
}

/* ====== Мобильный режим ==================================================== */
@media (max-width: 720px) {
  /* Шапка: компактная, табы убраны в нижнюю навигацию */
  .site-header { padding: 10px 14px; }
  .header-top { gap: 10px; }
  .brand { gap: 10px; }
  .brand-emoji { font-size: 30px; }
  .brand h1 { font-size: 19px; line-height: 1.15; }
  .subtitle { display: none; }              /* экономим высоту липкой шапки */
  .tabs { display: none; }                  /* навигация уходит вниз */

  .mode-switch { font-size: 12px; }
  .mode-btn { padding: 6px 10px; }

  .search-row { padding: 10px 0 2px; }
  .search-box { padding: 8px 14px; }

  /* Контент: отступ снизу под фиксированную нижнюю панель */
  .container { padding: 14px; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .site-footer { margin-top: 28px; padding: 16px 12px; }

  /* Карточки — две колонки, плотнее */
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card-title { font-size: 15px; }
  .card-body { padding: 10px 12px 12px; }
  .card:hover { transform: none; }          /* нет hover на тач-экранах */

  .hero { padding: 20px 18px; }
  .hero h2 { font-size: 21px; }
  .stats-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-cell { padding: 10px 6px; }
  .stat-num { font-size: 21px; }
  .stat-lbl { font-size: 11px; }

  /* Drawer → нижний «лист» (bottom sheet) c ручкой для свайпа */
  .drawer-overlay { align-items: flex-end; justify-content: center; }
  .drawer-card {
    width: 100%;
    height: 92vh;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    animation: sheet-up .25s ease;
  }
  @keyframes sheet-up {
    from { transform: translateY(60px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
  .drawer-bar {
    position: sticky; top: 0;
    padding-top: 18px;                       /* место под «ручку» */
    border-radius: 20px 20px 0 0;
  }
  .drawer-bar::before {
    content: "";
    position: absolute;
    top: 7px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px;
    border-radius: 2px;
    background: #d8cdb5;
  }
  .drawer-back, .drawer-close { padding: 8px 12px; }   /* крупнее тач-таргет */
  .drawer-body { padding: 16px 18px 32px; }
  .drawer-body .drawer-img { max-height: 280px; }
  .chip { padding: 7px 12px; font-size: 13.5px; }       /* удобнее тапать */

  /* Лайтбокс поверх нижней панели */
  .lightbox { z-index: 300; }
}
