:root {
  --bg: #f6f3ee;
  --paper: #ffffff;
  --ink: #1f2430;
  --muted: #6b7180;
  --line: #e4ded4;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --ok: #2b8a3e;
  --ok-bg: #e6f6ea;
  --bad: #d6336c;
  --bad-bg: #fdecf2;
  --warn: #e8590c;
  --chip: #fff7e0;
  --chip-line: #f0d98a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 36, 48, .06), 0 4px 16px rgba(31, 36, 48, .06);
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 16px; line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(246, 243, 238, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 1240px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.logo { font-weight: 800; font-size: 19px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.logo b { background: var(--accent); color: #fff; border-radius: 9px; width: 30px; height: 30px; display: grid; place-items: center; font-size: 16px; }
.topbar nav a { color: var(--ink); font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.topbar nav a.on, .topbar nav a:hover { background: var(--paper); text-decoration: none; }
.who { font-size: 14px; color: var(--muted); }

main { max-width: 1240px; margin: 0 auto; padding: 24px 20px 80px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* buttons & inputs */
button, .btn { font: inherit; font-weight: 700; font-size: 15px; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none !important; }
button:hover, .btn:hover { border-color: #c9c1b3; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.ghost { background: transparent; border-color: transparent; }
button.sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input:not([type]), textarea, select {
  font: inherit; font-size: 15px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; color: var(--ink); width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 14px; line-height: 1.55; }
label.f { display: block; font-weight: 700; font-size: 14px; margin: 12px 0 6px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.err { color: var(--bad); font-weight: 600; margin-top: 10px; min-height: 1em; }

/* auth */
.auth { max-width: 420px; margin: 8vh auto; }
.auth .card { padding: 28px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.item .t { font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c9c1b3; display: inline-block; flex: none; }
.dot.on { background: #37b24d; box-shadow: 0 0 0 3px #d3f9d8; }
.badge { font-size: 12px; font-weight: 800; border-radius: 99px; padding: 2px 9px; background: #f1ede6; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.mid { background: #fff4e6; color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.given { color: var(--bad); font-weight: 700; }
td.corr { color: var(--ok); font-weight: 700; }
.linkbox { display: flex; gap: 8px; margin-top: 10px; }
.linkbox input { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* lesson layout */
.lesson { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .lesson { grid-template-columns: 1fr; } }
.side { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.side h3 { margin: 4px 4px 10px; }
.exlink { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.exlink:hover { background: #f4f0e8; text-decoration: none; }
.exlink.on { background: var(--accent-soft); color: var(--accent); }
.exlink .n { width: 24px; height: 24px; border-radius: 7px; background: #f1ede6; display: grid; place-items: center; font-size: 12px; flex: none; color: var(--muted); }
.exlink.done .n { background: var(--ok-bg); color: var(--ok); }
.exlink.part .n { background: #fff4e6; color: var(--warn); }
.exlink .here { margin-left: auto; font-size: 11px; font-weight: 800; color: #fff; background: #37b24d; padding: 1px 7px; border-radius: 99px; }
.lessonhead { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 800; margin: 14px 6px 6px; }

/* exercise */
.ex-head { margin-bottom: 14px; }
.ex-type { font-size: 12px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.ex-title { font-size: 22px; font-weight: 800; margin: 2px 0 6px; }
.ex-instr { color: var(--muted); }
.ex-text { background: #fbf9f5; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 14px 0; white-space: pre-wrap; font-size: 15px; }
.stage { position: relative; }
.ex-foot { display: flex; align-items: center; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.score { font-weight: 800; font-size: 15px; padding: 6px 12px; border-radius: 10px; }
.score.ok { background: var(--ok-bg); color: var(--ok); }
.score.mid { background: #fff4e6; color: var(--warn); }
.score.bad { background: var(--bad-bg); color: var(--bad); }

/* choice */
.q { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; background: #fff; transition: border-color .15s, background .15s; }
.q .qt { font-weight: 600; margin-bottom: 10px; }
.q .qt .num { color: var(--muted); margin-right: 6px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { font-weight: 600; background: #fff; border: 1.5px solid var(--line); padding: 7px 14px; border-radius: 10px; }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.q.ok { border-color: #8ce99a; background: var(--ok-bg); }
.q.bad { border-color: #faa2c1; background: var(--bad-bg); }
.q.ok .opt.sel { border-color: var(--ok); background: var(--ok); color: #fff; }
.q.bad .opt.sel { border-color: var(--bad); background: var(--bad); color: #fff; }

/* gaps text */
.gtext { font-size: 17px; line-height: 2.25; white-space: pre-wrap; }
.gtext input.gap { width: auto; display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 16px; min-width: 70px; border: 1.5px solid #c9c1b3; background: #fffdf8; line-height: 1.4; vertical-align: baseline; }
.gtext select.gap { width: auto; display: inline-block; padding: 2px 6px; border-radius: 8px; font-size: 16px; border: 1.5px solid #c9c1b3; background: #fffdf8; }
.gap.ok, .slot.ok, .tinput.ok { border-color: var(--ok) !important; background: var(--ok-bg) !important; color: var(--ok) !important; font-weight: 700; }
.gap.bad, .slot.bad, .tinput.bad { border-color: var(--bad) !important; background: var(--bad-bg) !important; color: var(--bad) !important; font-weight: 700; }
.focus-remote { box-shadow: 0 0 0 3px #ffd43b !important; }

/* bank + slots */
.bank { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border: 1.5px dashed var(--chip-line); border-radius: 12px; background: #fffcf2; margin-bottom: 16px; min-height: 54px; position: sticky; top: 62px; z-index: 5; }
.bank.empty::after { content: "Все карточки разложены"; color: var(--muted); font-size: 14px; align-self: center; }
.chip { user-select: none; touch-action: none; cursor: grab; background: var(--chip); border: 1.5px solid var(--chip-line); border-radius: 9px; padding: 5px 12px; font-weight: 700; font-size: 15px; line-height: 1.35; }
.chip:hover { border-color: #e0b93f; }
.chip.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.ghost { position: fixed; z-index: 1000; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.18); transform: rotate(-2deg); }
.chip.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.chip.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.slot { display: inline-flex; align-items: center; min-width: 110px; min-height: 34px; padding: 2px 10px; border: 1.5px dashed #b9b0a1; border-radius: 9px; background: #fff; vertical-align: middle; cursor: pointer; font-weight: 700; line-height: 1.35; }
.slot.filled { border-style: solid; border-color: var(--chip-line); background: var(--chip); }
.slot.hover, .col.hover { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.mrow { display: grid; grid-template-columns: 1fr minmax(180px, 40%); gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: #fff; }
.mrow .slot { width: 100%; min-height: 40px; }
.mrow .num { color: var(--muted); font-weight: 700; margin-right: 6px; }
@media (max-width: 600px) { .mrow { grid-template-columns: 1fr; } }

/* pictures */
.pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.pic { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 10px; display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.pic .img { height: 150px; display: grid; place-items: center; border-radius: 8px; background: #f7f5f0; overflow: hidden; }
.pic .img img { max-width: 100%; max-height: 150px; object-fit: contain; }
.pic .img .emoji { font-size: 84px; line-height: 1; }
.pic .slot { width: 100%; justify-content: center; min-height: 38px; }
.pic .tinput { text-align: center; font-weight: 600; border: 1.5px solid #c9c1b3; }

/* sort */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.col { border: 1.5px dashed #b9b0a1; border-radius: 12px; background: #fff; min-height: 160px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.col h4 { margin: 0 0 4px; font-size: 15px; text-align: center; padding: 6px; border-radius: 8px; background: #f4f0e8; }
.col .chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* cursors */
.rcursor { position: absolute; z-index: 40; pointer-events: none; transition: left .06s linear, top .06s linear; }
.rcursor svg { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.rcursor span { position: absolute; left: 16px; top: 16px; font-size: 11px; font-weight: 800; color: #fff; padding: 1px 7px; border-radius: 99px; white-space: nowrap; }

/* live bar */
.livebar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 16px; margin-bottom: 16px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.pill { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; padding: 6px 12px; border-radius: 99px; background: #fff; border: 1px solid var(--line); }
.pill.live { background: #ebfbee; border-color: #b2f2bb; color: #2b8a3e; }
.mirror-note { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(59, 91, 219, .5); } 100% { box-shadow: 0 0 0 14px rgba(59, 91, 219, 0); } }

/* editor */
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.types button { justify-content: flex-start; text-align: left; padding: 14px; height: 100%; }
.imgrow { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.imgrow .thumb { width: 90px; height: 70px; border-radius: 8px; border: 1px solid var(--line); display: grid; place-items: center; background: #f7f5f0; overflow: hidden; font-size: 40px; }
.imgrow .thumb img { max-width: 100%; max-height: 100%; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 600; z-index: 2000; box-shadow: var(--shadow); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.slot.filled { touch-action: none; }

/* показанный правильный ответ (после 3 неверных попыток) */
.gap.shown, .slot.shown, .tinput.shown, .chip.shown { border-color: #f59f00 !important; background: #fff4e0 !important; color: #b35c00 !important; font-weight: 700; border-style: solid !important; }
.q.shown { border-color: #ffd8a8; background: #fff9f0; }
.q.shown .opt.sel { border-color: #f59f00; background: #f59f00; color: #fff; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.check-msg { font-size: 14px; color: var(--muted); }
.subject { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 99px; margin-right: 8px; }

/* подсказка с ответом, треугольники ошибок */
.anstip { position: absolute; z-index: 3000; display: none; background: #1f2430; color: #fff; font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 8px; pointer-events: none; white-space: nowrap; box-shadow: var(--shadow); }
.mk { font: inherit; font-size: 11px; font-weight: 800; color: var(--bad); background: var(--bad-bg); border: 1px solid #faa2c1; border-radius: 99px; padding: 0 6px; margin: 0 4px; cursor: pointer; vertical-align: middle; line-height: 18px; }
.q .qt .mk { margin-left: 8px; }
.mkpop { position: absolute; z-index: 60; width: 230px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 10px 12px; font-size: 13px; }
.mkpop .mkh { font-weight: 800; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.mkpop .mki { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.mkpop .mki b { color: var(--bad); flex: 1; }
.mkpop .mki .n { color: var(--muted); }
.mkpop .mkok { margin-top: 6px; } .mkpop .mkok b { color: var(--ok); }
/* письмо и эссе */
textarea.essay { width: 100%; min-height: 320px; font-family: Georgia, "Times New Roman", serif; font-size: 17px; line-height: 1.6; padding: 14px 16px; resize: vertical; }
.wcount { margin-top: 8px; font-size: 14px; font-weight: 700; color: var(--muted); }
.wcount.ok { color: var(--ok); } .wcount.mid { color: var(--warn); } .wcount.bad { color: var(--bad); }
.task-img, .ex-img { margin: 12px 0; } .task-img img, .ex-img img { max-width: 100%; max-height: 420px; border-radius: 10px; border: 1px solid var(--line); }
.task-img .emoji, .ex-img .emoji { font-size: 80px; }
.grade { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 16px; background: #fbf9f5; }
.grade table td, .grade table th { padding: 6px 8px; }
.grade select { width: auto; padding: 4px 8px; }

.modal { position: fixed; inset: 0; background: rgba(31,36,48,.45); z-index: 4000; display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(560px, 100%); max-height: 92vh; overflow: auto; }
.dropzone { margin-top: 14px; border: 2px dashed #c9c1b3; border-radius: 12px; padding: 26px 14px; text-align: center; color: var(--muted); font-weight: 600; background: #fbf9f5; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.mrow { grid-template-columns: 1fr minmax(180px, 40%) auto; }

.aibox { margin: 12px 0; padding: 12px 14px; border: 1px dashed #b197fc; border-radius: 12px; background: #f8f5ff; }
.aibox h4 { margin: 14px 0 6px; font-size: 14px; }
.aibox details summary { cursor: pointer; font-weight: 700; font-size: 14px; margin-top: 6px; }
.marked { white-space: pre-wrap; font-family: Georgia, serif; font-size: 16px; line-height: 1.7; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 8px; }
.marked mark { color: inherit; border-radius: 3px; padding: 0 1px; }
.errtable tr.off td { opacity: .45; text-decoration: line-through; }
.errtable select, .aibox table select { width: auto; padding: 3px 6px; font-size: 13px; }
tr.asp-missing td:nth-child(2) { color: var(--bad); font-weight: 700; } tr.asp-partial td:nth-child(2) { color: var(--warn); font-weight: 700; }
