/* Matrix Lab — Apple-minimal, self-contained (shares the site's
   token values from app-style.css; tools with their own style.css do not
   get the shared sheet, so the tokens and the classes this page uses are
   duplicated here). */
:root {
  color-scheme: light;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
  --canvas: #f5f5f7;
  --surface: #fff;
  --recessed: #f5f5f7;
  --ink: #1d1d1f;
  --muted: #65656b;
  --line: rgb(0 0 0 / .06);
  --control-line: rgb(0 0 0 / .14);
  --selected: rgb(0 0 0 / .075);
  --accent: #0071e3;
  --accent-hover: #0065cc;
  --accent-ink: #fff;
  --motion: .2s cubic-bezier(.16, 1, .3, 1);
  color: var(--ink);
  background: var(--canvas);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #161618;
  --surface: #1e1e20;
  --recessed: #242426;
  --ink: #f5f5f7;
  --muted: #ababaf;
  --line: rgb(255 255 255 / .08);
  --control-line: rgb(255 255 255 / .19);
  --selected: rgb(255 255 255 / .10);
  --accent: #5aaaf9;
  --accent-hover: #7bbaff;
  --accent-ink: #101820;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; transition: background-color var(--motion), color var(--motion); }
main { width: min(896px, calc(100% - 32px)); margin: clamp(32px, 7vw, 80px) auto; }
h1 { font-size: clamp(2.25rem, 5vw, 4rem); font-weight: 600; line-height: 1.12; letter-spacing: -.045em; margin: 16px 0 8px; }
h2 { font-size: 1.25rem; font-weight: 600; margin: 0; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { color: var(--muted); margin: 0; }
a { color: var(--ink); text-underline-offset: .2em; }
.panel { display: grid; gap: 24px; margin-block-start: 32px; border: 1px solid var(--line); border-radius: 24px; padding: clamp(16px, 4vw, 32px); background: var(--surface); }
label { min-width: 0; font-size: 14px; font-weight: 500; display: grid; gap: 8px; }
label:has(output) { grid-template-columns: 1fr auto; }
label input[type=range] { grid-column: 1 / -1; accent-color: var(--accent); }
input, select, textarea { min-width: 0; width: 100%; color: inherit; background: var(--recessed); border: 1px solid var(--control-line); border-radius: 8px; font: inherit; padding: 8px 12px; }
.of-url-note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
button, .button { display: inline-flex; justify-content: center; align-items: center; background: var(--accent); color: var(--accent-ink); border: 1px solid transparent; border-radius: 8px; min-height: 44px; font: inherit; font-size: 14px; font-weight: 500; padding: 8px 16px; text-decoration: none; cursor: pointer; transition: background-color var(--motion), transform var(--motion); }
button:not(:disabled):hover, .button:hover { background: var(--accent-hover); }
button:not(:disabled):active, .button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: wait; }
.secondary { color: var(--ink); background: var(--recessed); }
.secondary:not(:disabled):hover, a.secondary:hover { background: var(--selected); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: inline-flex; gap: 4px; background: var(--recessed); border: 1px solid var(--control-line); border-radius: 10px; padding: 4px; }
.seg button { background: transparent; color: var(--ink); border: 0; min-height: 36px; border-radius: 7px; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 640px) { .fields { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } :active { transform: none !important; } }

/* Discreet brand line on every standalone app (Chan, 2026-11-27). */
.brand-line { text-align: center; color: var(--muted); font-size: 12.5px; letter-spacing: .14em; padding: 20px 0 28px; margin: 0; }

/* --- Pythagoras specific --- */
.subtitle { font-size: 1.25rem; color: var(--muted); margin: 0 0 8px; }
.lede { max-width: 62ch; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.badges span { white-space: nowrap; }
#chart { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); touch-action: manipulation; }
.sq-results { display: flex; flex-wrap: wrap; gap: 12px; }
.sq-stat { flex: 1 1 120px; min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--recessed); padding: 12px 16px; }
.sq-stat .num { font-size: 24px; font-weight: 700; line-height: 1.2; overflow-wrap: break-word; }
.sq-stat .lbl { font-size: 13px; color: var(--muted); margin-top: 2px; }
#share-status:empty { display: none; }
#share-status { color: var(--muted); font-size: 14px; }
.sq-msg-good { color: #1e7e34 !important; }
.sq-msg-bad { color: #c0392b !important; }
#quiz-options { display: grid; gap: 8px; }
#quiz-options button { justify-content: flex-start; text-align: left; min-height: 44px; }
#quiz-options button.sq-opt-correct { outline: 2px solid #1e7e34; outline-offset: 1px; }
#quiz-options button.sq-opt-wrong { outline: 2px solid #c0392b; outline-offset: 1px; }
#quiz-question { font-size: 17px; font-weight: 600; color: var(--ink); }
#quiz-progress { font-size: 13px; }
@media (max-width: 640px) {
  .sq-stat .num { font-size: 20px; }
}

/* --- Pythagoras specific --- */
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input[type=checkbox] { width: auto; accent-color: var(--accent); }
.sq-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sq-table th, .sq-table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.sq-table th { color: var(--muted); font-weight: 600; }
.sq-table td { color: var(--ink); font-variant-numeric: tabular-nums; }

/* --- Matrix Lab specific --- */
.mx-matrices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.mx-matrix-block { display: grid; gap: 12px; align-content: start; }
.mx-grid { display: grid; gap: 8px; }
.mx-grid input { text-align: center; font-variant-numeric: tabular-nums; padding: 8px 4px; }
.mx-grid input.mx-cell-bad { outline: 2px solid #c0392b; outline-offset: 1px; }
.mx-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.mx-result-block { display: grid; gap: 12px; align-content: start; }
.mx-matrix-view { overflow-x: auto; padding: 4px 2px; }
.mx-matrix-view table { border-collapse: collapse; margin: 0 auto; }
.mx-matrix-view td { padding: 6px 12px; text-align: center; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.mx-matrix-view table tr td:first-child { border-left: 2px solid var(--ink); }
.mx-matrix-view table tr td:last-child { border-right: 2px solid var(--ink); }
.mx-matrix-view table tr:first-child td { border-top: 2px solid var(--ink); }
.mx-matrix-view table tr:last-child td { border-bottom: 2px solid var(--ink); }
.mx-steps { color: var(--ink); font-size: 15px; margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.mx-steps li { overflow-wrap: break-word; font-variant-numeric: tabular-nums; }
.mx-result-line { color: var(--ink); font-size: 18px; font-weight: 600; }
.mx-result-line span:last-child { font-variant-numeric: tabular-nums; }
.mx-msg-good { color: #1e7e34 !important; }
.mx-msg-bad { color: #c0392b !important; }
#quiz-options button.mx-opt-correct { outline: 2px solid #1e7e34; outline-offset: 1px; }
#quiz-options button.mx-opt-wrong { outline: 2px solid #c0392b; outline-offset: 1px; }
@media (max-width: 640px) {
  .mx-matrices, .mx-results { grid-template-columns: 1fr; }
}
