/* Style overrides for Numerical Methods.
 *
 * Loaded after the shared design system and the generated tokens, so a
 * rule here wins. Prefer setting token values in book.yaml; keep this file
 * for components that are genuinely specific to this book, and keep it
 * small — a book should be recognisable, not a different design system.
 */

@layer book {
  /* Methods, A to Z: the step column is a formula, and MathML cannot wrap.
   *
   * With the browser's automatic table layout, one long update sets the width of the
   * step column and every price wraps into a narrow strip. The page measured 12,500px
   * tall at a 1280px viewport, and much of that was the last column. A fixed layout
   * gives the price the width its prose needs and holds the formulas in a column the
   * page can plan for; the longest updates are broken over lines in the page itself.
   *
   * Only on a wide screen. On a phone the table keeps its automatic layout and
   * scrolls, which is how every data table in the collection behaves. */
  @media (min-width: 1024px) {
    .method-index table {
      table-layout: fixed;
      width: 100%;
    }

    .method-index th:nth-child(1),
    .method-index td:nth-child(1) {
      width: 18%;
    }

    .method-index th:nth-child(2),
    .method-index td:nth-child(2) {
      width: 17%;
    }

    .method-index th:nth-child(3),
    .method-index td:nth-child(3) {
      width: 41%;
    }

    .method-index th:nth-child(4),
    .method-index td:nth-child(4) {
      width: 24%;
    }
  }

  /* Methods, A to Z: one section per class, one block per method.
   *
   * The page was five four-column tables until 2026-10-27. A table earns its keep when
   * a reader compares values down a shared column; these rows were records — a name, a
   * class, a formula and a sentence of price — and at 390px the table was 650px wide
   * inside a 358px box, so 45% of it was off screen. Cards fixed the clipping and lost
   * the column names; the page is one class per section now, with the method as a
   * heading, its class as a link, the step, and the price. Nothing is hidden at any
   * width and nothing needs a label to say what it is.
   *
   * The class headings stick: the page is 34,000px on a phone, and a reader deep inside
   * "Moving problems" needs to know which section they are in. `top` clears the masthead,
   * which is sticky, so it is the masthead's own height rather than zero; the paper
   * background is what stops the text scrolling underneath. */

  .method-index h2 {
    position: sticky;
    top: var(--tb-masthead-height);
    z-index: 1;
    background: var(--md-default-bg-color);
    padding: 0.4rem 0;
    /* A hairline under a stuck heading, so it reads as a bar rather than as text
     * floating over the paragraph that has slid beneath it. */
    box-shadow: 0 1px 0 var(--md-default-fg-color--lightest);
  }

  .method-index h3 {
    margin: 1.6rem 0 0.3rem;
    font-family: var(--tb-font-display);
    font-size: 1.0625rem;
    line-height: 1.3;
  }

  /* The class line, the step and the price are three short paragraphs that belong
   * together, so the gaps inside a block are tighter than the gap between blocks. */
  .method-index h3 + p,
  .method-index h3 + p + p,
  .method-index h3 + p + p + p {
    margin-top: 0;
    margin-bottom: 0.35rem;
  }

  .method-index h3 + p {
    color: var(--md-default-fg-color--light);
    font-size: 0.95rem;
  }

  /* The nine-kinds table: the page's central artefact, and the hardest thing on it.
   *
   * Measured at 1280px before this: 662px wide with columns 116/184/210/142, so the
   * recognition column — the one the page tells a reader to read first — was about 18
   * characters and every cell wrapped to five lines in a 126px row. On a phone it was
   * 544px inside a 358px scroll box, 34% off screen. The A–Z in this book had the same
   * problem in 2026-10-27 and answered it with one card per method; this is the same
   * object and the more important one, so it gets the same two answers at once.
   *
   * **Above 60rem, a wider column.** The cap was not the screen: `.content` is held at
   * the 70ch prose measure, which is right for prose and wrong for a four-column table.
   * The content column grows for this page only — its paragraphs keep their measure
   * because `extra.css` scopes that rule to `> p, > ul, > ol, > blockquote` — and the
   * table takes the grid column's own width, capped at 56rem.
   *
   * **Below 60rem, one card per kind.** `wrap_tables` puts each cell's heading on the
   * cell as `data-label`, so a row can stack into labelled lines: the kind, then the
   * question, the model and the recognition line, each under its own name. Nothing is
   * off screen and no column name is lost with the header row. */
  @media (min-width: 60rem) {
    .content:has(.table-scroll > table.table--cards) {
      max-width: min(56rem, 100%);
    }

    /* The columns are the page's four questions, and each needs room for prose. A
     * fixed layout gives the recognition line the width it reads at — auto layout
     * spent it on the question column and left the column the page says to read
     * first at 218px, two short of the 220 the item asks for. Measured at 1280px,
     * these percentages of 56rem are 115 / 293 / 203 / 276, and the table is 887px
     * tall against 1,308px before. */
    .md-typeset table.table--cards {
      table-layout: fixed;
    }

    /* Priced, not guessed: 9 rows at 0.4em of cell padding is 887px, and the item asks
     * for a third off the table's 1,308px. A tenth of an em a side takes it to 858. */
    .md-typeset table.table--cards th,
    .md-typeset table.table--cards td {
      padding: 0.3em 0.5em;
    }

    .md-typeset table.table--cards th:nth-child(1),
    .md-typeset table.table--cards td:nth-child(1) { width: 13%; }

    .md-typeset table.table--cards th:nth-child(2),
    .md-typeset table.table--cards td:nth-child(2) { width: 34%; }

    .md-typeset table.table--cards th:nth-child(3),
    .md-typeset table.table--cards td:nth-child(3) { width: 22%; }

    .md-typeset table.table--cards th:nth-child(4),
    .md-typeset table.table--cards td:nth-child(4) { width: 32%; }
  }

  /* The phone card layout for `<!-- table: cards -->` is in `assets/stylesheets/extra.css`.
   *
   * It was written here first, for the nine-kinds grid, and living in this book's local
   * stylesheet meant the engine's marker did nothing in any other book: the class was
   * emitted, no rule matched, and a page that had been marked looked untouched. The
   * layout is a property of the marker, so it is shared. What stays here is what is about
   * *this* table — the wider content column and the four column widths above.
   */
}
