/* TableSync Codex (RM843) - the app's own styles, after css/apps/shell.css. Graphite (DESIGN.md): tokens only, radius 0,
 * no shadow, blur, glow or gradient; Spectral reads, IBM Plex Sans operates, IBM Plex Mono measures.
 *
 * THE ACCENT, SPENT ONCE PER VIEW: the open record's row - a marginal pilcrow and the accent wash, the Player's
 * rubrication (DESIGN.md "The accent as rubrication"). Nothing else here takes --aa-accent; the focus ring is the
 * brand's own (tokens.css) and is not a second role.
 *
 * TEXT SIZE: Settings > Text size writes the Player's own preference (js/player/prefs.js), which stamps
 * html[data-text]; the two sizes below are the RM824 exception DESIGN.md records for the Player (only ever larger
 * than the device default). CONTRAST: html[data-contrast="high"] re-points the body and muted inks at the full ink
 * and the hairline at the rule - token to token, no new value. */

:root { --cx-list-w: 400px; }
html[data-text="large"] { font-size: 112.5%; }
html[data-text="larger"] { font-size: 125%; }
:root[data-contrast="high"] {
  --aa-ink-body: var(--aa-ink);
  --aa-ink-muted: var(--aa-ink);
  --aa-hairline: var(--aa-rule);
}
:root[data-contrast="high"][data-theme="dark"] { --aa-ground: var(--aa-recess); }
@media (prefers-color-scheme: dark) {
  :root[data-contrast="high"]:not([data-theme]) { --aa-ground: var(--aa-recess); }
}

/* shell.css's `.tf-app button` (padding 8px 16px, 14px type) outranks its own `.tf-tab` rule, so the tab labels were
   pushed out of the bar and cut ("Mons"); put the tab's own values back. Recorded for the lead as a shell.css bug. */
.tf-app .tf-tab { padding: 0 2px; font-size: var(--t-meta); font-weight: 400; line-height: 1.2; min-height: 44px; }
@media (min-width: 600px) { .tf-app .tf-tab { font-size: var(--t-ui); } }

/* ---------------- masthead: the search field lives in the title row on the Search tab ---------------- */
.cx-q-wrap { display: none; flex: 1 1 auto; min-width: 0; position: relative; align-items: center; }
.cx-q-wrap > svg { position: absolute; left: 12px; top: 50%; margin-top: -10px; width: 20px; height: 20px;
                   color: var(--aa-ink-muted); pointer-events: none; }
.tf-app input.cx-q { padding-left: 42px; padding-right: 48px; font-size: var(--t-body); background: var(--aa-recess); }
/* the browser's own clear glyph is a system colour; the Codex draws its own (Graphite) */
.tf-app input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.tf-app .cx-q-clear { position: absolute; right: 0; top: 0; bottom: 0; color: var(--aa-ink-muted); }
body.cx-on-search .cx-q-wrap { display: flex; }
body.cx-on-search .tf-title { display: none; }
.tf-app .cx-icon-btn { min-width: 44px; min-height: 44px; padding: 0; border-color: transparent; }
.cx-icon-btn svg { width: 22px; height: 22px; }
.tf-app .tf-actions .cx-icon-btn { min-height: 44px; padding: 0; }

/* ---------------- panes: the list column, and the reader beside it from 720 px ---------------- */
.cx-reader {
  position: fixed; left: 0; right: 0; z-index: 30;
  top: calc(var(--tf-top-h) + var(--tf-safe-t));
  bottom: calc(var(--tf-tabs-h) + var(--tf-safe-b));
  background: var(--aa-ground); display: flex; flex-direction: column;
}
.cx-reader[hidden] { display: none !important; }
/* each pane is its own layout root: a keystroke's new results never re-lay the masthead, the tabs or the reader */
.tf-app .tf-pane, .cx-reader { contain: strict; }
@media (min-width: 720px) {
  :root { --cx-list-w: min(42vw, 440px); }
  .tf-app .tf-panes { right: auto; width: var(--cx-list-w); border-right: 1px solid var(--aa-rule); }
  .cx-reader { left: var(--cx-list-w); z-index: 10; }
}
@media (min-width: 1100px) { :root { --cx-list-w: 460px; } }

.cx-rd-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-1) var(--tf-gutter); border-bottom: 1px solid var(--aa-hairline); background: var(--aa-sheet);
  min-height: 56px;
}
.cx-rd-title {
  flex: 1 1 auto; min-width: 0; margin: 0; font-family: var(--aa-read); font-weight: 400; font-size: var(--t-4);
  color: var(--aa-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none;
}
.cx-rd-scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--s-3) var(--tf-gutter) var(--s-8); }
.cx-rd-kind { margin: 0 0 var(--s-2); font-family: var(--aa-measure); font-size: var(--t-meta); letter-spacing: .12em;
              text-transform: uppercase; color: var(--aa-ink-muted); }
.cx-rd-empty { padding: var(--s-6) 0; max-width: var(--aa-prose); }
.cx-printings { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: 0 0 var(--s-3); }
.cx-from-link { margin: 0 0 var(--s-3); }

/* ---------------- rows: the ruled roster of the Ledger register ---------------- */
.cx-rows { border-top: 1px solid var(--aa-hairline); }
.tf-app .cx-row {
  display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: 2px;
  width: 100%; min-height: 56px; margin: 0; padding: var(--s-2) var(--s-2) var(--s-2) 22px;
  background: none; border: none; border-bottom: 1px solid var(--aa-hairline); border-radius: 0;
  text-align: left; color: var(--aa-ink-body); font-weight: 400; position: relative;
}
.tf-app .cx-row:hover { background: var(--aa-sheet); border-color: var(--aa-hairline); }
.tf-app .cx-row:active { background: var(--aa-recess); }
.cx-row-top { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; }
.cx-row-name { flex: 1 1 auto; min-width: 0; font-family: var(--aa-read); font-size: var(--t-body); color: var(--aa-ink);
               overflow-wrap: anywhere; line-height: 1.3; }
.cx-row-src { flex: 0 0 auto; font-family: var(--aa-measure); font-size: var(--t-meta); color: var(--aa-ink-muted); }
.cx-row-meta { font-size: var(--t-ui); color: var(--aa-ink-muted); line-height: 1.35; overflow-wrap: anywhere; }
/* the one accent: the open record */
.tf-app .cx-row.open { background: var(--aa-accent-wash); }
.cx-row.open::before {
  content: '\00B6'; position: absolute; left: 4px; top: var(--s-2); font-family: var(--aa-read);
  font-size: var(--t-body); line-height: 1.3; color: var(--aa-accent);
}
.cx-listitem { display: flex; align-items: stretch; border-bottom: 1px solid var(--aa-hairline); }
.cx-listitem .cx-row { border-bottom: none; flex: 1 1 auto; }
.cx-listitem .cx-gone { flex: 1 1 auto; margin: 0; padding: var(--s-3) 0 var(--s-3) 22px; }
.tf-app .cx-rm { flex: 0 0 auto; align-self: center; }

.cx-group { margin: 0 0 var(--s-5); }
/* results below the fold are not laid out until they scroll near (a keystroke repaints ~50 rows; the screen shows ~10) */
.cx-group, .cx-home-sec { content-visibility: auto; contain-intrinsic-size: auto 360px; }
.cx-browse-list > .cx-row { content-visibility: auto; contain-intrinsic-size: auto 60px; }
.cx-group-h, .cx-list-h, .cx-chapter-h {
  display: flex; align-items: baseline; gap: var(--s-2); margin: var(--s-4) 0 var(--s-2);
  font-family: var(--aa-read); font-weight: 600; font-size: var(--t-body); color: var(--aa-ink);
}
.cx-chapter-h { font-weight: 400; font-size: var(--t-3); margin-top: var(--s-2); }
.cx-list-h { margin: var(--s-4) 0 0; padding: var(--s-2) 0; border-bottom: 1px solid var(--aa-rule); }
.cx-count { font-family: var(--aa-measure); font-weight: 400; font-size: var(--t-meta); color: var(--aa-ink-muted); }
.tf-app .cx-more-btn { width: 100%; justify-content: flex-start; padding-left: 22px; }
.cx-status { min-height: 1.2em; margin: 0 0 var(--s-2); font-size: var(--t-ui); color: var(--aa-ink-muted); }
.cx-status:empty { margin: 0; min-height: 0; }
.cx-teach { margin: var(--s-2) 0 var(--s-3); }
.cx-noresults { margin-top: var(--s-3); }
.cx-failed { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-3); }
.cx-more { height: 1px; }

/* ---------------- Search home ---------------- */
.cx-home-sec { margin: 0 0 var(--s-5); }
.cx-sec-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.cx-sec-head .cx-group-h { margin-bottom: var(--s-2); }
.cx-browse { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.tf-app .cx-browse .tf-btn { justify-content: flex-start; text-align: left; }
.cx-inline-form { display: flex; gap: var(--s-2); align-items: stretch; margin: 0 0 var(--s-2); }
.cx-inline-form > input, .cx-inline-form > select { flex: 1 1 auto; min-width: 0; width: auto; }
.cx-inline-form > .tf-btn { flex: 0 0 auto; }
.tf-app .cx-up { padding-left: 0; }

/* ---------------- browse toolbars ---------------- */
.cx-toolbar { display: flex; gap: var(--s-2); align-items: stretch; margin: 0 0 var(--s-2); }
.cx-filter-btn svg { width: 20px; height: 20px; }
.cx-sort { flex: 1 1 auto; min-width: 0; display: flex; }
.cx-sort select { flex: 1 1 auto; }
.cx-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tf-app input.cx-namefilter { margin: 0 0 var(--s-2); }
.cx-active { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.cx-active:empty { display: none; }
.cx-active-text { flex: 1 1 auto; min-width: 0; font-size: var(--t-ui); color: var(--aa-ink-body); }

/* ---------------- chips (filters, settings, printings): pressed is filled ink, never the accent ---------------- */
.cx-fs { border: none; margin: 0 0 var(--s-4); padding: 0; min-width: 0; }
.cx-legend { padding: 0; margin: 0 0 var(--s-2); font-size: var(--t-ui); font-weight: 600; color: var(--aa-ink); }
.cx-chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.tf-app .cx-chip { min-height: 44px; padding: var(--s-2) var(--s-3); font-weight: 400; color: var(--aa-ink-body); }
.tf-app .cx-chip.on { background: var(--aa-ink); color: var(--aa-ground); border-color: var(--aa-ink); }
.cx-pair { display: flex; gap: var(--s-3); }
.cx-pair-l { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--s-1); }
.cx-pair-k { font-size: var(--t-ui); color: var(--aa-ink-muted); }
.cx-filter-foot { position: sticky; bottom: calc(-1 * var(--s-5)); background: var(--aa-sheet); border-top: 1px solid var(--aa-hairline);
                  padding: var(--s-2) 0 var(--s-3); margin-top: var(--s-2); }
.cx-filter-foot .tf-row { margin: var(--s-2) 0 0; flex-wrap: nowrap; }
.cx-filter-foot .tf-row > .tf-btn { flex: 1 1 0; }
.cx-filter-count { margin: 0; font-size: var(--t-ui); color: var(--aa-ink-muted); }
.tf-app .cx-pin-toggle { justify-content: flex-start; }
.tf-app .cx-pin-toggle.on { background: var(--aa-ink); color: var(--aa-ground); border-color: var(--aa-ink); }

/* ---------------- the record ---------------- */
.cx-rec { max-width: 46rem; }
.cx-sub { margin: 0 0 var(--s-3); font-size: var(--t-ui); color: var(--aa-ink-muted); }
.cx-facts { border-top: 1px solid var(--aa-rule); border-bottom: 1px solid var(--aa-rule); padding: var(--s-2) 0; margin: 0 0 var(--s-3); }
.cx-kv { display: flex; gap: var(--s-2); padding: 2px 0; line-height: 1.5; }
.cx-k { flex: 0 0 auto; font-weight: 600; color: var(--aa-ink); font-size: var(--t-ui); padding-top: 1px; }
.cx-v { flex: 1 1 auto; min-width: 0; color: var(--aa-ink-body); font-size: var(--t-ui); overflow-wrap: anywhere; }
.cx-classes { display: flex; gap: var(--s-2); margin: var(--s-3) 0 0; padding-top: var(--s-2); border-top: 1px solid var(--aa-hairline); }
.cx-p { font-family: var(--aa-read); font-size: var(--t-body); line-height: 1.6; color: var(--aa-ink-body); margin: 0 0 var(--s-3);
        max-width: var(--aa-prose); overflow-wrap: break-word; }
.cx-runin { font-weight: 600; color: var(--aa-ink); }
.cx-note { color: var(--aa-ink-muted); }
.cx-caption { margin: var(--s-3) 0 var(--s-1); font-weight: 600; color: var(--aa-ink); font-size: var(--t-ui); }
.cx-sec { margin: var(--s-4) 0 0; }
.cx-h { margin: 0 0 var(--s-2); padding-bottom: var(--s-1); border-bottom: 1px solid var(--aa-rule);
        font-family: var(--aa-read); font-weight: 400; font-size: var(--t-4); color: var(--aa-ink); }
.cx-feat-h { margin: var(--s-4) 0 var(--s-1); font-family: var(--aa-read); font-weight: 600; font-size: var(--t-body); color: var(--aa-ink); }
.cx-feat-lv { font-family: var(--aa-measure); font-weight: 400; font-size: var(--t-meta); color: var(--aa-ink-muted);
              letter-spacing: .04em; margin-right: var(--s-1); }
.cx-source { margin: var(--s-5) 0 0; padding-top: var(--s-2); border-top: 1px solid var(--aa-hairline);
             font-family: var(--aa-measure); font-size: var(--t-meta); color: var(--aa-ink-muted); letter-spacing: .04em; }
.cx-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }
/* the drop cap of the Ledger register, on prose that opens with prose */
.cx-k-condition > .cx-p:first-of-type::first-letter, .cx-k-rule > .cx-p:first-of-type::first-letter,
.cx-spell-text > .cx-p:first-child::first-letter, .cx-item-text > .cx-p:first-child::first-letter {
  float: left; font-family: var(--aa-read); font-size: var(--t-1); line-height: .9; padding: 4px 6px 0 0; color: var(--aa-ink);
}

/* the stat block: the six scores */
.cx-abil { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; margin: 0 0 var(--s-3);
           border-bottom: 1px solid var(--aa-rule); padding-bottom: var(--s-2); }
.cx-ab { text-align: center; padding: var(--s-1) 0; }
.cx-ab-k { font-family: var(--aa-measure); font-size: var(--t-meta); letter-spacing: .08em; color: var(--aa-ink-muted); }
.cx-ab-s { font-family: var(--aa-measure); font-size: var(--t-4); color: var(--aa-ink); line-height: 1.2; }
.cx-ab-m { font-family: var(--aa-measure); font-size: var(--t-ui); color: var(--aa-ink-body); }
.cx-sb-top { border-bottom: none; margin-bottom: 0; }
.cx-spellblock .cx-spl { list-style: none; margin: 0 0 var(--s-3); padding: 0 0 0 var(--s-3); border-left: 1px solid var(--aa-hairline); }
.cx-spl li { font-family: var(--aa-read); font-size: var(--t-body); line-height: 1.6; color: var(--aa-ink-body); }
.cx-spl-k { font-family: var(--aa-operate); font-size: var(--t-ui); color: var(--aa-ink-muted); }

/* links and dice inside running text. A cross-reference is an inline <a> (it wraps with its sentence); a die is a
   small inline-block button. Both reach past their glyphs with an invisible ::after, so the thumb gets a taller target
   without the line spacing changing - inline targets inside prose (WCAG 2.5.8's inline exception). */
.cx-ref {
  color: var(--aa-ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  text-decoration-color: var(--aa-ink-muted); position: relative; cursor: pointer;
}
.cx-ref:hover { text-decoration-color: var(--aa-ink); background: var(--aa-recess); }
.tf-app .cx-inline {
  display: inline-block; min-height: 0; min-width: 0; margin: 0; padding: var(--s-1) 0; border: none; border-radius: 0;
  background: none; font-family: var(--aa-measure); font-size: inherit; font-weight: 400; line-height: 1.2; color: var(--aa-ink);
  cursor: pointer; position: relative; vertical-align: baseline;
  text-decoration: underline; text-decoration-style: dashed; text-decoration-thickness: 1px; text-underline-offset: 3px;
  text-decoration-color: var(--aa-ink-muted);
}
.tf-app .cx-inline:hover { background: var(--aa-recess); border: none; }
.cx-ref::after, .tf-app .cx-inline::after { content: ''; position: absolute; left: -2px; right: -2px; top: -9px; bottom: -9px; }

/* tables: one horizontal scroller each, never a vertical one (DESIGN.md 6a) */
.cx-table-wrap { overflow-x: auto; overflow-y: hidden; margin: 0 0 var(--s-3); max-width: 100%; }
.cx-table { border-collapse: collapse; font-size: var(--t-ui); color: var(--aa-ink-body); min-width: 100%; }
.cx-table th, .cx-table td { text-align: left; vertical-align: top; padding: var(--s-1) var(--s-2); border-bottom: 1px solid var(--aa-hairline); }
.cx-table thead th { color: var(--aa-ink); font-weight: 600; border-bottom: 1px solid var(--aa-rule); white-space: nowrap; }
.cx-table tbody th { color: var(--aa-ink); font-weight: 400; white-space: nowrap; }
.cx-table .tf-num { font-family: var(--aa-measure); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cx-level td.cx-level-f { min-width: 12rem; }
.cx-table tr.cx-hit th, .cx-table tr.cx-hit td { background: var(--aa-recess); color: var(--aa-ink); font-weight: 600; }
.tf-app .cx-roll-on { margin: 0 0 var(--s-3); }

/* ---------------- the roll card (above the tabs, like the toast, but it can be answered) ---------------- */
#cxRoll {
  position: fixed; left: var(--tf-gutter); right: var(--tf-gutter); z-index: 85;
  bottom: calc(var(--tf-tabs-h) + var(--tf-safe-b) + var(--s-3));
  background: var(--aa-sheet); border: 1px solid var(--aa-rule); padding: var(--s-3) var(--s-4); display: none;
}
#cxRoll.show { display: block; }
@media (min-width: 720px) { #cxRoll { left: auto; width: 380px; } }
.cx-roll-head { display: flex; justify-content: space-between; gap: var(--s-2); color: var(--aa-ink-muted); font-size: var(--t-ui); }
.cx-roll-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-roll-expr { font-family: var(--aa-measure); }
.cx-roll-body { display: flex; align-items: baseline; gap: var(--s-3); margin: var(--s-1) 0; }
.cx-roll-total { font-family: var(--aa-measure); font-size: var(--t-2); color: var(--aa-ink); line-height: 1.1; }
.cx-roll-faces { font-family: var(--aa-measure); font-size: var(--t-ui); color: var(--aa-ink-body); overflow-wrap: anywhere; }
.cx-roll-nat { font-family: var(--aa-measure); font-size: var(--t-meta); letter-spacing: .12em; text-transform: uppercase; color: var(--aa-ok); }
.cx-roll-row { display: flex; gap: var(--s-2); justify-content: flex-end; }

/* the Player's dice tray (js/player/dicetray.js builds it; css/player.css styles it there) */
#diceTray { position: fixed; inset: 0; z-index: 400; touch-action: none; cursor: pointer; }
#diceTray[hidden] { display: none; }
#diceTray canvas { display: block; }
body.tray-on #cxRoll, body.tray-on #tfToast { visibility: hidden; }

.cx-share .tf-btn { justify-content: flex-start; }
.cx-copy { margin-top: var(--s-3); }

@media (max-width: 380px) {
  .cx-browse { grid-template-columns: 1fr; }
  .cx-ab-s { font-size: var(--t-body); }
}
@media (prefers-reduced-motion: reduce) {
  .tf-app .cx-row { transition: none; }
}
