:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint-color: var(--tg-theme-hint-color, #8a8a8e);
  --card: var(--tg-theme-secondary-bg-color, #faf7f5);
  --accent: #c4506b;
  --accent-soft: rgba(196, 80, 107, 0.14);
  --line: rgba(128, 128, 128, 0.22);
  --safe-top: calc(max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.hint { color: var(--hint-color); font-size: 13px; }

/* ---------- каркас: телефон ---------- */
.layout { min-height: 100vh; }
.main { padding: calc(var(--safe-top) + 14px) 16px calc(84px + var(--safe-bottom)); max-width: 860px; margin: 0 auto; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: var(--bg); border-top: 1px solid var(--line); padding: 6px 0 calc(8px + var(--safe-bottom));
}
.brand { display: none; }
.nav-item {
  flex: 1; border: 0; background: none; color: var(--hint-color); font-size: 11px; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: color .2s;
}
.nav-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.active { color: var(--accent); font-weight: 600; }

.tab { display: none; }
.tab.active { display: block; animation: fadein .25s ease-out; }
.head { margin: 4px 2px 14px; }
.head h1 { font-size: 26px; letter-spacing: -0.3px; }

/* ---------- модули ---------- */
.mods { display: grid; gap: 10px; }
.mod {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0;
  background: var(--card); border-radius: 16px; padding: 12px 14px; transition: transform .12s, background .2s;
}
.mod:active { transform: scale(0.985); }
.mod-n {
  flex: none; width: 34px; height: 34px; border-radius: 11px; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.mod-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mod-t b { font-weight: 600; font-size: 15px; line-height: 1.25; }
.mod-ch { color: var(--hint-color); font-size: 20px; }
.status { padding: 14px 4px; color: var(--hint-color); display: flex; gap: 10px; align-items: center; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 14px; text-decoration: none; }
.admin-link { display: inline-block; margin-top: 22px; }

/* ---------- пустые вкладки ---------- */
.center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 12px; max-width: 360px; margin: 0 auto; }
.center h2 { font-size: 18px; }
.icon-box { width: 68px; height: 68px; border-radius: 22px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.icon-box svg { width: 32px; height: 32px; fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- кнопки ---------- */
.btn { display: block; width: 100%; border: 0; border-radius: 13px; padding: 13px; font-weight: 600; font-size: 15px; margin-top: 8px; transition: opacity .2s, transform .12s; }
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn[disabled] { opacity: 0.45; cursor: default; }

/* ---------- всплывающее окно ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal-dim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.42); animation: fadein .2s; }
.sheet {
  position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + var(--safe-bottom));
  animation: rise .26s ease-out;
}
.grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 17px; margin-bottom: 10px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { border: 0; background: var(--card); border-radius: 16px; padding: 6px 13px; font-size: 13px; }
.pill.on { background: var(--accent); color: #fff; font-weight: 600; }
.pill.soon { opacity: 0.55; }
.prev {
  position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; padding: 0; overflow: hidden;
  border-radius: 16px; background: linear-gradient(135deg, #f4d6dc, #e9c4a8);
}
.prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prev .play {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; transform: translate(-50%, -50%);
  border-radius: 50%; background: rgba(255, 255, 255, 0.92); display: flex; align-items: center; justify-content: center;
}
.prev .play::after { content: ""; margin-left: 4px; border-left: 15px solid var(--accent); border-top: 10px solid transparent; border-bottom: 10px solid transparent; }
.prev .soon-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #7a5a55; font-weight: 600; padding: 12px; text-align: center; }
.prev[disabled] { cursor: default; }
.lesson-title { font-weight: 600; margin: 12px 0 6px; line-height: 1.3; }

/* ---------- админ-панель ---------- */
.panel h2 { font-size: 17px; margin: 22px 0 10px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 12px; color: var(--hint-color); }
.arow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--card); border-radius: 12px; padding: 9px 12px; margin-bottom: 6px; font-size: 14px; }
.arow.sub { margin-left: 18px; }
.arow .t { flex: 1; min-width: 160px; }
.arow .c { color: var(--hint-color); font-size: 12px; }
.mini { border: 1px solid var(--line); background: none; border-radius: 9px; padding: 3px 10px; font-size: 12px; }
.mini.danger { color: #c0392b; border-color: rgba(192, 57, 43, 0.35); }
.editor { background: var(--card); border-radius: 16px; padding: 14px; margin: 14px 0; display: grid; gap: 10px; }
.editor label { display: grid; gap: 4px; font-size: 13px; color: var(--hint-color); }
.editor input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%; }
.row { display: flex; gap: 8px; }
.row .btn { margin-top: 0; }
.error { color: #c0392b; font-size: 13px; min-height: 1em; }
.gate { padding: 40px 8px; text-align: center; color: var(--hint-color); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table td, .table th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.table th { color: var(--hint-color); font-weight: 500; }

/* ---------- анимации ---------- */
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- компьютер ---------- */
@media (min-width: 820px) {
  .layout { display: flex; }
  .nav {
    position: sticky; top: 0; align-self: flex-start; height: 100vh; width: 210px; flex: none; flex-direction: column;
    justify-content: flex-start; gap: 4px; border-top: 0; border-right: 1px solid var(--line); padding: 24px 12px;
  }
  .brand { display: block; font-weight: 700; font-size: 15px; margin: 0 10px 18px; }
  .nav-item { flex: none; flex-direction: row; gap: 10px; font-size: 14px; padding: 10px 12px; border-radius: 12px; justify-content: flex-start; }
  .nav-item.active { background: var(--accent-soft); }
  .main { flex: 1; padding: 32px 36px; margin: 0; max-width: 900px; }
  .mods { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .modal { align-items: center; }
  .sheet { width: 460px; border-radius: 20px; padding: 20px 22px 22px; animation: pop .2s ease-out; }
  .grab { display: none; }
}
