:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f7df6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7df6);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ok: #1fa463;
  --warn: #f29d0c;
  --danger: #e5484d;
  --info: #3b82f6;
  --radius: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }

#top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 12px 16px 8px; background: var(--bg);
}
#title { flex: 1; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); background: var(--card); flex: none; }
.icon-btn:active { opacity: .6; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.badge { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: linear-gradient(135deg, #7c5cff, #2f7df6); color: #fff; flex: none; }
.badge.trial { background: linear-gradient(135deg, #f29d0c, #f2620c); }

#view { padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 20px); max-width: 720px; margin: 0 auto; }
#view.no-nav { padding-bottom: calc(var(--safe-b) + 24px); }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--sep);
}
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--hint); font-size: 11px; position: relative; }
#tabs svg { width: 24px; height: 24px; fill: currentColor; }
#tabs button.on { color: var(--accent); }
#tabs .dot { position: absolute; top: 9px; left: calc(50% + 8px); min-width: 8px; height: 8px; border-radius: 4px; background: var(--danger); }

/* ---------- building blocks ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.card.flush { padding: 0; overflow: hidden; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--hint); margin: 18px 4px 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.section-title button { color: var(--link); text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--sep); min-height: 52px; }
.row:last-child { border-bottom: 0; }
button.row, a.row { width: 100%; text-align: left; color: var(--text); }
button.row:active, a.row:active { background: var(--soft); }
.row .grow { flex: 1; min-width: 0; }
.row .t1 { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { font-size: 13px; color: var(--hint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.row .chev { color: var(--hint); flex: none; }
.ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 19px; flex: none; background: var(--soft); }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pre { white-space: pre-wrap; word-break: break-word; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; padding: 12px 16px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn:active { opacity: .8; transform: scale(.99); }
.btn.ghost { background: var(--soft); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn + .btn { margin-top: 10px; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btns .btn + .btn { margin-top: 0; }

.seg { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; padding: 8px 14px; border-radius: 99px; background: var(--card); color: var(--text); font-size: 14px; font-weight: 500; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.seg.wrap { flex-wrap: wrap; margin: 0; padding: 0 0 4px; overflow: visible; }
#sheet .seg button:not(.on) { background: var(--bg); }
.seg button .n { opacity: .7; margin-left: 4px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat .l { font-size: 13px; color: var(--hint); }
button.stat { text-align: left; }
button.stat:active { opacity: .7; }

.bar { height: 8px; border-radius: 4px; background: var(--sep); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width .5s; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); }
.bar.danger > i, .bar.over > i { background: var(--danger); }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: var(--soft); color: var(--accent); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.danger, .pill.over { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pill.grey { background: var(--sep); color: var(--hint); }

.grade { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; color: #fff; }
.g5 { background: var(--ok); } .g4 { background: var(--info); } .g3 { background: var(--warn); } .g2 { background: var(--danger); } .g0 { background: var(--sep); color: var(--hint); }

/* lessons */
.lesson { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--sep); }
.lesson:last-child { border-bottom: 0; }
.lesson .time { width: 52px; flex: none; font-variant-numeric: tabular-nums; }
.lesson .time b { display: block; font-size: 15px; }
.lesson .time span { font-size: 12px; color: var(--hint); }
.lesson .body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 10px; }
.lesson.k-lab .body { border-color: #9b5cf6; } .lesson.k-pr .body { border-color: var(--ok); } .lesson.k-sem .body { border-color: var(--warn); }
.lesson.now { background: var(--soft); }
.lesson.past { opacity: .55; }
.lesson .subj { font-weight: 600; }
.lesson .meta { font-size: 13px; color: var(--hint); margin-top: 2px; }
.day-h { font-weight: 700; margin: 18px 4px 8px; display: flex; gap: 8px; align-items: center; }

/* hero */
.hero { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #7c5cff)); color: #fff; border-radius: 20px; padding: 18px; margin-bottom: 12px; position: relative; overflow: hidden; }
.hero h2 { margin: 0 0 4px; font-size: 21px; }
.hero p { margin: 0; opacity: .9; font-size: 14px; }
.hero .ring { position: absolute; right: 14px; top: 14px; }
.ring { width: 64px; height: 64px; }
.ring text { font-weight: 700; font-size: 20px; fill: currentColor; }

/* task */
.deadline { font-size: 12px; font-weight: 600; }
.deadline.soon { color: var(--danger); } .deadline.mid { color: var(--warn); } .deadline.far { color: var(--hint); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--hint); } .kv dd { margin: 0; text-align: right; font-weight: 500; word-break: break-word; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--sep); }
.file-row:last-child { border-bottom: 0; }
.file-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row button { color: var(--link); font-weight: 500; font-size: 14px; flex: none; }

.choice { display: grid; gap: 10px; }
.choice button { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; background: var(--bg); border: 2px solid transparent; text-align: left; }
.choice button.on { border-color: var(--accent); background: var(--soft); }
.choice .big { font-size: 26px; }

/* forms */
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 6px; }
.input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--sep); background: var(--card); outline: none; font-size: 16px; }
.input:focus { border-color: var(--accent); }
.search { position: sticky; top: 56px; z-index: 4; background: var(--bg); padding-bottom: 8px; }

.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 15px; background: var(--sep); transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }

/* chat */
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 18px; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.msg.typing { color: var(--hint); }
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(8px + var(--safe-b)); background: var(--card); border-top: 1px solid var(--sep); }
.composer textarea { flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px; border: 1.5px solid var(--sep); background: var(--bg); outline: none; font-size: 16px; }
.composer button { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.composer button[disabled] { opacity: .4; }

/* plans */
.plan { border: 2px solid var(--sep); border-radius: 16px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; margin-bottom: 10px; width: 100%; text-align: left; background: var(--card); }
.plan.best { border-color: var(--accent); }
.plan .price { font-size: 20px; font-weight: 700; }
.plan .tag { font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); padding: 2px 8px; border-radius: 99px; }
.feat { display: flex; gap: 10px; padding: 8px 0; align-items: flex-start; }
.feat b { font-weight: 500; }
.cmp { width: 100%; border-collapse: collapse; font-size: 14px; }
.cmp td { padding: 9px 4px; border-bottom: 1px solid var(--sep); }
.cmp td:nth-child(n+2) { text-align: center; width: 64px; }

/* states */
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 25%, color-mix(in srgb, var(--card) 80%, var(--hint)) 50%, var(--card) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; height: 72px; margin-bottom: 12px; }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 36px 16px; color: var(--hint); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; margin-bottom: 12px; font-size: 14px; background: var(--soft); align-items: flex-start; }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.notice.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.notice.ok { background: color-mix(in srgb, var(--ok) 13%, transparent); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--sep); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
.progress-steps { list-style: none; padding: 0; margin: 12px 0 0; }
.progress-steps li { display: flex; gap: 10px; align-items: center; padding: 8px 0; color: var(--hint); }
.progress-steps li.on { color: var(--text); font-weight: 600; }
.progress-steps li.done { color: var(--ok); }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 20; margin: 0 auto; max-width: 480px; background: rgba(20, 22, 26, .92); color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); animation: up .2s; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }

#sheet-wrap { position: fixed; inset: 0; z-index: 30; }
#sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
#sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--card); border-radius: 20px 20px 0 0; padding: 10px 16px calc(16px + var(--safe-b)); animation: slide .25s ease-out; max-width: 720px; margin: 0 auto; }
#sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 12px; }
#sheet h3 { margin: 0 0 12px; font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(100%); } }

.avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--soft); display: grid; place-items: center; font-size: 26px; font-weight: 700; color: var(--accent); flex: none; }
.chart-row { display: grid; grid-template-columns: 1fr 120px 40px; gap: 10px; align-items: center; padding: 7px 0; font-size: 14px; }
.chart-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-row b { text-align: right; font-variant-numeric: tabular-nums; }
.lock { text-align: center; padding: 28px 16px; }
.lock .e { font-size: 46px; }
.lock h3 { margin: 8px 0 6px; }
.fade-in { animation: fi .2s ease-out; }
@keyframes fi { from { opacity: 0; transform: translateY(6px); } }
