@import url('/vendor/fonts/nunito.css');

/* «Мягкая пластика»: собственная палитра, а не цвета темы Telegram —
   неоморфизм держится на точном соотношении фона и двух теней, любой чужой
   цвет фона его ломает. От клиента берём только светлую/тёмную схему. */
:root {
  --bg: #e6e9f4;
  --surface: #eef0f8;
  --card: #ffffff;
  --text: #3b3f5c;
  /* Из макета серый #9aa0c0 и сиреневый #8878e0 дают на светлом фоне контраст
     2.1 и 3.0 — мелкий текст плывёт. Для текста берём тона темнее (те же
     оттенки), а исходные цвета оставляем заливкам, где контраст не важен. */
  --muted: #5f6684;
  --muted-soft: #9aa0c0;
  --accent: #6f5dd0;
  --accent-fill: #8878e0;
  --accent-soft: #a99bf0;
  --on-accent: #ffffff;

  --sh-dark: rgba(163, 171, 204, .5);
  --sh-light: rgba(255, 255, 255, .95);
  --out: 8px 8px 18px var(--sh-dark), -8px -8px 18px var(--sh-light);
  --out-sm: 6px 6px 14px var(--sh-dark), -6px -6px 14px var(--sh-light);
  --out-press: 4px 4px 10px var(--sh-dark), -4px -4px 10px var(--sh-light);
  --in: inset 6px 6px 12px var(--sh-dark), inset -6px -6px 12px var(--sh-light);
  --card-sh: 0 10px 24px rgba(140, 150, 200, .18);
  --glow: 0 8px 20px rgba(136, 120, 224, .4);
}

:root[data-scheme="dark"] {
  --bg: #232632;
  --surface: #2a2e3d;
  --card: #313648;
  --text: #e7e9f5;
  --muted: #969cba;
  --accent: #a99bf0;
  --accent-fill: #8878e0;
  --accent-soft: #b9adf5;
  --on-accent: #ffffff;

  --sh-dark: rgba(15, 17, 24, .55);
  --sh-light: rgba(70, 77, 102, .38);
  --card-sh: 0 10px 24px rgba(10, 12, 18, .35);
  --glow: 0 8px 20px rgba(120, 104, 210, .45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --bg: #232632;
    --surface: #2a2e3d;
    --card: #313648;
    --text: #e7e9f5;
    --muted: #969cba;
    --accent: #a99bf0;
    --accent-fill: #8878e0;
    --accent-soft: #b9adf5;
    --on-accent: #ffffff;
    --sh-dark: rgba(15, 17, 24, .55);
    --sh-light: rgba(70, 77, 102, .38);
    --card-sh: 0 10px 24px rgba(10, 12, 18, .35);
    --glow: 0 8px 20px rgba(120, 104, 210, .45);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); color: var(--text); overscroll-behavior: none; }
/* Плавную смену цвета вешаем на карточки, но НЕ на body: там переход
   подвешивает background-color, унаследованный от переменной, и фон не меняется. */
.tile, .row, .md, .group, .search-field, .theme-btn, .admin-row, .fbox, .dl-btn, .pill, .add-row, .toolbar button {
  transition: background-color .25s ease, color .25s ease, box-shadow .25s ease;
}
body {
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; line-height: 1.5; font-weight: 600;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  max-width: 720px; margin: 0 auto;
}
#app { padding: 18px 20px 0; }
a { color: var(--accent); text-decoration: none; font-weight: 700; }
button { font-family: inherit; }

.enter { animation: enter .24s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- типографика ---------- */

.screen-title { font-size: 24px; font-weight: 800; line-height: 1.2; margin: 6px 0 4px; }
.screen-sub { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.caps {
  font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 26px 0 12px; padding-left: 4px;
}
.caps:first-child { margin-top: 2px; }

/* ---------- поиск и переключатель темы ---------- */

.top-bar { display: flex; align-items: center; gap: 12px; }
.top-bar .search-field { flex: 1; min-width: 0; }

.theme-btn {
  flex: none; width: 52px; height: 52px; border: none; border-radius: 18px;
  background: var(--surface); color: var(--accent); cursor: pointer;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--out-sm);
  transition: box-shadow .18s ease;
}
.theme-btn:active { box-shadow: var(--out-press); }
.theme-btn svg { width: 22px; height: 22px; }

.search-field {
  width: 100%; height: 52px; border: none; border-radius: 20px;
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 0 20px; outline: none; box-shadow: var(--in);
}
.search-field::placeholder { color: var(--muted); font-weight: 600; }
.search-sticky { position: sticky; top: 0; background: var(--bg); padding: 10px 0 12px; z-index: 5; }

/* ---------- разделы плитками ---------- */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, 1fr); } }

.tile {
  background: var(--surface); border-radius: 22px; padding: 18px;
  box-shadow: var(--out); cursor: pointer; transition: box-shadow .18s ease;
}
.tile:active { box-shadow: var(--out-press); }
.tile .name { font-size: 16px; font-weight: 800; margin-top: 18px; line-height: 1.25; }
.tile .count { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 3px; }

.mono {
  width: 40px; height: 40px; border-radius: 14px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
  background: var(--accent-soft); box-shadow: 0 6px 14px rgba(140, 120, 230, .45);
}
/* Цвет монограммы закреплён за разделом — не скачет при перестановке. */
[data-hue="0"] .mono { background: #a99bf0; box-shadow: 0 6px 14px rgba(140, 120, 230, .45); }
[data-hue="1"] .mono { background: #7ec8e0; box-shadow: 0 6px 14px rgba(100, 180, 210, .45); }
[data-hue="2"] .mono { background: #f0a9c0; box-shadow: 0 6px 14px rgba(230, 140, 175, .45); }
[data-hue="3"] .mono { background: #8fd6b4; box-shadow: 0 6px 14px rgba(110, 200, 160, .45); }
[data-hue="4"] .mono { background: #f5c58a; box-shadow: 0 6px 14px rgba(230, 175, 105, .45); }

/* ---------- карточки-строки ---------- */

.row {
  background: var(--card); border-radius: 22px; padding: 16px 20px;
  display: flex; align-items: center; gap: 14px; cursor: pointer;
  box-shadow: var(--card-sh); margin-bottom: 12px;
  transition: transform .16s ease;
}
.row:active { transform: scale(.985); }
.row:last-child { margin-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .kicker { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.row .kicker .type { color: var(--accent); }
.row .title { font-size: 18px; font-weight: 800; line-height: 1.3; }
.row .title.sm { font-size: 16px; font-weight: 700; }
.row .desc {
  font-size: 14px; font-weight: 600; color: var(--muted); margin-top: 5px; line-height: 1.45;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.row .meta { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.row .chev { color: var(--muted); flex: none; font-size: 20px; opacity: .7; }

.recent-row { flex-direction: column; align-items: stretch; gap: 0; }
.recent-row .rmeta { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.recent-row .rmeta .type { color: var(--accent); }
.recent-row .rtitle { font-size: 18px; font-weight: 800; line-height: 1.3; }

/* ---------- материал ---------- */

.player-wrap { border-radius: 22px; overflow: hidden; background: #000; margin: 0 0 12px; box-shadow: var(--card-sh); }
.player { position: relative; width: 100%; aspect-ratio: 16/9; }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.open-ext { display: block; text-align: right; font-size: 14px; margin: 0 0 10px; }

.material-meta { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 2px 0 16px; }

.md {
  background: var(--card); border-radius: 22px; padding: 20px;
  box-shadow: var(--card-sh); font-size: 15.5px; font-weight: 600; line-height: 1.7;
}
.md > *:last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0 0 14px; }
.md h1, .md h2, .md h3 { font-size: 18px; font-weight: 800; margin: 22px 0 10px; line-height: 1.3; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin-bottom: 8px; }
.md li::marker { color: var(--accent-soft); }
.md img { max-width: 100%; border-radius: 14px; }
.md pre {
  background: var(--surface); padding: 14px 16px; border-radius: 14px;
  overflow-x: auto; font-size: 13px; line-height: 1.5; box-shadow: var(--in);
}
.md code { background: var(--surface); border-radius: 6px; padding: 2px 6px; font-size: 13.5px; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent-soft); padding-left: 14px; color: var(--muted); }

/* ---------- файлы ---------- */

.fbox {
  width: 42px; height: 42px; border-radius: 14px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 800; letter-spacing: .02em;
  background: var(--surface); color: var(--accent); box-shadow: var(--out-sm);
}
.fname { font-size: 15px; font-weight: 700; }
.fmeta { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.dl-btn {
  flex: none; background: var(--surface); border: none; color: var(--accent);
  font-size: 13px; font-weight: 800; padding: 10px 16px; border-radius: 14px;
  cursor: pointer; box-shadow: var(--out-sm);
}
.dl-btn:active { box-shadow: var(--out-press); }
.file-row .fbox { font-size: 10.5px; }

/* ---------- поиск: результаты ---------- */

.result-snippet { font-size: 14px; font-weight: 600; line-height: 1.5; color: var(--muted); margin-top: 6px; }
.result-snippet mark {
  color: var(--text); background: rgba(169, 155, 240, .28);
  border-radius: 6px; padding: 1px 4px; font-weight: 700;
}
.result-count { font-size: 12.5px; font-weight: 700; color: var(--muted); margin: 2px 0 12px; padding-left: 4px; }

/* ---------- служебные экраны ---------- */

.center-screen {
  min-height: 62vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 30px 20px;
}
.center-screen h2 { font-size: 21px; font-weight: 800; margin: 20px 0 10px; }
.center-screen p { font-size: 15px; font-weight: 600; line-height: 1.6; color: var(--muted); max-width: 300px; margin-bottom: 24px; }

.lock { width: 44px; height: 56px; position: relative; opacity: .55; }
.lock::before {
  content: ''; position: absolute; top: 0; left: 8px; width: 28px; height: 26px;
  border: 4px solid var(--muted); border-bottom: none; border-radius: 16px 16px 0 0;
}
.lock::after { content: ''; position: absolute; bottom: 0; left: 0; width: 44px; height: 32px; background: var(--muted); border-radius: 12px; }

.err-circle { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--muted); opacity: .5; position: relative; }
.err-circle::after { content: ''; position: absolute; top: 50%; left: -5px; right: -5px; height: 4px; background: var(--muted); transform: rotate(-45deg); border-radius: 2px; }
.empty-square { width: 46px; height: 46px; border: 3px dashed var(--muted); border-radius: 16px; opacity: .5; }
.tg-square {
  width: 56px; height: 56px; background: var(--surface); border-radius: 20px;
  display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: var(--out);
}

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 28px; border: none; border-radius: 18px;
  background: var(--accent-fill); color: #fff; font-size: 16px; font-weight: 800;
  cursor: pointer; box-shadow: var(--glow); transition: transform .16s ease;
}
.btn:active { transform: scale(.97); }
.btn.outline { background: var(--surface); color: var(--accent); box-shadow: var(--out); }
.linklike {
  background: none; border: none; color: var(--accent);
  font-size: 14.5px; font-weight: 800; cursor: pointer; padding: 4px 0;
}
.pill {
  background: var(--surface); border: none; border-radius: 16px; padding: 12px 22px;
  font-size: 13.5px; font-weight: 800; color: var(--accent); cursor: pointer; box-shadow: var(--out-sm);
}
.pill:active { box-shadow: var(--out-press); }
.admin-open-wrap { display: flex; justify-content: flex-end; margin-top: 26px; }

/* ---------- скелетоны ---------- */

.skel { background: var(--surface); border-radius: 18px; box-shadow: var(--out-sm); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
.skel.d1 { animation-duration: 1.5s; } .skel.d2 { animation-duration: 1.7s; }

/* ---------- формы и админка ---------- */

.group { background: var(--card); border-radius: 22px; margin-bottom: 16px; overflow: hidden; box-shadow: var(--card-sh); }
.group .g-row { display: block; padding: 14px 20px; border-bottom: 1px solid rgba(154, 160, 192, .16); cursor: text; }
.group .g-row:last-child { border-bottom: none; }
.group .lbl { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.group input[type=text], .group textarea, .group select {
  width: 100%; border: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: 16px; font-weight: 700; outline: none;
  padding: 6px 0; min-height: 34px;
}
.group select { cursor: pointer; }
.group textarea { font-size: 15px; font-weight: 600; line-height: 1.65; min-height: 128px; resize: vertical; }
.group .parse-ok { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--accent); margin-top: 8px; }
.group-hint { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: -8px 6px 18px; line-height: 1.5; }

.editor {
  min-height: 170px; outline: none; padding: 8px 0;
  font-size: 15px; font-weight: 600; line-height: 1.7; word-break: break-word;
}
.editor:empty::before, .editor.is-empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.editor.is-empty > * { display: none; }
.editor h1, .editor h2, .editor h3 { font-size: 18px; font-weight: 800; margin: 16px 0 8px; }
.editor p { margin: 0 0 10px; }
.editor ul, .editor ol { padding-left: 22px; margin: 0 0 10px; }
.editor li { margin-bottom: 6px; }
.editor blockquote { border-left: 3px solid var(--accent-soft); padding-left: 14px; color: var(--muted); margin: 0 0 10px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px; border-bottom: 1px solid rgba(154, 160, 192, .16); }
.toolbar button {
  background: var(--surface); border: none; color: var(--accent);
  font-size: 13px; font-weight: 800; padding: 8px 14px; border-radius: 12px;
  cursor: pointer; box-shadow: var(--out-sm);
}
.toolbar button:active { box-shadow: var(--out-press); }

.admin-row {
  display: flex; align-items: center; gap: 12px; min-height: 62px;
  background: var(--card); border-radius: 18px; padding: 12px 16px;
  margin-bottom: 10px; box-shadow: var(--card-sh);
}
.admin-row .drag { flex: none; width: 18px; cursor: grab; opacity: .4; padding: 8px 4px; }
.admin-row .drag span { display: block; width: 18px; height: 2.5px; background: var(--text); border-radius: 2px; margin: 3px 0; }
.admin-row .grow { flex: 1; min-width: 0; }
.admin-row .name { font-size: 16px; font-weight: 800; }
.admin-row .cnt { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.sec-row { cursor: grab; touch-action: pan-x; user-select: none; -webkit-user-select: none; }
.sec-row:active { cursor: grabbing; }
.admin-row.dragging { opacity: .6; box-shadow: var(--glow); position: relative; z-index: 3; }

.move-btns { display: flex; flex-direction: column; gap: 4px; flex: none; }
.move-btn {
  width: 34px; height: 26px; border: none; border-radius: 9px; cursor: pointer;
  background: var(--surface); color: var(--accent); font-size: 14px; font-weight: 800;
  line-height: 1; box-shadow: var(--out-sm);
}
.move-btn:active { box-shadow: var(--out-press); }
.add-row {
  display: block; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 10px;
  color: var(--accent); font-size: 15px; font-weight: 800; cursor: pointer;
  background: var(--surface); border: none; border-radius: 18px; box-shadow: var(--out-sm);
}
.add-row:active { box-shadow: var(--out-press); }

.head-actions { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; gap: 12px; }
.head-actions .screen-title { margin: 0; }

.fallback-main {
  position: sticky; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  width: 100%; margin-top: 20px; height: 54px; border-radius: 18px;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--card); color: var(--text); font-size: 14px; font-weight: 700;
  border-radius: 16px; padding: 12px 20px; z-index: 50; box-shadow: var(--card-sh);
  animation: enter .2s ease both; max-width: 90%;
}
.spacer { height: 18px; }

.web-back {
  display: block; margin: 14px 0 0 20px; background: none; border: none;
  color: var(--accent); font-size: 15px; font-weight: 800; cursor: pointer; padding: 6px 0;
}

/* ---------- широкий экран (вкладка браузера) ---------- */

@media (min-width: 800px) {
  body { max-width: 860px; }
  #app { padding: 30px 34px 0; }
  .web-back { margin: 22px 0 0 34px; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .screen-title { font-size: 30px; }
  .md { font-size: 16.5px; padding: 26px; }
  .center-screen { min-height: 72vh; }
  .editor { min-height: 250px; }
}

/* ---------- иконки разделов ---------- */

.mono svg { width: 22px; height: 22px; }
.mono-sm { width: 34px; height: 34px; border-radius: 12px; font-size: 14px; }
.mono-sm svg { width: 19px; height: 19px; }

.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.icon-cell {
  aspect-ratio: 1; border: none; border-radius: 16px; cursor: pointer;
  background: var(--surface); color: var(--muted); box-shadow: var(--out-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800; transition: all .16s ease;
}
.icon-cell svg { width: 23px; height: 23px; }
.icon-cell:active { box-shadow: var(--out-press); }
.icon-cell.on {
  background: var(--accent-fill); color: #fff; box-shadow: var(--glow);
}

/* ---------- черновики ---------- */

.draft-tag {
  display: inline-block; background: rgba(240, 169, 192, .22); color: #b05678;
  border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em;
}
:root[data-scheme="dark"] .draft-tag { background: rgba(240, 169, 192, .18); color: #f0a9c0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) .draft-tag { background: rgba(240, 169, 192, .18); color: #f0a9c0; }
}

.switch-row { display: flex; align-items: center; gap: 14px; cursor: default; }
.switch-title { font-size: 16px; font-weight: 700; }
.switch-note { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.switch {
  flex: none; width: 54px; height: 32px; border: none; border-radius: 16px; cursor: pointer;
  background: var(--surface); box-shadow: var(--in); padding: 0; position: relative;
  transition: background-color .2s ease;
}
.switch span {
  position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--card); box-shadow: 0 2px 6px rgba(90, 100, 140, .35);
  transition: transform .2s ease, background-color .2s ease;
}
.switch.on { background: var(--accent-fill); box-shadow: none; }
.switch.on span { transform: translateX(22px); background: #fff; }
