/* ==========================================================================
   Nazorat ishi — общий стиль. «Тетрадь в клетку»: бумага, синие чернила,
   красная ручка учителя. Только системные шрифты: в классе нет интернета.
   ========================================================================== */
:root {
  --paper: #f6f8fc;
  --grid: #dfe7f3;
  --sheet: #ffffff;
  --ink: #1a2238;
  --muted: #5e6982;
  --line: #d5ddea;
  --blue: #2747c7;
  --blue-dark: #1c369e;
  --blue-soft: #e8edfd;
  --red: #d23b3b;
  --red-soft: #fdecec;
  --green: #18875a;
  --green-soft: #e3f4ec;
  --amber: #a86d00;
  --amber-soft: #fdf3dc;
  --margin: #f2b8b8;

  --f-display: "Bahnschrift", "DIN Alternate", "Arial Narrow", "Segoe UI", sans-serif;
  --f-body: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --f-pen: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;

  --r-s: 6px;
  --r-m: 10px;
  --cell: 24px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); font: 17px/1.55 var(--f-body);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-attachment: fixed;
}
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: .005em; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 17px/1 var(--f-body); padding: 14px 22px; border-radius: var(--r-s);
  border: 1.5px solid var(--line); background: var(--sheet); color: var(--ink);
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { border-color: #b9c4d8; background: #f9fbff; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.go { background: var(--green); border-color: var(--green); color: #fff; }
.btn.go:hover { background: #12704a; border-color: #12704a; }
.btn.wide { width: 100%; }
.btn.big { font-size: 19px; padding: 17px 24px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.busy { pointer-events: none; opacity: .75; }
.btn.busy::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- верхняя полоса ученика ---------- */
.bar {
  position: sticky; top: 0; z-index: 10; background: var(--sheet); border-bottom: 1.5px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 10px max(20px, calc((100vw - 1180px) / 2));
}
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 42px; height: 42px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--blue-soft); color: var(--blue); font: 600 16px var(--f-display);
}
.who b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { display: block; color: var(--muted); font-size: 14px; }
.bar .grow { flex: 1; }
.timer {
  font: 600 22px/1 var(--f-display); font-variant-numeric: tabular-nums; padding: 9px 14px;
  border: 1.5px solid var(--line); border-radius: var(--r-s); display: flex; gap: 8px; align-items: center;
}
.timer small { font: 500 13px var(--f-body); color: var(--muted); }
.timer.low { color: var(--red); border-color: var(--red); background: var(--red-soft); }

/* ---------- лист ученика ---------- */
.shell { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }

.stepper { list-style: none; margin: 0 0 22px; padding: 0; display: flex; gap: 6px; }
.stepper li {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: var(--sheet); border: 1.5px solid var(--line); border-radius: var(--r-s); color: var(--muted);
}
.stepper .n {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font: 600 16px var(--f-display); border: 1.5px solid currentColor;
}
.stepper .t { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper li.done { color: var(--green); border-color: #bfe3d1; background: var(--green-soft); }
.stepper li.done .n { background: var(--green); border-color: var(--green); color: #fff; }
.stepper li.cur { color: var(--blue); border-color: var(--blue); box-shadow: inset 0 -3px 0 var(--blue); }
.stepper li.cur .n { background: var(--blue); border-color: var(--blue); color: #fff; }
.stepper li.cur .t { color: var(--ink); font-weight: 600; }

.flash { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--r-s); margin: 0 0 18px; font-weight: 600; }
.flash.ok { background: var(--green-soft); color: #0f6643; border: 1.5px solid #bfe3d1; }
.flash.err { background: var(--red-soft); color: #a32020; border: 1.5px solid #f3c4c4; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 22px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } .panel { position: static; } }

/* задание — лист тетради с красной линией поля */
.sheet {
  position: relative; background: var(--sheet); border: 1.5px solid var(--line); border-radius: var(--r-m);
  padding: 26px 30px 30px 58px;
}
.sheet::before { content: ""; position: absolute; top: 0; bottom: 0; left: 36px; width: 2px; background: var(--margin); }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.sheet-head h1 { font-size: 30px; }
.sheet-head h1 span { color: var(--muted); font-weight: 400; }
.pts { flex: none; font: 600 15px var(--f-display); color: var(--red); border: 1.5px solid var(--red); border-radius: 999px; padding: 4px 12px; }
.task-text { font-size: 18px; line-height: 1.65; max-width: 72ch; }
.task-text b { color: var(--blue-dark); }
.task-text code { font: 15px Consolas, "Cascadia Mono", monospace; background: var(--blue-soft); padding: 1px 6px; border-radius: 4px; word-break: break-all; }
.refs { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.refs.row { flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
.refs img { display: block; max-width: 100%; border: 1.5px solid var(--line); border-radius: var(--r-s); background: #fff; }
.refs.mid img { max-width: 440px; }
.refs.small img { max-width: 220px; }
table.sample { border-collapse: collapse; margin: 14px 0 4px; font-size: 16px; background: #fff; }
table.sample th, table.sample td { border: 1.5px solid #b9c4d8; padding: 5px 16px; text-align: center; }
table.sample th { background: var(--blue-soft); font-weight: 600; }
table.sample td:first-child { text-align: left; }

.note { margin-top: 22px; padding: 14px 16px; border-left: 4px solid var(--blue); background: var(--blue-soft); border-radius: 0 var(--r-s) var(--r-s) 0; font-size: 16px; }
.note p { margin: 0 0 10px; }
.note p:last-child { margin: 0; }

/* правая панель: сдача */
.panel { background: var(--sheet); border: 1.5px solid var(--line); border-radius: var(--r-m); padding: 22px; position: sticky; top: 86px; }
.panel h2 { font-size: 22px; margin-bottom: 10px; }
.panel .lead { color: var(--muted); font-size: 15px; margin: 0 0 14px; }
.panel.state-check { border-color: var(--amber); box-shadow: inset 0 4px 0 var(--amber); }
.panel.state-lock { border-color: var(--red); box-shadow: inset 0 4px 0 var(--red); }
.panel.state-live { border-color: var(--blue); box-shadow: inset 0 4px 0 var(--blue); }

.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 4px; min-height: 150px; padding: 18px; margin-bottom: 12px; cursor: pointer;
  border: 2px dashed #a8b6d0; border-radius: var(--r-m); background: #fbfcff; transition: border-color .12s, background .12s;
}
.drop:hover, .drop.over { border-color: var(--blue); background: var(--blue-soft); }
.drop.has { border-style: solid; border-color: var(--green); background: var(--green-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.drop .ico { font-size: 30px; line-height: 1; }
.drop .main { font-weight: 600; color: var(--blue); }
.drop.has .main { color: var(--green); }
.drop.has .sub { display: none; }
.drop .picked:empty { display: none; }
.drop .sub { font-size: 14px; color: var(--muted); }
.drop .picked { font-size: 14px; color: var(--ink); word-break: break-all; }
.drop.small { min-height: 0; padding: 12px; flex-direction: row; gap: 10px; }
.drop.small .ico { font-size: 20px; }
.or { text-align: center; color: var(--muted); font-size: 14px; margin: 2px 0 10px; }

.checks { list-style: none; margin: 0 0 14px; padding: 0; font-size: 15px; }
.checks li { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid #eef1f6; }
.checks li:last-child { border: 0; }
.checks .y { color: var(--green); font-weight: 700; }
.checks .x { color: var(--red); font-weight: 700; }
.checks .i { color: var(--muted); }
.mine { display: block; width: 100%; max-height: 260px; object-fit: contain; background: #fff; border: 1.5px solid var(--line); border-radius: var(--r-s); margin-bottom: 14px; }
.filebox { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--r-s); margin-bottom: 14px; }
.filebox .ico { font-size: 28px; }
.filebox b { display: block; word-break: break-all; }
.filebox small { color: var(--muted); }
.warnline { font-size: 14px; color: var(--muted); margin: 10px 0 0; }
details.again { margin-top: 16px; border-top: 1.5px dashed var(--line); padding-top: 12px; }
details.again summary { cursor: pointer; color: var(--blue); font-weight: 600; font-size: 15px; }
details.again[open] summary { margin-bottom: 12px; }

.done-list { margin-top: 26px; }
.done-list h3 { font-size: 18px; margin-bottom: 12px; }
.thumbs { display: flex; gap: 12px; flex-wrap: wrap; }
.thumb { background: var(--sheet); border: 1.5px solid #bfe3d1; border-radius: var(--r-s); padding: 8px; font-size: 14px; color: var(--green); font-weight: 600; text-align: center; }
.thumb img { display: block; height: 76px; max-width: 160px; object-fit: contain; margin: 0 auto 6px; }
.thumb small { display: block; color: var(--muted); font-weight: 400; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* финиш */
.finish { max-width: 640px; margin: 30px auto 0; text-align: center; background: var(--sheet); border: 1.5px solid var(--line); border-radius: var(--r-m); padding: 40px 30px; }
.finish .seal { width: 96px; height: 96px; margin: 0 auto 18px; border-radius: 50%; border: 3px solid var(--green); color: var(--green); display: grid; place-items: center; font-size: 46px; }
.finish h1 { font-size: 32px; margin-bottom: 10px; }
.finish p { color: var(--muted); margin: 0; }

/* ---------- экран с кодом ---------- */
.code-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px 20px; }
.code-screen h1 { font-size: 26px; color: var(--muted); font-weight: 400; margin-bottom: 30px; }
.code-screen .label { font: 600 20px var(--f-display); margin: 0 0 14px; }
.cells { display: flex; margin-bottom: 30px; }
.cells span {
  width: calc(var(--cell) * 5); height: calc(var(--cell) * 6); display: grid; place-items: center;
  font: 600 108px/1 var(--f-display); color: var(--blue); background: var(--sheet);
  border: 2px solid var(--blue); margin-left: -2px;
}
.cells span:first-child { border-radius: var(--r-m) 0 0 var(--r-m); margin-left: 0; }
.cells span:last-child { border-radius: 0 var(--r-m) var(--r-m) 0; }
.code-screen .say { font-size: 20px; max-width: 34em; margin: 0 0 22px; }
.wait { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 16px; background: var(--sheet); padding: 8px 16px; border-radius: 999px; border: 1.5px solid var(--line); }
.wait i { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.code-screen .both { color: var(--muted); font-size: 18px; margin: 4px 0; }

/* ---------- вход учителя ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 380px; background: var(--sheet); border: 1.5px solid var(--line); border-radius: var(--r-m); padding: 30px 30px 30px 52px; position: relative; }
.login form::before { content: ""; position: absolute; top: 0; bottom: 0; left: 30px; width: 2px; background: var(--margin); }
.login h1 { font-size: 28px; margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 20px; font-size: 15px; }
.field { display: block; width: 100%; font: 18px var(--f-body); padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--r-s); margin-bottom: 14px; background: #fff; color: var(--ink); }
.field:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.login .err { color: var(--red); font-weight: 600; margin: 0 0 12px; font-size: 15px; }

@media (max-width: 700px) {
  .stepper .t { display: none; }
  .stepper li { justify-content: center; }
  .sheet { padding: 20px 18px 22px 40px; }
  .sheet::before { left: 24px; }
  .sheet-head h1 { font-size: 24px; }
  .cells span { width: calc(var(--cell) * 3.4); height: calc(var(--cell) * 4.2); font-size: 72px; }
  .bar .timer small { display: none; }
}
