:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2e0d9;
  --accent: #2f6fde;
  --accent-soft: #e6eefc;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --bad: #c0392b;
  --bad-soft: #fbe7e4;
  --code-bg: #1e2127;
  --code-text: #e6e6e6;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1c1f24;
    --text: #e8e6e1;
    --muted: #9a9ea6;
    --line: #2c3037;
    --accent: #6c9cf0;
    --accent-soft: #1f2a3d;
    --ok: #4cc27f;
    --ok-soft: #173024;
    --bad: #ef6b5d;
    --bad-soft: #3a1c19;
    --code-bg: #0f1114;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--accent); }
.hidden { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 18px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs a {
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px;
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.tabs a.on { background: var(--accent); color: #fff; }
.overall { font-size: 14px; color: var(--muted); }

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 80px; }

h1 { font-size: 1.6em; line-height: 1.25; margin: .4em 0 .6em; }
h2 { font-size: 1.3em; line-height: 1.3; margin: 1.6em 0 .5em; }
h3 { font-size: 1.1em; margin: 1.3em 0 .4em; }
p, ul, ol { margin: .6em 0; }
li { margin: .25em 0; }

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px;
}
pre {
  background: var(--code-bg); color: var(--code-text);
  padding: 14px; border-radius: var(--radius); overflow-x: auto;
  font-size: 14px; line-height: 1.5;
}
pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
blockquote {
  margin: 1em 0; padding: 10px 14px;
  border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0;
}
blockquote p { margin: .3em 0; }
table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 15px; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--accent-soft); }

button {
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

.login { max-width: 360px; margin: 12vh auto; }
.login input { width: 100%; font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); margin-bottom: 10px; }
.login button { width: 100%; padding: 12px; }
.err { color: var(--bad); min-height: 1.4em; }

/* карта курсу */
.module {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 12px 0;
}
.module h2 { margin: 0 0 4px; font-size: 1.1em; }
.module .desc { color: var(--muted); font-size: 15px; margin: 0 0 8px; }
.module.locked { opacity: .55; }
.lessons { list-style: none; padding: 0; margin: 0; }
.lessons li { margin: 0; border-top: 1px solid var(--line); }
.lessons a, .lessons span.soon {
  display: flex; justify-content: space-between; gap: 10px; padding: 10px 0;
  text-decoration: none; color: var(--text);
}
.lessons .mark { color: var(--muted); font-size: 14px; white-space: nowrap; }
.lessons .mark.done { color: var(--ok); font-weight: 600; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0 10px; }
.bar > i { display: block; height: 100%; background: var(--ok); }

/* інтерактиви */
.box {
  border: 1px solid var(--line); background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin: 18px 0;
}
.box .tag { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.box h4 { margin: 4px 0 8px; font-size: 1em; }
.opts { display: grid; gap: 8px; margin: 10px 0; }
.opt {
  text-align: left; font-weight: 400; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); padding: 10px 12px;
}
.opt.right { background: var(--ok-soft); border-color: var(--ok); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.explain { font-size: 15px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); }

textarea.code {
  width: 100%; min-height: 160px; resize: vertical;
  font: 14px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  tab-size: 2;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.out {
  white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 8px;
  max-height: 340px; overflow: auto;
}
.out .warn { color: #c98a00; }
.out .error { color: var(--bad); }
.tests { list-style: none; padding: 0; margin: 8px 0 0; font-size: 15px; }
.tests li { padding: 4px 0; }
.tests .p { color: var(--ok); }
.tests .f { color: var(--bad); }
.tests small { color: var(--muted); display: block; font-family: ui-monospace, Menlo, monospace; word-break: break-word; }
.passed-badge { color: var(--ok); font-weight: 700; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  table { font-size: 13.5px; }
  th, td { padding: 5px 7px; }
  td code { word-break: break-all; }
}

.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }
.check input { width: 22px; height: 22px; margin-top: 3px; flex: none; }

.lesson-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 32px; flex-wrap: wrap; }
.finish { margin-top: 28px; text-align: center; }
.crumbs { font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); }

/* кубик */
.goal { font-weight: 600; }
.cubeview { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: center; margin: 6px 0; }
.cube3d { max-width: 62vw; height: auto; }
.cube3d .flab { font: 700 12px sans-serif; fill: #555; text-anchor: middle; }
.net { display: grid; grid-template-columns: repeat(4, 54px); gap: 3px; }
.net .face { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: #111; padding: 2px; border-radius: 4px; position: relative; }
.net .face i { display: block; aspect-ratio: 1; border-radius: 2px; }
.net .face b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; color: rgba(0,0,0,.55); pointer-events: none; }
.movepad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.movepad .mv { padding: 10px 0; font-family: ui-monospace, Menlo, monospace; background: var(--bg); color: var(--text); border-color: var(--line); }
.movepad .mv:active { background: var(--accent-soft); }
.algrow input { flex: 1; min-width: 0; font: 15px ui-monospace, Menlo, monospace; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.history { white-space: pre-wrap; }

/* шахи */
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; max-width: 400px; margin: 10px auto;
  aspect-ratio: 1; border: 2px solid #5a4632; border-radius: 4px; overflow: hidden; user-select: none; touch-action: manipulation;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; min-width: 0; min-height: 0; overflow: hidden; }
.sq.lt { background: #f0d9b5; }
.sq.dk { background: #b58863; }
.sq.sel { background: #f6f669 !important; }
.sq.last { box-shadow: inset 0 0 0 100px rgba(255, 255, 0, .28); }
.sq.dot::after { content: ''; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 85, 30, .5); }
.sq.cap { box-shadow: inset 0 0 0 4px rgba(20, 85, 30, .6); }
.pc { font-size: min(8.5vw, 38px); line-height: 1; font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols 2", sans-serif; }
.pc.w { color: #fff; text-shadow: 0 0 2px #000, 0 0 1px #000, 1px 1px 1px #000; }
.pc.b { color: #111; text-shadow: 0 0 1px #fff8; }
.sq small { position: absolute; font-size: 10px; font-weight: 700; opacity: .7; color: #3b2a1a; }
.sq small.rk { top: 1px; left: 2px; }
.sq small.fl { bottom: 0; right: 2px; }
.status { min-height: 1.5em; font-size: 15px; padding: 6px 10px; border-radius: 10px; }
.status.ok { background: var(--ok-soft); }
.status.bad { background: var(--bad-soft); }
