/* Phone tables: every table marked .ts-stack becomes a stack of cards on a
   narrow screen, so nothing scrolls sideways. Desktop and print keep the
   table. Cell labels come from each cell's data-label (its column header),
   written into the HTML (scripts/table-stack.mjs) or added at render time
   for tables built in the browser. Colors follow the page's own text color,
   so the same file works on ink and paper pages. */

@media screen and (max-width: 640px) {
  table.ts-stack {
    --ts-line: rgba(128, 128, 128, .38);
    --ts-line: color-mix(in srgb, currentColor 20%, transparent);
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    table-layout: auto !important;
  }
  table.ts-stack caption { display: block; text-align: left; margin-bottom: 10px; }
  /* Headers move into each cell's label, so the header row is hidden but still read. */
  table.ts-stack thead,
  table.ts-stack tr.ts-hrow {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    border: 0 !important;
  }
  table.ts-stack tbody,
  table.ts-stack tfoot { display: block !important; width: 100% !important; }
  table.ts-stack tr {
    display: block;
    margin: 0 0 12px;
    padding: 4px 16px 10px;
    border: 1px solid var(--ts-line);
    background: transparent;
    break-inside: avoid;
  }
  table.ts-stack tbody tr:last-child { margin-bottom: 0; }
  table.ts-stack tr:hover { background: transparent; }
  table.ts-stack td,
  table.ts-stack th {
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    position: static !important;
    padding: 9px 0 !important;
    border: 0 !important;
    border-top: 1px solid var(--ts-line) !important;
    background: transparent !important;
    text-align: left !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  /* The first cell names the row, so it reads as the card's title. */
  table.ts-stack tr > :first-child {
    border-top: 0 !important;
    padding-top: 10px !important;
    font-weight: 600;
    font-size: 1.04em;
  }
  table.ts-stack [data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    font-family: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10.5px;
    font-weight: 400;
    line-height: 1.35;
    letter-spacing: .08em;
    text-transform: uppercase;
    opacity: .78;
  }
  table.ts-stack td:empty:not([contenteditable]) { display: none !important; }
  /* A blank row left to fill in on paper would be an empty card here. */
  table.ts-stack tbody tr:not(:has(> :not(:empty))):not(:has([contenteditable])) { display: none; }
  /* Cells you can type into keep a visible place to tap. */
  table.ts-stack td[contenteditable] { min-height: 2.6em; border-bottom: 1px dashed var(--ts-line) !important; }
  /* Sortable tables keep their header buttons, laid out as a row of chips. */
  table.ts-sort thead {
    position: static !important;
    display: block !important;
    width: auto !important;
    height: auto !important;
    margin: 0 0 12px !important;
    overflow: visible !important;
    clip: auto !important;
  }
  table.ts-sort thead tr {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: 0;
  }
  table.ts-sort thead th {
    display: block !important;
    padding: 0 !important;
    border: 1px solid var(--ts-line) !important;
    border-top: 1px solid var(--ts-line) !important;
    font-size: 11px !important;
  }
  table.ts-sort thead th button { display: block; min-height: 36px; padding: 6px 10px; }
  /* Academy lessons show one row per operating system. Keep their show/hide. */
  html[data-os="mac"] table.ts-stack tr[data-os~="mac"],
  html[data-os="win"] table.ts-stack tr[data-os~="win"],
  html[data-os="wsl"] table.ts-stack tr[data-os~="wsl"] { display: block; }
  /* The table no longer needs a sideways scroller around it. */
  .ts-wrap-fit { overflow: visible !important; border: 0 !important; }
}
