:root {
  --bg: #f3f1fa;
  --ink: #1b1530;
  --muted: #6b6485;
  --line: #e2ddf0;
  --card: #ffffff;
  --brand: #3b1f8f;
  --brand-dark: #261361;
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #ffbe0b;
  --green: #26890c;
  --ok: #1d7a0b;
  --ok-bg: #e7f6e2;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
kbd {
  font: 600 12px/1 var(--mono); padding: 3px 6px; border-radius: 5px;
  background: rgba(0, 0, 0, .08); border: 1px solid rgba(0, 0, 0, .12); color: inherit;
}
:focus-visible { outline: 3px solid #8a6cff; outline-offset: 2px; }

/* buttons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 10px; border: 1px solid transparent;
  padding: 8px 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  transition: background .12s, transform .08s, box-shadow .12s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.big { padding: 12px 20px; font-size: 17px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); box-shadow: 0 1px 0 rgba(0,0,0,.05); }
.btn.secondary:hover:not(:disabled) { border-color: #b9aee0; }
.btn.secondary.active { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.btn.ghost { background: rgba(255,255,255,.12); color: #fff; }
.btn.ghost:hover { background: rgba(255,255,255,.22); }
.btn.ghost-dark { background: transparent; color: var(--brand); border-color: #cfc5ef; }
.btn.ghost-dark:hover { background: #ebe6fb; }

/* shapes / logo */
.c0 { --c: var(--red); } .c1 { --c: var(--blue); } .c2 { --c: var(--yellow); } .c3 { --c: var(--green); }
svg { fill: currentColor; }
.logo { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.logo span { width: 40px; height: 40px; border-radius: 10px; background: var(--c); color: #fff; display: grid; place-items: center; }
.logo span.c2 { color: #3a2a00; }
.logo svg { width: 22px; height: 22px; }

/* login */
.login { flex: 1; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #5a34c9 0, transparent 60%), linear-gradient(160deg, #3b1f8f, #1e0f4d); }
.login-card { width: min(420px, 100%); background: var(--card); border-radius: 20px; padding: 32px; box-shadow: 0 24px 60px rgba(10, 0, 40, .45); display: flex; flex-direction: column; }
.login-card h1 { text-align: center; }
.login-card > p.muted { text-align: center; margin: 0 0 20px; }
.login-card label { font-weight: 600; font-size: 14px; margin: 10px 0 6px; }
.login-card input { font: inherit; padding: 12px 14px; border-radius: 10px; border: 1.5px solid var(--line); }
.login-card input:focus { border-color: var(--brand); outline: none; }
.form-error { color: var(--red); min-height: 1.5em; margin: 10px 0; font-weight: 600; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 8px 20px; min-height: 52px; background: var(--brand); color: #fff; flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me { font-weight: 600; opacity: .9; }
.progress { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 160px; max-width: 520px; }
.bar { display: block; flex: 1; height: 8px; border-radius: 99px; background: rgba(255,255,255,.2); overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7ee06a, #3fc22a); border-radius: 99px; transition: width .35s ease; }
.counter { font: 700 14px/1 var(--mono); white-space: nowrap; }

/* subjects */
.subjects { width: min(1280px, 100%); margin: 0 auto; padding: 32px 16px 48px; }
.subjects-head { margin-bottom: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  position: relative; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 20px 18px 76px;
  display: flex; flex-direction: column; gap: 6px; min-height: 120px; transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(40, 20, 100, .12); }
.card-shape { position: absolute; left: 18px; top: 20px; width: 42px; height: 42px; border-radius: 10px; background: var(--c); color: #fff; display: grid; place-items: center; }
.card.c2 .card-shape { color: #3a2a00; }
.card-shape svg { width: 22px; height: 22px; }
.card-name { font-size: 19px; font-weight: 700; }
.card-count { color: var(--ink); font-size: 14px; }
.card .bar { background: #ece8f7; margin-top: auto; flex: none; }
.card.complete { border-color: #9fd98f; }
.card.complete .card-name::after { content: "  ✓"; color: var(--ok); }

/* review layout: question scrolls, answer zone pinned at the bottom */
.review { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.q-scroll { flex: 1; overflow-y: auto; padding: 24px 24px 12px; }
.question { width: min(1200px, 100%); margin: 0 auto; animation: slideIn .22s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.q-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 14px; font-size: 14px; }
.pill { background: #e9e4fa; color: var(--brand); font-weight: 700; padding: 3px 10px; border-radius: 99px; }
.pill.current { background: var(--ok-bg); color: var(--ok); }
.q-topic { color: var(--muted); }
.q-text { font-size: 24px; line-height: 1.45; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.q-text.code { font-family: var(--mono); font-size: 19px; font-weight: 500; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; overflow-x: auto; overflow-wrap: normal; }
.q-text.small { font-size: 16px; font-weight: 400; }
.q-images { display: flex; flex-wrap: wrap; gap: 14px; margin: 16px 0 4px; }
.q-img { padding: 0; border: 1px solid var(--line); background: #fff; border-radius: 12px; cursor: zoom-in; overflow: hidden; }
.q-img img { display: block; max-width: min(720px, 100%); max-height: 46vh; object-fit: contain; }
.options { list-style: none; padding: 0; margin: 18px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 8px 14px; }
.options li { display: flex; align-items: flex-start; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-size: 17px; }
.opt-letter { flex: none; width: 26px; height: 26px; border-radius: 7px; background: #eeebf6; color: var(--muted); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.opt-text { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.opt-text.code { font-family: var(--mono); font-size: 15px; }
.options li.correct { border: 2px solid var(--ok); background: var(--ok-bg); padding: 9px 13px; }
.options li.correct .opt-letter { background: var(--ok); color: #fff; }
.opt-mark { flex: none; color: var(--ok); font-weight: 800; font-size: 14px; }
.explanation { margin-top: 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; }
.explanation summary { cursor: pointer; font-weight: 700; color: var(--brand); }

/* answer zone */
.answer-zone { flex: none; background: #fff; border-top: 1px solid var(--line); padding: 14px 24px 16px; box-shadow: 0 -8px 24px rgba(40, 20, 100, .06); }
.tiles, .actions, .none-panel { width: min(1400px, 100%); margin: 0 auto; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  position: relative; display: flex; align-items: center; gap: 16px; text-align: left; font: inherit;
  min-height: 96px; padding: 14px 64px 14px 18px; border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--c); color: #fff; box-shadow: 0 5px 0 rgba(0,0,0,.22);
  transition: transform .1s, box-shadow .1s, filter .12s, opacity .2s;
}
.tile.c2 { color: #2b1f00; }
.tile:hover:not(:disabled) { filter: brightness(1.07); transform: translateY(-1px); }
.tile:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.22); }
.tile.disabled { opacity: .18; cursor: default; filter: grayscale(.6); }
.tile.chosen { box-shadow: 0 5px 0 rgba(0,0,0,.22), 0 0 0 4px #fff, 0 0 0 7px var(--ink); }
.tile-shape { flex: none; width: 40px; height: 40px; display: grid; place-items: center; }
.tile-shape svg { width: 34px; height: 34px; }
.tile-body { display: flex; flex-direction: column; min-width: 0; }
.tile-name { font-size: 20px; font-weight: 800; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-path { font-size: 13px; opacity: .88; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.tile-p { position: absolute; right: 14px; bottom: 12px; font: 800 15px/1 var(--mono); background: rgba(0,0,0,.2); padding: 4px 7px; border-radius: 6px; }
.tile.c2 .tile-p { background: rgba(0,0,0,.12); }
.tile kbd { position: absolute; right: 14px; top: 12px; background: rgba(255,255,255,.25); border-color: rgba(255,255,255,.35); font-size: 14px; }
.tile.c2 kbd { background: rgba(0,0,0,.08); border-color: rgba(0,0,0,.15); }

/* pick confirmation */
.answer-zone.committing .tile:not(.picked), .answer-zone.committing .actions { opacity: .25; transition: opacity .15s; }
.tile.picked { animation: pick .38s ease-out forwards; z-index: 2; }
.tile.picked::after {
  content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 56px; font-weight: 900;
  color: #fff; background: rgba(0,0,0,.18); border-radius: inherit; animation: check .3s ease-out;
}
@keyframes pick { 0% { transform: scale(1); } 35% { transform: scale(1.04); } 100% { transform: scale(1.02); } }
@keyframes check { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.actions .spacer { flex: 1; }
.none-panel { display: flex; gap: 10px; margin-top: 12px; }
.none-input { flex: 1; font: inherit; padding: 10px 14px; border: 1.5px solid var(--brand); border-radius: 10px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 10, 50, .55); display: grid; place-items: start center; padding: 8vh 16px 16px; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.picker { width: min(860px, 100%); max-height: 80vh; background: #fff; border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.picker-head { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; padding: 16px 18px 6px; font-size: 14px; }
.picker-head strong { font-size: 18px; }
.picker-input { margin: 8px 18px 12px; font: inherit; font-size: 18px; padding: 12px 14px; border: 2px solid var(--brand); border-radius: 10px; outline: none; }
.picker-list { list-style: none; margin: 0; padding: 0 8px 10px; overflow-y: auto; }
.picker-list li { padding: 9px 12px; border-radius: 9px; cursor: pointer; display: flex; flex-direction: column; }
.picker-list li:hover { background: #f4f1fd; }
.picker-list li.sel { background: #e7e0fd; box-shadow: inset 3px 0 0 var(--brand); }
.picker-list li.current .pk-name::after { content: " · текущее решение"; color: var(--ok); font-weight: 600; font-size: 13px; }
.picker-list li.empty { color: var(--muted); cursor: default; }
.pk-name { font-weight: 700; }
.pk-path { font-size: 13px; color: var(--muted); }
.lightbox { place-items: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; background: #fff; border-radius: 10px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }

/* done */
.done { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.done-card { text-align: center; background: #fff; border-radius: 20px; padding: 40px 32px; width: min(620px, 100%); border: 1px solid var(--line); }
.done-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; transition: opacity .15s, transform .15s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #b0122d; }

/* narrow windows: still usable, not the target */
@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr; gap: 8px; }
  .tile { min-height: 64px; }
  .tile-name { font-size: 17px; }
  .q-text { font-size: 19px; }
  .q-scroll, .answer-zone { padding-left: 16px; padding-right: 16px; }
  .options { grid-template-columns: 1fr; }
  .review { flex: none; }
  .q-scroll { overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
