:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5b6470;
  --border: #dde1e6;
  --accent: #6d28d9;
  --accent-text: #fff;
  --accent-soft: #efe9fd;
  --ok: #1f7a3a;
  --ok-soft: #e3f4e8;
  --warn: #8a5a00;
  --warn-soft: #fdf2dc;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 8px 24px rgb(0 0 0 / .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --math: "Cambria Math", "STIX Two Math", "Latin Modern Math", Cambria, "Times New Roman", serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaef;
    --muted: #9aa3af;
    --border: #2a2f3a;
    --accent: #a78bfa;
    --accent-text: #0f1115;
    --accent-soft: #2a2147;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --warn: #fbbf24;
    --warn-soft: #33270a;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
}

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

code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 0 .3em; }

.site-header, main, .site-footer { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.site-header { padding-top: 28px; padding-bottom: 8px; }

.site-header h1 { margin: 0 0 4px; font-size: clamp(1.6rem, 4vw, 2.1rem); letter-spacing: -.01em; }

.lead { margin: 0; color: var(--muted); max-width: 72ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 16px 0;
  min-width: 0;
}

.card h2 { margin: 0 0 12px; font-size: 1.2rem; }

.card h3 { font-size: 1.02rem; margin: 22px 0 8px; }

.card-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-bottom: 10px; }

.card-head h2 { margin: 0; }

label { font-weight: 600; }

label.inline { display: inline-flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .95rem; }

select, input[type="text"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  max-width: 100%;
}

textarea { width: 100%; min-height: 9em; font-family: var(--mono); resize: vertical; }

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

input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 7px 12px;
}

.btn:hover { border-color: var(--accent); }

.btn.small { font-size: .88rem; padding: 4px 10px; }

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

.ops label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  cursor: pointer;
  font-weight: 500;
  background: var(--surface-2);
}

.ops label { position: relative; padding: 6px 14px; }

.ops label:has(input:checked) { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.ops label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

.ops input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }

.op-options { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }

.op-options [hidden] { display: none; }

.examples { display: flex; flex-wrap: wrap; gap: 6px; }

/* Editor da matriz */
.editor-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin-bottom: 12px; }

.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.tabs button { font: inherit; border: 0; background: var(--surface-2); color: var(--text); padding: 7px 14px; cursor: pointer; }

.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.grid-wrap { overflow-x: auto; padding: 4px 2px 8px; position: relative; }

.grid { display: inline-grid; gap: 6px; align-items: center; }

.grid input {
  width: 4.6em;
  text-align: center;
  font-family: var(--mono);
  padding: 6px 4px;
}

.grid .head { font-size: .8rem; color: var(--muted); text-align: center; }

.grid .bcol { border-left: 2px solid var(--muted); padding-left: 8px; }

.editor-error { color: var(--danger); margin: 8px 0 0; }

/* Notação matemática */
.math, .result { font-family: var(--font); }

.q { white-space: nowrap; }

.fr {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  font-size: .82em;
  line-height: 1.15;
  margin: 0 .08em;
}

.fr-n { border-bottom: 1px solid currentColor; padding: 0 .15em; }

.fr-d { padding: 0 .15em; }

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

.mtx { display: inline-block; vertical-align: middle; position: relative; padding: 0 .4em; margin: .25em .15em; line-height: 1.35; }

.mtx::before, .mtx::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: .38em;
  border: 1.6px solid currentColor;
}

.mtx::before { left: 0; border-right: 0; border-radius: 3px 0 0 3px; }

.mtx::after { right: 0; border-left: 0; border-radius: 0 3px 3px 0; }

.mtx.det::before, .mtx.det::after { width: 0; border-top: 0; border-bottom: 0; border-radius: 0; }

.mtx table { border-collapse: collapse; }

.mtx td { padding: .12em .5em; text-align: center; border: 0; font-variant-numeric: tabular-nums; }

.mtx td.aug { border-left: 1.6px solid currentColor; }

.mtx tr.hl td, .mtx td.hlc { background: var(--accent-soft); }

.poly i, .math i, .var { font-family: var(--math); font-style: italic; }

.sqrt .rad { border-top: 1.4px solid currentColor; padding: 0 .1em; }

.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 8px 0; overflow-x: auto; position: relative; }

.step { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 100%; }

.arrow { display: inline-flex; flex-direction: column; align-items: center; font-size: .8rem; color: var(--muted); padding: 0 4px; }

.arrow .op { color: var(--text); white-space: nowrap; }

.arrow::after { content: "→"; font-size: 1.3rem; line-height: 1; }

code.op { background: var(--accent-soft); border-color: transparent; }

.eq { margin: 10px 0; line-height: 2.1; overflow-x: auto; overflow-y: hidden; position: relative; }

.piece { display: inline-block; margin-right: 1.2em; }

.badge {
  display: inline-block;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 999px;
  margin-right: 8px;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); }

.badge.warn { background: var(--warn-soft); color: var(--warn); }

.badge.bad { background: var(--danger-soft); color: var(--danger); }

.callout {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px;
  margin: 12px 0;
}

.callout.bad { border-left-color: var(--danger); background: var(--danger-soft); }

.callout.ok { border-left-color: var(--ok); background: var(--ok-soft); }

.final { font-size: 1.08rem; }

.result ol, .result ul { padding-left: 22px; }

.result li { margin: 6px 0; }

.lines { list-style: none; padding: 0 0 0 12px !important; border-left: 2px solid var(--muted); margin: 8px 0; }

.lines li { margin: 4px 0; }

.terms { list-style: none; padding: 0 !important; }

.terms > li { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; margin: 8px 0; overflow-x: auto; }

details.sub { margin: 6px 0 0 4px; }

details.sub > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .92rem; }

.scroll { overflow-x: auto; max-width: 100%; position: relative; }

.muted { color: var(--muted); }

.small { font-size: .88rem; }

span.ok { color: var(--ok); }

span.bad { color: var(--danger); }

.error-box {
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.tips ul { padding-left: 20px; margin: 0; }

.tips li { margin: 6px 0; }

.site-footer { color: var(--muted); padding-top: 8px; padding-bottom: 32px; font-size: .92rem; }

.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;
}

@media (min-width: 720px) {
  .card { padding: 22px; }
}

@media (max-width: 480px) {
  .grid input { width: 3.8em; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; color: #000; }
  .ops, .op-options, .examples, .editor-bar, .btn, .tips, .site-footer { display: none !important; }
  .card { box-shadow: none; border-color: #999; }
  details { display: block; }
  details > * { display: block !important; }
}
