:root {
  --bg: #0f1420;
  --bg-soft: #161d2e;
  --card: #1c2436;
  --line: #2a3350;
  --text: #e7ecf5;
  --muted: #9aa6c0;
  --accent: #4c8dff;
  --accent-2: #6aa6ff;
  --danger: #ff5d6c;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2740, transparent), var(--bg);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
code { background: #0c1018; padding: 2px 6px; border-radius: 6px; color: var(--accent-2); }
.muted { color: var(--muted); }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  background: rgba(15,20,32,.8); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8a5cff); color: #fff; font-weight: 800;
}
.brand-name { font-size: 18px; letter-spacing: .3px; }
.nav { display: flex; gap: 6px; }
.nav-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; transition: .15s;
}
.nav-btn:hover { color: var(--text); border-color: var(--line); }
.nav-btn.active { background: var(--bg-soft); color: var(--text); border-color: var(--accent); }
.user-box { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.user-box img { width: 32px; height: 32px; border-radius: 50%; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px 80px; }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px;
}
.notice h2 { margin-top: 0; }
.hero { text-align: center; padding: 56px 28px; }
.hero h1 { font-size: 30px; margin: 0 0 12px; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 26px; line-height: 1.5; }
.login-error { color: #f87171; margin-top: 12px; font-size: 14px; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: .15s; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6a7bff); border: none; color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.toolbar h2 { margin: 0; }
.section-title { margin: 28px 0 14px; font-size: 16px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.album {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: .18s;
}
.album:hover { transform: translateY(-3px); border-color: var(--accent); }
.album .cover { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #0c1018; display: block; }
.album .meta { padding: 12px 14px; }
.album .title { font-weight: 600; margin: 0 0 4px; font-size: 15px; }
.album .count { color: var(--muted); font-size: 13px; }
.album.special .cover-fallback {
  width: 100%; aspect-ratio: 4/3; display: grid; place-items: center;
  background: linear-gradient(135deg, #233, #1a2740); font-size: 40px;
}

/* Panel */
.panel { position: fixed; inset: 0; background: rgba(5,8,14,.6); display: grid; place-items: center; z-index: 50; }
.panel-card {
  width: min(520px, 92vw); background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px; position: relative;
}
.panel-close { position: absolute; top: 14px; right: 16px; background: none; border: none; color: var(--muted); font-size: 26px; cursor: pointer; }
.panel-card h3 { margin: 0 0 4px; }
.opt { display: flex; align-items: center; gap: 10px; margin: 18px 0; flex-wrap: wrap; }
.opt select { background: var(--bg-soft); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-left: auto; }
.panel-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* Stats / визуализация активности */
.stats-hint { margin: -6px 0 18px; }

.stats-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 18px; margin-bottom: 20px; }
.seg-group { display: flex; flex-direction: column; gap: 6px; }
.seg-cap { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.segmented { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg { background: transparent; border: none; color: var(--muted); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; transition: .15s; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--accent); color: #fff; font-weight: 600; }

.stats-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat-peak { cursor: pointer; border-color: var(--accent); }
.stat-peak:hover { background: var(--bg-soft); }
.stat-v { font-size: 20px; font-weight: 700; }
.stat-l { color: var(--muted); font-size: 13px; margin-top: 4px; }

.wave-wrap {
  position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; overflow: hidden;
}
.wave-wrap canvas { display: block; width: 100%; cursor: pointer; }
.wave-tooltip {
  position: absolute; top: 12px; transform: translateX(-50%);
  background: #0c1018; border: 1px solid var(--line); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-size: 12px; pointer-events: none;
  white-space: nowrap; line-height: 1.4; z-index: 2;
}
.wave-tooltip b { color: var(--accent-2); }

/* Stats: дни недели + список постов */
.stats-grid { display: grid; grid-template-columns: 320px 1fr; gap: 18px; margin-top: 20px; }
@media (max-width: 760px) { .stats-grid { grid-template-columns: 1fr; } }
.stats-grid .card { padding: 18px; }
.stats-grid h4 { margin: 0 0 14px; font-size: 15px; }

.weekday-chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; }
.wd-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.wd-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.wd-bar { width: 100%; min-height: 3px; border-radius: 5px 5px 0 0; background: linear-gradient(180deg, #6aa6ff, #365fb0); transition: height .4s ease; }
.wd-label { color: var(--muted); font-size: 12px; }

.posts-card { min-height: 150px; }
.posts-list { display: flex; flex-direction: column; gap: 12px; max-height: 420px; overflow-y: auto; }
.post-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--bg-soft); }
.post-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.post-date { color: var(--muted); font-size: 12px; }
.post-link { font-size: 12px; color: var(--accent-2); text-decoration: none; white-space: nowrap; }
.post-link:hover { text-decoration: underline; }
.post-text { font-size: 14px; line-height: 1.45; word-break: break-word; }
.post-attach { opacity: .7; }
.post-stats { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Обзор: график роста по годам */
.growth-legend { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 12px; }
.growth-legend .lg { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.growth-legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.growth-legend .sw-line { width: 16px; height: 0; border-radius: 0; border-top: 3px solid #ffcf5c; }
.seg-photos { background: linear-gradient(180deg, #6aa6ff, #365fb0); }
.seg-posts { background: linear-gradient(180deg, #8a5cff, #5b3db0); }
.seg-videos { background: linear-gradient(180deg, #3fd2c0, #1f8f86); }
.growth-wrap { position: relative; }
.growth-chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; }
.growth-col { flex: 1; min-width: 0; height: 100%; }
.growth-bar-wrap { height: 100%; width: 100%; display: flex; flex-direction: column-reverse; align-items: stretch; }
.growth-seg { width: 100%; min-height: 0; }
.growth-col .growth-seg:last-child { border-radius: 5px 5px 0 0; }
.growth-col.peak .growth-bar-wrap { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.growth-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.growth-line .cum-line { fill: none; stroke: #ffcf5c; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.growth-years { display: flex; gap: 6px; margin-top: 6px; }
.growth-year { flex: 1; min-width: 0; text-align: center; color: var(--muted); font-size: 11px; }
.growth-year.peak { color: var(--accent-2); font-weight: 700; }
.growth-peak { margin-top: 14px; font-size: 14px; }
.overview-note { margin-top: 18px; font-size: 13px; line-height: 1.5; }

/* Обзор: состав контента */
.composition { display: flex; flex-direction: column; gap: 10px; }
.comp-row { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 12px; }
.comp-label { color: var(--muted); font-size: 13px; }
.comp-track { background: var(--line); border-radius: 6px; height: 14px; overflow: hidden; }
.comp-bar { height: 100%; border-radius: 6px; }
.comp-val { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.seg-audios { background: linear-gradient(90deg, #ff8a5c, #d65f33); }
.seg-albums { background: linear-gradient(90deg, #f06aa6, #b03570); }
.seg-notes { background: linear-gradient(90deg, #9aa6ff, #5f6bd6); }
.comp-bar.seg-photos, .comp-bar.seg-posts, .comp-bar.seg-videos { background-image: none; }
.comp-bar.seg-photos { background: #5a86d8; }
.comp-bar.seg-posts { background: #7a5cd8; }
.comp-bar.seg-videos { background: #2faaa0; }

/* Обзор: демография друзей */
.friends-demo { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.card.sub { background: var(--panel-2, rgba(255,255,255,.02)); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.card.sub h5 { margin: 0 0 12px; font-size: 14px; }
.sex-bar { display: flex; height: 18px; border-radius: 6px; overflow: hidden; background: var(--line); }
.sex-bar span { height: 100%; }
.sex-f { background: #f06aa6; }
.sex-m { background: #5a86d8; }
.sex-u { background: #6a6a76; }
.sex-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.sex-legend .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.age-chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; }
.age-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.age-bar { width: 100%; min-height: 2px; background: linear-gradient(180deg, #6aa6ff, #365fb0); border-radius: 4px 4px 0 0; }
.age-lbl { color: var(--muted); font-size: 11px; white-space: nowrap; }
.rank-list { display: flex; flex-direction: column; gap: 8px; }
.rank-row { display: grid; grid-template-columns: 1fr 90px 48px; align-items: center; gap: 10px; }
.rank-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-track { background: var(--line); border-radius: 5px; height: 10px; overflow: hidden; }
.rank-bar { display: block; height: 100%; background: linear-gradient(90deg, #6aa6ff, #365fb0); border-radius: 5px; }
.rank-val { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }

/* AI-портрет */
.ai-privacy { margin-top: 16px; font-size: 13px; }
.ai-spinner {
  width: 44px; height: 44px; margin: 8px auto 16px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite;
}
#ai-loading { text-align: center; padding: 36px; }
@keyframes spin { to { transform: rotate(360deg); } }

.ai-archetypes { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.archetype {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  background: linear-gradient(135deg, rgba(76,141,255,.18), rgba(138,92,255,.18));
  border: 1px solid var(--line); border-radius: 999px; font-weight: 600; font-size: 15px;
}
.arch-emoji { font-size: 22px; }

.ai-summary { font-size: 17px; line-height: 1.6; margin-bottom: 22px; }
.ai-summary p { margin: 0; }

.ai-timeline { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.period-card { display: flex; gap: 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.period-when {
  flex: 0 0 110px; font-weight: 700; color: var(--accent-2); font-size: 15px;
  border-right: 1px solid var(--line); padding-right: 16px;
}
.period-body { flex: 1; }
.period-title { font-weight: 600; font-size: 16px; margin-bottom: 6px; }
.period-desc { color: var(--text); line-height: 1.55; }
.period-themes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.theme-chip { background: var(--bg-soft); border: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 999px; }

.ai-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
@media (max-width: 700px) { .ai-extra { grid-template-columns: 1fr; } .period-card { flex-direction: column; gap: 8px; } .period-when { border-right: none; border-bottom: 1px solid var(--line); padding: 0 0 8px; } }
.ai-extra h4 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.ai-extra p { margin: 0; line-height: 1.55; }
.ai-actions { margin: 6px 0 12px; }
.ai-disclaimer { font-size: 12px; }

/* Progress */
.progress { margin-top: 18px; }
.progress-bar { width: 100%; height: 8px; background: var(--bg-soft); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #8a5cff); transition: width .2s; }
.progress-text { color: var(--muted); font-size: 13px; margin-top: 8px; }
