/* 荔枝方程 · 界面样式 */
:root {
  --accent: #c0304a;
  --accent-soft: rgba(192, 48, 74, 0.08);
  --accent-line: rgba(192, 48, 74, 0.22);
  --bg: #faf8f5;
  --card: #ffffff;
  --text: #1e1c1a;
  --muted: #8b847b;
  --line: rgba(30, 28, 26, 0.08);
  --shadow: 0 1px 2px rgba(30, 28, 26, 0.04), 0 12px 32px -18px rgba(30, 28, 26, 0.28);
  --radius: 18px;
  --ok: #2f7d5a;
  --warn: #a8642a;
}

html[data-theme="dark"] {
  --accent: #ef6a80;
  --accent-soft: rgba(239, 106, 128, 0.12);
  --accent-line: rgba(239, 106, 128, 0.3);
  --bg: #151317;
  --card: #1e1b21;
  --text: #f1ece7;
  --muted: #9a9289;
  --line: rgba(255, 255, 255, 0.09);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 40px -24px rgba(0, 0, 0, 0.9);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

.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;
}

.page {
  max-width: 780px;
  margin: 0 auto;
  padding: 28px 22px 60px;
}

/* ---------- 顶部 ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.logo { width: 42px; height: 42px; flex: 0 0 auto; }
.logo svg { width: 100%; height: 100%; display: block; }

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: .2px;
}

.brand p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.theme-btn {
  margin-left: auto;
  width: 36px; height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.theme-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- 输入 ---------- */

.input-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  transition: background .25s;
}

#eqInput {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, "PingFang SC", monospace;
  font-size: 21px;
  line-height: 1.5;
  padding: 4px 4px 0;
  height: 36px;
  min-height: 36px;
  max-height: 150px;
  overflow-y: auto;
}

#eqInput::placeholder { color: var(--muted); opacity: .75; font-size: 17px; }

.input-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.input-hint {
  font-size: 11.5px;
  color: var(--muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.solve-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  transition: transform .15s ease, filter .2s, opacity .2s;
}
.solve-btn:hover { filter: brightness(1.06); }
.solve-btn:active { transform: scale(.97); }
.solve-btn[disabled] { opacity: .5; cursor: default; }

/* ---------- 示例 ---------- */

.samples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px 2px 4px;
}

.sample {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.sample:hover { background: var(--accent-soft); color: var(--accent); }
.sample.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- 结果 ---------- */

.result { margin-top: 22px; }
.result:empty { display: none; }

.result-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 2px 12px;
}

.kind-badge {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
}

.input-echo {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.answer-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 20px;
  margin-bottom: 26px;
  position: relative;
  overflow: hidden;
}
.answer-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: .8;
}

.answer-label {
  font-size: 11.5px;
  letter-spacing: .12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.answer-main {
  font-size: clamp(21px, 4.6vw, 30px);
  line-height: 1.5;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}
.answer-main .katex { font-size: 1.05em; }

.answer-text {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.answer-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.ghost-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.ghost-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- 步骤 ---------- */

.steps-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 2px 12px;
}
.steps-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}
.steps-head span { font-size: 12px; color: var(--muted); }

.steps {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 22px 14px;
}

.step {
  display: flex;
  gap: 14px;
  padding: 14px 0;
  position: relative;
}
.step + .step { border-top: 1px solid var(--line); }

.step-no {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.step-body { flex: 1; min-width: 0; }

.step-title {
  font-size: 13.5px;
  font-weight: 600;
  margin: 0 0 8px;
}

.step-line {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 0;
  font-size: 16px;
}
.step-line .katex { font-size: 1.02em; }
.step-line .katex-display { margin: .18em 0; text-align: left; }
.step-line .katex-display > .katex { text-align: left; }
.step-line.is-bad { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

.step-note {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.65;
}

.step-aside {
  margin-top: 8px;
  font-size: 12px;
  color: var(--warn);
}

/* ---------- 错误 ---------- */

.error-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  border-left: 3px solid var(--accent);
}

.error-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 6px;
}

.error-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 空状态 ---------- */

.empty {
  margin-top: 30px;
}

.empty-title {
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--muted);
  margin: 0 0 12px 2px;
}

.cap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.cap {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.cap b {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
}
.cap span {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.empty-tip {
  margin: 18px 2px 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- 历史 ---------- */

.history { margin-top: 30px; }

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin: 0 2px 8px;
}

.link-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn:hover { color: var(--accent); }

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-item {
  border: none;
  background: var(--card);
  color: var(--text);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.history-item:hover { color: var(--accent); background: var(--accent-soft); }

/* ---------- 页脚 ---------- */

.footer {
  margin-top: 44px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  opacity: .8;
}

/* ---------- 动画 ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.result:not(:empty) .answer-card,
.result:not(:empty) .steps,
.result:not(:empty) .error-card {
  animation: rise .28s ease both;
}

/* ---------- 移动端 ---------- */

@media (max-width: 560px) {
  .page { padding: 20px 14px 48px; }
  .header { margin-bottom: 18px; }
  .brand h1 { font-size: 18px; }
  #eqInput { font-size: 19px; }
  .input-hint { display: none; }
  .solve-btn { margin-left: auto; }
  .cap-grid { grid-template-columns: 1fr; }
  .steps { padding: 6px 16px 12px; }
  .answer-card { padding: 18px 18px 16px; }
  .step { gap: 11px; }
}

/* ---------- 打印 ---------- */

@media print {
  .samples, .history, .theme-btn, .answer-actions, .footer { display: none; }
  body { background: #fff; }
  .answer-card, .steps { box-shadow: none; border: 1px solid #ddd; }
}

.answer-complex {
  color: var(--accent);
  margin-top: 2px;
}
