/* rStats.js demo. Colours are tokens on :root, redefined for dark mode (system setting or data-theme). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #dfe3e8;
  --border-strong: #c6ccd4;
  --text: #1b1f24;
  --muted: #5b6470;
  --accent: #2456c8;
  --accent-soft: #e6edfb;
  --accent-text: #ffffff;
  --visited: #8a3ab9;
  --curve-2: #d9480f;
  --hist: #8fa9e6;
  --ok: #1a7f37;
  --ok-soft: #e3f4e8;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --warn: #8a6100;
  --warn-soft: #fbf3dc;
  --code-bg: #f4f6f9;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2b323c;
    --border-strong: #3b4450;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --accent: #7aa2ff;
    --accent-soft: #1d2a47;
    --accent-text: #0b1020;
    --visited: #d09cf5;
    --curve-2: #ff8a50;
    --hist: #3d5a9e;
    --ok: #4cc26a;
    --ok-soft: #13301c;
    --bad: #ff6b6b;
    --bad-soft: #3a1717;
    --warn: #e3b341;
    --warn-soft: #33290f;
    --code-bg: #12161b;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e232b;
  --border: #2b323c;
  --border-strong: #3b4450;
  --text: #e6e9ee;
  --muted: #9aa4b2;
  --accent: #7aa2ff;
  --accent-soft: #1d2a47;
  --accent-text: #0b1020;
  --visited: #d09cf5;
  --curve-2: #ff8a50;
  --hist: #3d5a9e;
  --ok: #4cc26a;
  --ok-soft: #13301c;
  --bad: #ff6b6b;
  --bad-soft: #3a1717;
  --warn: #e3b341;
  --warn-soft: #33290f;
  --code-bg: #12161b;
  --shadow: none;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}
a:visited {
  color: var(--visited);
}

code,
pre,
.mono,
.num {
  font-family: var(--mono);
  font-size: 0.92em;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
  z-index: 10;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 6px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- header ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner,
.status,
.tabs,
main,
.site-footer p {
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: 24px;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding-block: 18px 8px;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}
.brand-name {
  font-family: var(--mono);
}
.brand-sub {
  font-weight: 500;
  color: var(--muted);
}
.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status {
  margin-block: 0;
  padding-block: 4px 12px;
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 6px;
  vertical-align: 1px;
}

.status-url {
  font-size: 0.875rem;
}
.status-bad {
  color: var(--bad);
  font-weight: 600;
}

/* ---------- buttons and controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover {
  background: var(--surface-2);
}
.btn-small {
  min-height: 36px;
  padding: 4px 12px;
  font-size: 0.875rem;
}

input[type="text"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}
input[type="text"],
textarea {
  font-family: var(--mono);
  font-size: 0.9rem;
}
textarea {
  resize: vertical;
  line-height: 1.45;
}
input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  min-width: 0;
}
.field > label {
  font-weight: 600;
  font-size: 0.88rem;
}
.opt-mark {
  font-weight: 400;
  color: var(--muted);
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}
.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0 12px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 14px;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.9rem;
  cursor: pointer;
}
.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.option-group {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.option-group > .check {
  margin-bottom: 12px;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}
.card > .hint,
.examples-head .hint {
  margin-bottom: 14px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: -6px 0 14px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.seg-btn {
  min-height: 40px;
  padding: 6px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.seg-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  margin: 14px 0;
}
.inline-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}
.inline-label select {
  width: auto;
}

/* ---------- tabs ---------- */

.tabs-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  padding: 12px 14px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- layout ---------- */

main {
  padding-block: 24px 40px;
}
main:focus {
  outline: none;
}

.panel:focus {
  outline: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-title {
  margin: 0 0 4px;
  font-size: 1.15rem;
}
.sub-heading {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
:lang(ja) .sub-heading {
  letter-spacing: 0.02em;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.form-card {
  position: sticky;
  top: 64px;
}
.result-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.result-card > .sub-heading {
  margin-bottom: -6px;
}

.output:empty {
  display: none;
}

.error-box {
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--bad);
  border-radius: 8px;
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.notice {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  background: var(--warn-soft);
  font-size: 0.9rem;
  margin: 0;
}

/* ---------- tables, vectors, matrices ---------- */

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
th,
td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: top;
}
tr:last-child > th,
tr:last-child > td {
  border-bottom: 0;
}
thead th {
  background: var(--surface-2);
  font-weight: 600;
  white-space: nowrap;
}
.data-table td,
.data-table tbody th {
  font-family: var(--mono);
  font-size: 0.86rem;
}
.data-table tbody th {
  font-weight: 500;
  color: var(--muted);
}
.data-table.compact th,
.data-table.compact td {
  padding: 5px 9px;
  white-space: nowrap;
}
/* name / value tables whose values are long (lists of numbers, sentences) */
.data-table.kv th,
.data-table.kv td {
  text-align: left;
}
.data-table.kv tbody th {
  white-space: nowrap;
  width: 1%;
}
.data-table.kv td {
  white-space: normal;
  overflow-wrap: anywhere;
}
.matrix-wrap {
  width: fit-content;
}
.matrix {
  width: auto;
}
.matrix td,
.matrix th {
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: nowrap;
}
.matrix tbody th,
.matrix thead th {
  color: var(--muted);
  font-weight: 500;
}

.vector {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
}
.vec-item {
  display: inline-flex;
  gap: 6px;
  white-space: nowrap;
}
.vec-index {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--muted);
  min-width: 2.2em;
  text-align: right;
  padding-top: 1px;
}
.scroll-box .vector {
  max-height: 220px;
  overflow-y: auto;
}

.scalar {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.object-view {
  margin: 0;
  display: grid;
  gap: 6px;
}
.object-view dt {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 6px;
}
.object-view dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
.object-view .object-view {
  padding-left: 12px;
  border-left: 2px solid var(--border);
}
.ok {
  color: var(--ok);
  font-weight: 700;
}
.bad {
  color: var(--bad);
  font-weight: 700;
}

/* ---------- htest print, JSON, code ---------- */

.htest,
.json,
.code-block pre {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
  tab-size: 8;
}
.htest {
  white-space: pre;
}
.json {
  max-height: 340px;
  overflow: auto;
}
.json-details summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.code-panel {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.code-panel .hint {
  margin-bottom: 10px;
}
.code-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.code-block {
  min-width: 0;
}
.code-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.code-lang {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.copy-status {
  margin-left: auto;
  font-size: 0.875rem;
  color: var(--ok);
}
.copy-btn {
  margin-left: auto;
}
.copy-status:not(:empty) + .copy-btn {
  margin-left: 0;
}
.code-block pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- plots ---------- */

.plots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.plots:empty {
  display: none;
}
.plots-single {
  grid-template-columns: minmax(0, 1fr);
}
.figure {
  margin: 0;
}
.figure figcaption {
  margin-top: 4px;
}
.plot {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.plot .grid {
  stroke: var(--border);
  stroke-width: 1;
}
.plot .frame {
  fill: none;
  stroke: var(--border-strong);
}
.plot .tick {
  fill: var(--muted);
  font: 11px var(--mono);
}
.plot .axis-label,
.plot .plot-title {
  fill: var(--text);
  font: 600 12px var(--font);
}
.plot .curve {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
}
.plot .curve.series-1 {
  stroke: var(--accent);
}
.plot .curve.series-2 {
  stroke: var(--curve-2);
}
.plot .bar.series-1 {
  fill: var(--accent);
  opacity: 0.85;
}
.plot .bar.series-hist {
  fill: var(--hist);
}
.plot .dot.series-2 {
  fill: var(--curve-2);
}
.plot .marker {
  stroke: var(--curve-2);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

/* ---------- examples ---------- */

.examples {
  margin-top: 32px;
}
.section-title {
  margin: 0 0 4px;
  font-size: 1.15rem;
}
.count {
  color: var(--muted);
  font-weight: 500;
}
.example-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}
.example-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.example-card.status-fail {
  border-color: var(--bad);
}
.example-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.example-head h4 {
  margin: 0;
  font-size: 0.98rem;
}
.example-card .code-block pre {
  padding: 8px 10px;
  font-size: 0.875rem;
}
.example-values {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
  font-size: 0.85rem;
}
.example-values dt {
  color: var(--muted);
  font-weight: 600;
}
.example-values dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-pass {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge-fail {
  background: var(--bad-soft);
  color: var(--bad);
}
.badge-noR {
  background: var(--warn-soft);
  color: var(--warn);
}

/* ---------- compare tab ---------- */

.compare-summary {
  margin-top: 8px;
}
.summary-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 6px;
}
.big-count {
  font-size: 1.25rem;
  font-weight: 700;
}
.big-count .num {
  font-size: 1.35rem;
}
.big-count.all-pass .num {
  color: var(--ok);
}
.big-count.has-fail .num {
  color: var(--bad);
}
.compare-table th,
.compare-table td {
  text-align: left;
}
.compare-table tbody th {
  font-family: var(--font);
  color: var(--text);
  font-weight: 600;
  min-width: 220px;
}
.compare-table tbody th {
  max-width: 340px;
}
.compare-table td.wrap {
  min-width: 190px;
  max-width: 320px;
  overflow-wrap: anywhere;
}
.compare-table td.tab-name {
  font-family: var(--font);
  white-space: nowrap;
}
.small-code {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}
tr.status-fail td,
tr.status-fail th {
  background: var(--bad-soft);
}

/* ---------- load error ---------- */

.load-error {
  max-width: 760px;
  border-color: var(--bad);
}
.error-text {
  color: var(--bad);
  overflow-wrap: anywhere;
}
.load-error code {
  overflow-wrap: anywhere;
}
.steps li {
  margin-bottom: 4px;
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer p {
  margin-block: 0;
  padding-block: 18px 28px;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .workbench {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-card {
    position: static;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 16px;
  }
  .header-inner,
  .status,
  .tabs,
  main,
  .site-footer p {
    padding-inline: 16px;
  }
  .header-inner {
    padding-top: 14px;
  }
  .card {
    padding: 16px;
  }
  .example-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .tab {
    padding: 10px 10px 8px;
    font-size: 0.9rem;
  }
  .field-row {
    grid-template-columns: minmax(0, 1fr);
  }
  .code-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .plots {
    grid-template-columns: minmax(0, 1fr);
  }
}

.btn:visited {
  color: var(--text);
}

.plots-single .plot {
  max-width: 760px;
}
