/* physwithme – фирменный стиль: насыщенный тёмно-синий, яркие синие и фиолетовые акценты,
   тетрадная сетка, рваные бумажные края. Условия задач – на белых карточках. */
:root {
  --navy: #0f1c86;
  --navy-deep: #0a1366;
  --blue: #3b3ce8;
  --blue-bright: #4f56ff;
  --violet: #7b5cff;
  --paper: #e8e1d3;
  --paper-dark: #cfc5b1;
  --bg: #eceef8;
  --card: #ffffff;
  --text: #141838;
  --muted: #5d6286;
  --line: #d9dcef;
  --ok: #138a4e;
  --ok-bg: #e5f6ec;
  --bad: #c3283b;
  --bad-bg: #fbe8ea;
  --part: #b26a00;
  --part-bg: #fff3df;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(15, 28, 134, .08);
  --head: 'Unbounded', 'Arial Black', system-ui, sans-serif;
  --body: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: hidden; }
body { margin: 0; font-family: var(--body); color: var(--text); background: var(--bg); font-size: 16px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; outline: none; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: #fff; padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.loading { padding: 64px 16px; text-align: center; color: var(--muted); }

/* ---------- Тетрадная сетка на тёмном фоне ---------- */
.grid-bg {
  background-color: var(--navy);
  background-image:
    linear-gradient(rgba(255,255,255,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ---------- Шапка ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--navy-deep); color: #fff; box-shadow: 0 2px 0 rgba(255,255,255,.06); }
.topbar__inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.logo { font-family: var(--head); font-weight: 800; color: #fff; text-decoration: none; font-size: 22px; letter-spacing: -.02em; }
.logo--small { font-size: 15px; }
.topnav { display: flex; gap: 6px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topnav a { color: #dfe2ff; text-decoration: none; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; white-space: nowrap; }
.topnav a:hover { background: rgba(255,255,255,.1); }
.topnav a.active { background: #fff; color: var(--navy); }
.tg { display: inline-flex; align-items: center; gap: 6px; color: #fff; text-decoration: none; font-weight: 700; font-size: 14px; background: var(--blue); padding: 8px 12px; border-radius: 999px; }
.tg:hover { background: var(--blue-bright); }
@media (max-width: 860px) {
  .topbar__inner { flex-wrap: wrap; gap: 8px; }
  .topnav { order: 3; width: 100%; margin: 0; }
  .tg { margin-left: auto; }
  .tg span { display: none; }
}

/* ---------- Главный экран ---------- */
.hero { position: relative; overflow: hidden; color: #fff; padding: 88px 16px 120px; text-align: center; }
.hero__title { font-family: var(--head); font-weight: 800; font-size: clamp(44px, 10vw, 128px); line-height: 1; margin: 0; letter-spacing: -.03em; position: relative; z-index: 2; }
.hero__sub { font-family: var(--head); font-weight: 500; font-size: clamp(15px, 2.6vw, 28px); letter-spacing: .12em; margin: 22px 0 0; position: relative; z-index: 2; }
.hero__sub b { font-weight: 800; }
.hero__lead { max-width: 640px; margin: 22px auto 0; color: #d7dbff; position: relative; z-index: 2; }
.deco { position: absolute; inset: 0; pointer-events: none; user-select: none; z-index: 1; }
.deco span { position: absolute; font-family: 'Times New Roman', serif; font-style: italic; color: rgba(255,255,255,.13); white-space: nowrap; }
.deco svg { position: absolute; opacity: .16; }
.torn { position: absolute; left: 0; width: 100%; pointer-events: none; z-index: 1; display: block; }
.torn--top { top: 0; }
.torn--bottom { bottom: -1px; }

.exam-cards { max-width: 1040px; margin: -64px auto 0; padding: 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; position: relative; z-index: 3; }
.exam-card { display: block; background: var(--card); border-radius: 24px; padding: 28px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); border: 2px solid transparent; transition: transform .15s, border-color .15s; }
.exam-card:hover { transform: translateY(-3px); border-color: var(--blue); }
.exam-card h2 { font-family: var(--head); font-size: 26px; margin: 10px 0 8px; }
.exam-card p { margin: 0 0 16px; color: var(--muted); }
.exam-card .links { display: flex; flex-wrap: wrap; gap: 8px; }
.home-info { max-width: 1040px; margin: 40px auto 56px; padding: 0 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.home-info div { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.home-info h3 { font-family: var(--head); font-size: 15px; margin: 0 0 6px; color: var(--navy); }
.home-info p { margin: 0; color: var(--muted); font-size: 14px; }
@media (max-width: 760px) { .exam-cards, .home-info { grid-template-columns: 1fr; } }

/* ---------- Заголовок раздела ---------- */
.pagehead { position: relative; color: #fff; padding: 36px 16px 64px; overflow: hidden; }
.pagehead__inner { max-width: 1240px; margin: 0 auto; position: relative; z-index: 2; }
.pagehead h1 { font-family: var(--head); font-size: clamp(24px, 4vw, 40px); margin: 0 0 16px; letter-spacing: -.02em; }
.pagehead .crumbs { color: #c9cdfb; font-size: 14px; margin-bottom: 8px; }
.pagehead .crumbs a { color: #fff; }
.pagehead__row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.seg { display: inline-flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 4px; }
.seg button, .seg a { border: 0; background: none; color: #fff; padding: 8px 18px; border-radius: 999px; font-weight: 800; cursor: pointer; text-decoration: none; font-size: 14px; }
.seg .on { background: #fff; color: var(--navy); }
.seg--light { background: #e3e6f7; }
.seg--light button { color: var(--navy); }
.seg--light .on { background: var(--navy); color: #fff; }
.docstatus { font-size: 13px; color: #dfe2ff; background: rgba(123,92,255,.35); border-radius: 10px; padding: 6px 10px; }
.docstatus a { color: #fff; }

.wrap { max-width: 1240px; margin: -36px auto 48px; padding: 0 16px; position: relative; z-index: 3; }
.wrap--narrow { max-width: 900px; }

/* ---------- Карточки ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin-top: 0; }
.card-title { font-family: var(--head); font-size: 18px; color: var(--navy); margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.badge { display: inline-block; font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 8px; background: #e4e6fb; color: var(--navy); white-space: nowrap; }
.badge--blue { background: var(--blue); color: #fff; }
.badge--violet { background: #ece6ff; color: #5434d8; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--bad { background: var(--bad-bg); color: var(--bad); }
.badge--part { background: var(--part-bg); color: var(--part); }
.badge--demo { background: #f2eee5; color: #6b5a2c; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 2px solid transparent; background: var(--blue); color: #fff; padding: 9px 16px; border-radius: 12px; font-weight: 800; cursor: pointer; text-decoration: none; font-size: 14px; line-height: 1.2; }
.btn:hover { background: var(--blue-bright); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn--ghost:hover { background: #f3f4fd; border-color: var(--blue); }
.btn--violet { background: var(--violet); }
.btn--violet:hover { background: #8d72ff; }
.btn--danger { background: #fff; color: var(--bad); border-color: #f0c3c9; }
.btn--sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn--lg { padding: 13px 22px; font-size: 16px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Задача ---------- */
.task { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; border: 1px solid var(--line); }
.task + .task { margin-top: 14px; }
.task__head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.task__id { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; font-weight: 700; color: var(--muted); }
.task__num { font-family: var(--head); font-weight: 700; font-size: 15px; color: #fff; background: var(--navy); border-radius: 10px; padding: 3px 10px; }
.task__topic { font-size: 14px; color: var(--muted); }
.task__score { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.statement { font-size: 17px; line-height: 1.6; overflow-wrap: anywhere; }
.statement p { margin: 0 0 10px; }
.statement .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.statement .ans-table { border-collapse: collapse; margin: 8px 0; }
.statement .ans-table th { border: 1px solid #999; padding: 6px 12px; font-weight: 600; font-size: 15px; background: #f6f6fb; }
.statement .ans-table td { border: 1px solid #999; height: 30px; }
.tex-error { display: inline-block; background: var(--bad-bg); color: var(--bad); border: 1px dashed var(--bad); border-radius: 6px; padding: 1px 6px; font-size: 14px; font-family: var(--body); }
.tex-error code { font-size: 12px; }
.task__images { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0; }
.task__images img { max-height: 320px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.source { text-align: right; font-style: italic; color: #444; font-size: 14px; margin-top: 10px; }
.source a { color: #7a7f99; }
.source + .source { margin-top: 2px; }
.task__foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.ext-note { display: inline-flex; gap: 6px; align-items: center; background: #f1effe; color: #4b33c2; padding: 8px 12px; border-radius: 10px; font-weight: 700; font-size: 14px; }
.practical { background: var(--part-bg); color: #6a4300; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.reveal { margin-top: 14px; background: #f7f8fe; border-radius: 12px; padding: 14px 16px; border-left: 4px solid var(--violet); }
.reveal h4 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--violet); }
.criteria { list-style: none; padding: 0; margin: 0; }
.criteria li { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.criteria li:first-child { border-top: 0; }
.criteria .pts { font-weight: 800; color: var(--navy); }

/* ---------- Поля ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.input, select.input, textarea.input { border: 2px solid var(--line); border-radius: 12px; padding: 9px 12px; background: #fff; min-width: 0; width: 100%; }
.input:focus { border-color: var(--blue); outline: none; }
textarea.input { resize: vertical; min-height: 90px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.answer-input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; letter-spacing: .08em; max-width: 260px; }
.answer-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }

.result { border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 14px; }
.result--ok { background: var(--ok-bg); color: var(--ok); }
.result--bad { background: var(--bad-bg); color: var(--bad); }
.result--part { background: var(--part-bg); color: var(--part); }
.alert { border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; background: #fff; border-left: 5px solid var(--blue); box-shadow: var(--shadow); }
.alert--warn { border-left-color: #e0a100; background: #fffaf0; }
.alert--bad { border-left-color: var(--bad); background: #fff6f7; }
.alert--ok { border-left-color: var(--ok); background: #f4fbf7; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Каталог ---------- */
.catalog { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.tree { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree li ul { padding-left: 14px; }
.tree button { width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; justify-content: space-between; font-size: 14px; }
.tree button:hover { background: #f1f2fc; }
.tree button.on { background: var(--navy); color: #fff; }
.tree .n { color: var(--muted); font-size: 12px; }
.tree button.on .n { color: #c9cdfb; }
.tree .num { font-weight: 800; }
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.filters .wide { grid-column: span 2; }
.listhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 6px 0 12px; flex-wrap: wrap; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.mobile-tree-toggle { display: none; }
@media (max-width: 980px) {
  .catalog { grid-template-columns: minmax(0, 1fr); }
  .tree { position: static; max-height: none; display: none; }
  .tree.open { display: block; }
  .mobile-tree-toggle { display: inline-flex; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: span 2; }
}

/* ---------- Конструктор ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.side { position: sticky; top: 76px; }
.parthead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 18px 4px 10px; flex-wrap: wrap; }
.parthead h2 { font-family: var(--head); font-size: 22px; margin: 0; color: var(--navy); }
.pos { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.pos + .pos { margin-top: 10px; }
.pos.on { border-color: var(--blue); }
.pos.off { opacity: .65; }
.pos__row { display: grid; grid-template-columns: auto 44px 1fr auto auto; gap: 12px; align-items: center; }
.pos__num { font-family: var(--head); font-weight: 700; color: var(--navy); }
.pos__title { font-weight: 600; }
.pos__meta { font-size: 13px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 34px; height: 34px; border-radius: 10px; border: 0; background: #eef0fa; font-size: 20px; font-weight: 700; cursor: pointer; color: var(--navy); }
.stepper button.plus { background: var(--blue); color: #fff; }
.stepper input { width: 48px; text-align: center; border: 2px solid var(--line); border-radius: 10px; height: 34px; }
.chev { width: 34px; height: 34px; border-radius: 50%; border: 0; background: #e3e5f3; cursor: pointer; transition: transform .2s; font-size: 14px; }
.chev.open { transform: rotate(180deg); }
.pos__topics { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); display: grid; gap: 6px; }
.pos__topics .sub { padding-left: 26px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.summary dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0 0 14px; }
.summary dt { color: var(--text); }
.summary dd { margin: 0; color: var(--muted); text-align: right; }
.radios { display: grid; gap: 8px; margin: 8px 0 16px; }
.howto { background: #dfe5f6; border-radius: 16px; padding: 14px 16px; margin-top: 14px; font-size: 14px; }
.howto b { color: var(--navy); }
.preview-item { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: start; }
@media (max-width: 1020px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
}
@media (max-width: 600px) {
  .pos__row { grid-template-columns: auto 36px 1fr auto; }
  .pos__row .stepper { grid-column: 2 / 5; justify-self: start; }
  .pos__row .chev { grid-row: 1; grid-column: 4; }
}

/* ---------- Прохождение ---------- */
.solve { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: start; }
.navgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.navgrid a { display: flex; align-items: center; justify-content: center; height: 36px; border-radius: 10px; text-decoration: none; font-weight: 800; font-size: 14px; background: #eef0fa; color: var(--navy); border: 2px solid transparent; }
.navgrid a.filled { background: var(--navy); color: #fff; }
.navgrid a.ext { background: #ece6ff; color: #5434d8; }
.navgrid a.current { border-color: var(--violet); }
.legend { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin: 12px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }
.progress { height: 8px; background: #e7e9f6; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--blue), var(--violet)); }
.savehint { font-size: 12px; color: var(--muted); }
@media (max-width: 900px) {
  .solve { grid-template-columns: minmax(0, 1fr); }
  .solve .side { position: sticky; top: 98px; z-index: 5; order: -1; }
  .solve .side .card { padding: 12px; }
  .solve .navgrid { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 38px; overflow-x: auto; padding-bottom: 4px; }
  .solve .side .hide-m { display: none; }
}

/* ---------- Результаты ---------- */
.score-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.score-box { border-radius: 16px; padding: 16px; background: #f4f5fd; }
.score-box .v { font-family: var(--head); font-size: 32px; font-weight: 800; color: var(--navy); }
.score-box .l { font-size: 13px; color: var(--muted); }
.score-box--main { background: var(--navy); color: #fff; }
.score-box--main .v { color: #fff; }
.score-box--main .l { color: #c9cdfb; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.data td.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.selfscore { display: flex; flex-wrap: wrap; gap: 6px; }
.selfscore label { cursor: pointer; }
.selfscore input { position: absolute; opacity: 0; }
.selfscore span { display: inline-flex; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: 12px; border: 2px solid var(--line); font-weight: 800; }
.selfscore input:checked + span { background: var(--violet); border-color: var(--violet); color: #fff; }
.selfscore input:focus-visible + span { outline: 3px solid var(--violet); outline-offset: 2px; }

/* ---------- Админ ---------- */
.admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-grid .s2 { grid-column: span 2; }
.form-grid .s4 { grid-column: span 4; }
.rowlist { display: grid; gap: 8px; }
.rowlist .r { display: grid; gap: 8px; align-items: center; }
.preview-pane { position: sticky; top: 76px; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 14px; }
legend { font-weight: 800; color: var(--navy); padding: 0 6px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs figure { margin: 0; position: relative; }
.thumbs img { height: 90px; border-radius: 8px; border: 1px solid var(--line); }
.thumbs button { position: absolute; top: 4px; right: 4px; }
@media (max-width: 1020px) { .admin-grid { grid-template-columns: minmax(0, 1fr); } .preview-pane { position: static; } }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .s4, .form-grid .s2 { grid-column: span 2; } }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy-deep); color: #fff; padding: 12px 18px; border-radius: 14px; z-index: 99; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* ---------- Подвал ---------- */
.footer { background: var(--navy-deep); color: #c9cdfb; font-size: 14px; }
.footer__inner { max-width: 1240px; margin: 0 auto; padding: 22px 16px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.footer a { color: #fff; }
.footer__links { display: flex; gap: 16px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .topbar, .footer, .side, .pagehead .seg, .task__foot, .btns { display: none !important; }
  .pagehead { color: #000; background: none !important; padding: 0; }
  .torn, .deco { display: none; }
  body { background: #fff; }
}
