/* Graphing calculator + geometry board. Everything is scoped to .mathtool, so it can't leak. */
.mathtool {
  --mt-canvas: #0d0a29; --mt-grid: rgba(207,200,255,.07); --mt-grid-major: rgba(207,200,255,.16);
  --mt-axis: rgba(207,200,255,.55); --mt-tick: #b3aee0; --mt-ink: #eceafc; --mt-tip: rgba(20,14,56,.94);
  --mt-panel: #17114a; --mt-panel2: #211a63; --mt-line: rgba(179,174,224,.22); --mt-accent: #a78bfa; --mt-accent2: #7c5cf5; --mt-bad: #ff8a8a;
  display: flex; flex-direction: column; width: 100%; height: min(78vh, 780px); min-height: 520px;
  background: var(--mt-panel); color: var(--mt-ink); border: 1px solid var(--mt-line); border-radius: 18px; overflow: hidden;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Armenian", sans-serif;
  box-shadow: 0 18px 50px rgba(8, 4, 40, .45);
}
.mathtool *, .mathtool *::before, .mathtool *::after { box-sizing: border-box; }
.mathtool button, .mathtool input, .mathtool select { font: inherit; color: inherit; }
.mathtool [hidden] { display: none !important; }
.mathtool .mt-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.mt-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px; background: var(--mt-panel2); border-bottom: 1px solid var(--mt-line); }
.mt-spacer { flex: 1; }
.mt-group { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.mt-geo-bar .mt-actions { margin-left: auto; }
.mt-btn, .mt-iconbtn, .mt-select, .mt-tab, .mt-key {
  border: 1px solid var(--mt-line); background: rgba(255,255,255,.05); border-radius: 10px; cursor: pointer; transition: background .12s, border-color .12s, transform .06s;
}
.mt-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px; }
.mt-iconbtn { display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; flex: none; }
.mt-select { min-height: 38px; padding: 0 10px; background: rgba(255,255,255,.07); max-width: 190px; }
.mt-select option { color: #111; }
.mt-btn:hover, .mt-iconbtn:hover, .mt-tab:hover, .mt-key:hover { background: rgba(167,139,250,.2); border-color: rgba(167,139,250,.6); }
.mt-btn:active, .mt-iconbtn:active, .mt-key:active { transform: scale(.96); }
.mathtool :focus-visible { outline: 2px solid #ffd479; outline-offset: 2px; }
.mt-btn[aria-pressed="true"], .mt-iconbtn[aria-pressed="true"], .mt-tab[aria-selected="true"] { background: linear-gradient(135deg, var(--mt-accent2), var(--mt-accent)); border-color: transparent; color: #fff; }
.mt-tool[aria-pressed="true"] { box-shadow: 0 0 0 2px rgba(255,212,121,.55); }
.mt-deg { min-width: 56px; justify-content: center; font-weight: 700; letter-spacing: .04em; }
.mt-hint { margin: 0; padding: 6px 12px; font-size: 14px; color: #cfc8ff; background: rgba(0,0,0,.18); border-bottom: 1px solid var(--mt-line); }
.mt-hint strong { color: #ffd479; }

/* body: sidebar + stage */
.mt-body { flex: 1; display: flex; min-height: 0; }
.mt-side { width: 330px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--mt-panel); }
.mt-graph .mt-side { border-right: 1px solid var(--mt-line); }
.mt-geo .mt-side { border-left: 1px solid var(--mt-line); width: 300px; }
.mt-side-scroll { flex: 1; overflow: auto; padding: 10px; min-height: 0; }
.mt-side-collapsed .mt-side { width: auto; }
.mt-side-collapsed .mt-side .mt-side-scroll { display: none; }
.mt-side-collapsed.mt-graph .mt-side { display: none; }
.mt-panel-toggle { margin: 8px 10px 0; }
.mt-geo .mt-panel-toggle { align-self: flex-start; }
.mt-stage { position: relative; flex: 1; min-width: 0; min-height: 260px; background: var(--mt-canvas); overflow: hidden; }
.mt-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline-offset: -3px; }
.mt-badge { position: absolute; left: 10px; bottom: 10px; padding: 4px 10px; border-radius: 999px; background: var(--mt-tip); border: 1px solid var(--mt-line); font-size: 13px; pointer-events: none; font-variant-numeric: tabular-nums; }
.mt-note { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); padding: 8px 14px; border-radius: 12px; background: var(--mt-tip); border: 1px solid rgba(255,212,121,.5); font-size: 14px; max-width: 90%; text-align: center; pointer-events: none; }
.mt-empty { position: absolute; left: 0; right: 0; bottom: 22px; text-align: center; padding: 8px 20px; color: rgba(207,200,255,.7); font-size: 15px; pointer-events: none; text-shadow: 0 0 8px #0a0624, 0 0 2px #0a0624; }

/* tabs */
.mt-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.mt-tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; font-weight: 600; }

/* expression rows */
.mt-rows, .mt-objs, .mt-sliders-list, .mt-calc-hist { list-style: none; margin: 0; padding: 0; }
.mt-row { position: relative; display: grid; grid-template-columns: 30px 1fr auto auto auto; align-items: center; gap: 4px; padding: 6px; margin-bottom: 6px; border: 1px solid var(--mt-line); border-radius: 12px; background: rgba(255,255,255,.04); }
.mt-row.mt-off .mt-input { opacity: .5; }
.mt-row.mt-bad { border-color: rgba(255,138,138,.6); }
.mt-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: var(--c, #a78bfa); cursor: pointer; padding: 0; justify-self: center; }
.mt-dot-hidden { background: transparent; }
.mt-input { width: 100%; min-width: 0; height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid transparent; background: rgba(0,0,0,.22); font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 16px; }
.mt-input:focus { border-color: var(--mt-accent); outline: none; background: rgba(0,0,0,.35); }
.mt-err { grid-column: 1 / -1; color: var(--mt-bad); font-size: 13px; padding: 2px 6px; }
.mt-err:empty { display: none; }
.mt-palette { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 4px; }
.mt-swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); background: var(--c); cursor: pointer; padding: 0; }
.mt-add { width: 100%; justify-content: center; margin: 4px 0 10px; border-style: dashed; }

/* sliders + table */
.mt-h { margin: 12px 0 6px; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: #cfc8ff; }
.mt-sliders-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; margin-bottom: 6px; border: 1px solid var(--mt-line); border-radius: 12px; background: rgba(255,255,255,.04); }
.mt-slider-name { font-weight: 700; min-width: 18px; }
.mt-range { flex: 1 1 110px; min-width: 90px; accent-color: var(--mt-accent); height: 28px; }
.mt-num { width: 78px; height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--mt-line); background: rgba(0,0,0,.25); }
.mt-num-s { width: 64px; }
.mt-slider-set { flex-basis: 100%; display: flex; gap: 8px; flex-wrap: wrap; }
.mt-set { display: grid; gap: 2px; font-size: 12px; color: #b3aee0; }
.mt-table { border: 1px solid var(--mt-line); border-radius: 12px; padding: 8px; margin-top: 8px; background: rgba(255,255,255,.04); }
.mt-table-head { display: flex; align-items: center; justify-content: space-between; }
.mt-table-head .mt-h { margin: 0; }
.mt-table-ctl { display: flex; gap: 10px; margin: 6px 0; }
.mt-table-wrap { max-height: 220px; overflow: auto; }
.mt-tbl-grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.mt-tbl-grid th, .mt-tbl-grid td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--mt-line); }
.mt-tbl-grid th { position: sticky; top: 0; background: var(--mt-panel2); }

/* calculator */
.mt-calc-hist { max-height: 170px; overflow: auto; margin-bottom: 8px; }
.mt-calc-item { width: 100%; display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; margin-bottom: 4px; text-align: left; border: 1px solid var(--mt-line); border-radius: 10px; background: rgba(255,255,255,.04); cursor: pointer; }
.mt-calc-expr { color: #b3aee0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-calc-res { font-weight: 700; color: #ffd479; font-variant-numeric: tabular-nums; }
.mt-calc-form { display: flex; gap: 6px; }
.mt-calc-err { color: var(--mt-bad); font-size: 13px; min-height: 18px; padding: 4px 2px; }
.mt-keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-top: 6px; }
.mt-key { min-height: 40px; padding: 0; font-size: 16px; }
.mt-key-num { background: rgba(255,255,255,.1); font-weight: 600; }
.mt-eq { min-width: 48px; justify-content: center; background: linear-gradient(135deg, var(--mt-accent2), var(--mt-accent)); border-color: transparent; font-weight: 800; }

/* geometry object list */
.mt-objs-empty { margin: 8px 4px; color: #b3aee0; font-size: 14px; }
.mt-obj { display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin-bottom: 6px; border: 1px solid var(--mt-line); border-left: 4px solid var(--c, #a78bfa); border-radius: 12px; background: rgba(255,255,255,.04); cursor: pointer; }
.mt-obj.mt-selected { background: rgba(167,139,250,.22); border-color: var(--mt-accent); }
.mt-obj.mt-off { opacity: .55; }
.mt-obj-ico { color: var(--c); display: grid; place-items: center; }
.mt-obj-main { flex: 1; min-width: 0; }
.mt-obj-line { display: flex; align-items: center; gap: 8px; }
.mt-obj-name { width: 72px; height: 30px; padding: 0 8px; border-radius: 8px; border: 1px solid transparent; background: rgba(0,0,0,.25); font-weight: 700; }
.mt-obj-name:focus { border-color: var(--mt-accent); outline: none; }
.mt-obj-name[aria-invalid="true"] { border-color: var(--mt-bad); }
.mt-obj-kind { font-size: 12px; color: #b3aee0; }
.mt-obj-val { font-size: 13px; color: #d6d1ff; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.mt-obj.mt-undef .mt-obj-val { color: var(--mt-bad); }

/* phones */
@media (max-width: 760px) {
  .mathtool { height: auto; min-height: 0; }
  .mt-body { flex-direction: column; }
  .mt-graph .mt-body { flex-direction: column-reverse; }
  .mt-stage { flex: none; height: min(56vh, 460px); }
  .mt-side, .mt-geo .mt-side { width: 100%; border: 0; border-top: 1px solid var(--mt-line); }
  .mt-side-scroll { max-height: 300px; }
  .mt-graph .mt-side { max-height: 360px; }
  .mt-btn-text { display: none; }
  .mt-iconbtn { width: 42px; height: 42px; }
  .mt-keys { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) { .mathtool * { transition: none !important; } }
