:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --text: var(--tg-theme-text-color, #14151a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #6c5ce7);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 127, 0.14);
  --danger: #e5484d;
  --ok: #2fb67c;
  --gold: #f5b301;
  --brand-1: #6c5ce7;
  --brand-2: #a855f7;
  --brand-3: #ec4899;
  --pro-1: #ffb347;
  --pro-2: #ff6b3d;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(20, 20, 40, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #1b1c22; --bg2: #0f1014; --text: #f2f3f7; --hint: #8a8f98;
                   --shadow: 0 6px 24px rgba(0, 0, 0, 0.35); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg2); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
}
main { max-width: 520px; margin: 0 auto; padding: 16px 16px 112px; }
h1 { font-size: 24px; margin: 4px 0 12px; letter-spacing: -0.02em; }
h2 { font-size: 13px; margin: 24px 4px 10px; text-transform: uppercase; letter-spacing: 0.06em;
     color: var(--hint); font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--hint); }
.center { text-align: center; }
code { background: var(--bg2); padding: 1px 7px; border-radius: 7px; font-size: 14px; }
.fade-in { animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- герой ---------- */
.hero {
  position: relative; overflow: hidden; color: #fff; border-radius: 24px; padding: 20px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2) 55%, var(--brand-3));
  box-shadow: 0 12px 32px rgba(108, 92, 231, 0.35);
}
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px;
               border-radius: 50%; background: rgba(255,255,255,.12); }
.hero-top { display: flex; align-items: center; gap: 14px; }
.hero .name { font-size: 20px; font-weight: 700; }
.hero .lvl { opacity: .9; font-size: 14px; }
.hero .pts { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; margin-top: 14px; line-height: 1; }
.hero .pts small { font-size: 15px; font-weight: 600; opacity: .85; margin-left: 6px; }
.bar { height: 8px; background: rgba(255,255,255,.25); border-radius: 99px; margin-top: 12px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #fff; border-radius: 99px; transition: width .6s ease; }
.hero .next { font-size: 13px; opacity: .85; margin-top: 6px; }

.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
          font-weight: 700; color: #fff; font-size: 18px; }
.hero .avatar { width: 52px; height: 52px; background: rgba(255,255,255,.22); font-size: 22px; }
.avatar.sm { width: 36px; height: 36px; font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--bg); border-radius: 16px; padding: 12px 8px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; letter-spacing: -0.02em; }
.stat span { font-size: 12px; color: var(--hint); }

/* ---------- списки ---------- */
.card { background: var(--bg); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.list { background: var(--bg); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%; text-align: left;
       background: none; border: 0; border-bottom: 1px solid var(--line); color: inherit; font: inherit; }
.row:last-child { border-bottom: 0; }
button.row { cursor: pointer; }
button.row:active { background: var(--bg2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--hint); }
.row .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.chev { color: var(--hint); font-size: 22px; }
.me { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px;
         vertical-align: middle; margin-left: 6px; color: #fff;
         background: linear-gradient(90deg, var(--pro-1), var(--pro-2)); }

/* ---------- экран чата ---------- */
.back { background: none; border: 0; color: var(--accent); font: inherit; padding: 4px 0; margin-bottom: 6px; cursor: pointer; }
.chat-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.chat-head h1 { margin: 0; }
.streak { display: inline-flex; gap: 6px; align-items: center; background: var(--bg); border-radius: 99px;
          padding: 6px 12px; font-size: 14px; box-shadow: var(--shadow); margin: 4px 0 4px; }
.seg { display: flex; background: var(--bg); border-radius: 14px; padding: 4px; gap: 4px; box-shadow: var(--shadow); }
.seg button { flex: 1; border: 0; border-radius: 10px; padding: 8px; background: none; color: var(--text);
              font: inherit; font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-text); }

.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 8px; margin: 18px 0 10px; }
.pod { text-align: center; }
.pod .avatar { margin: 0 auto 6px; }
.pod .nm { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pod .pt { font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.pod .step { border-radius: 14px 14px 6px 6px; color: #fff; font-weight: 800; font-size: 22px;
             display: grid; place-items: center; }
.pod.p1 .step { height: 92px; background: linear-gradient(180deg, #ffd54a, #f5a300); }
.pod.p2 .step { height: 68px; background: linear-gradient(180deg, #cfd6e0, #98a2b3); }
.pod.p3 .step { height: 52px; background: linear-gradient(180deg, #f3b07c, #c9773f); }
.pod.p1 .avatar { width: 56px; height: 56px; font-size: 22px; box-shadow: 0 0 0 3px var(--gold); }

.topics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.topic { background: var(--bg); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); min-height: 84px; }
.topic .cat { font-size: 13px; color: var(--hint); }
.topic .who { font-weight: 700; margin-top: 4px; }
.topic .acc { font-size: 13px; color: var(--ok); }
.topic.locked .who { filter: blur(5px); user-select: none; }
.topic.locked { position: relative; cursor: pointer; }
.topic.locked::after { content: "🔒"; position: absolute; right: 10px; top: 10px; }

.qcard { background: var(--bg); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.qcard .q { font-weight: 600; }
.qcard .ok { color: var(--ok); font-size: 14px; margin-top: 4px; }
.qcard .wrong { color: var(--hint); font-size: 14px; }
.qcard .del { background: none; border: 0; color: var(--danger); font: inherit; font-size: 14px; cursor: pointer; padding: 6px 0 0; }
.meter { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--hint); margin: -2px 4px 10px; }
.meter .bar { flex: 1; background: var(--line); margin: 0; height: 6px; }
.meter .bar > i { background: var(--accent); }

/* ---------- кнопки ---------- */
.btn { display: block; width: 100%; border: 0; border-radius: 16px; padding: 15px; background: var(--accent);
       color: var(--accent-text); font: inherit; font-weight: 700; cursor: pointer; transition: transform .08s; }
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.btn.ghost { background: none; color: var(--hint); font-weight: 600; }
.btn.pro { color: #fff; background: linear-gradient(90deg, var(--pro-1), var(--pro-2));
           box-shadow: 0 8px 22px rgba(255, 107, 61, .35); }
.btn + .btn { margin-top: 10px; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        background: linear-gradient(180deg, transparent, var(--bg2) 35%); }
.dock > div { max-width: 488px; margin: 0 auto; }

/* ---------- пустое состояние ---------- */
.empty { text-align: center; padding: 28px 20px; }
.empty .big { font-size: 48px; }
.steps { text-align: left; margin: 14px 0 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 6px 0 6px 36px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 5px; width: 26px; height: 26px;
                    border-radius: 50%; background: var(--accent); color: var(--accent-text);
                    display: grid; place-items: center; font-size: 13px; font-weight: 700; }

/* ---------- шторка и формы ---------- */
.sheet { position: fixed; inset: 0; background: rgba(10, 10, 20, .45); display: flex; align-items: flex-end;
         z-index: 10; animation: fade .2s; }
.sheet-body { background: var(--bg); width: 100%; max-width: 520px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
              border-radius: 24px 24px 0 0; padding: 22px 16px calc(20px + env(safe-area-inset-bottom));
              animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
.sheet-body h1 { margin-top: 0; }
label { display: block; font-size: 13px; color: var(--hint); margin: 14px 0 6px; font-weight: 600; }
input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1.5px solid transparent;
        background: var(--bg2); color: var(--text); font: inherit; outline: none; }
input:focus { border-color: var(--accent); }
.opt { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.opt span { flex: none; width: 28px; text-align: center; }
.note { font-size: 13px; color: var(--hint); margin: 12px 0 16px; }
.hidden { display: none !important; }
.toast { position: fixed; top: 14px; left: 16px; right: 16px; max-width: 488px; margin: 0 auto; z-index: 20;
         background: rgba(20, 20, 30, .92); color: #fff; padding: 12px 16px; border-radius: 14px; animation: fade .2s; }

/* ---------- пейволл ---------- */
.pw-hero { text-align: center; margin: -4px 0 16px; }
.pw-hero .star { width: 72px; height: 72px; margin: 0 auto 10px; border-radius: 22px; display: grid; place-items: center;
                 font-size: 38px; background: linear-gradient(135deg, var(--pro-1), var(--pro-2));
                 box-shadow: 0 10px 26px rgba(255, 107, 61, .4); }
.pw-hero h1 { margin: 0 0 4px; }
.cmp { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 14px; }
.cmp th { font-size: 12px; color: var(--hint); font-weight: 600; text-align: center; padding: 0 4px 6px; }
.cmp th:first-child { text-align: left; }
.cmp td { padding: 9px 4px; border-top: 1px solid var(--line); text-align: center; }
.cmp td:first-child { text-align: left; }
.cmp .y { color: var(--ok); font-weight: 700; }
.cmp .n { color: var(--hint); }
.share { background: var(--bg2); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.plans { display: grid; gap: 10px; margin-bottom: 14px; }
.plan { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px;
        border: 2px solid var(--line); border-radius: 16px; padding: 14px; cursor: pointer; background: var(--bg);
        color: var(--text); font: inherit; text-align: left; width: 100%; }
.plan.sel { border-color: var(--pro-2); background: color-mix(in srgb, var(--pro-2) 7%, var(--bg)); }
.plan .pl-t { font-weight: 700; }
.plan .pl-s { font-size: 13px; color: var(--hint); }
.plan .pl-p { font-weight: 800; font-size: 18px; white-space: nowrap; }
.plan .tag { position: absolute; top: -10px; right: 14px; font-size: 11px; font-weight: 800; color: #fff; padding: 2px 8px;
             border-radius: 99px; background: linear-gradient(90deg, var(--pro-1), var(--pro-2)); }
