/* ===== Turkiston maktabi — fanlar mini app (barcha fanlar uchun umumiy) ===== */
:root {
  /* Brend ranglari (logotip ranglariga moslab o'zgartiring) */
  --brand: #061ab7;   /* Turkistan School logotip rangi */
  --brand-2: #2b47d9;
  --gold: #f2a900;

  --bg: #f3f6fa;
  --card: #ffffff;
  --text: #13202e;
  --muted: #5d6b7c;
  --line: #dfe5ec;
  --chip: #eaf1f9;

  --sim-bg: #fbfcfe;
  --sim-grid: #e6ebf1;
  --c-red: #e5484d;
  --c-green: #2f9e44;
  --c-blue: #1c7ed6;
  --c-orange: #f08c00;
  --c-purple: #7048e8;
  --c-teal: #0ca678;

  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs: 15px;
}
:root[data-theme="dark"] {
  --bg: #0f1620;
  --card: #18222e;
  --text: #e8eef5;
  --muted: #93a2b3;
  --line: #2a3644;
  --chip: #213041;
  --sim-bg: #121b26;
  --sim-grid: #223040;
  --brand-2: #7088ff;
  --c-red: #ff6b6f;
  --c-green: #51cf66;
  --c-blue: #4dabf7;
  --c-orange: #ffa94d;
  --c-purple: #9775fa;
  --c-teal: #38d9a9;
}
:root.big { --fs: 19px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--brand-2); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.top {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  padding: calc(14px + var(--tg-safe-top, 0px)) 0 18px;
}
.top .row { display: flex; align-items: center; gap: 12px; }
.logo { height: 40px; width: auto; flex: none; display: block; }
.top h1 { font-size: 1.15em; margin: 0; line-height: 1.2; }
.top .sub { font-size: .82em; opacity: .85; }
.spacer { flex: 1; }
.langs { display: flex; background: rgba(255,255,255,.16); border-radius: 10px; padding: 3px; }
.langs button {
  border: 0; background: transparent; color: #fff; padding: 5px 9px; border-radius: 8px;
  font-size: .8em; font-weight: 600; opacity: .8;
}
.langs button.on { background: #fff; color: var(--brand); opacity: 1; }
.hero-txt { margin: 14px 0 0; font-size: .92em; opacity: .92; max-width: 640px; }

.stats { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.stat { background: rgba(255,255,255,.14); border-radius: 10px; padding: 6px 10px; font-size: .8em; }
.stat b { font-size: 1.15em; display: block; }

/* ---------- Home ---------- */
.filter { display: flex; gap: 8px; margin: 16px 0 6px; flex-wrap: wrap; }
.chipbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: .85em;
}
.chipbtn.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.chapter { margin: 18px 0 8px; }
.chapter h2 {
  font-size: .78em; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 8px; font-weight: 700;
}
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); text-decoration: none; color: inherit;
}
.item:last-child { border-bottom: 0; }
.item .num {
  min-width: 34px; height: 34px; padding: 0 4px; box-sizing: border-box; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--chip); color: var(--muted); font-weight: 700; font-size: .85em;
}
.item.has-sim .num { background: var(--brand); color: #fff; }
.item .ttl { flex: 1; font-size: .95em; }
.item .tag {
  font-size: .7em; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: rgba(242,169,0,.16); color: #b37d00; white-space: nowrap;
}
:root[data-theme="dark"] .item .tag { color: var(--gold); }
.item .soon { font-size: .72em; color: var(--muted); white-space: nowrap; }
.item.has-sim:active { background: var(--chip); }
.item:not(.has-sim) .ttl { color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: .78em; padding: 28px 16px 36px; }

/* ---------- Topic page ---------- */
.tbar {
  position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--tg-safe-top, 0px)) 0 8px;
}
.tbar .row { display: flex; align-items: center; gap: 10px; }
.iconbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  height: 36px; min-width: 36px; padding: 0 10px; display: inline-flex; align-items: center; gap: 6px;
  font-size: .82em; font-weight: 600;
}
.iconbtn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tbar .kick { font-size: .72em; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.tbar h1 { font-size: 1.02em; margin: 0; line-height: 1.25; }
.tbar .meta { flex: 1; min-width: 0; }

.simcard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin-top: 14px; overflow: hidden;
}
.stage {
  position: relative; width: 100%; aspect-ratio: var(--ar, 16 / 10);
  max-height: 62vh; background: var(--sim-bg); touch-action: none;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.controls { padding: 12px 14px 14px; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.ctl label { display: flex; justify-content: space-between; font-size: .82em; color: var(--muted); margin-bottom: 4px; gap: 8px; }
.ctl label b { color: var(--text); font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--brand-2); height: 28px; }
.ctl select {
  width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: .9em;
}
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 6px; border-radius: 8px; font-size: .82em; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 700; font-size: .88em;
  background: var(--brand); color: #fff;
}
.btn.ghost { background: var(--chip); color: var(--text); }
.btn:active { transform: scale(.97); }

.readout {
  border-top: 1px solid var(--line); padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 8px 18px;
  font-variant-numeric: tabular-nums; font-size: .9em; background: var(--bg);
}
.readout .r { white-space: nowrap; }
.readout .r i { color: var(--muted); font-style: normal; }
.readout .r b { font-weight: 700; }

.tabs { display: flex; gap: 6px; margin: 16px 0 10px; overflow-x: auto; }
.tabs button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px;
  font-size: .86em; font-weight: 600; white-space: nowrap;
}
.tabs button.on { background: var(--text); color: var(--card); border-color: var(--text); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.panel p { margin: 0 0 10px; }
.panel ul { margin: 0; padding-left: 20px; }
.panel li { margin-bottom: 6px; }
.formula {
  display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.formula:last-child { border-bottom: 0; }
.formula .f { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 1.35em; min-width: 120px; font-style: italic; }
.formula .d { font-size: .88em; color: var(--muted); }
/* SUBJECT.formulaStyle = 'terms': formula o'rniga atama va uning ta'rifi */
.panel.terms .formula .f { font-family: inherit; font-style: normal; font-weight: 700; font-size: 1em; min-width: 150px; max-width: 40%; color: var(--brand-2); }
.q { border-bottom: 1px solid var(--line); padding: 10px 0; }
.q:last-child { border-bottom: 0; }
.q .qa { display: flex; gap: 8px; }
.q .qa b { color: var(--brand-2); }
.q button { margin-top: 8px; border: 0; background: var(--chip); border-radius: 8px; padding: 5px 10px; font-size: .8em; font-weight: 600; }
.q .ans { margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--c-green); background: var(--bg); border-radius: 0 8px 8px 0; font-size: .92em; }
.hint { font-size: .8em; color: var(--muted); padding: 0 14px 12px; }
.extra { font-size: .78em; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 22px 0 0; font-weight: 700; }
.videos { display: grid; gap: 10px; margin-top: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.video { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.video .thumb { width: 112px; aspect-ratio: 16 / 9; border-radius: 10px; flex: none; background: #000 center / cover; display: grid; place-items: center; }
.video .yt { width: 34px; height: 24px; background: #ff0000; border-radius: 7px; display: grid; place-items: center; color: #fff; font-size: 11px; }
.video .vtxt { display: flex; flex-direction: column; gap: 3px; min-width: 0; font-size: .9em; line-height: 1.3; }
.video .vtxt small { color: var(--muted); font-size: .8em; }

/* Ustoz rejimi: sahna kattaroq, yozuvlar yirik */
:root.teach .stage { max-height: 78vh; }
:root.teach .wrap { max-width: 1400px; }

@media (max-width: 560px) {
  .stage { aspect-ratio: var(--ar-m, var(--ar)); max-height: 72vh; }
}
@media (max-width: 520px) {
  .controls { grid-template-columns: 1fr; }
  .formula { flex-direction: column; align-items: flex-start; gap: 2px; }
  .panel.terms .formula .f { max-width: none; }
}

/* SUBJECT.parts: bitta ilovada bir nechta darslik (masalan Ona tili | Adabiyot) */
.parts { display: flex; gap: 8px; margin: 16px 0 0; }
.parts button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 11px 10px; font-weight: 700; font-size: .95em; color: var(--muted);
}
.parts button span { font-size: 1.2em; }
.parts button.on { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(6,26,183,.22); }

/* Sinflar (parts[].grade): bosh sahifada avval sinf tanlanadi */
.grades { display: flex; gap: 6px; margin: 16px 0 0; overflow-x: auto; padding-bottom: 2px; min-width: 0; max-width: 100%; }
.grades button {
  flex: 1 1 0; min-width: 44px; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 7px 8px 6px; display: flex; flex-direction: column; align-items: center; color: var(--muted); line-height: 1.1;
}
.grades button b { font-size: 1.25em; color: var(--text); }
.grades button small { font-size: .68em; font-weight: 600; }
.grades button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.grades button.on b { color: #fff; }
.grades + .parts { flex-wrap: wrap; margin-top: 10px; }
.grades + .parts button { flex: 1 1 140px; }
