:root {
  --math-safe-top: env(safe-area-inset-top, 0px);
  --math-safe-right: env(safe-area-inset-right, 0px);
  --math-safe-bottom: env(safe-area-inset-bottom, 0px);
  --math-safe-left: env(safe-area-inset-left, 0px);
  --math-focus: #2563eb;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body { max-width: 100vw; overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button, a, [role="button"] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
img, svg, canvas, video, iframe { max-width: 100%; }
iframe { border: 0; }
:focus-visible { outline: 3px solid var(--math-focus) !important; outline-offset: 3px !important; }
.math-overflow-x { max-width: 100%; overflow-x: auto !important; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.math-overflow-x > table { min-width: max-content; }
.math-sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

.math-global-tools {
  position: fixed; right: max(12px, var(--math-safe-right)); bottom: max(12px, var(--math-safe-bottom)); z-index: 2147483000;
  display: flex; gap: 8px; align-items: center; padding: 7px; border-radius: 999px;
  background: rgba(15, 23, 42, .92); color: #fff; box-shadow: 0 12px 30px rgba(15,23,42,.28);
  border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(12px);
}
.math-tool-btn { min-width: 42px; height: 42px; padding: 0 12px; border: 0; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; background: transparent; color: inherit; cursor: pointer; font-weight: 800; }
.math-tool-btn:hover { background: rgba(255,255,255,.14); }
.math-tool-btn[data-active="true"] { background: #2563eb; }
.math-tool-btn svg { width: 20px; height: 20px; flex: none; }
.math-tool-label { font-size: 12px; }
.math-network-chip { position: fixed; left: max(10px,var(--math-safe-left)); bottom: max(10px,var(--math-safe-bottom)); z-index: 2147482999; padding: 8px 12px; border-radius: 999px; color: #fff; background: #b91c1c; box-shadow: 0 8px 24px rgba(0,0,0,.2); font: 700 12px/1.2 system-ui,sans-serif; }
.math-app-toast { position: fixed; left: 50%; bottom: calc(76px + var(--math-safe-bottom)); transform: translate(-50%,18px); z-index: 2147483646; max-width: min(92vw,560px); padding: 12px 16px; border-radius: 14px; background: #0f172a; color: #fff; box-shadow: 0 18px 44px rgba(15,23,42,.3); opacity: 0; pointer-events: none; transition: .22s ease; font: 700 14px/1.45 system-ui,sans-serif; text-align: center; }
.math-app-toast.show { opacity: 1; transform: translate(-50%,0); }
.math-load-fallback { position: fixed; inset: 0; z-index: 2147483600; display: grid; place-items: center; padding: 24px; background: rgba(248,250,252,.97); font-family: system-ui,sans-serif; }
.math-load-card { width: min(92vw,520px); padding: 26px; border-radius: 22px; background: #fff; box-shadow: 0 24px 70px rgba(15,23,42,.18); border: 1px solid #e2e8f0; text-align: center; }
.math-load-card h2 { margin: 0 0 10px; color:#0f172a; }
.math-load-card p { color:#475569; line-height:1.65; }
.math-load-actions { display:flex; flex-wrap:wrap; justify-content:center; gap:10px; margin-top:18px; }
.math-load-actions a,.math-load-actions button { min-height:44px; border-radius:12px; padding:10px 16px; border:1px solid #cbd5e1; background:#fff; color:#0f172a; font-weight:800; text-decoration:none; cursor:pointer; }
.math-load-actions .primary { background:#2563eb; color:#fff; border-color:#2563eb; }
body.exam-mode .math-global-tools, body[data-math-tools="off"] .math-global-tools, body[data-math-tools="off"] .math-network-chip { display:none !important; }

@media (pointer: coarse) {
  button, a, [role="button"], input[type="checkbox"], input[type="radio"], select { min-height: 44px; }
}
@media (max-width: 640px) {
  body { padding-left: var(--math-safe-left); padding-right: var(--math-safe-right); }
  .math-global-tools { left: 50%; right: auto; transform: translateX(-50%); max-width: calc(100vw - 20px); }
  .math-tool-label { display:none; }
  .math-tool-btn { min-width:44px; padding:0 10px; }
  .math-app-toast { bottom: calc(74px + var(--math-safe-bottom)); }
  table { font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior:auto; }
  *, *::before, *::after { animation-duration:.001ms !important; animation-iteration-count:1 !important; transition-duration:.001ms !important; }
}
@media print {
  .math-global-tools,.math-network-chip,.math-app-toast,.math-load-fallback { display:none !important; }
}

/* V8 compact utility dock */
@media(max-width:700px){.math-global-tools{left:auto!important;right:max(8px,var(--math-safe-right))!important;bottom:max(8px,var(--math-safe-bottom))!important;transform:none!important;padding:4px!important;gap:2px!important;border-radius:16px!important;max-width:calc(100vw - 16px)!important;background:rgba(15,23,42,.88)!important}.math-tool-btn{min-width:36px!important;width:36px!important;height:36px!important;padding:0!important}.math-tool-btn svg{width:18px!important;height:18px!important}.math-app-toast{bottom:56px!important}.math-network-chip{font-size:10px!important;padding:6px 9px!important}}
