:root {
  --brand: #2563eb;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, white);
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f6f8fc;
  --card: #ffffff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --gold: #f59e0b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 24px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5; font-size: 15px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.7rem; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--ink); font-size: 1.1rem; }
.logo img { height: 34px; width: auto; border-radius: 8px; }
.logo .mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 7px 12px; border-radius: 10px; color: var(--ink); font-weight: 500; }
.nav a:hover, .nav a.active { background: var(--brand-soft); color: var(--brand); text-decoration: none; }
.userbox { display: flex; align-items: center; gap: 10px; }
.coins-pill { display: inline-flex; align-items: center; gap: 6px; background: #fff7e6; color: #92400e; border: 1px solid #fde68a; padding: 4px 10px; border-radius: 999px; font-weight: 700; }
.coin { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fde68a, var(--gold)); box-shadow: inset 0 0 0 2px #fbbf24; display: inline-block; }
.langs { display: flex; gap: 2px; }
.langs a { font-size: .75rem; padding: 3px 6px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.langs a.on { background: var(--ink); color: #fff; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin-bottom: .3em; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; background: var(--brand); color: #fff; padding: 9px 16px; border-radius: 10px; font-weight: 600; cursor: pointer; font-size: .95rem; font-family: inherit; }
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.danger { background: var(--bad); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #fff; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
label { font-weight: 600; font-size: .9rem; display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.errorlist { color: var(--bad); margin: 4px 0; padding-left: 18px; font-size: .85rem; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.tbl tr:hover td { background: #fafcff; }
code, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: #eef2ff; color: #4338ca; }
.badge.A { background: #dcfce7; color: #166534; }
.badge.B { background: #fef3c7; color: #92400e; }
.badge.C { background: #fee2e2; color: #991b1b; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 10px; background: var(--brand-soft); margin-bottom: 8px; }
.messages li.error { background: var(--bad-soft); color: var(--bad); }
.messages li.success { background: var(--ok-soft); color: #14532d; }

/* Hero / landing */
.hero { background: linear-gradient(135deg, var(--brand), #7c3aed); color: #fff; border-radius: 22px; padding: 44px 36px; position: relative; overflow: hidden; }
.hero h1 { font-size: 2.3rem; }
.hero p { font-size: 1.1rem; opacity: .92; max-width: 640px; }
.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 260px; height: 260px; border-radius: 50%; background: rgba(255,255,255,.12); }
.feature { display: flex; gap: 12px; }
.feature .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; font-size: 1.3rem; flex: none; }

/* Login */
.auth { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 24px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .org-logo { max-height: 70px; display: block; margin: 0 auto 12px; }

/* Course */
.chapter { margin-bottom: 22px; }
.chapter h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.lesson { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; color: var(--ink); }
.lesson:hover { border-color: var(--brand); text-decoration: none; box-shadow: var(--shadow); }
.lesson .num { width: 34px; height: 34px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; font-size: .85rem; }
.lesson.done .num { background: var(--ok-soft); color: var(--ok); }
.lesson .t { flex: 1; }
.lesson .sub { font-size: .8rem; color: var(--muted); }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand); border-color: var(--brand); text-decoration: none; }
.tabs a .cnt { background: #eef2f7; border-radius: 999px; padding: 1px 7px; font-size: .75rem; margin-left: 4px; }

/* Task */
.task { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 14px; transition: border-color .2s; }
.task.ok { border-color: #86efac; background: linear-gradient(0deg, #f0fdf4, #fff 40%); }
.task.bad { border-color: #fca5a5; }
.task .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.task .q { font-size: 1.02rem; margin-bottom: 12px; }
.task .q pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.opts { display: grid; gap: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 500; margin: 0; }
.opt:hover { background: #f8fafc; }
.opt input { margin-top: 4px; }
.opt .l { font-weight: 700; color: var(--muted); width: 18px; }
.feedback { margin-top: 10px; font-weight: 600; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.coin-pop { display: inline-flex; align-items: center; gap: 4px; color: #92400e; animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0 } 60% { transform: scale(1.25) } 100% { transform: scale(1); opacity: 1 } }

.pres-card { display: flex; align-items: center; gap: 16px; padding: 18px; border-radius: 16px; color: #fff; background: linear-gradient(135deg, var(--brand), #0ea5e9); margin-bottom: 18px; }
.pres-card:hover { text-decoration: none; filter: brightness(1.05); }
.pres-card .big { font-size: 2rem; }

.stat { font-size: 1.8rem; font-weight: 800; }
.progress { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); }

.rank { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rank .pos { width: 30px; font-weight: 800; color: var(--muted); }
.rank.me { background: var(--brand-soft); border-radius: 10px; }
.medal-1 .pos { color: #d97706; } .medal-2 .pos { color: #64748b; } .medal-3 .pos { color: #b45309; }

@media (max-width: 760px) {
  .topbar-in { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .hero { padding: 28px 20px; }
  .hero h1 { font-size: 1.7rem; }
  .tbl { font-size: .85rem; }
  .tbl th, .tbl td { padding: 8px 6px; }
}

/* --- Бастауыш сынып: суреттер мен Scratch-блоктар --- */
.qimg { display: block; max-width: 160px; height: auto; margin: 4px 0 12px; }
.qimgs { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 12px; }
.qimgs .qimg { margin: 0; max-width: 96px; }
.opt .big { font-size: 1.8rem; line-height: 1; }
.sbs { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; align-items: flex-start; }
.sb { display: inline-block; padding: 7px 14px 7px 12px; border-radius: 6px 10px 10px 6px; color: #fff; font-weight: 600; font-size: .95rem;
      box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); position: relative; }
.sb::before { content: ""; position: absolute; left: 14px; top: -4px; width: 18px; height: 6px; border-radius: 0 0 4px 4px; background: inherit; }
.sb-event { background: #e6a700; border-radius: 22px 10px 10px 6px; }
.sb-event::before { display: none; }
.sb-motion { background: #4c97ff; } .sb-looks { background: #9966ff; } .sb-sound { background: #cf63cf; }
.sb-control { background: #ffab19; } .sb-sensing { background: #5cb1d6; } .sb-operator { background: #59c059; }
.sb-variable { background: #ff8c1a; } .sb-pen { background: #0fbd8c; } .sb-robot { background: #ff6680; }
.kidsmode .task { border-width: 2px; border-radius: 18px; }
.kidsmode .task .q { font-size: 1.22rem; font-weight: 600; }
.kidsmode .opt { font-size: 1.12rem; padding: 14px 16px; border-radius: 14px; border-width: 2px; }
.kidsmode .opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.kidsmode .btn.js-check { font-size: 1.05rem; padding: 10px 22px; border-radius: 14px; }
.kidsmode .qimg { max-width: 180px; }

/* ---------- Практика ---------- */
.ptask { margin-bottom: 16px; border-left: 5px solid var(--line); }
.ptask.ok { border-left-color: var(--ok); }
.ptask .q { margin: 10px 0; }
.ptask .q pre, .ptask .q code { background: #f1f5f9; border-radius: 6px; padding: 1px 5px; font-family: "JetBrains Mono", ui-monospace, monospace; }
.ptask .q pre { padding: 8px 10px; }
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pgrid-html { grid-template-columns: 1fr 1fr; }
@media (max-width: 800px) { .pgrid { grid-template-columns: 1fr; } }
textarea.code { width: 100%; font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.5;
  background: #0f172a; color: #e2e8f0; border: 0; border-radius: 10px; padding: 10px 12px; resize: vertical; tab-size: 4; }
textarea.code.js-stdin { background: #1e293b; margin-top: 4px; }
pre.out { min-height: 120px; max-height: 300px; overflow: auto; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 4px 0 0; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13.5px; white-space: pre-wrap; }
pre.out .err, .pres .err { color: #b91c1c; }
iframe.preview { width: 100%; height: 260px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.pres { margin-top: 8px; font-size: .92rem; }
.pres .sum { font-weight: 700; padding: 6px 10px; border-radius: 8px; margin-bottom: 6px; }
.pres .sum.pass { background: var(--ok-soft); color: var(--ok); }
.pres .sum.fail { background: #fee2e2; color: #991b1b; }
.pres .pass { color: var(--ok); } .pres .fail { color: #b91c1c; }
.pres .diff { color: var(--ink); font-size: .85rem; margin: 4px 0 8px 18px; }
.pres .diff pre { background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; margin: 2px 0 6px; white-space: pre-wrap; }
table.res { border-collapse: collapse; font-size: .85rem; margin-top: 4px; }
table.res th, table.res td { border: 1px solid var(--line); padding: 3px 8px; }
table.res th { background: #eef2ff; }
