/* RPverse — дизайн-токены и адаптивные утилиты (Dark Charcoal + Ultra Violet, Really Black, Light подтемы). */
:root,
:root[data-light-theme="soft-lavender"] {
  --bg: 247 246 251;
  --surface: 255 255 255;
  --subtle: 238 235 246;
  --line: 220 215 234;
  --ink: 26 24 35;
  --ink-2: 85 80 104;
  --ink-3: 136 131 154;
  --accent: 95 75 139;
  --on-accent: 255 255 255;
  --danger: 196 48 48;
  --msg-size: 15px;
}
:root[data-light-theme="warm-terracotta"] {
  --bg: 250 249 247;
  --surface: 255 255 255;
  --subtle: 243 241 238;
  --line: 230 227 222;
  --ink: 28 25 23;
  --ink-2: 87 83 78;
  --ink-3: 140 135 128;
  --accent: 176 82 58;
  --on-accent: 255 255 255;
}
:root[data-light-theme="sage-forest"] {
  --bg: 244 248 245;
  --surface: 255 255 255;
  --subtle: 232 240 235;
  --line: 208 223 213;
  --ink: 22 32 26;
  --ink-2: 72 90 79;
  --ink-3: 122 140 129;
  --accent: 45 122 89;
  --on-accent: 255 255 255;
}
:root[data-light-theme="sky-slate"] {
  --bg: 243 247 252;
  --surface: 255 255 255;
  --subtle: 230 237 247;
  --line: 206 218 236;
  --ink: 20 29 44;
  --ink-2: 74 89 112;
  --ink-3: 125 140 162;
  --accent: 46 105 224;
  --on-accent: 255 255 255;
}
:root[data-light-theme="sakura-mist"] {
  --bg: 253 247 250;
  --surface: 255 255 255;
  --subtle: 248 235 242;
  --line: 234 212 224;
  --ink: 36 22 30;
  --ink-2: 98 72 86;
  --ink-3: 148 122 136;
  --accent: 219 39 119;
  --on-accent: 255 255 255;
}
:root[data-light-theme="ivory-gold"] {
  --bg: 251 248 241;
  --surface: 255 255 255;
  --subtle: 242 236 220;
  --line: 223 213 189;
  --ink: 38 32 21;
  --ink-2: 104 93 73;
  --ink-3: 154 142 120;
  --accent: 183 121 31;
  --on-accent: 255 255 255;
}
:root[data-light-theme="mint-breeze"] {
  --bg: 241 250 247;
  --surface: 255 255 255;
  --subtle: 225 243 236;
  --line: 191 224 212;
  --ink: 19 42 35;
  --ink-2: 63 103 91;
  --ink-3: 113 150 138;
  --accent: 13 148 136;
  --on-accent: 255 255 255;
}
:root[data-light-theme="peach-silk"] {
  --bg: 253 245 240;
  --surface: 255 255 255;
  --subtle: 247 230 220;
  --line: 229 202 189;
  --ink: 43 28 23;
  --ink-2: 116 85 75;
  --ink-3: 164 132 121;
  --accent: 234 88 12;
  --on-accent: 255 255 255;
}

/* Основная тёмная тема: Космический неон */
.dark,
.dark[data-dark-theme="cosmic-violet"] {
  --bg: 15 14 22;
  --surface: 24 23 35;
  --subtle: 36 34 52;
  --line: 54 51 76;
  --ink: 245 244 250;
  --ink-2: 192 188 210;
  --ink-3: 136 131 158;
  --accent: 139 92 246;
  --on-accent: 255 255 255;
  --danger: 239 98 98;
}
/* Тёмный угольный + Ultra Violet (Pantone 18-3838) */
.dark[data-dark-theme="ultra-violet"] {
  --bg: 20 20 24;
  --surface: 28 28 35;
  --subtle: 38 37 47;
  --line: 55 53 68;
  --ink: 241 240 245;
  --ink-2: 184 180 198;
  --ink-3: 126 121 142;
  --accent: 118 92 178;
  --on-accent: 255 255 255;
  --danger: 239 98 98;
}
/* Really Black (#000000 OLED) */
.dark[data-dark-theme="really-black"] {
  --bg: 0 0 0;
  --surface: 12 12 15;
  --subtle: 22 22 26;
  --line: 36 36 42;
  --ink: 242 242 246;
  --ink-2: 176 176 188;
  --ink-3: 112 112 126;
  --accent: 112 92 168;
  --on-accent: 255 255 255;
  --danger: 239 98 98;
}
/* Графит + Терракота */
.dark[data-dark-theme="graphite-ember"] {
  --bg: 17 17 19;
  --surface: 24 24 27;
  --subtle: 33 33 37;
  --line: 44 44 49;
  --ink: 236 236 238;
  --ink-2: 172 172 180;
  --ink-3: 115 115 124;
  --accent: 226 136 110;
  --on-accent: 26 16 12;
  --danger: 239 98 98;
}
/* Полночный океан */
.dark[data-dark-theme="midnight-ocean"] {
  --bg: 10 15 26;
  --surface: 16 24 40;
  --subtle: 24 35 56;
  --line: 37 52 80;
  --ink: 232 240 250;
  --ink-2: 162 179 204;
  --ink-3: 104 123 152;
  --accent: 77 166 255;
  --on-accent: 10 18 32;
  --danger: 239 98 98;
}
/* Багровый бархат */
.dark[data-dark-theme="crimson-velvet"] {
  --bg: 19 13 18;
  --surface: 28 19 26;
  --subtle: 40 27 37;
  --line: 58 40 54;
  --ink: 246 239 243;
  --ink-2: 198 176 188;
  --ink-3: 138 116 128;
  --accent: 225 29 72;
  --on-accent: 255 255 255;
  --danger: 239 98 98;
}
/* Тёмный красный */
.dark[data-dark-theme="dark-crimson"] {
  --bg: 18 9 12;
  --surface: 28 15 20;
  --subtle: 42 22 29;
  --line: 66 35 46;
  --ink: 247 236 239;
  --ink-2: 203 178 186;
  --ink-3: 142 112 122;
  --accent: 220 38 38;
  --on-accent: 255 255 255;
  --danger: 248 113 113;
}
/* Тёмный розовый */
.dark[data-dark-theme="dark-rose"] {
  --bg: 20 11 18;
  --surface: 31 17 28;
  --subtle: 46 26 41;
  --line: 72 41 64;
  --ink: 248 238 245;
  --ink-2: 204 180 197;
  --ink-3: 145 115 137;
  --accent: 236 72 153;
  --on-accent: 255 255 255;
  --danger: 244 114 182;
}
/* Читаемость текстового акцента на ультра-тёмном фоне */
.dark[data-dark-theme="cosmic-violet"] .text-accent,
.dark[data-dark-theme="ultra-violet"] .text-accent,
.dark[data-dark-theme="really-black"] .text-accent {
  color: rgb(176 156 236);
}

html, body { height: 100%; overflow-x: hidden; }
body {
  background: rgb(var(--bg));
  color: rgb(var(--ink));
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea, [contenteditable] {
  user-select: text;
  -webkit-user-select: text;
}
.dark[data-dark-theme="cosmic-violet"] body {
  background-image: radial-gradient(ellipse 80% 42% at 50% -8%, rgb(139 92 246 / 0.14), transparent 70%);
}
::selection { background: rgb(var(--accent) / .25); }
:focus-visible { outline: 2px solid rgb(var(--accent)); outline-offset: 2px; border-radius: 6px; }

/* Безопасный отступ снизу под единую навигацию + safe-area (на десктопе нижний бар скрыт) */
.has-bottom-nav {
  padding-bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px)) !important;
}
@media (min-width: 768px) {
  .has-bottom-nav {
    padding-bottom: 1.5rem !important;
  }
  body.rv-with-desktop-sidebar {
    padding-left: 240px;
  }
}
#rv-bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Безопасный отступ в шапке для полноэкранного режима Telegram WebApp (кнопка «Назад» / «Закрыть») */
html.rv-tg-fullscreen body > header,
html.rv-tg-fullscreen main > header {
  padding-top: var(--rv-tg-safe-top, 0px);
  height: calc(3.5rem + var(--rv-tg-safe-top, 0px));
}
html.rv-tg-fullscreen body > header > div,
html.rv-tg-fullscreen main > header {
  padding-left: calc(1rem + var(--rv-tg-header-pl, 0px));
}
@media (min-width: 768px) {
  html.rv-tg-fullscreen body > header > div,
  html.rv-tg-fullscreen main > header {
    padding-left: calc(1.5rem + var(--rv-tg-header-pl, 0px));
  }
  html.rv-tg-fullscreen #rv-desktop-sidebar > div:first-child,
  html.rv-tg-fullscreen #sidebar > div:first-child {
    padding-top: var(--rv-tg-safe-top, 0px);
    height: calc(3.5rem + var(--rv-tg-safe-top, 0px));
    padding-left: calc(1rem + var(--rv-tg-header-pl, 0px));
  }
}

/* Тонкий / скрытый скроллбар */
.scroll-thin { scrollbar-width: thin; scrollbar-color: rgb(var(--line)) transparent; }
.scroll-thin::-webkit-scrollbar { width: 6px; height: 6px; }
.scroll-thin::-webkit-scrollbar-thumb { background: rgb(var(--line)); border-radius: 3px; }
.hide-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.hide-scrollbar::-webkit-scrollbar { display: none; }

/* Roblox-лента (карточки в ряд + стрелки прокрутки) */
.rv-carousel-wrap {
  position: relative;
}
.rv-carousel {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.rv-carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(var(--surface) / 0.92);
  border: 1px solid rgb(var(--line));
  color: rgb(var(--ink));
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.32);
  backdrop-filter: blur(6px);
  transition: opacity 0.18s ease, transform 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
}
.rv-carousel-arrow:hover {
  border-color: rgb(var(--accent) / 0.7);
}
.rv-carousel-arrow.prev { left: 0.25rem; }
.rv-carousel-arrow.next { right: 0.25rem; }
.rv-carousel-arrow.is-hidden {
  opacity: 0;
  pointer-events: none;
}
.rv-carousel-card {
  scroll-snap-align: start;
  flex: 0 0 calc((100% - 2.25rem) / 4);
  min-width: 146px;
}
@media (max-width: 767px) {
  .rv-carousel-card {
    flex: 0 0 calc((100% - 1.5rem) / 3);
    min-width: 146px;
  }
}
@media (max-width: 470px) {
  .rv-carousel-card {
    flex: 0 0 calc((100% - 1rem) / 2.25);
    min-width: 142px;
  }
}

/* Подсветка поля ввода в 18+ ветке без верхнего баннера (#5) */
.nsfw-composer-glow {
  border-color: rgb(var(--danger) / .55) !important;
  box-shadow: 0 0 0 1px rgb(var(--danger) / .2), 0 6px 20px -10px rgb(var(--danger) / .45);
}

/* Текст сообщений */
.msg-text { font-size: var(--msg-size); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-serif .msg-text { font-family: Literata, Georgia, serif; }
.msg-text em { color: rgb(var(--accent)); font-style: italic; }
.dark[data-dark-theme="ultra-violet"] .msg-text em,
.dark[data-dark-theme="really-black"] .msg-text em { color: rgb(176 156 236); }
.msg-user .msg-text em { color: inherit; opacity: .85; }
.no-action-highlight .msg-text em { color: inherit; font-style: normal; opacity: 1; }

/* Индикатор «печатает» */
.typing span { width: 6px; height: 6px; border-radius: 9999px; background: rgb(var(--ink-3)); display: inline-block; animation: rv-blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes rv-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* Появление сообщений и модалок */
.fade-in { animation: rv-fade .2s cubic-bezier(.16,1,.3,1); }
@keyframes rv-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes rv-modal-in { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
[id$="Modal"]:not(.hidden) > div { animation: rv-modal-in .2s cubic-bezier(.16,1,.3,1); }

/* Глобальный индикатор загрузки и splash-экран */
html.rv-cold-boot body {
  overflow: hidden !important;
}
html.rv-cold-boot body > *:not(#rv-splash):not(#rv-toast) {
  opacity: 0 !important;
  visibility: hidden !important;
}

#rv-top-loader {
  position: fixed; top: 0; left: 0; right: 0; height: 2.5px; z-index: 9990;
  background: linear-gradient(90deg, transparent, rgb(var(--accent)), transparent);
  background-size: 45% 100%;
  box-shadow: 0 0 8px rgb(var(--accent) / .4);
  opacity: 0; pointer-events: none; transition: opacity .2s ease-out;
}
#rv-top-loader.active {
  opacity: 1;
  animation: rv-progress 1s infinite ease-in-out;
}
@keyframes rv-progress { 0% { background-position: -60% 0; } 100% { background-position: 160% 0; } }

#rv-splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background-color: #141418;
  background-color: rgb(var(--bg));
  color: rgb(var(--ink));
  isolation: isolate;
  will-change: opacity;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .35s cubic-bezier(.16, 1, .3, 1), visibility .35s cubic-bezier(.16, 1, .3, 1);
}
#rv-splash.visible {
  opacity: 1; visibility: visible; pointer-events: auto;
}
#rv-splash.instant {
  transition: none !important;
}
.rv-splash-logo {
  width: 96px; height: 96px; border-radius: 26px;
  background: radial-gradient(circle at 50% 50%, rgb(var(--accent) / .24), rgb(var(--accent) / .06) 72%);
  border: 1px solid rgb(var(--accent) / .38);
  display: flex; align-items: center; justify-content: center;
  color: rgb(var(--ink));
  box-shadow: 0 0 36px -4px rgb(var(--accent) / .42);
}
.rv-splash-svg {
  filter: drop-shadow(0 0 8px rgb(var(--accent) / .45));
}
/* Плавные переходы между страницами и анимация меню */
@keyframes rv-page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
body > main,
body > .flex {
  animation: rv-page-in .2s cubic-bezier(.16, 1, .3, 1);
}
html.rv-page-leaving body > main,
html.rv-page-leaving body > .flex {
  opacity: 0;
  transform: translateY(3px);
  transition: opacity .14s ease-out, transform .14s ease-out;
}

#rv-splash.visible .rv-splash-crescents {
  transform-origin: 50px 50px;
  animation: rvCrescentSpin 2.8s linear infinite;
}
#rv-splash.visible .rv-splash-star {
  transform-origin: 50px 50px;
  animation: rvStarPulse 1.7s ease-in-out infinite;
}
#rv-splash.visible .rv-dot {
  transform-box: fill-box;
  transform-origin: center;
  animation: rvDotPulse 1.9s ease-in-out infinite;
}
#rv-splash.visible .rv-dot-1 { animation-delay: 0s; }
#rv-splash.visible .rv-dot-2 { animation-delay: 0.35s; animation-duration: 2.2s; }
#rv-splash.visible .rv-dot-3 { animation-delay: 0.75s; animation-duration: 1.7s; }
#rv-splash.visible .rv-dot-4 { animation-delay: 1.15s; animation-duration: 2.4s; }
#rv-splash.visible .rv-dot-5 { animation-delay: 1.5s; animation-duration: 2.0s; }
@keyframes rvCrescentSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes rvStarPulse {
  0%, 100% { transform: scale(0.88); opacity: 0.72; }
  50% { transform: scale(1.12); opacity: 1; }
}
@keyframes rvDotPulse {
  0%, 100% { transform: scale(0.65); opacity: 0.35; }
  50% { transform: scale(1.35); opacity: 1; }
}
@keyframes rv-hex-draw {
  0% { stroke-dashoffset: 160; }
  50% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -160; }
}
@keyframes rv-v-pulse {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}
@keyframes rv-orbit-glow {
  0%, 100% { opacity: .65; }
  50% { opacity: 1; }
}
.rv-splash-title {
  font-size: 14px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25;
}
.rv-splash-sub {
  font-size: 11px; color: rgb(var(--ink-3)); line-height: 1.25;
}

/* Сегментированный переключатель */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: rgb(var(--subtle)); border: 1px solid rgb(var(--line)); max-width: 100%; overflow-x: auto; }
.seg button { padding: 6px 12px; font-size: 13px; border-radius: 8px; color: rgb(var(--ink-2)); transition: background .15s, color .15s; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: rgb(var(--surface)); color: rgb(var(--ink)); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

/* Тумблер */
.switch { position: relative; width: 38px; height: 22px; border-radius: 9999px; background: rgb(var(--line)); transition: background .15s; flex-shrink: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 9999px; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .2); }
.switch[aria-checked="true"] { background: rgb(var(--accent)); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch:disabled { opacity: .45; cursor: not-allowed; }

/* Поля ввода */
.field { width: 100%; background: rgb(var(--surface)); border: 1px solid rgb(var(--line)); border-radius: 10px; padding: 10px 12px; font-size: 14px; color: rgb(var(--ink)); transition: border-color .15s; }
.field:focus { outline: none; border-color: rgb(var(--accent)); }
.field::placeholder { color: rgb(var(--ink-3)); }

/* Кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px; font-size: 14px; font-weight: 500; transition: all .2s ease-out; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary {
  background: rgb(var(--accent));
  color: rgb(var(--on-accent));
}
.btn-primary:hover { opacity: .92; }
.dark[data-dark-theme="cosmic-violet"] .btn-primary {
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 65%, #ec4899 100%);
  box-shadow: 0 4px 16px -4px rgb(139 92 246 / 0.45);
}
.dark[data-dark-theme="cosmic-violet"] .btn-primary:hover {
  opacity: .94;
  box-shadow: 0 6px 20px -4px rgb(168 85 247 / 0.55);
}
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { color: rgb(var(--ink-2)); }
.btn-ghost:hover { background: rgb(var(--subtle)); color: rgb(var(--ink)); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 10px; color: rgb(var(--ink-2)); transition: background .15s, color .15s, transform .15s; flex-shrink: 0; }
.icon-btn:hover { background: rgb(var(--subtle)); color: rgb(var(--ink)); }
.icon-btn:active { transform: scale(.94); }

/* Скелетон-загрузка (лёгкая пульсация без тяжёлого blur для экономии CPU/GPU) */
.rv-skeleton {
  position: relative;
  overflow: hidden;
  background: rgb(var(--subtle));
  animation: rv-skel-pulse 1.8s ease-in-out infinite;
}
.rv-blur-section {
  position: relative;
  transition: opacity .22s ease;
}
.rv-blur-section.is-loading {
  opacity: 0.6;
  pointer-events: none;
}
.rv-blur-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  background: rgb(var(--bg) / 0.55);
  transition: opacity .2s ease, visibility .2s ease;
}
.rv-blur-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
@keyframes rv-skel-pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.5; }
}

/* Акцентная типографика заголовков историй */
.font-display { font-family: Literata, Georgia, serif; }

/* Тост */
#rv-toast { position: fixed; left: 50%; bottom: calc(5.2rem + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 12px); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s, transform .2s, visibility .2s; z-index: 10000; max-width: calc(100vw - 24px); text-align: center; }
#rv-toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
