:root {
  --ink: #140b3f;
  --muted: #55497f;
  --purple: #6a2fd6;
  --purple-dark: #4b17b0;
  --soft: #e9e0ff;
  --card: rgba(255, 255, 255, 0.72);
  --shadow: 0 8px 22px rgba(95, 60, 190, 0.16);
  --ok: #17951a;
  --ok-bg: #e0f8dc;
  --bad: #d3121f;
  --bad-bg: #ffe0e5;
  --hanzi: "KaiTi", "STKaiti", "Kaiti SC", "Noto Serif CJK SC", "Noto Serif SC", serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: #ded6fb; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  background: linear-gradient(180deg, #ece6ff 0%, #f1e9ff 45%, #ddd4ff 100%);
  overflow-x: clip;
}
.screen {
  min-height: 100dvh;
  padding: 0 16px calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.2; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1rem; }
ul, ol { list-style: none; margin: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #8b5cf6; outline-offset: 2px; }
.icon { flex: none; }
.muted { color: var(--muted); font-size: 0.85rem; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
[lang="zh-CN"] { font-family: var(--hanzi); }

/* Tugmalar */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow);
  font-weight: 700;
}
.btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(180deg, #9547f0, #5320c4);
}
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.6; }
.round {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow);
  padding: 0;
}
.round.small { width: 38px; height: 38px; color: var(--purple-dark); }
.round:disabled { opacity: 0.4; }
.link { align-self: center; background: none; border: 0; color: var(--purple-dark); font-weight: 600; padding: 8px; }

/* Sarlavha */
.hero {
  position: relative;
  margin: 0 -16px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 8px;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
}
.hero::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 72%;
  aspect-ratio: 554 / 262;
  background: url("/img/hero.jpg") center / cover;
  -webkit-mask-image: radial-gradient(ellipse 100% 100% at 100% 0%, #000 58%, transparent 90%);
  mask-image: radial-gradient(ellipse 100% 100% at 100% 0%, #000 58%, transparent 90%);
}
.hero > * { position: relative; }
.topbar { display: flex; align-items: center; gap: 12px; }
.badge {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #8b45e6, #5a22b8);
  font-size: 0.85rem;
  font-weight: 600;
}
.badge.red { background: var(--bad); }
.heading { display: flex; align-items: center; gap: 12px; }
.heading h1, .heading p { text-shadow: 0 0 8px #fff, 0 0 14px #fff; }
.heading p { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.symbol {
  display: grid;
  place-items: center;
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(160deg, #a45cf0, #5520c0);
  box-shadow: var(--shadow);
}

.panel {
  background: var(--card);
  border: 1px solid #fff;
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card {
  position: relative;
  background: var(--card);
  border: 1px solid #fff;
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.list { display: flex; flex-direction: column; gap: 12px; }
.go {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--purple-dark);
}

/* Darsliklar */
.books-hero {
  position: relative;
  margin: 0 -16px;
  padding: calc(18px + env(safe-area-inset-top)) 16px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.books-hero h1 { font-size: 1.9rem; }
.books-icon { color: #5a4fd0; }
.profile { position: absolute; right: 16px; top: calc(14px + env(safe-area-inset-top)); }
.range {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 22px;
  border-radius: 999px;
  color: #fff;
  background: #6f6bd0;
  font-weight: 600;
}
.level {
  --tone: #ee5566;
  --bg: #ffe6ef;
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 86px;
  padding: 10px 14px;
  overflow: hidden;
  border: 1px solid #fff;
  border-radius: 24px;
  background: var(--bg);
  box-shadow: var(--shadow);
  text-align: left;
}
.level img {
  position: absolute;
  right: 40px;
  top: 0;
  height: 100%;
  width: 50%;
  object-fit: cover;
  object-position: 72% center;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 45%, #000 84%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 45%, #000 84%, transparent);
}
.books-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/img/hero.jpg") right top / 100% auto no-repeat;
  opacity: 0.5;
  -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent);
  mask-image: linear-gradient(180deg, #000 55%, transparent);
}
.books-hero > :not(.profile) { position: relative; }
.level > :not(img) { position: relative; z-index: 1; }
.tile { display: grid; place-items: center; width: 56px; height: 54px; border-radius: 16px; background: var(--tone); color: #fff; }
.level .info { flex: 1; display: flex; flex-direction: column; }
.level .info b { font-size: 1.35rem; }
.level .info small { color: var(--muted); font-weight: 600; }
.level .go { background: var(--tone); color: #fff; }
.level.locked { filter: saturate(0.55); }
.lock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  background: #5d567c;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}
.c2 { --tone: #5b6fd8; --bg: #e9e8ff; }
.c3 { --tone: #f5921e; --bg: #ffefe0; }
.c4 { --tone: #34a45c; --bg: #e3f6ec; }
.c5 { --tone: #3a8be0; --bg: #e1eeff; }
.c6 { --tone: #7d63d8; --bg: #ebe4fd; }
.c7 { --tone: #e5639b; --bg: #fde3f1; }
.c8 { --tone: #2a9fd8; --bg: #e0eefd; }
.c9 { --tone: #8a5ce6; --bg: #ece0ff; }

/* Darslar */
.lesson { display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 8px; }
.lesson img { width: 92px; height: 88px; object-fit: cover; border-radius: 16px; flex: none; }
.lesson .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; }
.num { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(160deg, #a870ec, #6a35c8); color: #fff; font-style: normal; font-size: 0.85rem; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips em { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; background: var(--soft); font-style: normal; font-size: 0.7rem; }

.section { display: flex; align-items: center; gap: 12px; padding: 12px; }
.section img { width: 100px; height: 72px; object-fit: cover; border-radius: 18px; flex: none; }
.section .info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.section .info b { font-size: 1.1rem; }
.section small, .exercise small { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid li { display: flex; }
.exercise { flex: 1; display: flex; flex-direction: column; gap: 6px; padding-bottom: 14px; overflow: hidden; }
.exercise img { width: 100%; height: 100px; object-fit: cover; }
.exercise b { padding: 0 12px; font-size: 0.95rem; line-height: 1.25; }
.exercise small { padding: 0 12px; flex: 1; }
.exercise .go { align-self: flex-end; margin-right: 10px; width: 32px; height: 32px; }
.tag { position: absolute; top: 8px; right: 8px; padding: 3px 9px; border-radius: 999px; background: #5d567c; color: #fff; font-size: 0.68rem; font-weight: 600; }

/* Yangi so'zlar */
.panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.words { display: flex; flex-direction: column; gap: 8px; margin: 0 -8px; }
.words li {
  display: grid;
  grid-template-columns: 28px minmax(64px, auto) 1fr 38px;
  grid-template-areas: "n zh py play" "n zh uz play";
  align-items: center;
  column-gap: 10px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 3px 10px rgba(95, 60, 190, 0.1);
  border: 2px solid transparent;
}
.words li.active { border-color: var(--purple); background: #f3ecff; }
.words li.empty { display: block; }
.words i { grid-area: n; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--soft); font-style: normal; font-size: 0.8rem; font-weight: 700; }
.words b { grid-area: zh; font-size: 1.8rem; }
.words b.long { font-size: 1.3rem; }
.words .py { grid-area: py; justify-self: start; padding: 2px 12px; border-radius: 999px; background: var(--soft); color: var(--purple-dark); font-weight: 600; font-size: 0.9rem; }
.words .uz { grid-area: uz; padding: 3px 12px 0; }
.words button { grid-area: play; }

/* Flashcard */
.deck { position: relative; padding: 0 14px 22px; }
.deck::before, .deck::after { content: ""; position: absolute; inset: 24px 14px 8px; border-radius: 30px; background: rgba(190, 165, 255, 0.45); transform: rotate(-4deg); }
.deck::after { transform: rotate(4deg); }
.flash {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 330px;
  padding: 56px 20px 32px;
  border-radius: 30px;
  background: #fbf9ff;
  box-shadow: var(--shadow);
  text-align: center;
  cursor: pointer;
}
.flash b { font-size: 5rem; line-height: 1.1; }
.flash b.long { font-size: 3rem; }
.flash .py { font-size: 2rem; font-weight: 700; color: var(--purple); }
.flash .meaning { font-size: 2.2rem; font-weight: 700; }
.flash.flipped { animation: flip 0.35s ease; }
@keyframes flip { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }
.speak { position: absolute; top: 14px; right: 14px; display: grid; place-items: center; width: 50px; height: 50px; border: 0; border-radius: 50%; color: #fff; background: linear-gradient(180deg, #9547f0, #5320c4); }
.deck.mini .flash { min-height: 220px; padding-top: 30px; cursor: default; gap: 6px; }
.deck.mini b { font-size: 3.2rem; }
.deck.mini .py { font-size: 1.5rem; }
.hint { text-align: center; color: var(--muted); font-size: 0.85rem; }
.flipper { align-self: center; width: 70px; height: 70px; border: 5px solid #fff; color: #fff; background: linear-gradient(180deg, #9547f0, #5320c4); }
.pager { display: flex; align-items: center; justify-content: space-between; }
.pager span { padding: 10px 40px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-weight: 700; font-size: 1.2rem; }

/* Sozlamalar */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 52px; padding: 8px 12px; border: 2px solid #e3dbfa; border-radius: 22px; background: #fff; text-align: left; font-weight: 600; font-size: 0.88rem; }
.choice small { display: block; font-weight: 400; color: var(--muted); }
.choice i { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #aaa0cc; color: transparent; }
.choice[aria-pressed="true"] { border-color: #9a6be8; background: #f1e9ff; }
.choice[aria-pressed="true"] i { border-color: var(--purple); background: var(--purple); color: #fff; }
.segment { display: grid; grid-template-columns: 1fr 1fr; background: #fff; border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.segment button { border: 0; background: none; border-radius: 999px; min-height: 44px; font-weight: 600; }
.segment button[aria-pressed="true"] { color: #fff; background: linear-gradient(180deg, #9547f0, #5320c4); }
.type { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 12px; border: 2px solid #fff; border-radius: 26px; background: var(--card); box-shadow: var(--shadow); }
.type .icon { color: var(--purple); }
.type small { color: var(--muted); }
.type[aria-pressed="true"] { border-color: #9a5ce8; background: #f4eaff; }

/* Savollar */
.progress { display: flex; align-items: center; gap: 12px; }
.progress span, .bar { flex: 1; height: 14px; border-radius: 999px; background: #d9cffb; overflow: hidden; }
.progress i, .bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #7b2cf0, #9c5cf5); }
.progress b { padding: 6px 14px; border-radius: 999px; background: #fff; box-shadow: var(--shadow); font-size: 0.9rem; }
.prompt { align-self: center; min-width: 60%; padding: 16px 28px; border-radius: 999px; background: var(--soft); text-align: center; font-size: 1.8rem; font-weight: 800; }
.prompt [lang="zh-CN"] { font-size: 2.6rem; }
.prompt small { display: block; font-size: 1rem; color: var(--purple-dark); }
.listen { align-self: center; display: grid; place-items: center; width: 120px; height: 120px; margin: 8px 0; border: 10px solid #fff; border-radius: 50%; color: #fff; background: linear-gradient(180deg, #9547f0, #5320c4); box-shadow: var(--shadow); }
.options { display: flex; flex-direction: column; gap: 10px; }
.option { display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 8px 18px; border: 2px solid #fff; border-radius: 999px; background: rgba(255, 255, 255, 0.85); box-shadow: var(--shadow); font-weight: 600; font-size: 1.05rem; text-align: left; }
.option:disabled { color: var(--ink); }
.option i { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #6d629a; }
.option [lang="zh-CN"] { font-size: 1.6rem; }
.option small { color: var(--purple-dark); }
.option.ok { border-color: var(--ok); background: var(--ok-bg); }
.option.bad { border-color: var(--bad); background: var(--bad-bg); }
.option.ok i { border: 6px double var(--ok); background: var(--ok); }
.option.bad i { border: 6px double var(--bad); background: var(--bad); }
.option.ok::after, .option.bad::after { content: "✓"; display: grid; place-items: center; flex: none; width: 30px; height: 30px; margin-left: auto; border-radius: 50%; background: var(--ok); color: #fff; }
.option.bad::after { content: "✕"; background: var(--bad); }

.feedback { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 24px; animation: pop 0.25s ease; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback > i { display: grid; place-items: center; flex: none; width: 46px; height: 46px; border-radius: 50%; background: currentColor; }
.feedback > i .icon { color: #fff; }
.feedback div { flex: 1; display: flex; flex-direction: column; }
.feedback div b { font-size: 1.3rem; }
.feedback span { color: var(--ink); font-size: 0.95rem; }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.next { align-self: flex-end; }

.task { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 700; }
p.task { flex-wrap: nowrap; }
.task input { width: 100%; font-size: 1.4rem; }
.question form { display: flex; flex-direction: column; gap: 12px; }
.tones { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tones button { display: flex; flex-direction: column; align-items: center; min-height: 52px; justify-content: center; border: 1px solid #d3c5fa; border-radius: 14px; background: #fff; font-size: 1.5rem; line-height: 1; }
.tones small { font-size: 0.65rem; color: var(--muted); }

.pad { position: relative; border: 2px solid #c9b8f8; border-radius: 24px; background: #fbf9ff; overflow: hidden; }
.pad::before, .pad::after { content: ""; position: absolute; pointer-events: none; border: 0 dashed #d6cdf5; }
.pad::before { left: 50%; top: 0; bottom: 0; border-left-width: 2px; }
.pad::after { top: 50%; left: 0; right: 0; border-top-width: 2px; }
.pad canvas { display: block; width: 100%; aspect-ratio: 1; touch-action: none; cursor: crosshair; }
.clear { position: absolute; top: 10px; right: 10px; z-index: 1; }
.pad-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pad-tools .btn { font-size: 0.85rem; padding-inline: 10px; }
.sample { display: flex; flex-direction: column; align-items: center; }
.sample:empty { display: none; }
.glyph { width: 130px; height: 130px; fill: var(--ink); }

/* Natija */
.score { align-items: center; text-align: center; }
.score strong { font-size: 3.4rem; }
.score em { color: var(--ok); font-style: normal; font-weight: 700; }
.score .bar { flex: none; width: 100%; }
.score .bar i { background: #1fb52a; }
.score .stats { width: 100%; }
.stats { display: flex; gap: 8px; }
.stats div { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 12px 4px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.stats b { font-size: 1.2rem; }
.stats small { color: var(--muted); font-size: 0.75rem; }
.stats .ok b { color: var(--ok); }
.stats .bad b { color: var(--bad); }
.mistakes { display: flex; flex-direction: column; gap: 8px; }
.mistakes details { padding: 10px 12px; border-radius: 18px; background: #ffedf2; }
.mistakes summary { display: grid; grid-template-columns: minmax(56px, auto) 1fr 1fr; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
.mistakes summary b { font-size: 1.4rem; }
.wrong, .right { padding: 6px 10px; border-radius: 999px; border: 1px solid; background: #fff; font-size: 0.82rem; overflow-wrap: anywhere; }
.wrong { color: var(--bad); }
.right { color: var(--ok); }
.right small { display: block; }
.mistakes p { padding-top: 8px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn { font-size: 0.9rem; padding-inline: 10px; }

/* Kirish */
.auth { justify-content: center; padding-top: 24px; background: url("/img/hero.jpg") top center / 100% auto no-repeat; }
.auth-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 80px; text-align: center; }
.auth-hero img { border-radius: 24px; box-shadow: var(--shadow); }
.auth-hero p { color: var(--muted); }
form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
input, select, textarea { min-height: 48px; padding: 10px 16px; border: 2px solid #d8ccfa; border-radius: 16px; background: #fff; font-size: 1rem; font-weight: 400; }
input:focus, select:focus, textarea:focus { border-color: var(--purple); outline: none; }
.error { color: var(--bad); font-weight: 600; font-size: 0.9rem; }
.error:empty { display: none; }
.steps { list-style: decimal; padding-left: 20px; line-height: 1.7; }
.dev { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 2px dashed #e0a100; border-radius: 18px; background: #fff7df; font-size: 0.85rem; }

.soon { align-items: center; justify-content: center; text-align: center; }
.soon .back { position: absolute; top: 16px; left: max(16px, calc(50% - 244px)); }
.soon img { width: 240px; max-height: 240px; object-fit: cover; border-radius: 32px; box-shadow: var(--shadow); }

/* Admin */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tabs a { padding: 12px; border-radius: 999px; background: #fff; text-align: center; font-weight: 700; font-size: 0.9rem; }
.tabs a.on { color: #fff; background: var(--purple); }
.rows { display: flex; flex-direction: column; gap: 8px; }
.rows a { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 16px; background: #fff; }
.rows a b { flex: 1; }
.rows a small { color: var(--muted); white-space: nowrap; }
.word { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; border-radius: 18px; background: #fff; }
.word input, .word select { min-width: 0; }
.word input[name="uz"] { grid-column: 1 / -1; }
#add input { width: 100%; }
details summary { cursor: pointer; font-weight: 600; color: var(--purple-dark); }
details form { padding-top: 12px; }
.person { gap: 8px; }
.person .badge { margin-left: 6px; padding: 2px 10px; font-size: 0.7rem; }
.person small { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 10; width: max-content; max-width: min(90vw, 480px); transform: translateX(-50%); padding: 12px 20px; border-radius: 20px; background: #2c1d63; color: #fff; text-align: center; box-shadow: var(--shadow); }

@media (max-width: 360px) {
  .screen { padding-inline: 12px; }
  .hero, .books-hero { margin-inline: -12px; }
  .lesson img, .section img { width: 72px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
