:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17201a;
  --muted: #5f6b62;
  --line: #dde3db;
  --accent: #1f9d55;
  --accent-ink: #ffffff;
  --accent-soft: #dff3e6;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --bad: #c0392b;
  --bad-soft: #fbe3e0;
  --lock: #9aa59d;
  --shadow: 0 1px 2px rgba(20, 40, 25, .06), 0 4px 14px rgba(20, 40, 25, .05);
  --radius: 16px;
  --radius-s: 10px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1411;
  --surface: #182019;
  --surface-2: #202a22;
  --text: #e8efe9;
  --muted: #9aa89d;
  --line: #2b362e;
  --accent: #34c172;
  --accent-ink: #06140b;
  --accent-soft: #173826;
  --warn: #e0a84a;
  --warn-soft: #3a2e17;
  --bad: #ef6b5c;
  --bad-soft: #3d1d1a;
  --lock: #5d6a60;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  overflow-x: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
img { max-width: 100%; }

.app { max-width: 640px; margin: 0 auto; padding: 16px 16px 112px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

h1 { font-size: 24px; line-height: 1.2; margin: 4px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 19px; line-height: 1.25; margin: 20px 0 10px; }
h3 { font-size: 16px; margin: 18px 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card.soft { background: var(--accent-soft); box-shadow: none; }
.card.warn { background: var(--warn-soft); box-shadow: none; }
.card.bad { background: var(--bad-soft); box-shadow: none; }
.card.tap { cursor: pointer; transition: transform .08s; }
.card.tap:active { transform: scale(.985); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 17px; }
.iconbtn { border: 0; background: var(--surface); box-shadow: var(--shadow); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; font-size: 18px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px; padding: 12px 18px;
  border: 0; border-radius: 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 16px;
  transition: opacity .15s, transform .08s;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); min-height: 42px; }
.btn.inline { width: auto; display: inline-flex; min-height: 40px; padding: 8px 14px; font-size: 15px; }
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.bottombar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }

.score { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score .num { font-size: 30px; font-weight: 700; line-height: 1.1; }

.module { display: flex; gap: 14px; align-items: center; }
.module .badge { flex: none; width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.module.locked .badge { background: var(--surface-2); color: var(--lock); }
.module .title { font-weight: 600; }

.lesson { display: flex; align-items: center; gap: 12px; padding: 13px 14px; background: var(--surface); border-radius: var(--radius-s); margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow); }
.lesson .st { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.lesson.s0 { cursor: default; box-shadow: none; background: var(--surface-2); }
.lesson.s0 .st { color: var(--lock); }
.lesson.s0 .name { color: var(--muted); }
.lesson.s1 { outline: 2px solid var(--accent); }
.lesson.s1 .st { background: var(--accent); color: var(--accent-ink); }
.lesson.s2 .st { background: var(--accent-soft); color: var(--accent); }
.lesson .name { flex: 1; min-width: 0; font-size: 15px; }
.lesson .pc { font-size: 13px; color: var(--muted); }

.theory { font-size: 16.5px; line-height: 1.62; }
.theory p { margin: 0 0 12px; }
.theory h3 { color: var(--accent); font-size: 17px; margin-top: 22px; }
.theory figure { margin: 14px 0; }
.theory figure img { width: 100%; border-radius: 12px; background: var(--surface-2); }
.theory figcaption, .theory .pic { font-size: 14px; color: var(--muted); font-style: italic; }
.theory hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 12px 14px; border-radius: 16px; line-height: 1.5; word-wrap: break-word; }
.msg.bot { background: var(--surface); box-shadow: var(--shadow); border-top-left-radius: 6px; align-self: flex-start; }
.msg.me { background: var(--accent); color: var(--accent-ink); border-top-right-radius: 6px; align-self: flex-end; white-space: pre-wrap; }
.msg blockquote { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 50px; max-height: 160px; resize: none; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.composer .btn { width: 54px; min-height: 50px; padding: 0; font-size: 20px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; min-height: 50px;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.45; }

.opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1.5px solid var(--line); margin-bottom: 8px; cursor: pointer; user-select: none; }
.opt .box { flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); display: grid; place-items: center; font-size: 13px; font-weight: 700; margin-top: 1px; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt.on .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.opt.good { border-color: var(--accent); background: var(--accent-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }

.match-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.match-row:last-child { border-bottom: 0; }
.match-row .l { flex: 1; min-width: 0; font-size: 15px; }
.match-row .l b { color: var(--accent); margin-right: 4px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { min-width: 36px; height: 36px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; }
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.legend { font-size: 14px; color: var(--muted); padding: 10px 12px; background: var(--surface-2); border-radius: 10px; margin: 8px 0 12px; }
.legend div + div { margin-top: 2px; }

.seq-slots { display: flex; gap: 6px; flex-wrap: wrap; min-height: 44px; padding: 8px; border-radius: 12px; background: var(--surface-2); margin-bottom: 10px; }
.seq-slots .pill { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seq-slots .ph { color: var(--muted); font-size: 14px; align-self: center; padding-left: 4px; }

.qhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.qtext { white-space: pre-line; margin-bottom: 8px; }
.qhint { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.codetable { width: 100%; border-collapse: collapse; font-size: 12px; margin: 10px 0; }
.codetable th, .codetable td { border: 1px solid var(--line); padding: 3px 2px; text-align: center; }
.codetable th { background: var(--surface-2); }
.dots { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0 2px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.dots i.done { background: var(--accent); border-color: var(--accent); }
.dots i.cur { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.range { width: 100%; accent-color: var(--accent); }
.big { font-size: 44px; font-weight: 800; line-height: 1; }
.hero-emoji { font-size: 52px; line-height: 1; margin: 8px 0 6px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: fade .2s; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }
.loading .spinner { margin-bottom: 14px; }
.skeleton { height: 64px; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 10px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
