/* mathspeak.
 *
 * Built to be read by someone with low vision, so the defaults are the accessible ones
 * rather than a mode you switch into: 20px base type that scales from --scale, contrast
 * well above WCAG AA in both themes, focus that is always visible, and no animation that
 * a reader has to wait out.  Nothing here is decorative enough to be worth a trade.
 */

:root {
  --scale: 1;
  --bg: #ffffff;
  --fg: #14161a;
  --muted: #4a5058;
  --line: #c9ced6;
  --card: #f6f7f9;
  --accent: #0b4fa8;         /* 8.6:1 on white */
  --accent-fg: #ffffff;
  --warn-bg: #fdf4e3;
  --warn-line: #a8700b;
  --error-bg: #fdeceb;
  --error-line: #a81f16;
  --focus: #0b4fa8;
  --radius: 8px;
}

:root[data-theme="dark"], :root:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --fg: #eef1f5;
    --muted: #aeb6c2;
    --line: #39404b;
    --card: #1a1e24;
    --accent: #8ab4f8;       /* 8.4:1 on #111317 */
    --accent-fg: #10141a;
    --warn-bg: #2b2413;
    --warn-line: #e3b341;
    --error-bg: #2d1715;
    --error-line: #f08a80;
    --focus: #8ab4f8;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111317;
  --fg: #eef1f5;
  --muted: #aeb6c2;
  --line: #39404b;
  --card: #1a1e24;
  --accent: #8ab4f8;
  --accent-fg: #10141a;
  --warn-bg: #2b2413;
  --warn-line: #e3b341;
  --error-bg: #2d1715;
  --error-line: #f08a80;
  --focus: #8ab4f8;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  /* The page's own text-size control multiplies the browser's setting rather than
     replacing it, so someone who has already set a large default keeps it. */
  font-size: calc(20px * var(--scale));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.65;
}

/* Focus is never removed, only made clearer. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute;
  left: -9999px;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 0.75rem 1rem;
  z-index: 10;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

a { color: var(--accent); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  border-bottom: 2px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--fg);
}
.controls { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.group { display: flex; align-items: center; gap: 0.35rem; }
.group-label { color: var(--muted); font-size: 0.85rem; }

button, select {
  font: inherit;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--fg);
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
button:hover:not(:disabled), select:hover { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.chip { padding: 0.3rem 0.6rem; font-size: 0.9rem; }

.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
  padding: 0.6rem 1.2rem;
}

main { padding: 1.5rem 1.25rem 3rem; }
main:focus { outline: none; }

.wrap { max-width: 62rem; margin: 0 auto; }

h1 { font-size: 1.9rem; line-height: 1.25; margin: 0.5rem 0 0.75rem; }
h2 { font-size: 1.3rem; line-height: 1.3; margin: 0 0 0.5rem; }

.lede { font-size: 1.05rem; color: var(--fg); max-width: 44rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.25rem 0;
}

.field { margin: 1.25rem 0; border: 0; padding: 0; }
.field > label, legend { display: block; font-weight: 600; margin-bottom: 0.35rem; }
input[type="file"] {
  font: inherit;
  width: 100%;
  padding: 0.6rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}

.radio { display: flex; gap: 0.6rem; align-items: flex-start; margin: 0.5rem 0; }
.radio input { margin-top: 0.45rem; width: 1.1rem; height: 1.1rem; }
.radio label { display: block; }
.radio .hint { display: block; }

.notice {
  border-left: 6px solid var(--warn-line);
  background: var(--warn-bg);
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  margin: 1.25rem 0;
}
.notice.error { border-left-color: var(--error-line); background: var(--error-bg); }
.notice p { margin: 0.4rem 0 0; }
.notice.small { font-size: 0.9rem; padding: 0.6rem 0.9rem; margin: 0.75rem 0; }
.notice ul { margin: 0; padding-left: 1.2rem; }

pre {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.7rem 0.85rem;
  margin: 0;
  overflow-x: auto;       /* long formulas scroll here, never the page */
  white-space: pre-wrap;
  word-break: break-word;
}

.tabs { display: flex; gap: 0.5rem; margin: 1.5rem 0 0; flex-wrap: wrap; }
.tab { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}

.player { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.player .status { flex-basis: 100%; margin: 0; color: var(--muted); min-height: 1.5rem; }
.inline { font-weight: 600; }

.reading { list-style: none; padding: 0; margin: 1rem 0 0; }
.passage {
  padding: 0.7rem 0.9rem;
  border-left: 6px solid transparent;
  border-radius: var(--radius);
  margin: 0.3rem 0;
  scroll-margin: 6rem;
}
.passage.formula {
  border-left-color: var(--accent);
  background: var(--card);
  font-size: 1.02rem;
}
.passage.speaking {
  background: var(--warn-bg);
  border-left-color: var(--warn-line);
  font-weight: 600;
}
.tag {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-right: 0.5rem;
}

.formula .meta { display: block; font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.formats { margin: 0.75rem 0 0; }
.format { margin: 0.9rem 0; }
.format dt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.format dd { margin: 0; }

.foot { border-top: 2px solid var(--line); border-bottom: 0; color: var(--muted); font-size: 0.9rem; }
.foot p { margin: 0; }
.foot-note { color: var(--muted); font-size: 0.9rem; margin-top: 2rem; }

@media (prefers-reduced-motion: no-preference) {
  .passage { transition: background-color 120ms linear; }
}

/* ------------------------------------------------------------------ conversion
 * A long paper takes seconds, and seconds of a blank page read the same as a lost
 * request.  The bar is a real <progress>, so a screen reader can query it, and the
 * message beside it is coarse -- announcing every page of a forty-page paper would be
 * worse than announcing nothing.
 */
.working { margin-top: 1.25rem; }
.working[hidden] { display: none; }

progress {
  width: 100%;
  height: 1.5rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--bg); border-radius: 6px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 6px; }
progress::-moz-progress-bar { background: var(--accent); }

.working .status {
  margin: 0.5rem 0 0.75rem;
  color: var(--fg);
  font-weight: 600;
  min-height: 1.6rem;
}

/* The button says what it is doing rather than just going grey. */
button.busy { opacity: 1; }
button.busy::after {
  content: "";
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 0.6em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.05em;
}
@media (prefers-reduced-motion: no-preference) {
  button.busy::after { animation: spin 0.8s linear infinite; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------- samples
 * Papers to try.  Each is a heading and a link rather than a button, because that is
 * what it is -- a link off to arXiv -- and because a list of headings is something a
 * screen reader can jump through.
 */
.paper-list { list-style: none; padding: 0; margin: 1rem 0 0; }

.paper {
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}
.paper:first-child { border-top: 0; padding-top: 0.25rem; }

.paper h3 { font-size: 1.05rem; line-height: 1.35; margin: 0 0 0.2rem; }
.paper p { margin: 0.3rem 0 0; }

.byline { color: var(--muted); font-size: 0.9rem; }

.caveat {
  font-size: 0.9rem;
  border-left: 4px solid var(--warn-line);
  background: var(--warn-bg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}
