/* ===== FONTS ===== */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;1,300;1,400&family=Cormorant+SC:wght@300;400&family=EB+Garamond:ital,wght@0,400;0,500;1,400&display=swap');

/* ===== VARIABLES ===== */
:root {
  --bg-dark: #1a1a18;
  --bg-panel: rgba(30, 29, 26, 0.72);
  --bg-panel-hover: rgba(38, 37, 33, 0.85);
  --border-color: rgba(210, 190, 140, 0.18);
  --gold: #c8a96e;
  --gold-dim: #8a7048;
  --gold-bright: #e2c98a;
  --text-main: #ffffff;
  --text-dim: #c8a96e;
  --text-poem: #ffffff;
  --accent-visited: #6a8060;
  --highlight-bg: rgba(200, 169, 110, 0.35);
  --highlight-border: #c8a96e;
  --font-display: 'Cormorant SC', serif;
  --font-body: 'Cormorant Garamond', serif;
  --font-poem: 'EB Garamond', serif;
  --radius: 12px;
  --sidebar-w: 260px;
  --transition: 0.25s ease;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  overflow-x: hidden;
  position: relative;
}

/* ===== LIGHT SOURCE ===== */
.light-source {
  pointer-events: none;
  position: fixed;
  top: -120px;
  left: -120px;
  width: 700px;
  height: 700px;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(200, 160, 80, 0.13) 0%,
    rgba(180, 130, 50, 0.07) 35%,
    transparent 70%
  );
  z-index: 0;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.5;
  z-index: 0;
  pointer-events: none;
}

/* ===== HEADER (десктоп) ===== */
.site-header {
  position: relative;
  z-index: 10;
  padding: 1.4rem 2.5rem 0.8rem;
  text-align: right;
}

.header-inner {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
}

.author-name {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 300;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  text-transform: uppercase;
  text-decoration: none;
  border: none;
  outline: none;
}

/* ===== ЛУПА ===== */
.search-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
  flex-shrink: 0;
}

.search-icon-btn:hover {
  color: var(--gold);
}

/* Лупа в панели стихотворения (мобильный) — скрыта на десктопе */
.poem-search-btn {
  display: none;
}

/* ===== MAIN LAYOUT (десктоп) ===== */
.layout {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 1.5rem;
  padding: 0.6rem 2rem 1.5rem;
  height: calc(100vh - 120px);
  align-items: start;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: sticky;
  top: 0.6rem;
  height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    -1px -1px 0 rgba(200, 169, 110, 0.22),
    inset 0 0 40px rgba(0,0,0,0.15);
}

.sidebar-header {
  padding: 1.2rem 1.2rem 0.6rem;
  flex-shrink: 0;
}

.sidebar-title {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 300;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.sidebar-divider {
  margin-top: 0.5rem;
  height: 1px;
  background: linear-gradient(to right, var(--gold-dim), transparent);
  opacity: 0.5;
}

/* ===== POEM LIST ===== */
.poem-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.poem-list::-webkit-scrollbar { width: 4px; }
.poem-list::-webkit-scrollbar-track { background: transparent; }
.poem-list::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 4px;
}

.poem-list-loading {
  padding: 1rem 1.2rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.poem-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.38rem 1.2rem;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.93rem;
  font-weight: 400;
  color: var(--text-main);
  transition: color var(--transition), background var(--transition);
  border-left: 2px solid transparent;
  line-height: 1.4;
  user-select: none;
}

.poem-item:hover {
  color: var(--gold-bright);
  background: rgba(200, 169, 110, 0.06);
}

.poem-item.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: rgba(200, 169, 110, 0.08);
}

.poem-item.visited {
  color: #8a703d; /* Тёмно-золотистый / бронзовый */
}

.poem-item.visited.active {
  color: var(--gold);
}

.poem-bullet {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.poem-item.active .poem-bullet {
  opacity: 1;
}

/* ===== CONTENT PANEL ===== */
.content-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  height: calc(100vh - 100px);
  padding: 2.5rem 3.5rem;
  overflow-y: auto;
  box-shadow:
    -1px -1px 0 rgba(200, 169, 110, 0.18),
    inset 0 0 60px rgba(0,0,0,0.12);
  position: relative;
}

/* ===== POEM DISPLAY ===== */
.poem-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-style: italic;
}

.poem-inner {
  max-width: 62ch;
  margin: 0 auto;
}

.poem-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-align: left;
  margin-bottom: 0.8rem;
}

.poem-title-divider {
  display: none;
}

.poem-body {
  font-family: var(--font-poem);
  font-size: 1.13rem;
  line-height: 1.6;
  color: var(--text-poem);
  white-space: pre-wrap;
}

.poem-body p {
  margin-bottom: 0.8em;
}

.poem-date {
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-align: right;
  margin-top: 1.5rem;
}

/* Подсветка найденного текста в стихотворении */
.poem-body mark,
.poem-title mark {
  background: var(--highlight-bg);
  color: var(--gold-bright);
  border-radius: 2px;
  padding: 0 1px;
}

.poem-loading {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem 0;
}

/* ===== FOOTER (десктоп) ===== */
.site-footer {
  position: relative;
  z-index: 5;
  text-align: center;
  padding: 0.8rem 2rem 1.2rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

/* ===== TRANSITIONS ===== */
.poem-display {
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================================
   ПАНЕЛЬ ПОИСКА
   =================================================== */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 10, 8, 0.7);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.search-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.search-panel {
  width: 100%;
  max-width: 580px;
  background: #222220;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

/* Строка ввода */
.search-input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.search-input-icon {
  color: var(--text-dim);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-main);
  caret-color: var(--gold);
}

.search-input::placeholder {
  color: var(--text-dim);
}

/* Убираем крестик встроенный в браузере для type=search */
.search-input::-webkit-search-cancel-button { display: none; }

.search-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 0.2rem 0.3rem;
  transition: color var(--transition);
  flex-shrink: 0;
}

.search-close-btn:hover {
  color: var(--text-main);
}

/* История поиска */
.search-history {
  flex-shrink: 0;
}

.search-history-title {
  padding: 0.5rem 1rem 0.2rem;
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.search-history-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dim);
  transition: color var(--transition), background var(--transition);
}

.search-history-item:hover {
  color: var(--text-main);
  background: rgba(255,255,255,0.04);
}

.search-history-icon {
  font-size: 0.75rem;
  opacity: 0.5;
}

/* Результаты поиска */
.search-results {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 4px;
}

.search-empty {
  padding: 1.5rem 1rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
}

.search-status {
  padding: 0.5rem 1rem;
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}

/* Один результат */
.search-result-item {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  transition: background var(--transition);
}

.search-result-item:hover {
  background: rgba(200, 169, 110, 0.07);
}

.search-result-title {
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 0.25rem;
}

.search-result-line {
  font-family: var(--font-poem);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-dim);
}

/* Подсветка в результатах */
.search-result-line mark,
.search-result-title mark {
  background: var(--highlight-bg);
  color: var(--gold-bright);
  border-radius: 2px;
  padding: 0 1px;
}

.search-indexing {
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
}

/* ===================================================
   ДЕСКТОП: скрыть мобильные элементы
   =================================================== */
@media (min-width: 769px) {
  .sidebar-header .author-name { display: none; }
  .mobile-search-btn { display: none; }
  .sidebar-header { display: block; }
  .sidebar .site-footer { display: none; }
  .site-footer-desktop { display: block; }
  .poem-search-btn { display: none; }
}

/* ===================================================
   МОБИЛЬНАЯ ВЕРСИЯ
   =================================================== */
@media (max-width: 768px) {

  body {
    overflow: hidden;
    height: 100dvh;
  }

  .light-source {
    width: 400px;
    height: 400px;
    top: -80px;
    left: -80px;
  }

  .layout {
    display: block;
    padding: 0;
    min-height: unset;
    height: unset;
  }

  /* Шапка вне сайдбара — скрыта */
  .site-header { display: none; }

  /* Sidebar-header: flex-строка Стихи / Алексей Захарчук / лупа */
  .sidebar-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 0.8rem 0 1.2rem;
  flex-shrink: 0;
}

  .sidebar-title {
    font-size: 0.78rem;
    font-weight: 300;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    line-height: 1;
  }

  .sidebar-header .author-name {
    font-family: var(--font-display);
    font-size: 0.78rem;
    font-weight: 300;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    text-transform: uppercase;
    line-height: 1;
  }

  .sidebar-divider {
    margin: 0.8rem 1.2rem 0;
    flex-shrink: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0;
    height: 100dvh;
    width: 100%;
    border-radius: 0;
    border: none;
    z-index: 20;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
  }

  .sidebar.hidden-mobile {
    transform: translateX(-100%);
  }

  .poem-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .site-footer {
    flex-shrink: 0;
    position: static;
    padding: 0.8rem 1.2rem 1.2rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.06em;
  }

  .site-footer.hidden-mobile { display: none; }
  .site-footer-desktop { display: none; }

  /* Панель стихотворения */
  .content-panel {
    position: fixed;
    inset: 0;
    height: 100dvh;
    width: 100%;
    border-radius: 0;
    border: none;
    padding: 3rem 1.4rem 2rem; /* место для лупы сверху */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: none;
    z-index: 10;
    min-height: unset;
  }

  .content-panel.visible-mobile {
    display: block;
  }

  /* Лупа в панели стихотворения (мобильный) */
  .poem-search-btn {
    display: flex;
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 15;
  }

  .poem-title {
    font-size: 1.5rem;
    margin-top: 0.5rem;
    text-align: center;
  }

  .poem-inner {
    max-width: 100%;
    margin: 0;
  }

.poem-body {
    font-size: 1.25rem;
  }

  .poem-item {
    font-size: 1.05rem;
  }
  .poem-date {
    text-align: left;
  }

  /* Панель поиска на мобильном — на весь экран */
  .search-overlay {
    padding-top: 0;
    align-items: flex-end;
  }

  .search-panel {
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 85dvh;
  }
}

/* ===== КНОПКА "НАЗАД К СПИСКУ" (мобильный) ===== */
.back-to-list-btn {
  display: none;
}
.pull-indicator {
  display: none;
}

@media (max-width: 768px) {
  .back-to-list-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 1.1rem;
    bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px));
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-panel-hover);
    border: 1px solid var(--gold);
    color: var(--gold);
    cursor: pointer;
    z-index: 15;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition), color var(--transition);
  }

  .back-to-list-btn:active {
    background: var(--gold);
    color: var(--bg-dark);
  }
  .pull-indicator {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 10dvh;
    background: linear-gradient(to bottom, rgba(200, 169, 110, 0) 0%, var(--gold-bright) 100%);
    transform: translateY(100%);
    pointer-events: none;
    z-index: 14;
  }
}

/* Анимация проявления и залета снизу */
.poem-animate-enter {
  animation: poemSlideIn 0.65s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes poemSlideIn {
  0% {
    opacity: 0;
    transform: translateY(45px); /* Увеличена дистанция вылета */
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
