:root {
  --bg: var(--tg-theme-bg-color, #14161c);
  --card-bg: var(--tg-theme-secondary-bg-color, #1f222b);
  --text: var(--tg-theme-text-color, #eef0f5);
  --muted: var(--tg-theme-hint-color, #969cb0);
  --accent: var(--tg-theme-button-color, #6c7cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
.app { max-width: 600px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 14px; }
.head { text-align: center; padding: 8px 0 0; }
.head h1 { margin: 0; font-size: 26px; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.status { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
/* Стрик дневника снов (retention) + кнопка поделиться серией (виральность). */
.streak-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 8px 0 0; }
.streak-badge { font-size: 14px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 12px; padding: 4px 12px; }
.streak-share { font-size: 13px; font-weight: 600; color: var(--accent); background: rgba(108,124,255,0.12); border: 1px solid var(--accent); border-radius: 12px; padding: 4px 12px; cursor: pointer; }
.card { background: var(--card-bg); border-radius: 16px; padding: 16px; }
textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); font-size: 16px; resize: vertical; font-family: inherit; margin-bottom: 10px; }
.primary { width: 100%; padding: 14px; border: none; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-size: 16px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: 0.6; }
.muted { color: var(--muted); font-size: 14px; }
.reading { white-space: pre-wrap; line-height: 1.55; margin: 0; }

/* Демо-пример на первом экране (видно, на что способен бот, ещё до первого сна) */
.demo { margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.demo-lead { margin: 0 0 8px; font-size: 13px; }
.demo-chip { width: 100%; text-align: left; padding: 12px; border-radius: 12px; border: 1px dashed rgba(255,255,255,0.18); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; cursor: pointer; }
.demo-out { margin: 8px 0 0; font-size: 13px; }
.share-btn { margin-top: 14px; }
.pro h2 { margin: 0 0 8px; font-size: 18px; }
.plan { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); cursor: pointer; }
.plan-popular { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.plan-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.plan-title { font-weight: 600; }
.plan-desc { font-size: 13px; color: var(--muted); }
.plan-price { font-weight: 600; color: var(--accent); }
.plan-badge { font-size: 11px; font-weight: 700; border-radius: 8px; padding: 1px 7px; white-space: nowrap; }
.plan-badge-pop { color: var(--accent-text); background: var(--accent); }
.plan-badge-save { color: #5fe0a8; background: rgba(95,224,168,0.14); }
.plan-group { margin: 14px 0 0; font-size: 13px; font-weight: 600; }
.plan-group:first-child { margin-top: 4px; }
/* «Подарить Pro другу» — вторичная кнопка под списком планов. */
.gift-pro-btn { margin-top: 16px; }
.gift-pro-hint { margin: 8px 0 0; font-size: 13px; line-height: 1.4; }
.history h2 { margin: 0 0 8px; font-size: 18px; }
.hist-item { width: 100%; text-align: left; display: block; padding: 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); cursor: pointer; }
.hist-title { font-size: 15px; }

/* Дневник снов (ядровой ctx.history): наглядная лента прошлых снов — карточки с датой/символом/смыслом */
.diary { border: 1px solid var(--accent); }
.diary h2 { margin: 0 0 4px; font-size: 18px; }
.diary #diaryLead { margin: 0 0 4px; }
.diary-item { width: 100%; text-align: left; display: block; padding: 12px 14px; margin-top: 10px; border-radius: 14px; border: 1px solid rgba(255,255,255,0.1); border-left: 3px solid var(--accent); background: var(--bg); color: var(--text); cursor: pointer; }
.diary-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.diary-sym { font-weight: 700; font-size: 15px; }
.diary-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.diary-meaning { margin-top: 6px; font-size: 13px; line-height: 1.45; }
.diary-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.diary-empty { margin: 10px 0 0; font-size: 14px; line-height: 1.5; text-align: center; padding: 10px; border-radius: 12px; border: 1px dashed rgba(255,255,255,0.18); }

.disclaimer { color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; padding: 4px 4px 0; }
.hidden { display: none; }
.tab-hidden { display: none; }

/* Вкладки */
.tabs { display: flex; gap: 8px; }
.tab { flex: 1; padding: 10px; border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; background: var(--card-bg); color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer; }
.tab-active { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* Поиск */
.search { width: 100%; padding: 10px 12px; margin-bottom: 10px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); font-size: 15px; font-family: inherit; }

/* Кнопки второго плана */
.secondary { width: 100%; padding: 12px; border: 1px solid rgba(255,255,255,0.16); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px; }
.secondary:disabled { opacity: 0.6; }

/* Диалог-уточнение */
.clarify { margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.clarify h3 { margin: 0 0 6px; font-size: 16px; }
.badge-pro { font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 8px; padding: 1px 7px; vertical-align: middle; }
.clarify textarea { margin-bottom: 8px; }
.clarify-answer { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid rgba(255,255,255,0.08); }

/* Память символов */
.symbols h2 { margin: 0 0 4px; font-size: 18px; }
.sym-item { padding: 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); }
.sym-repeat { border-color: var(--accent); }
.sym-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sym-title { font-weight: 600; font-size: 15px; }
.sym-count { color: var(--accent); font-weight: 700; font-size: 14px; }
.sym-note { margin-top: 4px; font-size: 13px; }
.sym-meaning { margin-top: 4px; font-size: 13px; line-height: 1.45; }

/* Чипы символов в истории */
.hist-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 12px; color: var(--muted); background: rgba(255,255,255,0.06); border-radius: 10px; padding: 2px 8px; }

/* Динамика снов (мини-график без внешних библиотек) */
.trends h2 { margin: 0 0 4px; font-size: 18px; }
.trend-weeks { display: flex; align-items: flex-end; gap: 6px; margin-top: 12px; }
.twk-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.twk-bar-wrap { width: 100%; height: 64px; display: flex; align-items: flex-end; }
.twk-bar { width: 100%; border-radius: 6px 6px 3px 3px; background: var(--accent); transition: height 0.2s ease; }
.twk-bar-empty { background: rgba(255,255,255,0.12); }
.twk-count { font-size: 12px; font-weight: 700; color: var(--accent); min-height: 14px; }
.twk-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.trend-symbols { margin-top: 8px; }
.trend-sym { padding: 10px 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); }
.trend-sym-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.trend-sym-title { font-weight: 600; font-size: 14px; }
.trend-sym-count { color: var(--accent); font-weight: 700; font-size: 13px; }
.trend-spark { display: flex; align-items: flex-end; gap: 3px; height: 22px; margin-top: 8px; }
.spark-bar { flex: 1; border-radius: 3px 3px 1px 1px; background: var(--accent); opacity: 0.85; }

/* Карта повторяющихся символов: тепловая таблица «символ × неделя» (цвет ячейки по частоте). */
.symbols-map { border: 1px solid var(--accent); }
.symbols-map h2 { margin: 0 0 4px; font-size: 18px; }
.smap { margin-top: 12px; overflow-x: auto; }
.smap-grid { display: grid; gap: 4px; align-items: center; min-width: 320px; }
.smap-corner { min-height: 14px; }
.smap-week { font-size: 10px; color: var(--muted); text-align: center; white-space: nowrap; padding-bottom: 2px; }
.smap-row-label { display: flex; align-items: center; gap: 6px; font-size: 13px; min-width: 0; padding-right: 6px; }
.smap-emoji { flex: 0 0 auto; }
.smap-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.smap-total { flex: 0 0 auto; color: var(--accent); font-weight: 700; font-size: 12px; }
.smap-grid .smap-cell { aspect-ratio: 1 / 1; min-height: 22px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--accent-text); }
/* Ступени «жара»: от едва заметной до насыщенной акцентом. */
.smap-l0 { background: rgba(255,255,255,0.05); }
.smap-cell-empty { color: transparent; }
.smap-l1 { background: rgba(108,124,255,0.28); }
.smap-l2 { background: rgba(108,124,255,0.5); }
.smap-l3 { background: rgba(108,124,255,0.74); }
.smap-l4 { background: var(--accent); }
.smap-legend { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; }
.smap-legend.hidden { display: none; }
.smap-legend-cells { display: inline-flex; gap: 4px; }
.smap-legend .smap-cell { width: 16px; height: 16px; border-radius: 4px; }
#symbolsMapEmpty.smap-empty { margin: 10px 0 0; font-size: 14px; line-height: 1.5; text-align: center; padding: 10px; border-radius: 12px; border: 1px dashed rgba(255,255,255,0.18); color: var(--muted); }

/* Справочник символов */
.dict h2 { margin: 0 0 4px; font-size: 18px; }
.dict-item { padding: 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); }
.dict-title { font-weight: 600; font-size: 15px; }
.dict-meaning { margin-top: 4px; font-size: 13px; line-height: 1.45; }

/* Реферальная программа («пригласи друга — неделя Pro обоим») */
.referral { border: 1px solid var(--accent); }
.referral h2 { margin: 0 0 6px; font-size: 17px; }
.ref-row { display: flex; gap: 8px; margin: 12px 0 8px; }
.ref-row .primary, .ref-row .secondary { margin-top: 0; }
.referral #referralStats { margin: 0; }

/* Дисклеймер по нише под результатом (П-5) */
.niche-disclaimer { margin: 10px 0 0; font-size: 12px; line-height: 1.45; opacity: 0.85; }

/* Экран согласия на обработку ПДн (П-2) */
.consent-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 18px; background: rgba(0, 0, 0, 0.55);
}
.consent-overlay.hidden { display: none; }
.consent-box {
  width: 100%; max-width: 440px; background: var(--card-bg);
  border-radius: 16px; padding: 20px;
}
.consent-box h2 { margin: 0 0 10px; font-size: 19px; }
.consent-box .muted { font-size: 14px; line-height: 1.5; }
.consent-box a { color: var(--accent); }
.consent-check {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 14px 0; font-size: 13px; line-height: 1.45; cursor: pointer;
}
.consent-check input { margin-top: 2px; width: 18px; height: 18px; flex: 0 0 auto; }
.consent-box .primary { margin-top: 4px; }
#consentHint { margin: 8px 0 0; font-size: 12px; }

/* Авторитетная утилита скрытия: объявлена ПОСЛЕДНЕЙ, чтобы при равной специфичности побеждать
   любые одноклассовые display-правила компонентов (корень бага .hidden-специфичности). 2-классовые
   show-правила и инлайн-стили НЕ перебивает (без !important). */
.hidden { display: none; }
