/*
 * Список задач: страница предмета, страница темы и «все задачи».
 *
 * Собрано из двух макетов: topic_tasks_a.html дал каркас «фильтры слева,
 * карточки справа», tasks_all_a.html — поисковую шапку. Страницы отличаются
 * только шапкой, поэтому стили у них общие, а файл один.
 *
 * Правок против макетов три, и все из-за реальных данных. Сортировка и
 * страницы — ссылки, а не кнопки: они часть адреса, поэтому стили повторены
 * для <a> и <span>. Фасеты, за которыми нет данных, нарисованы серыми.
 * Блок цифр в шапке назван .hero-facts: имя .facts уже занято столбиком
 * «факт — число» из общих стилей.
 */

  .page.tasks { padding-top: 26px; padding-bottom: 76px; }

  /* Колонки местами: сначала «чем сузить», потом сам список. */
  .desk-filters { grid-template-columns: minmax(0, 292px) minmax(0, 1fr); }

  /* Панель фильтров длиннее экрана, поэтому липкой она не держится. */
  .desk-filters > .rail { position: static; max-height: none; overflow: visible; }

  .vh {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* ---------- хлебные крошки ---------- */
  .crumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 14px;
  }
  .crumbs a { font-weight: 500; }
  .crumbs a:hover { color: var(--accent); }
  .crumbs b { color: var(--ink); font-weight: 600; }
  .crumbs .mi { font-size: 15px; color: var(--muted-2); }

  /* ---------- шапка предмета или темы ---------- */
  .topic-hero { padding: 26px 28px; margin-bottom: 18px; }
  .kicker {
    display: inline-block;
    padding: 5px 10px;
    margin-bottom: 12px;
    border-radius: 999px;
    background: var(--accent-50);
    color: var(--accent-700);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
  }
  .topic-hero h1 {
    font-size: clamp(26px, 3vw, 34px);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 10px;
  }
  .topic-hero h1 em {
    font-family: "Instrument Serif", Georgia, serif;
    font-style: italic;
    font-weight: 400;
    color: var(--accent);
  }
  .topic-hero .lede { font-size: 14px; color: var(--muted); max-width: 68ch; }
  .hero-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 26px;
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
  }
  .hero-facts .v {
    font-family: "Instrument Serif", Georgia, serif;
    font-size: 30px;
    line-height: 1;
    letter-spacing: -0.02em;
  }
  .hero-facts .l { font-size: 11px; color: var(--muted); font-weight: 500; margin-top: 5px; }

  /* ---------- поисковая шапка «всех задач» ---------- */
  .finder {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 30px 32px 26px;
    margin-bottom: 24px;
  }
  .finder::before {
    content: "";
    position: absolute;
    width: 320px; height: 320px;
    right: -110px; top: -160px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow), transparent 70%);
    pointer-events: none;
  }
  .finder > * { position: relative; }
  .finder h1 {
    font-size: clamp(26px, 3.2vw, 36px);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 8px;
  }
  .finder h1 em {
    font-family: "Instrument Serif", Georgia, serif;
    font-style: italic;
    font-weight: 400;
    color: var(--accent);
  }
  .finder .lede {
    font-size: 14px;
    color: var(--muted);
    max-width: 68ch;
    margin-bottom: 20px;
  }
  .qform {
    display: flex;
    gap: 10px;
    align-items: stretch;
    flex-wrap: wrap;
  }
  .qwrap {
    flex: 1 1 320px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: all 0.18s;
  }
  .qwrap:focus-within {
    background: var(--surface);
    border-color: var(--accent-200);
    box-shadow: 0 0 0 4px var(--accent-50);
  }
  .qwrap > .mi { font-size: 20px; color: var(--muted-2); }
  .qwrap input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 15px 0;
    font: inherit;
    font-size: 16px;
    color: var(--ink);
    background: none;
    border: 0;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
  }
  .qwrap input::placeholder { color: var(--muted-2); }
  .qwrap input::-webkit-search-cancel-button { display: none; }
  .qgo {
    flex: none;
    justify-content: center;
    padding: 13px 26px;
    font-size: 15px;
  }
  .qgo:hover { background: var(--accent); }
  .qbase {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }
  .qbase b { color: var(--ink); font-weight: 600; }
  .qbase a { color: var(--accent-700); font-weight: 600; }

  /* ---------- панель фильтров ---------- */
  .f-form { padding: 18px; }
  .f-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
  }
  .f-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
  .f-reset { font-size: 12px; font-weight: 600; color: var(--muted); }
  .f-reset:hover { color: var(--accent); }
  .f-count {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
  }
  .f-count b { color: var(--ink); font-weight: 600; }

  .f-form fieldset { border: 0; padding: 0; margin: 0 0 16px; }
  .f-form legend {
    padding: 0;
    margin-bottom: 7px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .f-opt {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 7px;
    margin: 0 -7px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--ink-2);
    cursor: pointer;
    transition: background 0.15s;
  }
  .f-opt:hover { background: var(--surface-2); }
  .f-opt input {
    width: 15px; height: 15px;
    margin: 0;
    flex: none;
    accent-color: var(--accent);
    cursor: pointer;
  }
  .f-opt .n { min-width: 0; }
  .f-opt .c {
    margin-left: auto;
    padding-left: 4px;
    font-size: 11px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
  }
  .f-opt input:checked ~ .n { font-weight: 600; color: var(--ink); }

  /*
   * Номеров заданий бывает под сорок: столбиком они занимают панель целиком.
   * grid-column у legend — на случай браузера, который втягивает его в сетку.
   */
  .f-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 6px;
  }
  .f-grid legend { grid-column: 1 / -1; }
  .f-grid .f-opt { margin: 0; gap: 7px; }

  /* Тема на своей странице выбирается переходом, а не галочкой. */
  .f-link {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 7px;
    margin: 0 -7px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--ink-2);
    transition: background 0.15s;
  }
  .f-link:hover { background: var(--surface-2); color: var(--ink); }
  .f-link .n { min-width: 0; }
  .f-link .c {
    margin-left: auto;
    padding-left: 4px;
    font-size: 11px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
  }
  .f-link.here {
    background: var(--accent-50);
    color: var(--accent-700);
    font-weight: 600;
  }
  .f-link.here .c { color: var(--accent-700); }

  /* Номера на странице номера — ссылки в той же сетке, что и галочки. */
  .f-grid .f-link { margin: 0; }
  .f-grid .f-link:last-child { grid-column: 1 / -1; }

  /* Фасет, за которым ещё нет данных: видно, что он будет, но трогать нечего. */
  .f-dead .f-opt { cursor: default; color: var(--muted-2); }
  .f-dead .f-opt:hover { background: none; }
  .f-dead .f-opt input { cursor: default; }
  .f-hint {
    margin-top: 6px;
    font-size: 11.5px;
    line-height: 1.45;
    color: var(--muted-2);
  }

  .f-done { display: none; }

  /* ---------- строка сортировки и плотности ---------- */
  .toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
  }
  .toolbar .lbl { font-size: 12px; color: var(--muted-2); font-weight: 500; }
  .toolbar .filter-chip { padding: 7px 13px; }
  .toolbar .filter-chip[aria-current="true"] {
    background: var(--ink);
    color: white;
    border-color: var(--ink);
  }
  .seg {
    display: flex;
    gap: 4px;
    margin-left: auto;
    padding: 3px;
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 12px;
    flex: none;
  }
  .seg button {
    padding: 5px 11px;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 500;
    transition: all 0.18s;
  }
  .seg button:hover { color: var(--ink); }
  .seg button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
  }

  /* ---------- кнопка фильтров, только мобильная ---------- */
  .fbar {
    display: none;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 14px;
    padding: 11px 16px;
    border-radius: 999px;
    background: var(--ink);
    color: white;
    font-size: 14px;
    font-weight: 600;
  }
  .fbar .n { margin-left: auto; font-variant-numeric: tabular-nums; opacity: 0.75; }
  .fscrim { display: none; }

  /* ---------- карточка задачи ---------- */
  .list { display: flex; flex-direction: column; gap: 12px; }
  .tk {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
    transition: box-shadow 0.2s, border-color 0.2s;
  }
  .tk:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
  .tk-top {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-bottom: 9px;
  }
  .tk-idx {
    font-family: "Geist Mono", ui-monospace, monospace;
    font-size: 11px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
  }
  .tk-code {
    font-family: "Geist Mono", ui-monospace, monospace;
    font-size: 11px;
    color: var(--muted);
    padding: 2px 7px;
    border-radius: 5px;
    background: var(--surface-2);
    letter-spacing: 0.02em;
  }
  .tk-top .tag { flex: none; }
  a.tag-ghost:hover { background: var(--accent-50); color: var(--accent-700); }
  a.tag-violet:hover { background: var(--accent-100); color: var(--accent-700); }
  .tk-t {
    display: block;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.3;
    margin-bottom: 6px;
  }
  .tk-text {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--muted);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
  }
  /*
   * KaTeX набирает формулу на 1.21em крупнее окружающего текста: на странице
   * задачи это к месту, а в превью формула начинала бы спорить с названием
   * задачи. Здесь она ровно в размер строки, чтобы обрезка по трём строкам
   * считалась предсказуемо.
   */
  .tk-text .katex { font-size: 1em; }

  .tk-marks {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 11px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
  }
  .tk-marks span { display: inline-flex; align-items: center; gap: 5px; }
  .tk-marks .mi { font-size: 14px; color: var(--muted-2); }
  .tk-marks .st-ok { color: var(--green); }
  .tk-marks .st-ok .mi { color: var(--green); }
  .tk-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 13px;
    padding-top: 13px;
    border-top: 1px solid var(--border);
  }
  .tk-foot .btn { padding: 9px 16px; font-size: 13px; }
  .btn-soft { background: var(--surface-2); color: var(--ink); }
  .btn-soft:hover { background: var(--accent-50); color: var(--accent-700); }
  .tk-foot .pct {
    margin-left: auto;
    font-size: 12px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
  }
  .tk-answer {
    margin-top: 12px;
    padding: 13px 15px;
    border-radius: var(--radius);
    background: var(--accent-50);
    font-size: 13.5px;
    color: var(--ink-2);
    animation: rev 0.28s cubic-bezier(.2,.8,.2,1) both;
  }
  .tk-answer b { font-weight: 600; }
  .tk-answer .v {
    font-family: "Geist Mono", ui-monospace, monospace;
    font-size: 15px;
    font-weight: 500;
    color: var(--accent-700);
  }
  .tk-answer .m { margin-top: 6px; font-size: 12px; color: var(--muted); }

  /* Компактная плотность: тот же ритм, меньше воздуха. */
  .list.compact { gap: 8px; }
  .list.compact .tk { padding: 12px 15px; border-radius: var(--radius); }
  .list.compact .tk-t { font-size: 14px; margin-bottom: 4px; }
  .list.compact .tk-text { -webkit-line-clamp: 1; line-clamp: 1; font-size: 13px; }
  .list.compact .tk-marks { margin-top: 8px; }
  .list.compact .tk-foot { margin-top: 9px; padding-top: 9px; }
  .list.compact .tk-foot .btn { padding: 7px 13px; font-size: 12.5px; }

  /* ---------- пара «задания ↔ решения» ---------- */
  .pair-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--accent-50);
    color: var(--accent-700);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.18s;
  }
  .pair-link:hover { background: var(--accent-100); }
  .pair-link .mi { font-size: 16px; }

  /* ---------- карточка решения ---------- */
  /*
   * Та же .tk, но заголовок — ссылка на разбор, а под условием первые шаги и
   * открытый ответ. Шаги — кружок с номером, как на странице разбора, только
   * мельче: здесь это превью, а не выкладка.
   */
  .sol .tk-t a:hover { color: var(--accent); }
  .sol .tk-text { -webkit-line-clamp: 2; line-clamp: 2; }
  .sol-steps {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
  }
  .sol-steps li {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ink-2);
  }
  .sol-steps .dot {
    width: 22px; height: 22px;
    margin-top: 1px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }
  .sol-steps .st { min-width: 0; }
  .sol-steps .fx {
    display: block;
    margin-top: 3px;
    color: var(--ink);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sol-more { margin: 7px 0 0 32px; font-size: 12px; color: var(--muted-2); }
  .sol-ans {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 12px;
    padding: 11px 14px;
    border-radius: var(--radius);
    background: var(--accent-50);
    font-size: 13.5px;
    color: var(--ink-2);
  }
  .sol-ans .lbl { font-weight: 600; }
  .sol-ans .v {
    min-width: 0;
    font-family: "Geist Mono", ui-monospace, monospace;
    font-size: 15px;
    font-weight: 500;
    color: var(--accent-700);
    overflow-wrap: anywhere;
  }
  .sol-ans.long .v { font-family: inherit; font-size: 13.5px; font-weight: 400; color: var(--ink-2); }
  .sol-ans .src {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--muted);
  }
  .sol-ans a.src:hover { color: var(--accent); }
  .sol-ans .src.ok, .sol-ans .src.ok .mi { color: var(--green); }
  .sol-ans .src .mi { font-size: 14px; }
  .list.compact .sol-steps { margin-top: 8px; gap: 6px; }
  .list.compact .sol-ans { margin-top: 8px; padding: 8px 12px; }

  /* ---------- пусто ---------- */
  .empty {
    padding: 44px 24px;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-xl);
  }
  .empty .ic {
    width: 46px; height: 46px;
    margin: 0 auto 14px;
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--muted-2);
    display: grid;
    place-items: center;
  }
  .empty .ic .mi { font-size: 22px; }
  .empty b { display: block; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
  .empty p { font-size: 13px; color: var(--muted); }
  .empty a { color: var(--accent); font-weight: 600; }

  /* ---------- страницы списка ---------- */
  .pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 22px;
  }
  .pager a,
  .pager > span {
    min-width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    transition: all 0.18s;
  }
  .pager a:hover { color: var(--ink); border-color: var(--border-strong); }
  .pager [aria-current="page"] { background: var(--ink); color: white; border-color: var(--ink); }
  .pager .gap { border: 0; background: none; min-width: 0; padding: 0 2px; }

  .all-link {
    margin-top: 26px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
  }
  .all-link a { color: var(--ink); font-weight: 600; }
  .all-link a:hover { color: var(--accent); }

  /* ---------- узкие экраны: фильтры выезжают панелью ---------- */
  @media (max-width: 1000px) {
    .desk.desk-filters { display: block; }
    .desk.desk-filters > .flow { display: block; }
    .topic-hero { padding: 20px 18px; }
    .finder { padding: 22px 18px 20px; }
    .qgo { flex: 1 1 auto; }
    .hero-facts { gap: 18px; }
    .fbar { display: flex; }
    .toolbar .seg { margin-left: 0; }

    /*
     * Пока панель открыта, .page поднимается над липкой шапкой: иначе её
     * z-index держит и панель, и затемнение под шапкой.
     */
    body.f-open .page { z-index: 90; }

    .desk.desk-filters > .rail {
      display: block;
      position: fixed;
      top: 0; left: 0; bottom: 0;
      width: min(340px, 90vw);
      max-height: none;
      z-index: 80;
      margin: 0;
      padding: 0;
      background: var(--surface);
      transform: translateX(-101%);
      visibility: hidden;
      transition: transform 0.25s cubic-bezier(.2,.8,.2,1), visibility 0.25s;
      overflow-y: auto;
    }
    body.f-open .desk.desk-filters > .rail {
      transform: none;
      visibility: visible;
      box-shadow: var(--shadow-lg);
    }
    .desk.desk-filters > .rail .f-form {
      min-height: 100%;
      border: 0;
      border-radius: 0;
      box-shadow: none;
      padding: 18px 18px 24px;
    }
    .f-done {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      margin-top: 6px;
      padding: 12px;
      border-radius: 999px;
      background: var(--ink);
      color: white;
      font-size: 14px;
      font-weight: 600;
    }
    .fscrim {
      display: block;
      position: fixed;
      inset: 0;
      z-index: 75;
      background: rgba(15, 15, 20, 0.45);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s;
    }
    body.f-open .fscrim { opacity: 1; pointer-events: auto; }
    body.f-open { overflow: hidden; }
  }
  @media (max-width: 430px) {
    .topic-hero h1, .finder h1 { font-size: 24px; }
    .hero-facts { gap: 14px 22px; }
    .hero-facts .v { font-size: 26px; }
    .qwrap input { font-size: 15px; }
    .qbase { line-height: 1.6; }
    .tk-foot .btn { flex: 1 1 auto; justify-content: center; }
    .tk-foot .pct { width: 100%; margin-left: 0; text-align: center; }
    .sol-ans .src { width: 100%; margin-left: 0; }
  }
