/* ==========================================================================
   甲苯 — precision graphing workspace
   ========================================================================== */

:root {
  --panel-w: 392px;
  --bg: #f2f0e9;
  --surface: #ffffff;
  --surface-soft: #f7f6f1;
  --surface-sunk: #f1efe8;
  --ink: #172033;
  --ink-soft: #4a5568;
  --ink-muted: #7b879c;
  --line: rgba(23, 32, 51, 0.1);
  --line-strong: rgba(23, 32, 51, 0.16);
  --blue: #2458e6;
  --blue-dark: #1b46c2;
  --blue-soft: #e8efff;
  --amber: #d97706;
  --danger: #d92d20;
  --success: #0e8a64;
  --canvas: #fbfaf6;
  --shadow-sm: 0 2px 10px rgba(20, 28, 45, 0.07);
  --shadow-md: 0 10px 30px rgba(20, 28, 45, 0.13);
  --shadow-lg: 0 24px 70px rgba(16, 24, 40, 0.22);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-math: "STIX Two Text", "Cambria Math", "Latin Modern Math", Georgia,
    "Times New Roman", serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --hit: 48px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  cursor: pointer;
  background: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

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

/* -------------------------------------------------------------------------- */
/* Layout                                                                      */
/* -------------------------------------------------------------------------- */

.app {
  position: relative;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

@supports (height: 100dvh) {
  .app {
    height: 100dvh;
  }
}

.plot-shell {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas);
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

#graphCanvas.dragging {
  cursor: grabbing;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 13px;
  color: #fff;
  background:
    linear-gradient(145deg, #345de8 0%, #1c47cc 54%, #15359b 100%);
  box-shadow: 0 7px 16px rgba(36, 88, 230, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.brand-mark .icon {
  width: 27px;
  height: 27px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.05;
}

.brand-name {
  font-family: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", Georgia, serif;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--ink);
}

.brand-sub {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.brand-desktop {
  padding: 0 2px 15px;
}

.brand-mobile {
  display: none;
}

.panel {
  position: relative;
  z-index: 3;
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 28px rgba(20, 28, 45, 0.045);
  overflow: visible;
}

.panel-grabber {
  display: none;
}

.panel-header {
  flex: 0 0 auto;
  padding: calc(22px + var(--safe-top)) 20px 12px;
  background:
    radial-gradient(120% 100% at 0% 0%, rgba(36, 88, 230, 0.055) 0%, rgba(255, 255, 255, 0) 55%),
    var(--surface);
}

.panel-heading {
  min-width: 0;
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}

.panel-title-row h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--ink);
}

.fn-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-sunk);
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 700;
}

.panel-actions {
  position: absolute;
  top: calc(24px + var(--safe-top));
  right: 16px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.panel-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 9px;
  border-radius: 9px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.panel-action:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.panel-action .icon {
  width: 17px;
  height: 17px;
}

.panel-action.icon-only {
  width: 36px;
  padding: 0;
}

/* -------------------------------------------------------------------------- */
/* Function list                                                               */
/* -------------------------------------------------------------------------- */

.function-list {
  flex: 1 1 auto;
  min-height: 72px;
  padding: 2px 12px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.function-list::-webkit-scrollbar {
  width: 10px;
}

.function-list::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(71, 85, 105, 0.22);
  background-clip: padding-box;
}

.fn-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  margin-bottom: 6px;
  padding: 9px 10px 9px 11px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  text-align: left;
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.fn-card:hover {
  background: var(--surface-soft);
}

.fn-card.is-active {
  border-color: rgba(36, 88, 230, 0.2);
  background: linear-gradient(90deg, rgba(36, 88, 230, 0.065), rgba(36, 88, 230, 0.015));
  box-shadow: inset 3px 0 0 var(--blue);
}

.fn-card.is-hidden {
  opacity: 0.52;
}

.fn-card.has-error .fn-color {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(217, 45, 32, 0.55);
}

.fn-color {
  position: relative;
  width: 11px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: var(--fn-color, #2563eb);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.fn-main {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fn-expression {
  display: block;
  overflow: hidden;
  font-family: var(--font-math);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.fn-expression.is-placeholder {
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-style: italic;
}

.fn-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.25px;
  color: var(--ink-muted);
}

.fn-meta .error-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

.fn-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  flex: 0 0 auto;
}

.fn-action {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--ink-muted);
  transition: background-color 0.14s ease, color 0.14s ease;
}

.fn-action:hover {
  background: rgba(23, 32, 51, 0.06);
  color: var(--ink);
}

.fn-action .icon {
  width: 16px;
  height: 16px;
}

.fn-action.danger:hover {
  background: rgba(217, 45, 32, 0.09);
  color: var(--danger);
}

.fn-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 140px;
  padding: 22px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  color: var(--ink-muted);
  text-align: center;
}

.fn-empty strong {
  color: var(--ink-soft);
  font-size: 13px;
}

.fn-empty span {
  font-size: 12px;
  line-height: 1.5;
}

.panel-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 10px;
}

.add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 13px;
  border: 1px solid rgba(36, 88, 230, 0.18);
  border-radius: 10px;
  background: var(--blue-soft);
  white-space: nowrap;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 700;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.add-btn:hover {
  background: #dce7ff;
}

.add-btn:active {
  transform: translateY(1px);
}

.add-btn .icon {
  width: 16px;
  height: 16px;
}

.mobile-only {
  display: none;
}

.mobile-action {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--ink-muted);
  background: var(--surface-soft);
}

.mobile-action:hover {
  color: var(--ink);
  background: var(--surface-sunk);
}

.mobile-action.mobile-only {
  display: none;
}

.mobile-action .icon {
  width: 18px;
  height: 18px;
}

.ghost-btn {
  height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
}

.ghost-btn:hover {
  color: var(--danger);
  background: rgba(217, 45, 32, 0.06);
}

.autosave-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 600;
}

.autosave-state .live-dot {
  background: var(--success);
}

/* -------------------------------------------------------------------------- */
/* Editor                                                                      */
/* -------------------------------------------------------------------------- */

.editor {
  position: relative;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 16px calc(12px + var(--safe-bottom));
}

.mode-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.mode-pills {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  padding: 2px;
  border-radius: 10px;
  background: var(--surface-sunk);
}

.mode-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.mode-pill:hover {
  color: var(--ink-soft);
}

.mode-pill.is-active {
  background: var(--surface);
  color: var(--blue-dark);
  box-shadow: 0 1px 4px rgba(20, 28, 45, 0.12);
}

.mode-help {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--surface-sunk);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 800;
}

.mode-help:hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.expr-row {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 48px;
  padding: 0 5px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(20, 28, 45, 0.04);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.expr-row:focus-within {
  border-color: rgba(36, 88, 230, 0.55);
  box-shadow: 0 0 0 3px rgba(36, 88, 230, 0.1);
}

.expr-row.has-error {
  border-color: rgba(217, 45, 32, 0.6);
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.08);
}

.expr-color {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--fn-color, #2563eb);
  box-shadow: 0 0 0 3px rgba(36, 88, 230, 0.09);
}

.expr-field {
  min-width: 0;
  flex: 1 1 auto;
  display: block;
}

.expr-field input {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: var(--font-math);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
  caret-color: var(--blue);
}

.expr-field input::placeholder {
  color: #a0a9b8;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 400;
}

.expr-tool {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 9px;
  color: var(--ink-muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.expr-tool:hover {
  background: var(--surface-sunk);
  color: var(--ink);
}

.expr-tool.is-on {
  background: var(--blue-soft);
  color: var(--blue);
}

.expr-tool .icon {
  width: 18px;
  height: 18px;
}

.expr-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 25px;
  padding: 5px 2px 0;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.4;
}

.feedback-text {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feedback-text.is-error {
  color: var(--danger);
  font-weight: 600;
}

.feedback-shortcut {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-sunk);
  color: var(--ink-muted);
  font-size: 9px;
  font-weight: 600;
}

/* -------------------------------------------------------------------------- */
/* Style popover                                                               */
/* -------------------------------------------------------------------------- */

.style-popover {
  position: absolute;
  z-index: 12;
  right: 12px;
  bottom: calc(100% - 2px);
  left: 12px;
  padding: 13px 14px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  animation: pop-in 0.16s ease both;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.style-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 11px;
  font-size: 12px;
  font-weight: 700;
}

.mini-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--ink-muted);
}

.mini-close:hover {
  background: var(--surface-sunk);
}

.mini-close .icon {
  width: 16px;
  height: 16px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
}

.color-swatch {
  position: relative;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.is-active::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 2px solid var(--swatch);
  border-radius: 50%;
}

.color-custom {
  position: relative;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
  color: var(--ink-muted);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
}

.color-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.style-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 11px;
  align-items: end;
}

.style-label {
  display: block;
  flex: 0 0 auto;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.style-control {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.style-control input[type="range"] {
  width: 100%;
  height: 26px;
  accent-color: var(--blue);
}

.style-control output {
  position: absolute;
  margin-top: -1px;
  margin-left: 2px;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
}

.style-control select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 11px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.range-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1 1 0;
  min-width: 0;
}

.range-row label span {
  flex: 0 0 auto;
  color: var(--ink-muted);
  font-size: 9px;
  font-weight: 600;
}

.range-row input {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-soft);
  font-family: var(--font-mono);
  font-size: 10px;
}

.style-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 13px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.text-danger,
.text-muted {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 0 2px;
  font-size: 10px;
  font-weight: 650;
}

.text-danger {
  color: var(--danger);
}

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

.text-danger .icon,
.text-muted .icon {
  width: 14px;
  height: 14px;
}

/* -------------------------------------------------------------------------- */
/* Virtual keyboard                                                            */
/* -------------------------------------------------------------------------- */

.keypad {
  margin-top: 8px;
  padding: 8px 6px 6px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  animation: keypad-in 0.2s ease both;
}

@keyframes keypad-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.keypad-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}

.keypad-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 9px;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 700;
}

.keypad-tab.is-active {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
}

.math-key {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 48px;
  padding: 2px 3px;
  border: 1px solid rgba(23, 32, 51, 0.075);
  border-radius: 9px;
  background: linear-gradient(180deg, #fbfaf7 0%, #f3f1ea 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset;
  color: var(--ink);
  font-family: var(--font-math);
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
  transition: background-color 0.1s ease, transform 0.08s ease;
  user-select: none;
  -webkit-user-select: none;
}

.math-key:hover {
  background: #fff;
}

.math-key:active,
.math-key.pressed {
  transform: scale(0.97);
  background: #e9eefc;
}

.math-key.is-function {
  color: #2458e6;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 650;
}

.math-key.is-symbol {
  font-size: 17px;
}

.math-key.is-action {
  color: #9a3412;
  background: linear-gradient(180deg, #fffaf4 0%, #f7ecdf 100%);
}

.math-key.is-ac {
  color: var(--danger);
  background: linear-gradient(180deg, #fff 0%, #fbe9e7 100%);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 750;
}

/* -------------------------------------------------------------------------- */
/* Top bar & floating controls                                                 */
/* -------------------------------------------------------------------------- */

.topbar {
  position: absolute;
  z-index: 5;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 0;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.cursor-readout {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid rgba(23, 32, 51, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.coord {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.coord i {
  color: var(--ink-muted);
  font-family: var(--font-math);
  font-size: 11px;
  font-style: italic;
}

.coord b {
  min-width: 28px;
  font-weight: 550;
}

.coord-sep {
  width: 1px;
  height: 12px;
  background: var(--line-strong);
}

.view-zoom {
  padding-left: 2px;
  color: var(--ink-muted);
  font-size: 9px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(23, 32, 51, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 650;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tb-btn:hover {
  background: #fff;
  color: var(--ink);
}

.tb-btn .icon {
  width: 16px;
  height: 16px;
}

.tb-btn.icon-only {
  width: 36px;
  padding: 0;
}

.install-btn {
  color: var(--blue-dark);
  background: rgba(232, 239, 255, 0.92);
  border-color: rgba(36, 88, 230, 0.16);
}

.floating-tools {
  position: absolute;
  z-index: 5;
  right: 16px;
  bottom: 54px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(23, 32, 51, 0.09);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(14px);
}

.tool-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  color: var(--ink-soft);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tool-btn:hover {
  background: var(--surface-sunk);
  color: var(--ink);
}

.tool-btn.is-on {
  color: var(--blue);
  background: var(--blue-soft);
}

.tool-btn .icon {
  width: 18px;
  height: 18px;
}

.tool-divider {
  height: 1px;
  margin: 2px 5px;
  background: var(--line);
}

.canvas-badge {
  position: absolute;
  z-index: 4;
  bottom: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(23, 32, 51, 0.07);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(10px);
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
}

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(14, 138, 100, 0.1);
}

.badge-sep {
  width: 1px;
  height: 10px;
  background: var(--line-strong);
}

.gesture-hint {
  position: absolute;
  z-index: 4;
  bottom: 58px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(23, 32, 51, 0.78);
  color: rgba(255, 255, 255, 0.86);
  font-size: 10px;
  font-weight: 600;
  opacity: 0;
  transform: translate(-50%, 6px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.gesture-hint.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.gesture-hint .dot {
  opacity: 0.5;
}

.hover-card {
  position: absolute;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 132px;
  max-width: min(260px, calc(100% - 16px));
  padding: 8px 10px;
  border: 1px solid rgba(23, 32, 51, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(14px);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 16px));
  animation: hover-in 0.1s ease both;
}

@keyframes hover-in {
  from { opacity: 0; transform: translate(-50%, calc(-100% - 10px)); }
  to { opacity: 1; transform: translate(-50%, calc(-100% - 16px)); }
}

.hover-card.below {
  transform: translate(-50%, 18px);
  animation: none;
}

.hover-swatch {
  width: 3px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--blue);
}

.hover-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hover-label {
  color: var(--ink-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.hover-coord {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.toast-host {
  position: absolute;
  z-index: 120;
  bottom: 22px;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(460px, 88vw);
  padding: 9px 13px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(23, 32, 51, 0.92);
  box-shadow: var(--shadow-md);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  animation: toast-in 0.2s ease both;
  backdrop-filter: blur(14px);
}

.toast.is-error {
  background: rgba(153, 27, 27, 0.94);
}

.toast .icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------------------- */
/* Modals                                                                      */
/* -------------------------------------------------------------------------- */

.modal-layer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 25, 40, 0.4);
  backdrop-filter: blur(7px);
  animation: fade-in 0.18s ease both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  display: flex;
  flex-direction: column;
  width: min(680px, 100%);
  max-height: min(86dvh, 820px);
  max-height: min(86vh, 820px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 14px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(110% 120% at 0% 0%, rgba(36, 88, 230, 0.06), rgba(255, 255, 255, 0) 55%),
    var(--surface);
}

.modal-title-wrap {
  min-width: 0;
}

.modal-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

.modal-head h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", Georgia, serif;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  color: var(--ink-muted);
}

.modal-close:hover {
  background: var(--surface-sunk);
  color: var(--ink);
}

.modal-close .icon {
  width: 18px;
  height: 18px;
}

.modal-body {
  flex: 1 1 auto;
  padding: 18px 22px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-body::-webkit-scrollbar {
  width: 12px;
}

.modal-body::-webkit-scrollbar-thumb {
  border: 4px solid transparent;
  border-radius: 999px;
  background: rgba(71, 85, 105, 0.22);
  background-clip: padding-box;
}

.modal-section {
  margin-bottom: 22px;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.section-title h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.2px;
}

.section-title span {
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 600;
}

.section-copy {
  margin: 0 0 12px;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.65;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn .icon {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 6px 14px rgba(36, 88, 230, 0.2);
}

.btn-primary:hover {
  background: var(--blue-dark);
}

.btn-secondary {
  border: 1px solid var(--line-strong);
  background: var(--surface-soft);
  color: var(--ink-soft);
}

.btn-secondary:hover {
  background: var(--surface-sunk);
}

.btn-danger {
  color: var(--danger);
  background: rgba(217, 45, 32, 0.07);
}

.btn-danger:hover {
  background: rgba(217, 45, 32, 0.11);
}

.btn-ghost {
  color: var(--ink-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  border-color: var(--line);
  background: var(--surface-soft);
}

.btn-icon {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 7px;
}

.inline-field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: 12px;
}

.inline-field input:focus {
  outline: 0;
  border-color: rgba(36, 88, 230, 0.55);
  box-shadow: 0 0 0 3px rgba(36, 88, 230, 0.1);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.action-card:hover {
  border-color: rgba(36, 88, 230, 0.3);
  background: var(--blue-soft);
}

.action-card strong {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.action-card span {
  color: var(--ink-muted);
  font-size: 10px;
  line-height: 1.35;
}

.action-card .icon {
  width: 15px;
  height: 15px;
  color: var(--blue);
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.saved-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.saved-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.saved-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 auto;
  min-width: 0;
}

.saved-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.saved-meta {
  color: var(--ink-muted);
  font-size: 9px;
}

.saved-thumbs {
  display: flex;
  gap: 3px;
  flex: 0 0 auto;
}

.saved-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--thumb);
}

.saved-actions {
  display: flex;
  gap: 2px;
}

.empty-state {
  padding: 22px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--ink-muted);
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.example-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
}

.example-card:hover {
  border-color: rgba(36, 88, 230, 0.32);
  background: #fff;
  transform: translateY(-1px);
}

.example-card strong {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.example-card code {
  display: block;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: var(--font-math);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.example-card small {
  color: var(--ink-muted);
  font-size: 9px;
}

.syntax-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.syntax-item {
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
}

.syntax-item code {
  display: block;
  margin-bottom: 3px;
  color: var(--blue-dark);
  font-family: var(--font-mono);
  font-size: 10px;
}

.syntax-item span {
  color: var(--ink-muted);
  font-size: 10px;
  line-height: 1.45;
}

.kbd-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.kbd-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-soft);
  font-size: 10px;
  color: var(--ink-muted);
}

.kbd-cap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 650;
}

.install-steps {
  display: grid;
  gap: 8px;
  counter-reset: step;
}

.install-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
}

.install-step::before {
  counter-increment: step;
  content: counter(step);
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.install-step div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.install-step strong {
  font-size: 11px;
  font-weight: 700;
}

.install-step span {
  color: var(--ink-muted);
  font-size: 10px;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-sunk);
  color: var(--ink-muted);
  font-size: 9px;
  font-weight: 650;
}

.noscript {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  text-align: center;
}

/* -------------------------------------------------------------------------- */
/* Responsive: tablet / phone                                                 */
/* -------------------------------------------------------------------------- */

@media (max-width: 1080px) {
  :root {
    --panel-w: 350px;
  }
}

@media (max-width: 820px) {
  :root {
    --panel-w: 100%;
    --hit: 48px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(150px, 1fr) auto;
    height: 100dvh;
  }

  .plot-shell {
    grid-column: 1;
    grid-row: 1;
    min-height: 150px;
  }

  .panel {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    max-height: 58dvh;
    border-top: 1px solid var(--line-strong);
    border-right: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -12px 34px rgba(20, 28, 45, 0.12);
    overflow: hidden;
  }

  .panel-grabber {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 18px;
    flex: 0 0 auto;
    cursor: grab;
  }

  .panel-grabber span {
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: rgba(23, 32, 51, 0.2);
  }

  .panel-header {
    display: none;
  }

  .function-list {
    flex: 0 1 auto;
    min-height: 60px;
    max-height: 92px;
    padding: 0 10px 5px;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    gap: 6px;
    scrollbar-width: none;
  }

  .function-list::-webkit-scrollbar {
    display: none;
  }

  .fn-card {
    width: auto;
    min-width: 142px;
    max-width: 220px;
    flex: 0 0 auto;
    min-height: 52px;
    margin: 0;
    padding: 7px 8px 7px 9px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface-soft);
  }

  .fn-card.is-active {
    border-color: rgba(36, 88, 230, 0.32);
    background: var(--blue-soft);
    box-shadow: none;
    box-shadow: inset 0 -2px 0 var(--blue);
  }

  .fn-color {
    width: 5px;
    height: 28px;
    border-radius: 3px;
  }

  .fn-expression {
    font-size: 14px;
  }

  .fn-meta {
    font-size: 9px;
  }

  .fn-actions {
    display: none;
  }

  .panel-toolbar {
    gap: 6px;
    padding: 3px 10px 5px;
  }

  .mobile-only {
    display: grid;
  }

  .mobile-action.mobile-only {
    display: grid;
  }

  .mobile-action {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  .panel-toolbar .add-btn {
    height: 48px;
    padding: 0 8px;
  }

  .panel-toolbar #clearBtn {
    display: none;
  }

  .panel-toolbar #mobileSaveBtn {
    margin-left: auto;
  }

  .add-btn {
    height: 48px;
    padding: 0 10px;
    border: 0;
    background: transparent;
    color: var(--blue);
  }

  .add-btn:hover {
    background: transparent;
  }

  .ghost-btn {
    margin-left: auto;
    height: 48px;
  }

  .autosave-state {
    display: none;
  }

  .editor {
    padding: 6px 10px calc(8px + var(--safe-bottom));
  }

  .mode-strip {
    margin-bottom: 6px;
  }

  .mode-pills {
    padding: 2px;
    border-radius: 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mode-pills::-webkit-scrollbar {
    display: none;
  }

  .mode-pill {
    height: 48px;
    min-width: 64px;
    padding: 0 9px;
    flex: 1 0 auto;
    font-size: 11px;
  }

  .mode-help {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    display: none;
  }

  .expr-row {
    height: 52px;
    gap: 5px;
    padding-left: 10px;
  }

  .expr-field input {
    height: 48px;
    font-size: 17px;
  }

  .expr-tool {
    width: 48px;
    height: 48px;
  }

  .expr-feedback {
    min-height: 22px;
    padding-top: 4px;
    font-size: 10px;
  }

  .feedback-shortcut {
    display: none;
  }

  .panel.keypad-open {
    max-height: 64dvh;
  }

  .panel.keypad-open .function-list,
  .panel.keypad-open .panel-toolbar,
  .panel.keypad-open .mode-strip,
  .panel.keypad-open .expr-feedback {
    display: none;
  }

  .panel.keypad-open .panel-grabber {
    height: 16px;
  }

  .keypad {
    margin: 6px -10px 0;
    padding: 6px 4px;
  }

  .keypad-tabs {
    gap: 4px;
    margin-bottom: 6px;
  }

  .keypad-tab {
    min-height: 48px;
    font-size: 11px;
  }

  .keypad-grid {
    gap: 4px;
  }

  .math-key {
    min-height: 48px;
    font-size: 16px;
  }

  .math-key.is-function {
    font-size: 11px;
  }

  .style-popover {
    position: fixed;
    z-index: 60;
    right: 10px;
    bottom: calc(12px + var(--safe-bottom));
    left: 10px;
    max-height: 70dvh;
    overflow-y: auto;
  }

  .brand-mobile {
    display: flex;
  }

  .brand-mobile .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
  }

  .brand-mobile .brand-mark .icon {
    width: 24px;
    height: 24px;
  }

  .brand-mobile .brand-name {
    font-size: 18px;
  }

  .brand-mobile .brand-sub {
    font-size: 8px;
    letter-spacing: 1.2px;
  }

  .topbar {
    align-items: flex-start;
    padding: calc(10px + var(--safe-top)) 10px 0;
  }

  .topbar-actions {
    gap: 4px;
  }

  .tb-btn {
    min-width: 48px;
    min-height: 48px;
    padding: 0 8px;
    border-radius: 11px;
  }

  .tb-btn span {
    display: none;
  }

  .tb-btn.icon-only {
    width: 48px;
  }

  .cursor-readout {
    position: absolute;
    top: calc(58px + var(--safe-top));
    left: 10px;
    min-height: 30px;
    padding: 0 9px;
    font-size: 9px;
    border-radius: 9px;
  }

  .cursor-readout .view-zoom {
    display: none;
  }

  .coord b {
    min-width: 22px;
  }

  .floating-tools {
    right: 10px;
    bottom: 44px;
    gap: 2px;
    padding: 3px;
    border-radius: 13px;
  }

  .floating-tools {
    right: 10px;
    bottom: 14px;
    display: grid;
    grid-template-columns: repeat(2, 48px);
    gap: 2px;
    padding: 4px;
  }

  .tool-divider {
    display: none;
  }

  .tool-btn {
    width: 48px;
    height: 48px;
    border-radius: 9px;
  }

  .canvas-badge {
    bottom: 10px;
    left: 10px;
    min-height: 26px;
    padding: 0 9px;
    font-size: 9px;
  }

  .gesture-hint {
    bottom: 48px;
    font-size: 10px;
  }

  .hover-card {
    transform: translate(-50%, calc(-100% - 18px));
  }

  .toast-host {
    bottom: 18px;
    width: 100%;
    padding: 0 12px;
  }

  .toast {
    max-width: 100%;
    font-size: 11px;
  }

  .modal-layer {
    align-items: end;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: 90dvh;
    border-radius: 22px 22px 0 0;
    animation: modal-up 0.26s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  }

  @keyframes modal-up {
    from { opacity: 0; transform: translateY(34px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .modal-head {
    padding: 18px 18px 12px;
    padding-top: calc(18px + var(--safe-top));
  }

  .modal-head h2 {
    font-size: 20px;
  }

  .modal-close {
    width: 48px;
    height: 48px;
    margin: -6px -8px 0 0;
  }

  .modal-body {
    padding: 15px 18px calc(22px + var(--safe-bottom));
  }

  .modal-body .btn,
  .action-card,
  .saved-card .btn,
  .saved-card .btn-icon,
  .inline-field input,
  .example-card,
  .syntax-item {
    min-height: 48px;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .action-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
  }

  .action-card span {
    display: none;
  }

  .example-grid,
  .syntax-grid {
    grid-template-columns: 1fr;
  }

  .kbd-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .saved-card {
    flex-wrap: wrap;
    padding: 10px;
  }

  .saved-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .saved-actions .btn {
    min-height: 48px;
  }

  .inline-field {
    flex-wrap: wrap;
  }

  .inline-field input {
    flex-basis: 100%;
  }

  .inline-field .btn {
    min-width: 96px;
  }

  .style-footer button,
  .mini-close,
  .mode-help,
  .color-swatch,
  .color-custom {
    min-width: 48px;
    min-height: 48px;
  }

  .color-swatch {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  .color-custom {
    width: 48px;
    height: 48px;
  }

  .style-control select,
  .range-row input {
    min-height: 48px;
  }

  .style-control input[type="range"] {
    min-height: 48px;
  }

  .fn-action,
  .panel-action {
    min-width: 44px;
    min-height: 44px;
  }

  .fn-action,
  .panel-action {
    display: none;
  }
}

@media (max-width: 380px) {
  .mode-pill {
    min-width: 58px;
    font-size: 10px;
  }

  .topbar .brand-sub {
    display: none;
  }

  .keypad {
    margin-right: -8px;
    margin-left: -8px;
    padding-right: 2px;
    padding-left: 2px;
  }

  .math-key {
    font-size: 14px;
  }

  .math-key.is-function {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
