:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --panel: #ffffff;
  --panel-soft: #fbfcfa;
  --ink: #20252b;
  --muted: #68707a;
  --line: #d9ded6;
  --line-strong: #b9c4bd;
  --teal: #0f766e;
  --teal-ink: #0b4f4a;
  --amber: #b45309;
  --red: #b91c1c;
  --code: #101418;
  --shadow: 0 18px 50px rgba(32, 37, 43, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.07), rgba(245, 247, 242, 0) 34%),
    var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(253, 253, 251, 0.9);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #e1f1ed;
  border: 1px solid #badbd3;
  color: var(--teal-ink);
  flex: 0 0 auto;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1,
.editor-head h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 780;
}

.brand p,
.editor-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.toolbar,
.editor-actions,
.preview-head,
.device-switch {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.device,
.format-button,
.chip {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.icon-button,
.device,
.format-button {
  width: 38px;
  height: 38px;
}

.icon-button:hover,
.device:hover,
.format-button:hover,
.chip:hover,
.tool-button:hover {
  border-color: var(--line-strong);
  background: #f7faf7;
}

.icon-button:active,
.device:active,
.format-button:active,
.chip:active,
.run-button:active {
  transform: translateY(1px);
}

.workspace {
  height: calc(100vh - 72px);
  min-height: 560px;
  display: grid;
  grid-template-columns: 210px minmax(420px, 0.95fr) minmax(420px, 1.05fr);
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 34px) 24px;
  align-items: stretch;
}

.tool-rail,
.editor-pane,
.preview-pane {
  min-width: 0;
  min-height: 0;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tool-rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
}

.tool-button {
  min-height: 62px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.tool-button span,
.tool-button small {
  display: block;
}

.tool-button span {
  font-size: 14px;
  font-weight: 780;
}

.tool-button small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tool-button.is-active {
  border-color: #badbd3;
  background: #e7f4f0;
  color: var(--teal-ink);
}

.editor-pane {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.editor-head,
.preview-head {
  flex: 0 0 auto;
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.editor-head h2 {
  font-size: 18px;
  font-weight: 800;
}

.toggle {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.run-button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--teal);
  color: white;
  font-weight: 780;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.22);
}

.run-button svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
  stroke: none;
}

.subtools {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f4f8f5;
  overflow-x: auto;
}

.subtools.is-visible {
  display: flex;
}

.split-tools label {
  min-width: 110px;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.split-tools label.grow {
  min-width: 220px;
  flex: 1 1 auto;
}

.split-tools input,
.split-tools select {
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

.chip {
  min-width: 64px;
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
}

.chip.is-active {
  border-color: #badbd3;
  background: var(--panel);
  color: var(--teal-ink);
  box-shadow: 0 6px 18px rgba(15, 118, 110, 0.09);
}

.format-button {
  flex: 0 0 auto;
  font-weight: 820;
}

.code-wrap {
  min-height: 0;
  height: 100%;
  flex: 1 1 0;
  align-self: stretch;
  display: grid;
  grid-template-columns: 54px 1fr;
  background: var(--code);
}

.line-numbers {
  min-height: 100%;
  padding: 18px 10px;
  overflow: hidden;
  border-right: 1px solid #26303a;
  background: #151a20;
  color: #7e8b96;
  font:
    13px/1.6 "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono",
    monospace;
  text-align: right;
  user-select: none;
  white-space: pre;
}

#codeEditor {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
  resize: none;
  border: 0;
  outline: 0;
  padding: 18px;
  background: var(--code);
  color: #edf3f7;
  caret-color: #facc15;
  font:
    14px/1.6 "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono",
    monospace;
  tab-size: 2;
  white-space: pre;
}

#codeEditor::selection {
  background: rgba(20, 184, 166, 0.32);
}

.statusbar {
  flex: 0 0 auto;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  background: var(--panel-soft);
}

.preview-title {
  display: grid;
  gap: 4px;
}

.preview-title strong {
  font-size: 15px;
}

.preview-title span {
  color: var(--muted);
  font-size: 13px;
}

.device-switch {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef3ed;
}

.device {
  width: 34px;
  height: 34px;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.device.is-active {
  color: var(--teal-ink);
  background: var(--panel);
  border-color: #cfe3dc;
}

.preview-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: auto;
  background:
    linear-gradient(45deg, #e7ebe4 25%, transparent 25%),
    linear-gradient(-45deg, #e7ebe4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7ebe4 75%),
    linear-gradient(-45deg, transparent 75%, #e7ebe4 75%);
  background-size: 24px 24px;
  background-position:
    0 0,
    0 12px,
    12px -12px,
    -12px 0;
  background-color: #f5f6f2;
}

#webPreview,
.preview-surface {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: white;
  box-shadow: 0 22px 60px rgba(32, 37, 43, 0.16);
  transition:
    width 180ms ease,
    height 180ms ease;
}

#webPreview {
  display: block;
}

.preview-surface {
  display: none;
  overflow: auto;
}

.preview-stage[data-kind="surface"] #webPreview {
  display: none;
}

.preview-stage[data-kind="surface"] .preview-surface {
  display: block;
}

.preview-stage[data-size="desktop"] #webPreview,
.preview-stage[data-size="desktop"] .preview-surface {
  width: min(1180px, 100%);
  height: min(760px, 100%);
}

.preview-stage[data-size="tablet"] #webPreview,
.preview-stage[data-size="tablet"] .preview-surface {
  width: min(768px, 100%);
  height: min(1024px, 100%);
}

.preview-stage[data-size="mobile"] #webPreview,
.preview-stage[data-size="mobile"] .preview-surface {
  width: min(390px, 100%);
  height: min(844px, 100%);
}

.surface-pad {
  padding: clamp(18px, 4vw, 42px);
}

.prose {
  max-width: 880px;
  margin: 0 auto;
  color: #1f2933;
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3 {
  line-height: 1.2;
  letter-spacing: 0;
}

.prose h1 {
  font-size: clamp(34px, 6vw, 54px);
}

.prose h2 {
  padding-bottom: 10px;
  border-bottom: 1px solid #e3e7df;
}

.prose p,
.prose li,
.prose td,
.prose th {
  line-height: 1.8;
}

.prose a {
  color: var(--teal);
  font-weight: 720;
  text-underline-offset: 3px;
}

.prose blockquote {
  margin: 20px 0;
  padding: 14px 18px;
  border-left: 4px solid var(--teal);
  background: #edf7f4;
  color: #42505a;
}

.prose code,
.prose pre {
  font-family: "Cascadia Code", Consolas, monospace;
}

.prose code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #eef3ed;
  color: var(--amber);
}

.prose pre {
  overflow: auto;
  padding: 18px;
  border-radius: var(--radius);
  background: #111827;
  color: #edf3f7;
}

.prose pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.prose table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
}

.prose th,
.prose td,
.data-table th,
.data-table td {
  border: 1px solid var(--line);
  padding: 9px 11px;
  text-align: left;
  vertical-align: top;
}

.prose th,
.data-table th {
  background: #eef3ed;
  font-weight: 800;
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px auto;
  border-radius: var(--radius);
}

.svg-box,
.mermaid-box {
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 18px;
}

.svg-box > svg,
.mermaid-box > svg {
  width: min(100%, 1080px) !important;
  height: auto !important;
  max-width: none !important;
}

.svg-box > svg {
  max-height: 72vh;
}

.mermaid-box > svg {
  min-width: min(100%, 720px);
}

.panel-grid {
  display: grid;
  gap: 18px;
}

.panel-grid h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.chart-wrap svg {
  width: 100%;
  height: auto;
  max-height: 420px;
}

.error-box {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  background: #fff1f2;
  color: var(--red);
  font: 14px/1.6 "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
}

.empty-box {
  max-width: 520px;
  margin: 0 auto;
  padding: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 48px));
  padding: 11px 14px;
  border-radius: var(--radius);
  background: #20252b;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  z-index: 30;
  font-size: 14px;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

:focus-visible {
  outline: 3px solid rgba(180, 83, 9, 0.34);
  outline-offset: 2px;
}

@media (max-width: 1120px) {
  .workspace {
    height: auto;
    grid-template-columns: 1fr;
  }

  .tool-rail {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .editor-pane,
  .preview-pane {
    min-height: 66vh;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    flex-wrap: wrap;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-end;
    overflow-x: auto;
  }

  .tool-rail {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .editor-head,
  .preview-head {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-actions {
    justify-content: space-between;
  }

  .code-wrap {
    grid-template-columns: 44px 1fr;
  }

  #codeEditor {
    padding: 14px;
    font-size: 13px;
  }

  .line-numbers {
    padding: 14px 8px;
    font-size: 12px;
  }
}
