/* tuiscint.uk — WCAG 2.2 AAA.
 *
 * Every colour pair below was solved rather than eyeballed: `scratchpad/contrast.py` computes the
 * ratio and lightens/darkens the smallest amount that clears the bar. The original palette failed
 * six pairs, all between 5.19 and 6.92 — close enough to look fine and not be. AAA is 7:1 for body
 * text, 4.5:1 for large text (>=18.66px, or 14px bold), 3:1 for UI component boundaries (1.4.11).
 *
 * Themes are a 3-way choice plus auto, because a two-state toggle cannot express "follow the
 * system" — which is the setting a user with a contrast or light-sensitivity need has usually
 * already made once, at the OS level.
 */

:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --chunk: #12151b;
  --line: #262b36;        /* decorative rule */
  --line-ui: #6b6f77;     /* 3.06:1 on the CARD — the lighter, harder background */
  --ink: #e6e9ef;         /* 14.32:1 on panel */
  --dim: #9ca6b6;         /* 7.08:1 */
  --accent: #6aa6ff;      /* 7.06:1 */
  --ok: #47bc57;          /* 7.13:1 */
  --warn: #d39c29;        /* 7.09:1 */
  --bad: #fa827c;         /* 7.09:1 */
  --txt: #c8cfdb;
  --mark-bg: #4a3a00;
  --mark-fg: #ffd97a;
  --focus: #ffd166;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --chunk: #f7f9fb;
  --line: #d9dee5;
  --line-ui: #898d91;     /* 3.05:1 on the PAGE bg, the harder of the two */
  --ink: #1a1d23;         /* 16.88:1 */
  --dim: #4c535f;         /* 7.16:1 on the page bg */
  --accent: #094db3;      /* 7.12:1 */
  --ok: #106028;          /* 7.12:1 */
  --warn: #744b01;        /* 7.05:1 */
  --bad: #a40e26;         /* 7.87:1 */
  --txt: #24292f;
  --mark-bg: #fff2b2;
  --mark-fg: #2b2000;
  --focus: #8a4b00;
}

/* Pure black/white: 21:1 everywhere. For anyone who needs more than AAA gives. */
:root[data-theme="contrast"] {
  color-scheme: dark;
  --bg: #000000; --panel: #000000; --chunk: #000000;
  --line: #ffffff; --line-ui: #ffffff;
  --ink: #ffffff; --dim: #ffffff; --txt: #ffffff;
  --accent: #7fd4ff; --ok: #6dff8f; --warn: #ffd166; --bad: #ff9c96;
  --mark-bg: #ffffff; --mark-fg: #000000; --focus: #ffd166;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    color-scheme: light;
    --bg: #f4f6f9; --panel: #ffffff; --chunk: #f7f9fb;
    --line: #d9dee5; --line-ui: #898d91;
    --ink: #1a1d23; --dim: #4c535f; --accent: #094db3;
    --ok: #106028; --warn: #744b01; --bad: #a40e26; --txt: #24292f;
    --mark-bg: #fff2b2; --mark-fg: #2b2000; --focus: #8a4b00;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* 2.4.1 bypass blocks: the source list gets long, so a keyboard user needs a way past it. */
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 10;
  background: var(--panel); color: var(--ink); padding: 12px 18px;
  border: 2px solid var(--focus); border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 0 22px; }
header { border-bottom: 1px solid var(--line); padding: 20px 0 16px; margin-bottom: 22px; }
.bar { display: flex; gap: 18px; align-items: flex-start; justify-content: space-between;
       flex-wrap: wrap; }
h1 { margin: 0 0 4px; font-size: 20px; font-weight: 650; letter-spacing: -.2px; }
h2 { font-size: 17px; margin: 26px 0 8px; }
.tag { color: var(--dim); font-size: 14px; margin: 0; max-width: 52ch; }

/* --- theme switcher ---------------------------------------------------- */
.themes { display: flex; gap: 6px; border: 0; padding: 0; margin: 0; flex-wrap: wrap; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; min-width: 44px; padding: 0 12px;   /* 2.5.8 target size */
  background: transparent; color: var(--dim);
  border: 1px solid var(--line-ui); border-radius: 8px;
  font: inherit; font-size: 13px; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; stroke: currentColor; }
.icon-btn svg [fill="none"] { fill: none; }
.icon-btn:hover { color: var(--ink); }
/* State is carried by border weight and a filled background, never by colour alone (1.4.1). */
.icon-btn[aria-pressed="true"] {
  color: var(--ink); border-color: var(--accent); border-width: 2px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  font-weight: 650;
}
.btn-label { display: inline; }

/* --- form -------------------------------------------------------------- */
.ask { display: flex; gap: 10px; }
input[type=text] {
  flex: 1; min-height: 48px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line-ui); border-radius: 9px; padding: 12px 15px; font: inherit;
}
button.primary {
  min-height: 48px; padding: 0 22px; border: 1px solid transparent; border-radius: 9px;
  background: var(--accent); color: var(--bg); font: inherit; font-weight: 650; cursor: pointer;
}
:root[data-theme="contrast"] button.primary { color: #000; border-color: #fff; }
button.primary:disabled { opacity: .55; cursor: default; }

:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px;
}

.stat { color: var(--dim); font-size: 14px; margin: 8px 0 0; min-height: 1.4em; }

/* --- collapsible settings ---------------------------------------------- */
.settings { margin: 14px 0 0; border: 1px solid var(--line); border-radius: 10px;
            background: var(--panel); }
.settings > summary {
  cursor: pointer; padding: 12px 16px; min-height: 44px; display: flex; align-items: center;
  gap: 8px; font-weight: 650; font-size: 14px; color: var(--ink); list-style: none;
}
.settings > summary::-webkit-details-marker { display: none; }
.chev { display: inline-block; transition: transform .15s ease; color: var(--dim); }
details[open] > summary .chev { transform: rotate(90deg); }
/* Grouped, not a flat auto-fit grid. With one grid of nine unequal cells, rows size to the
   tallest cell in them, so a long help line left a hole beside every short one and the last
   control was stranded alone on a row. Grouping is also just true: these are three decisions
   (what to read, how to check it, how to decode), and `align-items: start` lets each column end
   where its content does. */
.grid { padding: 4px 16px 18px; display: grid; gap: 22px; align-items: start;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.group { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 16px; }
.group > legend { padding: 0; font-size: 11px; font-weight: 700; letter-spacing: .9px;
                  text-transform: uppercase; color: var(--dim); margin-bottom: 10px; }
.field { margin: 0; display: flex; flex-direction: column; gap: 5px; }
.field > label, .field.check label { font-size: 14px; font-weight: 600; }
.field.check > span:first-child { display: flex; align-items: center; gap: 9px;
                                  min-height: 32px; }
/* Numbers are short: a full-width box invites a paragraph and misreads as a text field. */
.field input[type=number] { max-width: 8.5rem; }
.radios { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.radios > legend { padding: 0; font-size: 14px; font-weight: 600; color: var(--ink);
                   text-transform: none; letter-spacing: 0; margin: 0 0 2px; }
.radio { display: flex; align-items: center; gap: 9px; min-height: 32px; }
.radio label { font-weight: 400; font-size: 14px; }
input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }


/* --- narrow screens ------------------------------------------------------
 * The desktop layout assumes a wide row for the ask box and three columns of settings; neither
 * survives a phone. Sizes stay at 16px so iOS does not zoom the viewport on focus, and targets
 * stay at 44px because a demo people open on a phone is one they tap rather than click. */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .wrap { padding: 0 14px; }
  .bar { flex-direction: column; gap: 12px; }
  .themes { width: 100%; }
  .icon-btn { flex: 1; justify-content: center; padding: 0 8px; }
  .btn-label { display: none; }              /* icons carry it; each keeps its sr-only name */
  .ask { flex-direction: column; }           /* a side-by-side button leaves ~40% for the question */
  input[type=text], button.primary { width: 100%; font-size: 16px; }
  .grid { grid-template-columns: 1fr; gap: 20px; }
  .group { gap: 14px; }
  .field input[type=number], select { max-width: none; width: 100%; font-size: 16px; }
  .card { padding: 14px; border-radius: 10px; }
  .answer { font-size: 17px; }
  .src .txt { max-height: 220px; }           /* less horizontal room, so allow more vertical */
  /* A five-column table cannot fit; let it scroll rather than crush every cell to one word. */
  table.dbg { display: block; overflow-x: auto; white-space: nowrap; }
  table.dbg code { white-space: normal; }
  .eg { width: 100%; text-align: left; }
  footer p { max-width: none; }
}
.help { color: var(--dim); font-size: 13px; line-height: 1.45; }
select, input[type=number] {
  min-height: 44px; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line-ui); border-radius: 7px; padding: 8px 10px; font: inherit;
  font-size: 15px;
}
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }

.egs { margin: 14px 0 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
       color: var(--dim); font-size: 14px; }
.eg-row { display: flex; gap: 8px; flex-wrap: wrap; }
.eg {
  min-height: 44px; background: transparent; color: var(--ink);
  border: 1px solid var(--line-ui); border-radius: 99px; padding: 6px 15px;
  font: inherit; font-size: 14px; cursor: pointer;
}
.eg:hover { border-color: var(--accent); }

/* --- results ----------------------------------------------------------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
        padding: 16px 18px; margin: 18px 0; }
.card > h2 { margin: 0 0 10px; font-size: 12px; letter-spacing: .8px; text-transform: uppercase;
             color: var(--dim); font-weight: 700; }
.answer { font-size: 18px; line-height: 1.55; }
/* Badges pair a word with a symbol: colour alone must never carry meaning (1.4.1). */
.badge { display: inline-block; font-size: 13px; padding: 3px 10px; border-radius: 99px;
         font-weight: 650; margin-left: 8px; vertical-align: middle; border: 1px solid; }
.b-ok { color: var(--ok); border-color: var(--ok);
        background: color-mix(in srgb, var(--ok) 12%, transparent); }
.b-warn { color: var(--warn); border-color: var(--warn);
          background: color-mix(in srgb, var(--warn) 12%, transparent); }
.b-bad { color: var(--bad); border-color: var(--bad);
         background: color-mix(in srgb, var(--bad) 12%, transparent); }
.froms { margin-top: 10px; font-size: 14px; color: var(--dim); }
.froms a, .src a { color: var(--accent); }
.veto { border-left: 4px solid var(--warn); padding-left: 13px; margin-top: 14px; }
.veto .lbl { color: var(--warn); font-size: 12px; font-weight: 700; text-transform: uppercase;
             letter-spacing: .6px; }
.src { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; margin-bottom: 10px;
       background: var(--chunk); }
.src .meta { display: flex; gap: 12px; color: var(--dim); font-size: 13px; margin-bottom: 7px;
             flex-wrap: wrap; align-items: baseline; }
.src .dom { color: var(--ink); font-weight: 650; font-size: 14px; }
.src .txt { white-space: pre-wrap; font-size: 14px; color: var(--txt); max-height: 170px;
            overflow: auto; }
.src.cited { border-color: var(--warn); border-width: 2px; }
mark { background: var(--mark-bg); color: var(--mark-fg); border-radius: 3px; padding: 0 3px;
       font-weight: 600; }
details.card > summary { cursor: pointer; font-weight: 650; font-size: 14px; min-height: 44px;
                         display: flex; align-items: center; gap: 8px; list-style: none;
                         color: var(--ink); }
details.card > summary::-webkit-details-marker { display: none; }
table.dbg { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
table.dbg td, table.dbg th { border-top: 1px solid var(--line); padding: 8px; vertical-align: top;
                             text-align: left; }
table.dbg th { color: var(--dim); font-weight: 700; font-size: 12px; text-transform: uppercase;
               letter-spacing: .5px; border-top: 0; }
table.dbg td.dk { color: var(--dim); white-space: nowrap; width: 1%; }
table.dbg code { color: var(--txt); word-break: break-word; }
.won td { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.hint { color: var(--dim); font-size: 14px; margin-top: 8px; }
.err { color: var(--bad); }
footer { color: var(--dim); font-size: 15px; padding-bottom: 60px; }
footer p { margin: 10px 0; max-width: 70ch; }
.gloss { padding-left: 14px; border-left: 3px solid var(--line-ui); }
.gloss b { color: var(--ink); font-size: 17px; font-weight: 650; }
.ipa { color: var(--dim); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }
.say { color: var(--dim); }
.colophon { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.colophon a { color: var(--accent); }
footer strong, footer em { color: var(--ink); }

.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--line-ui);
        border-top-color: var(--accent); border-radius: 50%; animation: s .7s linear infinite;
        vertical-align: -2px; margin-right: 6px; }
@keyframes s { to { transform: rotate(360deg); } }
/* 2.3.3 — honour a stated preference for less motion. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .spin { animation: none; border-top-color: var(--ink); }
}

/* Signpost: the one card that is neither an answer nor an error. Border in the accent so it
   reads as deliberate; plain text, large tap targets on the numbers. */
.card.signpost { border-color: var(--accent); border-width: 2px; }
.card.signpost p { margin: 0 0 12px; font-size: 16px; line-height: 1.5; }
.helplines { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.helplines li { font-size: 16px; line-height: 1.5; }
.helplines a { color: var(--accent); font-weight: 600; text-decoration: underline;
               text-underline-offset: 3px; padding: 4px 0; display: inline-block; }
.helplines .note { color: var(--dim); font-size: 14px; }

/* The two always-visible lines under the input. .scope is quiet, like .stat; .notice is not
   dimmed -- the numbers in it are the point, and they must clear contrast on every theme. */
.scope { color: var(--dim); font-size: 14px; margin: 4px 0 0; }
.scope a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
