:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --accent: var(--tg-theme-button-color, #2b6cb0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(120, 128, 140, .28);
  --good: #1f8a4c;
  --hard: #b7791f;
  --bad: #c0392b;
  --good-bg: rgba(31, 138, 76, .12);
  --hard-bg: rgba(183, 121, 31, .14);
  --bad-bg: rgba(192, 57, 43, .12);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #12151a);
    --card: var(--tg-theme-bg-color, #1c2027);
    --text: var(--tg-theme-text-color, #eceef2);
    --hint: var(--tg-theme-hint-color, #98a1b0);
    --accent: var(--tg-theme-button-color, #4d9be6);
    --accent-text: var(--tg-theme-button-text-color, #08121e);
    --good: #4cc47f;
    --hard: #e2a64b;
    --bad: #ee6f60;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
main { max-width: 560px; margin: 0 auto; padding: 16px 16px 96px; }
h1 { font-size: 1.35rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.hint { color: var(--hint); font-size: .9rem; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

button, .btn {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; min-height: 44px;
  background: var(--accent); color: var(--accent-text); cursor: pointer; width: 100%;
}
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.small { width: auto; min-height: 36px; padding: 6px 12px; font-size: .9rem; }
button.danger { background: var(--bad); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
input[type=text], input[type=number], input[type=date], textarea {
  font: inherit; width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
textarea { min-height: 96px; resize: vertical; }
label { display: block; font-size: .9rem; color: var(--hint); margin-bottom: 4px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; text-align: center; padding: 10px 4px; font-size: .78rem; color: var(--hint);
  text-decoration: none; min-height: 52px;
}
.tabs a .ic { display: block; font-size: 1.25rem; line-height: 1.2; }
.tabs a[aria-current=page] { color: var(--accent); font-weight: 600; }

.big { font-size: 2.2rem; font-weight: 700; line-height: 1.1; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.4rem; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 56px; margin-top: 8px; }
.bars span { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars span.today { opacity: 1; outline: 2px solid var(--text); outline-offset: 1px; }
.bars-labels { display: flex; gap: 4px; font-size: .7rem; color: var(--hint); }
.bars-labels span { flex: 1; text-align: center; }

.chip { display: inline-block; font-size: .78rem; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--hint); margin: 2px 4px 2px 0; }
.chip.lock { background: var(--hard-bg); color: var(--hard); }
.chip.new { background: var(--good-bg); color: var(--good); }

.warn { background: var(--hard-bg); color: var(--text); border-left: 4px solid var(--hard); padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; font-size: .92rem; }
.error { background: var(--bad-bg); border-left: 4px solid var(--bad); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: .9rem; color: var(--hint); }
.question { font-size: 1.2rem; font-weight: 600; margin-bottom: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.opts { display: grid; gap: 8px; }
.opts button { background: var(--card); color: var(--text); border: 1px solid var(--line); text-align: left; }
.opts button:hover { border-color: var(--accent); }
.result { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.result.g2 { background: var(--good-bg); } .result.g1 { background: var(--hard-bg); } .result.g0 { background: var(--bad-bg); }
.result h2.g2 { color: var(--good); } .result h2.g1 { color: var(--hard); } .result h2.g0 { color: var(--bad); }
.answer { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.grades { display: grid; gap: 8px; }
.grades button.g0 { background: var(--bad); color: #fff; }
.grades button.g1 { background: var(--hard); color: #fff; }
.grades button.g2 { background: var(--good); color: #fff; }
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
details summary { cursor: pointer; color: var(--accent); }
pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: .82rem; white-space: pre-wrap; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 72px; max-width: 528px; margin: 0 auto; background: #222; color: #fff;
  padding: 10px 14px; border-radius: 10px; font-size: .92rem; text-align: center; z-index: 10;
}
.center { text-align: center; padding: 28px 8px; }
.emoji { font-size: 3rem; display: block; margin-bottom: 8px; }
@media (prefers-reduced-motion: no-preference) {
  .card, .result { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
.tabs[hidden], .toast[hidden] { display: none; }

/* v0.3: muddat, vaqt, AI */
.progress { height: 8px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 6px 0; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.progress.ok > i { background: var(--good); }
.chip.warn { background: var(--hard-bg); color: var(--hard); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.good { background: var(--good-bg); color: var(--good); }
.ai-box { border-left: 3px solid var(--accent); padding: 8px 12px; margin-top: 10px; white-space: pre-wrap; }
.draft { border: 1px dashed var(--hard); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
