/* ── Math Function Graphing Calculator ──────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b27;
  --surface2:  #1f2535;
  --border:    #2a3050;
  --accent:    #18b4f5;
  --accent-lo: rgba(24,180,245,.22);
  --green:     #3ddc84;
  --red:       #ff5555;
  --gold:      #f5c842;
  --blue:      #42a5f5;
  --text:      #dde3f0;
  --text-dim:  #8b9dc3;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Courier New', monospace;
  --radius:    12px;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; padding: 0 16px; }
#app { max-width: 1140px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ── Header ──────────────────────────────────────────────────── */
header { text-align: center; padding: 4px 0; }
header h1 {
  font-size: 1.8rem; font-weight: 700;
  background: linear-gradient(120deg, #18b4f5 0%, #7dd3fc 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 3px; }

/* ── Controls bar ────────────────────────────────────────────── */
.controls-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ctrl-group { display: flex; align-items: center; gap: 8px; }
.ctrl-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); white-space: nowrap; }

/* ── Pill tabs ───────────────────────────────────────────────── */
.pill-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.pill {
  padding: 8px 16px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 6px; cursor: pointer; font-size: 0.81rem; min-height: 44px;
  transition: background .18s, color .18s, box-shadow .18s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-lo); }
.pill:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 0.84rem; font-weight: 600; transition: filter .18s, box-shadow .18s, opacity .18s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.12); box-shadow: 0 0 12px var(--accent-lo); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* ── User Guide button ───────────────────────────────────────── */
.btn-guide {
  margin-left: auto;
  padding: 6px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 0.82rem; font-weight: 700; text-decoration: none;
  background: var(--gold); color: #1a1a2e;
  transition: filter .18s, box-shadow .18s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn-guide:hover { filter: brightness(1.1); box-shadow: 0 0 14px rgba(245,200,66,.35); }

/* ── Hint bar ────────────────────────────────────────────────── */
.hint-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--accent-lo); border: 1px solid rgba(24,180,245,.3);
  border-radius: var(--radius); font-size: 0.82rem; color: var(--text-dim);
}
.hint-text { flex: 1; line-height: 1.4; }
.hint-close {
  background: none; border: none; color: var(--text-dim); font-size: 1.3rem;
  cursor: pointer; padding: 4px 8px; border-radius: 4px; line-height: 1;
  transition: color .15s, background .15s;
}
.hint-close:hover { color: var(--text); background: rgba(255,255,255,.08); }

/* ── Presets bar ─────────────────────────────────────────────── */
.presets-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.presets-bar .ctrl-label { flex-shrink: 0; }
.presets-bar .pill-tabs { flex: 1; }

/* ── Graph layout ────────────────────────────────────────────── */
.graph-layout {
  display: flex; gap: 12px; min-height: 520px;
}
.expr-sidebar {
  width: 310px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0; overflow-y: auto; max-height: 620px;
  display: flex; flex-direction: column; gap: 0;
}
.graph-card {
  flex: 1;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px; position: relative; overflow: hidden;
}
.graph-card canvas {
  display: block; width: 100%; height: auto;
  cursor: crosshair; touch-action: none;
}

/* ── Fullscreen Mode ─────────────────────────────────────────── */
.fullscreen-btn {
  position: absolute; top: 64px; right: 10px; z-index: 6;
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.fullscreen-btn { text-shadow: 0 0 6px rgba(241,250,140,.6), 0 0 12px rgba(241,250,140,.3); }
.fullscreen-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--surface2); text-shadow: 0 0 8px rgba(241,250,140,.8); }

.sidebar-toggle {
  display: none; /* Hidden outside fullscreen */
  position: absolute; z-index: 12;
  top: 50%; left: 310px; transform: translateY(-50%);
  width: 24px; height: 48px; border-radius: 0 8px 8px 0;
  background: var(--surface2); border: 1px solid var(--border); border-left: none;
  color: var(--text-dim); font-size: 1rem; cursor: pointer;
  align-items: center; justify-content: center;
  transition: left .25s ease, color .15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.sidebar-toggle { text-shadow: 0 0 6px rgba(241,250,140,.6), 0 0 12px rgba(241,250,140,.3); }
.sidebar-toggle:hover { color: var(--accent); background: var(--accent-lo); text-shadow: 0 0 8px rgba(241,250,140,.8); }

/* Fullscreen state — applied via .is-fullscreen class */
.graph-layout.is-fullscreen {
  position: relative;
  background: var(--bg);
  gap: 0;
  width: 100%; height: 100%;
}

.graph-layout.is-fullscreen .sidebar-toggle {
  display: flex;
}

.graph-layout.is-fullscreen .expr-sidebar {
  max-height: none; height: 100%;
  border-radius: 0; border-right: 1px solid var(--border);
  border-top: none; border-bottom: none; border-left: none;
  transition: width .25s ease, opacity .2s ease;
  will-change: width;
  overflow-y: auto;
}

.graph-layout.is-fullscreen .expr-sidebar.collapsed {
  width: 0 !important; min-width: 0;
  overflow: hidden; opacity: 0;
  padding: 0; border: none;
}

.graph-layout.is-fullscreen .sidebar-toggle.sb-collapsed {
  left: 0; border-radius: 0 8px 8px 0;
}

.graph-layout.is-fullscreen .graph-card {
  border-radius: 0; border: none;
  flex: 1; min-height: 0;
}

.graph-layout.is-fullscreen .graph-card .tool-bar {
  border-radius: 0;
}

/* ── Graph toolbar (overlay on canvas) ───────────────────────── */
/* Export button — bottom-right of graph */
.export-btn {
  position: absolute; bottom: 10px; right: 10px; z-index: 5;
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.5; transition: all .2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.export-btn:hover { opacity: 1; border-color: var(--accent); color: var(--accent); background: var(--surface2); }

.graph-toolbar {
  position: absolute; bottom: 10px; left: 10px;
  display: flex; flex-direction: column; gap: 4px; z-index: 5;
}
.tb-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-dim); cursor: pointer; font-size: 1rem;
  transition: color .15s, border-color .15s, background .15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
.tb-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--surface2); }
.tb-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-lo); }

/* ── Sidebar: section structure ──────────────────────────────── */
.sb-section { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.sb-section:last-child { border-bottom: none; }
.sb-section-head {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-dim); font-weight: 700; padding: 0 0 6px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  user-select: none; list-style: none; display: flex; align-items: center; gap: 6px;
}
.sb-section-head::marker, .sb-section-head::-webkit-details-marker { display: none; }
.sb-details { border-bottom: 1px solid var(--border); padding: 0; }
.sb-details > .sb-section-head { padding: 10px 14px 10px; border-bottom: none; margin: 0; }
.sb-details[open] > .sb-section-head { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.sb-details > .sb-section-head::before {
  content: ''; display: inline-block; width: 0; height: 0;
  border-left: 4px solid var(--text-dim); border-top: 3px solid transparent;
  border-bottom: 3px solid transparent; transition: transform .2s; flex-shrink: 0;
}
.sb-details[open] > .sb-section-head::before { transform: rotate(90deg); }
.sb-details > .sb-section-head::after { display: none; }
.sb-details .sb-section { border-bottom: none; }
.sb-details > .sb-analysis-grid,
.sb-details > .sb-toggle-grid,
.sb-details > .sb-integral-row,
.sb-details > .sb-integral-result { padding: 0 14px; }
.sb-details > .sb-analysis-grid { padding-top: 6px; padding-bottom: 10px; }
.sb-details > .sb-toggle-grid { padding-top: 8px; padding-bottom: 10px; }
.sb-details > .sb-integral-row { padding-top: 8px; }
.sb-details > .sb-integral-result { padding-bottom: 10px; }

/* ── Sidebar: Function list area ────────────────────────────── */
.sb-func-list { display: flex; flex-direction: column; gap: 0; }

/* ── Sidebar: Add Function button ───────────────────────────── */
.sb-add-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: calc(100% - 28px); margin: 10px 14px; padding: 12px;
  border: 1.5px dashed var(--border); border-radius: 8px;
  background: transparent; color: var(--text-dim);
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: all .18s; letter-spacing: .02em;
  min-height: 44px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.sb-add-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-lo); }
.sb-add-icon {
  font-size: 1.1rem; font-weight: 300; line-height: 1;
}

/* ── Function cards ─────────────────────────────────────────── */
.func-card {
  background: var(--surface); border-left: 4px solid var(--border);
  padding: 0; position: relative;
  transition: background .18s, border-color .18s;
  border-bottom: 1px solid var(--border);
}
.func-card:last-child { border-bottom: none; }
.func-card:hover { background: var(--surface2); }
.func-card.selected { background: rgba(24,180,245,.14); }
.func-card.has-error .func-card-error { display: block; }

.func-card-body {
  padding: 10px 12px 10px 12px; cursor: pointer; position: relative;
}
.func-card-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.func-name {
  font-family: var(--mono); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim);
}
.func-card-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

/* Visibility: colored dot */
/* Eye icon visibility toggle */
.func-vis-btn {
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
  border: none; background: transparent; padding: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, background .15s;
  flex-shrink: 0; opacity: 0.85;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.func-vis-btn:hover { background: rgba(255,255,255,.08); opacity: 1; }
.func-vis-btn.vis-hidden { opacity: 0.35; }
.func-vis-btn svg { display: block; }

/* Delete: × appears on hover (desktop) or always visible on touch */
.func-del {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px;
  color: var(--text-dim); cursor: pointer; font-size: 1.1rem; line-height: 1;
  transition: all .12s; opacity: 0; pointer-events: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.func-card:hover .func-del { opacity: 1; pointer-events: auto; }
.func-card.selected .func-del { opacity: 0.6; pointer-events: auto; }
.func-del:hover { color: var(--red); background: rgba(255,85,85,.12); }

/* Expression input */
.func-expr-input {
  width: 100%; padding: 11px 14px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 0.92rem; color: var(--text);
  transition: border-color .15s, box-shadow .15s; outline: none;
  min-height: 44px;
}
.func-expr-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-lo); }
.func-expr-input::placeholder { color: var(--text-dim); opacity: 0.35; font-style: italic; }

.func-card-error {
  font-size: 0.7rem; color: var(--gold); padding: 6px 12px 8px; line-height: 1.5;
  display: none;
  background: rgba(245,200,66,.06);
  border-radius: 0 0 6px 6px;
  border-top: 1px dashed rgba(245,200,66,.25);
}

/* ── Analysis grid ──────────────────────────────────────────── */
.sb-analysis-grid { display: flex; flex-direction: column; gap: 10px; }
.sb-analysis-group {
  display: flex; flex-direction: column; gap: 5px;
}
.sb-analysis-group.sb-analysis-yint {
  flex-direction: row; align-items: center; gap: 8px;
  padding: 6px 0; border-top: 1px solid rgba(42,48,80,.25);
}
.sb-analysis-header {
  display: flex; align-items: center; gap: 6px;
}
.sb-analysis-key {
  color: var(--text-dim); font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: .05em; font-weight: 600;
}
.sb-analysis-count {
  font-size: 0.6rem; font-weight: 700; color: var(--accent);
  background: var(--accent-lo); border-radius: 8px;
  padding: 1px 6px; min-width: 18px; text-align: center;
  line-height: 1.3;
}
.sb-analysis-chips {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 4px;
}
.sb-analysis-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  padding: 3px 8px; border-radius: 6px;
  font-family: var(--mono); font-size: 0.72rem; line-height: 1.3;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); cursor: default;
  transition: background .12s, border-color .12s;
  text-align: center; white-space: nowrap;
}
.sb-analysis-chip:hover {
  background: var(--accent-lo); border-color: var(--accent); cursor: pointer;
}
.sb-analysis-chip.active {
  background: var(--accent-lo); border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-lo);
}
.sb-analysis-chip.ext-max.active { border-color: var(--green); box-shadow: 0 0 8px rgba(61,220,132,.3); background: rgba(61,220,132,.12); }
.sb-analysis-chip.ext-min.active { border-color: var(--red); box-shadow: 0 0 8px rgba(255,85,85,.3); background: rgba(255,85,85,.12); }
.sb-analysis-chip.inflect.active { border-color: var(--gold); box-shadow: 0 0 8px rgba(245,200,66,.3); background: rgba(245,200,66,.12); }
.sb-analysis-chip.root {
  color: var(--accent);
}
.sb-analysis-chip.ext-max {
  color: var(--green); border-color: rgba(61,220,132,.25);
}
.sb-analysis-chip.ext-max::before {
  content: '\25B2'; font-size: 0.55rem;
}
.sb-analysis-chip.ext-min {
  color: var(--red); border-color: rgba(255,85,85,.25);
}
.sb-analysis-chip.ext-min::before {
  content: '\25BC'; font-size: 0.55rem;
}
.sb-analysis-chip.inflect {
  color: var(--gold); border-color: rgba(245,200,66,.2);
}
.sb-analysis-chip.yint {
  color: var(--accent); font-weight: 600;
}
.sb-analysis-none {
  font-size: 0.75rem; color: var(--text-dim); font-style: italic;
}

/* ── Toggle switches ────────────────────────────────────────── */
.sb-toggle-grid { display: flex; flex-direction: column; gap: 8px; }
.sb-toggle {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 2px 0; font-size: 0.78rem; color: var(--text);
}
.sb-toggle input { display: none; }
.sb-toggle-track {
  width: 44px; height: 24px; border-radius: 12px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border);
  position: relative; transition: background .2s, border-color .2s;
  touch-action: manipulation; cursor: pointer;
}
.sb-toggle-track::after {
  content: ''; position: absolute; top: 2px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-dim); transition: transform .2s, background .2s;
}
.sb-toggle input:checked + .sb-toggle-track {
  background: var(--accent); border-color: var(--accent);
}
.sb-toggle input:checked + .sb-toggle-track::after {
  transform: translateX(19px); background: #fff;
}
.sb-toggle-label { flex: 1; font-size: 0.78rem; }

/* ── Integral section ───────────────────────────────────────── */
.sb-integral-row { display: flex; gap: 8px; margin-bottom: 8px; }
.sb-integral-field { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.sb-integral-label { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.sb-integral-input {
  width: 100%; padding: 7px 10px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 0.82rem; color: var(--text);
  outline: none; transition: border-color .15s;
}
.sb-integral-input:focus { border-color: var(--accent); }
.sb-integral-result {
  font-size: 0.82rem; color: var(--text-dim);
  padding: 8px 12px; background: var(--accent-lo); border-radius: 20px;
  display: inline-flex; align-items: center; gap: 6px;
}
.sb-integral-value { font-family: var(--mono); font-weight: 700; color: var(--accent); }

/* ── Slider rows (parameters a, b, c, etc.) ──────────────────── */
.slider-row {
  display: flex; flex-direction: column; gap: 2px; padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.slider-row:last-child { border-bottom: none; }
.slider-top-row {
  display: flex; align-items: center; gap: 6px;
}
.slider-bound-row {
  display: flex; align-items: center; gap: 4px;
  padding-left: 20px;
}
.slider-bound-label {
  font-size: 0.6rem; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .04em; font-family: var(--mono);
}
.func-check {
  font-size: 0.85rem; font-weight: 700; margin-right: 4px;
  line-height: 1;
}
.slider-label {
  font-family: var(--mono); font-size: 0.78rem; font-weight: 700;
  min-width: 14px; display: flex; align-items: center; gap: 4px;
}
.slider-label-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.slider-range {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 3px; background: var(--surface2); outline: none;
  touch-action: manipulation;
}
.slider-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  border: 2px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.4);
}
.slider-range::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  border: 2px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.4);
}
.slider-val {
  font-family: var(--mono); font-size: 0.72rem;
  min-width: 36px; flex-shrink: 0; text-align: right; color: var(--text);
}
.slider-bound-input {
  width: 52px; flex: 0 0 52px;
  height: 30px;
  padding: 0 4px;
  font-size: 0.72rem; font-family: var(--mono);
  color: var(--text-dim); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  text-align: center; outline: none;
  -moz-appearance: textfield;
  transition: border-color .15s, color .15s;
  touch-action: manipulation;
}
.slider-bound-input::-webkit-inner-spin-button,
.slider-bound-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.slider-bound-input:focus {
  border-color: var(--accent); color: var(--accent);
}

/* ── Analysis panel ──────────────────────────────────────────── */
.analysis-item {
  display: flex; gap: 6px; font-size: 0.8rem;
  padding: 5px 0; border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.analysis-item:last-child { border-bottom: none; }
.analysis-label {
  color: var(--text-dim); min-width: 70px; flex-shrink: 0;
  font-size: 0.74rem; text-transform: uppercase; letter-spacing: .04em;
}
.analysis-value {
  font-family: var(--mono); color: var(--accent); font-weight: 600;
  word-break: break-all;
}

/* ── Options checkboxes ──────────────────────────────────────── */
.opt-check {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.8rem; cursor: pointer; padding: 3px 0;
  color: var(--text-dim); user-select: none;
}
.opt-check input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0;
  border: 1.5px solid var(--border); background: var(--bg);
  cursor: pointer; position: relative; transition: border-color .15s, background .15s;
  touch-action: manipulation;
}
.opt-check input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
}
.opt-check input[type="checkbox"]:checked::after {
  content: '\2713'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: #fff; font-weight: 700;
}
.opt-check:hover { color: var(--text); }

/* ── Integral section ────────────────────────────────────────── */
.integral-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.integral-input {
  width: 70px; padding: 5px 8px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 0.82rem; color: var(--text);
  text-align: center;
}
.integral-input:focus { border-color: var(--accent); outline: none; }
.integral-label { font-size: 0.78rem; color: var(--text-dim); }
.integral-result {
  font-family: var(--mono); font-size: 0.88rem;
  color: var(--accent); font-weight: 700;
}

/* ── Table panel ─────────────────────────────────────────────── */
.table-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; max-height: 300px; overflow-y: auto;
}
.table-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.table-header .section-title { margin-bottom: 0; }
.table-panel table {
  width: 100%; border-collapse: collapse;
  font-family: var(--mono); font-size: 0.82rem;
}
.table-panel th {
  text-align: center; padding: 6px 10px;
  border-bottom: 2px solid var(--border);
  color: var(--accent); font-weight: 700; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 0; background: var(--surface);
}
.table-panel td {
  text-align: center; padding: 5px 10px;
  border-bottom: 1px solid var(--border); color: var(--text-dim);
}
.table-panel tr:nth-child(even) td { background: var(--surface2); }
.table-panel tr:hover td { background: var(--accent-lo); color: var(--text); }

/* ── Context menu ────────────────────────────────────────────── */
.graph-ctx-menu {
  position: fixed; z-index: 1000;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 0; min-width: 200px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.ctx-item {
  padding: 12px 16px; font-size: 0.86rem; color: var(--text);
  cursor: pointer; transition: background .12s;
  min-height: 44px; display: flex; align-items: center;
  touch-action: manipulation;
}
.ctx-item:hover { background: var(--accent-lo); }
.ctx-item-danger { color: #ff6b6b; }
.ctx-item-danger:hover { background: rgba(211,47,47,.15); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Readout row ─────────────────────────────────────────────── */
.readout-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
}
.readout-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; text-align: center;
}
.readout-label { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.readout-val { font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.readout-unit { font-size: 0.75rem; color: var(--text-dim); margin-left: 2px; }

/* ── Explore mode ────────────────────────────────────────────── */
.item-selector {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px;
}
.is-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.is-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; cursor: pointer; transition: border-color .15s, background .15s;
}
.is-card:hover { border-color: var(--accent); background: var(--surface2); }
.is-card.active { border-color: var(--accent); background: var(--accent-lo); }
.is-card-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.is-card-symbol { font-size: 0.7rem; color: var(--text-dim); margin-top: 2px; }

.item-info {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; line-height: 1.6;
}
.item-info h3 { font-size: 1.1rem; color: var(--accent); margin-bottom: 8px; }
.item-info h4 { font-size: 0.9rem; color: var(--blue); margin: 12px 0 4px; }
.item-info p { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; }
.item-info ul, .item-info ol { font-size: 0.83rem; color: var(--text-dim); padding-left: 20px; margin-bottom: 8px; }
.item-info li { margin-bottom: 3px; }
.item-info .formula-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-family: var(--mono); font-size: 0.85rem; color: var(--gold); margin: 8px 0;
}

/* ── Practice mode ───────────────────────────────────────────── */
.practice-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.pp-prompt { font-size: 0.95rem; line-height: 1.5; margin-bottom: 14px; }
.pp-input-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pp-input {
  width: 120px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 1rem;
}
.pp-unit { font-size: 0.85rem; color: var(--text-dim); }
.pp-bottom { margin-top: 12px; }
.feedback { font-weight: 600; font-size: 0.9rem; }
.feedback.correct { color: var(--green); }
.feedback.wrong { color: var(--red); }
.solution-panel {
  margin-top: 12px; padding: 12px 14px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 0.85rem; line-height: 1.6; color: var(--text-dim);
}
.practice-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.pbar-score { font-size: 0.85rem; color: var(--accent); font-weight: 600; }

/* ── Quiz mode ───────────────────────────────────────────────── */
.question-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.q-prompt { font-size: 0.95rem; line-height: 1.5; margin-bottom: 14px; }
.q-options { display: flex; flex-direction: column; gap: 8px; }
.q-opt {
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 0.88rem; transition: border-color .15s, background .15s;
}
.q-opt:hover { border-color: var(--accent); background: var(--surface2); }
.q-opt.selected { border-color: var(--accent); background: var(--accent-lo); }
.q-opt.correct { border-color: var(--green); background: rgba(61,220,132,.12); color: var(--green); }
.q-opt.wrong { border-color: var(--red); background: rgba(255,85,85,.12); color: var(--red); }
.quiz-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.qbar-counter { display: flex; align-items: baseline; gap: 4px; }
.qbar-q-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; }
.qbar-q-num { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.qbar-q-sep { color: var(--text-dim); }
.qbar-q-total { font-size: 0.9rem; color: var(--text-dim); }
.quiz-result {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center;
}
.quiz-result h3 { font-size: 1.3rem; color: var(--accent); margin-bottom: 8px; }
.quiz-result .score { font-size: 2rem; font-weight: 700; color: var(--gold); }

/* ── User Guide modal ────────────────────────────────────────── */
.guide-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center;
}
.guide-modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  max-width: 780px; width: 92%; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 48px rgba(0,0,0,.6);
}
.guide-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 1px solid var(--border);
}
.guide-header h2 { font-size: 1.15rem; color: var(--accent); }
.guide-close {
  background: none; border: none; color: var(--text-dim); font-size: 1.6rem;
  cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: color .15s, background .15s;
}
.guide-close:hover { color: var(--red); background: rgba(255,85,85,.12); }
.guide-body {
  overflow-y: auto; padding: 20px 24px; flex: 1;
}
.guide-body h3 { color: var(--accent); font-size: 1rem; margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.guide-body h3:first-child { margin-top: 0; }
.guide-body h4 { color: var(--blue); font-size: 0.88rem; margin: 12px 0 4px; }
.guide-body p { font-size: 0.84rem; color: var(--text-dim); line-height: 1.6; margin-bottom: 8px; }
.guide-body ul, .guide-body ol { font-size: 0.83rem; color: var(--text-dim); padding-left: 20px; margin-bottom: 8px; line-height: 1.5; }
.guide-body li { margin-bottom: 3px; }
.guide-body kbd {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--border); font-family: var(--mono);
  font-size: 0.78rem; color: var(--text);
}
.guide-body table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; font-size: 0.82rem; }
.guide-body th { text-align: left; padding: 6px 10px; border-bottom: 2px solid var(--border); color: var(--text); font-weight: 600; }
.guide-body td { padding: 5px 10px; border-bottom: 1px solid var(--border); color: var(--text-dim); }
.guide-body strong { color: var(--text); }

/* ── SEO article ─────────────────────────────────────────────── */
.seo-article {
  padding: 28px 24px; line-height: 1.75;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.seo-article h2 { font-size: 1.3rem; color: var(--text); margin-bottom: 12px; }
.seo-article h3 { font-size: 1.05rem; color: var(--accent); margin: 18px 0 6px; }
.seo-article p { font-size: 0.92rem; color: var(--text-dim); margin-bottom: 10px; }
.seo-article a { color: var(--accent); text-decoration: underline; }
.seo-article a:hover { color: #7dd3fc; }
.fn-ref-table {
  width: 100%; border-collapse: collapse; margin: 12px 0 18px; font-size: 0.88rem;
}
.fn-ref-table th {
  text-align: left; padding: 10px 12px; background: var(--surface2);
  color: var(--accent); font-weight: 600; border-bottom: 2px solid var(--border);
}
.fn-ref-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text-dim);
}
.fn-ref-table td code { color: var(--green); font-family: var(--mono); font-size: 0.85rem; }
.fn-ref-table tr:nth-child(even) td { background: var(--surface2); }
.fn-ref-table tr:hover td { background: var(--accent-lo); color: var(--text); }

/* ── Tool Mode Bar ──────────────────────────────────────────── */
.tool-bar {
  display: flex; gap: 6px; padding: 6px 8px; align-items: center;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tool-btn {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text-dim); font-size: 0.82rem;
  cursor: pointer; transition: all .15s; white-space: nowrap;
  min-height: 44px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
.tool-btn:hover { background: var(--surface); color: var(--text); border-color: var(--accent); }
.tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Sketch Tool Button Group ──────────────────────────────── */
.tool-btn-group {
  position: relative; display: flex; flex-shrink: 0;
}
.tool-btn-group .tool-btn-sketch {
  border-top-right-radius: 0; border-bottom-right-radius: 0;
  border-right: none;
}
.tool-btn-drop {
  padding: 8px 8px; border: 1px solid var(--border); border-radius: 0 8px 8px 0;
  background: transparent; color: var(--text-dim); font-size: 0.78rem;
  cursor: pointer; transition: all .15s; min-height: 44px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  display: flex; align-items: center;
}
.tool-btn-drop:hover { background: var(--surface); color: var(--text); }
.tool-btn-group .tool-btn-sketch.active ~ .tool-btn-drop,
.tool-btn-group .tool-btn-sketch.active + .tool-btn-drop {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Color indicator dot on sketch button */
.tool-btn-sketch::after {
  content: ''; display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-left: 5px; vertical-align: middle;
  background: var(--sketch-color, #fff); border: 1px solid rgba(255,255,255,.3);
  flex-shrink: 0;
}

/* Sketch dropdown */
.sketch-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 300;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-width: 180px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.sketch-dd-label {
  font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 6px; margin-top: 4px;
}
.sketch-dd-label:first-child { margin-top: 0; }
.sketch-colors { display: flex; gap: 6px; margin-bottom: 8px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
  cursor: pointer; transition: all .15s; flex-shrink: 0;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.sketch-widths { display: flex; gap: 6px; }
.width-btn {
  flex: 1; padding: 6px 0; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-dim); cursor: pointer;
  transition: all .15s; display: flex; align-items: center; justify-content: center;
  min-height: 32px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.width-btn:hover { background: var(--surface2); color: var(--text); }
.width-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.wline { display: block; border-radius: 2px; background: currentColor; }
.wline-thin  { width: 20px; height: 2px; }
.wline-med   { width: 20px; height: 4px; }
.wline-thick { width: 20px; height: 7px; }

/* Clear action button (not a tool mode) */
.tool-btn-action {
  border-color: rgba(211,47,47,.3); color: var(--text-dim);
}
.tool-btn-action:hover {
  background: rgba(211,47,47,.12); color: #ff6b6b; border-color: rgba(211,47,47,.5);
}

/* ── Shape Marking Tool ────────────────────────────────────── */
.tool-btn-shape::after {
  content: ''; display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-left: 5px; vertical-align: middle;
  background: var(--shape-color, #fff); border: 1px solid rgba(255,255,255,.3);
  flex-shrink: 0;
}
.tool-btn-group .tool-btn-shape {
  border-top-right-radius: 0; border-bottom-right-radius: 0;
  border-right: none;
}
.tool-btn-group .tool-btn-shape.active ~ .tool-btn-drop,
.tool-btn-group .tool-btn-shape.active + .tool-btn-drop {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.shape-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 300;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-width: 200px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.shape-picker {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px;
}
.shape-pick {
  padding: 6px 0; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-dim); cursor: pointer;
  font-size: 1rem; text-align: center; transition: all .15s;
  min-height: 34px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.shape-pick:hover { background: var(--surface2); color: var(--text); }
.shape-pick.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.shape-fill-row { display: flex; gap: 6px; }
.fill-btn {
  flex: 1; padding: 6px 0; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-dim); cursor: pointer;
  font-size: 0.78rem; transition: all .15s; text-align: center;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.fill-btn:hover { background: var(--surface2); color: var(--text); }
.fill-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Shape text inline input */
.shape-text-input {
  position: absolute; z-index: 50; padding: 4px 8px;
  background: rgba(13,17,23,.9); border: 1px solid var(--accent);
  border-radius: 6px; color: #fff; font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  outline: none; min-width: 80px; max-width: 220px;
}

/* ── Settings Panel ─────────────────────────────────────────── */
.settings-panel {
  position: absolute; top: 44px; right: 8px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0; min-width: 260px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.settings-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 0.85rem; font-weight: 700; color: var(--text);
}
.settings-close-btn {
  background: none; border: none; color: var(--text-dim); font-size: 1.2rem;
  cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.settings-close-btn:hover { color: var(--red); background: rgba(255,85,85,.1); }
.settings-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.settings-row {
  display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px; align-items: center;
}
.settings-row label { font-size: 0.75rem; color: var(--text-dim); }
.settings-row input {
  width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-family: var(--mono); font-size: 0.82rem;
}

/* ── Clear Analysis Confirmation Dialog ─────────────────────── */
.confirm-overlay {
  position: absolute; inset: 0; z-index: 200;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.confirm-dialog {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 24px; max-width: 320px; width: 90%;
  text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.confirm-icon { font-size: 2rem; margin-bottom: 8px; }
.confirm-title {
  font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 6px;
}
.confirm-msg {
  font-size: 0.8rem; color: var(--text-dim); line-height: 1.45; margin-bottom: 16px;
}
.clear-select {
  width: 100%; padding: 10px 12px; margin: 10px 0 6px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.85rem; font-family: var(--font);
  cursor: pointer; appearance: auto; outline: none;
}
.clear-select:focus { border-color: var(--accent); }
.clear-hint {
  font-size: 0.7rem; color: var(--text-dim); text-align: center;
  margin-bottom: 12px; line-height: 1.4; min-height: 2em;
}
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions .btn { flex: 1; padding: 8px 0; font-size: 0.82rem; border-radius: 8px; cursor: pointer; }
.btn-danger {
  background: #d32f2f; color: #fff; border: none; font-weight: 600;
}
.btn-danger:hover { background: #b71c1c; }

/* ── Slider Animation Button ────────────────────────────────── */
.slider-play-btn {
  width: 36px; height: 36px; border: none; border-radius: 50%;
  background: var(--surface2); color: var(--accent); cursor: pointer;
  font-size: 0.78rem; display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0; min-width: 44px; min-height: 44px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.slider-play-btn:hover { background: var(--accent); color: #fff; }

/* ── Free Point Labels ──────────────────────────────────────── */
.point-label {
  font-family: var(--mono); font-size: 0.75rem; color: var(--text);
}

/* ── Touch devices: ensure minimum tap targets ────────────────── */
@media (pointer: coarse) {
  .func-del { opacity: 0.5; pointer-events: auto; }
  .func-card.selected .func-del { opacity: 0.8; }
  .sb-section-head { padding: 12px 14px 12px; min-height: 44px; }
  .sb-toggle { padding: 6px 0; min-height: 44px; }
  .opt-check { padding: 6px 0; min-height: 44px; }
  .slider-row { padding: 8px 0; }
  .slider-top-row { gap: 8px; min-height: 36px; }
  .slider-bound-row { padding-top: 4px; gap: 6px; }
  .func-card-body { padding: 12px 14px 12px 14px; }
  .sb-integral-input { min-height: 40px; padding: 8px 10px; font-size: 0.88rem; }
  .tool-bar { gap: 6px; padding: 8px 10px; }
}

/* ── Responsive: iPad landscape (1024px) ─────────────────────── */
@media (max-width: 1024px) {
  .expr-sidebar { width: 280px; max-height: 560px; }
}

/* ── Responsive: tablet / iPad portrait ──────────────────────── */
@media (max-width: 768px) {
  .graph-layout { flex-direction: column; }
  .expr-sidebar {
    width: 100%; max-height: 280px; flex-direction: column;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  .sb-section { padding: 10px 14px; }
  .graph-card { min-height: 400px; }
  .readout-row { grid-template-columns: repeat(2, 1fr); }
  .guide-modal { width: 95%; max-height: 90vh; }
  .guide-header { padding: 14px 18px; }
  .guide-body { padding: 14px 18px; }
  .table-panel { max-height: 250px; }
  .presets-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .presets-bar .pill-tabs { flex-wrap: nowrap; }
}

/* ── Responsive: mobile ──────────────────────────────────────── */
@media (max-width: 500px) {
  header h1 { font-size: 1.3rem; }
  .controls-bar { padding: 8px 10px; gap: 8px; }
  .pill { padding: 8px 14px; font-size: 0.78rem; min-height: 44px; }
  .pill-tabs { flex-wrap: wrap; }
  .expr-sidebar { max-height: 240px; flex-direction: column; }
  .sb-func-list { min-width: unset; }
  .func-expr-input { font-size: 0.88rem; padding: 10px 12px; }
  .graph-card { min-height: 320px; }
  .readout-row { grid-template-columns: repeat(2, 1fr); }
  .graph-toolbar { bottom: 6px; left: 6px; }
  .tb-btn { width: 36px; height: 36px; font-size: 0.9rem; }
  .slider-val { min-width: 40px; font-size: 0.72rem; }
  .integral-input { width: 56px; }
  .guide-modal { width: 100%; max-height: 100vh; border-radius: 0; }
  .guide-header h2 { font-size: 0.95rem; }
  .guide-body { padding: 12px 14px; }
  .seo-article { padding: 18px 14px; }
  .seo-article h2 { font-size: 1.1rem; }
  .seo-article p { font-size: 0.85rem; }
  .tool-btn { padding: 6px 10px; font-size: 0.76rem; min-height: 40px; }
  .tool-bar { gap: 4px; padding: 6px 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ── Focus-visible for keyboard navigation ───────────────────── */
.pill:focus-visible, .tb-btn:focus-visible, .func-expr-input:focus-visible,
.func-del:focus-visible, .opt-check input:focus-visible,
button:focus-visible, input:focus-visible, select:focus-visible,
.q-opt:focus-visible, .is-card:focus-visible, .ctx-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
