/* ── 顶部广告横幅 ── */
#ad-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  height: 2.6rem;
  background: linear-gradient(90deg, #1a0a3d 0%, #2d1b69 50%, #1a2a6c 100%);
  color: #e8d5ff;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
}
.ad-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.ad-icon { font-size: 1rem; flex-shrink: 0; }
.ad-text {
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.9;
}
.ad-cta {
  flex-shrink: 0;
  padding: 0.25rem 0.75rem;
  background: #7c3aed;
  color: #fff;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.8rem;
  transition: background 0.2s;
}
.ad-cta:hover { background: #6d28d9; }
.ad-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #c4b5fd;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.ad-close:hover { opacity: 1; }

:root {
  --bg: #f2efe8;
  --panel: #fffdf8;
  --ink: #1c1a16;
  --muted: #6b655c;
  --line: #d9d2c4;
  --accent: #0f6b5c;
  --error: #9b2c2c;
  --font-ui: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #dceee8 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, #efe6d4 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
}

.top {
  padding: 1.25rem 1.5rem 0.75rem;
}

.top h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.top a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.top code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: rgba(15, 107, 92, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 0.75rem 1.5rem 1.5rem;
  min-height: calc(100vh - 5.5rem);
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.example-pick {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.28rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}

.example-pick:hover,
.example-pick:focus {
  border-color: var(--accent);
  outline: none;
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.28rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button.theme-opt {
  border: 0;
  background: transparent;
  padding: 0;
  font-weight: 500;
  color: var(--muted);
}

button.theme-opt:hover,
button.theme-opt.is-active {
  border-color: transparent;
  color: var(--accent);
}

.editor-host {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.editor-host .cm-editor {
  flex: 1;
  height: 100%;
  outline: none;
}

.editor-host .cm-editor.cm-focused {
  outline: none;
}

.cm-editor button {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: inherit;
  border-radius: 0;
}

.cm-editor button:hover {
  border-color: transparent;
  color: inherit;
}

.status {
  margin: 0;
  padding: 0.45rem 0.9rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.8rem;
}

.status.error {
  color: var(--error);
}

.preview {
  flex: 1;
  overflow: auto;
  padding: 1.25rem;
  background: #ffffff;
  color: #0f1115;
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  transition: background 0.3s, color 0.3s;
}

.preview .katex {
  color: #0f1115;
}

.preview.preview--dark {
  background: #151517;
  color: #e8e8ea;
}

.preview.preview--dark .katex {
  color: #e8e8ea;
}

.preview .katex-display {
  margin: 0.85em 0;
}

.preview .ds-math-wasm {
  display: inline-block;
  max-width: 100%;
  overflow: auto;
}

.preview .ds-math-wasm.katex-display {
  display: block;
  text-align: center;
}

.preview .ds-math-wasm svg {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

.preview .ds-math-error {
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 0.85em;
  white-space: pre-wrap;
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 100%;
  padding: 0.35rem 0.45rem;
  border: 1px solid rgba(155, 44, 44, 0.22);
  border-radius: 6px;
  background: rgba(155, 44, 44, 0.06);
}

.preview .ds-math-error-code {
  font-weight: 600;
}

.preview .ds-math-error-message {
  font-size: 0.9em;
  opacity: 0.92;
}

#engine {
  color: var(--accent);
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .editor-host {
    min-height: 240px;
  }
}
