/* ============ 函数图像生成器 · 深色玻璃主题（与 image-metadata-cleaner 同一设计系统） ============ */

:root {
  --bg: #0a0a0c;
  --topbar-h: 60px;
  --glass: rgba(13, 14, 18, 0.62);
  --glass-strong: rgba(16, 17, 22, 0.82);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f2f3f6;
  --text-2: rgba(233, 236, 242, 0.66);
  --text-3: rgba(233, 236, 242, 0.42);
  --ok: #3ddc97;
  --danger: #ff7a7a;
  --warn: #ffce5c;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --serif: Georgia, 'Times New Roman', 'STIX Two Math', serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  padding-top: var(--topbar-h);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Helvetica Neue', 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

#bgCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  display: block;
  transform: translateZ(0);
  backface-visibility: hidden;
}

::selection { background: rgba(255, 255, 255, 0.22); }

a { color: inherit; }

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

:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.55);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ============ 顶栏 ============ */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 24px;
  background: rgba(10, 10, 12, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 650; letter-spacing: 0.2px; }
.brand-text small { font-size: 11px; color: var(--text-3); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

/* ============ 主体布局 ============ */

main {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: clamp(28px, 6vw, 56px) clamp(16px, 4vw, 32px) 40px;
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 4vw, 30px);
}

.hero { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }

.hero h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 40px);
  line-height: 1.2;
  letter-spacing: -0.3px;
  font-weight: 700;
}

.hero p {
  margin: 0;
  max-width: 640px;
  color: var(--text-2);
  font-size: clamp(14px, 2.4vw, 16px);
}

/* ============ 玻璃面板 ============ */

.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: clamp(16px, 3vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-3); letter-spacing: 0.6px; text-transform: uppercase; }
.panel-head .ph-sub { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.panel-head .ph-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ============ 函数列表 ============ */

.fn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.fn-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.028);
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  cursor: pointer;
}

.fn-row:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.05); }

.fn-row.selected {
  border-color: color-mix(in srgb, var(--fn-color, #4cc2ff) 55%, transparent);
  background: color-mix(in srgb, var(--fn-color, #4cc2ff) 7%, rgba(255, 255, 255, 0.028));
}

.fn-row.dim .fn-input { opacity: 0.45; }
.fn-row.dim .fn-dot { opacity: 0.35; }

.fn-id { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }

.fn-dot {
  width: 26px;
  height: 5px;
  border-radius: 99px;
  background: var(--fn-color, #4cc2ff);
}

.fn-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14.5px;
  color: var(--text-2);
  white-space: nowrap;
}

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

.fn-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.fn-input:focus { border-color: rgba(255, 255, 255, 0.35); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06); }
.fn-input::placeholder { color: var(--text-3); }

.fn-err { color: var(--danger); font-size: 12px; padding-left: 2px; }

.fn-side { display: flex; flex-direction: column; gap: 6px; }

.fn-actions { display: flex; gap: 6px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.14s ease, color 0.14s ease;
}

.btn-icon:hover { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.btn-icon svg { width: 13px; height: 13px; }
.btn-icon.active { color: var(--ok); border-color: rgba(61, 220, 151, 0.35); background: rgba(61, 220, 151, 0.1); }

.fn-actions-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

.btn:active { transform: scale(0.98); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text-2);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost.active { color: var(--ok); border-color: rgba(61, 220, 151, 0.35); background: rgba(61, 220, 151, 0.1); }

.fn-empty { margin: 4px 0 0; color: var(--text-3); font-size: 13.5px; text-align: center; padding: 16px 0; }

/* ============ 函数库 ============ */

.lib { display: flex; flex-direction: column; gap: 8px; }

.lib-cat { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.lib-cat > span { font-size: 11.5px; color: var(--text-3); min-width: 64px; letter-spacing: 0.4px; }

.chip {
  font-size: 11px;
  line-height: 1.6;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-2);
  font-family: var(--mono);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.chip:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); border-color: var(--line-strong); }

/* ============ 画布 ============ */

.legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  font-family: var(--serif);
  font-style: italic;
  font-variant-numeric: tabular-nums;
}

.legend i {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); height: 2px; }

.plot-wrap { position: relative; }

#plot {
  display: block;
  width: 100%;
  height: 420px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  cursor: crosshair;
  touch-action: none;
  background: #15161a;
}

.tooltip {
  position: absolute;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
  color: var(--text-2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  white-space: nowrap;
  z-index: 5;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.tooltip.show { opacity: 1; }

.tooltip i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 6px;
}

.tooltip .tt-x { color: var(--text-3); }
.tooltip .tt-row { display: flex; align-items: center; }
.tooltip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.plot-hint { margin: 0; font-size: 11.5px; color: var(--text-3); text-align: center; }

/* ============ 分析面板 ============ */

.analysis-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }

.an-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.025);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.an-card h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); }

.an-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.order-ctrl { display: flex; align-items: center; gap: 7px; color: var(--text-3); font-size: 12.5px; }
.order-ctrl .btn-icon { padding: 2px 9px; }
.order-val { min-width: 1.3em; text-align: center; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }

.result-row { display: flex; align-items: flex-start; gap: 10px; }

.result-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.18rem;
  white-space: nowrap;
  padding-top: 0.2em;
}

.result-math {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 0.25em;
}

.result-math::-webkit-scrollbar { height: 6px; }
.result-math::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 3px; }

.an-hint { color: var(--text-3); font-size: 12.5px; margin: 0; }
.math {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.18rem;
  line-height: 1.85;
  word-break: break-word;
}

.math .num, .math .fn, .math .op, .math .paren, .math .ddx { font-style: normal; }
.math .v { margin: 0 0.04em; }
.math sup { font-size: 0.66em; vertical-align: 0.55em; line-height: 0; }
.math .gap { display: inline-block; width: 0.14em; }

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.18em;
  font-size: 0.94em;
  line-height: 1.25;
}

.frac .fnum { padding: 0 0.3em; }
.frac .fden { padding: 0 0.3em; border-top: 1.4px solid currentColor; }

.rad { white-space: nowrap; }
.rad-body { border-top: 1.4px solid currentColor; padding: 0 0.18em; margin-left: -1px; }

.ddx { font-size: 0.82em; opacity: 0.92; }

.math-inline { font-family: var(--serif); font-style: italic; }

.steps { list-style: none; margin: 0; padding: 0; }

.steps li {
  border-left: 2px solid rgba(255, 255, 255, 0.14);
  padding-left: 12px;
  margin: 0.55em 0;
}

.step-rule {
  display: block;
  font-size: 11.5px;
  color: var(--text-3);
}

.step-eq {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.02rem;
  overflow-x: auto;
  padding-bottom: 0.15em;
}

.step-eq .num, .step-eq .fn, .step-eq .op, .step-eq .paren, .step-eq .ddx { font-style: normal; }
.step-eq sup { font-size: 0.66em; vertical-align: 0.55em; line-height: 0; }

.step-more { border-left-color: transparent !important; color: var(--text-3); font-size: 12px; }

.tangent-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.tangent-row label { color: var(--text-3); font-size: 12.5px; white-space: nowrap; }

#tangentX {
  width: 100px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 6px 9px;
  outline: none;
}

#tangentX:focus { border-color: rgba(255, 255, 255, 0.35); }

.tangent-info { flex-basis: 100%; color: var(--text-2); font-size: 12.5px; line-height: 1.7; margin: 0; }
.tangent-info .strong { color: var(--text); font-weight: 600; font-size: 13.5px; }

/* ============ FAQ ============ */

.faq { display: flex; flex-direction: column; gap: 10px; }

.faq h2 { margin: 0 0 2px; font-size: 17px; font-weight: 650; }

.faq details {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  overflow: hidden;
}

.faq summary {
  cursor: pointer;
  list-style: none;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 550;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.faq summary::-webkit-details-marker { display: none; }

.faq summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 1.6px solid var(--text-3);
  border-bottom: 1.6px solid var(--text-3);
  transform: rotate(45deg);
  transition: transform 0.18s ease;
  flex: none;
}

.faq details[open] summary::after { transform: rotate(225deg); }

.faq details p {
  margin: 0;
  padding: 0 16px 14px;
  font-size: 13.5px;
  color: var(--text-2);
}

.faq details code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.07);
  padding: 0.08em 0.4em;
  border-radius: 5px;
}

.faq details:nth-of-type(2) { transition-delay: 70ms; }
.faq details:nth-of-type(3) { transition-delay: 140ms; }
.faq details:nth-of-type(4) { transition-delay: 210ms; }
.faq details:nth-of-type(5) { transition-delay: 280ms; }

/* ============ 计算日志（终端窗口，与 image-metadata-cleaner 同一形态） ============ */

.logpanel { padding: 0; overflow: hidden; gap: 0; }

.logpanel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
}

.logpanel-title { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.logpanel-title strong { font-weight: 600; }

.log-dots { display: inline-flex; gap: 5px; }
.log-dots i { width: 9px; height: 9px; border-radius: 50%; }
.log-dots i:nth-child(1) { background: #ff5f57; }
.log-dots i:nth-child(2) { background: #febc2e; }
.log-dots i:nth-child(3) { background: #28c840; }

.log-count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.logpanel-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.log-hint { font-size: 11.5px; color: var(--text-3); }

.log-body {
  font-family: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 11.5px;
  line-height: 1.75;
  padding: 12px 16px;
  max-height: 260px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.35);
  overscroll-behavior: contain;
}

.log-body::-webkit-scrollbar { width: 8px; }
.log-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 99px; }

.log-empty { margin: 0; color: var(--text-3); }

.log-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-lv-cmd { color: #e8ebf1; }
.log-lv-info { color: var(--text-2); }
.log-lv-ok { color: var(--ok); }
.log-lv-warn { color: var(--warn); }
.log-lv-err { color: var(--danger); }

/* ============ 页脚 ============ */

footer {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 10px clamp(16px, 4vw, 32px) 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
  justify-content: space-between;
  color: var(--text-3);
  font-size: 12.5px;
}

footer a { color: var(--text-2); text-decoration: none; border-bottom: 1px solid transparent; }
footer a:hover { color: var(--text); border-bottom-color: var(--line-strong); }

/* ============ Toast ============ */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 560px);
}

.toast {
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 12px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease;
}

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

/* ============ 卡片入场动画 ============ */

.js [data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.55s cubic-bezier(0.22, 0.61, 0.36, 1), transform 0.55s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.js [data-reveal].in {
  opacity: 1;
  transform: none;
}

/* ============ 响应式 ============ */

@media (max-width: 720px) {
  .analysis-grid { grid-template-columns: 1fr; }
  #plot { height: 300px; }
  .fn-row { grid-template-columns: 44px minmax(0, 1fr); }
  .fn-side { grid-column: 2; flex-direction: row; align-items: center; justify-content: space-between; }
  /* 画布之上的 backdrop-filter 是移动端滚动卡顿的主因：降模糊、提不透明度补偿 */
  .topbar, .panel, .faq details, .toast { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
  .panel { background: rgba(13, 14, 18, 0.8); }
  .faq details { background: rgba(13, 14, 18, 0.8); }
}

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