:root {
  color-scheme: light;
  --bg: #f5f8ff;
  --panel: #ffffff;
  --panel-soft: #f9fbff;
  --ink: #172033;
  --muted: #667085;
  --line: #dbe6f7;
  --line-strong: #b7c8e6;
  --blue: #2563eb;
  --blue-ink: #1d4ed8;
  --blue-soft: #eaf2ff;
  --amber: #b45309;
  --red: #b91c1c;
  --code: #ffffff;
  --code-soft: #f4f8ff;
  --shadow: 0 18px 50px rgba(37, 99, 235, 0.1);
  --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(37, 99, 235, 0.08), rgba(245, 248, 255, 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(255, 255, 255, 0.92);
  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: var(--blue-soft);
  border: 1px solid #c4d7ff;
  color: var(--blue-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;
}

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

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

.view-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.device,
.view-button,
.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,
.view-button:hover,
.format-button:hover,
.chip:hover,
.tool-button:hover {
  border-color: var(--line-strong);
  background: #f3f7ff;
}

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

.view-button {
  height: 34px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 780;
  white-space: nowrap;
}

.view-button.is-active {
  border-color: #b8ccff;
  background: var(--blue-soft);
  color: var(--blue-ink);
}

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

.workspace[data-layout="focus-preview"],
.workspace[data-layout="focus-editor"] {
  grid-template-columns: 260px minmax(520px, 1fr);
}

.workspace[data-layout="focus-preview"] .editor-pane,
.workspace[data-layout="focus-editor"] .preview-pane {
  display: none;
}

.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: 8px;
  padding: 10px;
}

.tool-library-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 4px 0;
}

.tool-library-head strong,
.tool-library-head span {
  display: block;
}

.tool-library-head strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 820;
}

.tool-library-head span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.tool-search {
  flex: 0 0 auto;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
}

.tool-search svg {
  width: 16px;
  height: 16px;
}

.tool-search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.tool-groups {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.tool-group {
  display: grid;
  gap: 3px;
}

.tool-group-title {
  margin: 0;
  padding: 6px 6px 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
}

.tool-button {
  min-height: 36px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  width: 100%;
}

.tool-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.09);
  color: var(--blue-ink);
}

.tool-icon svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

.tool-copy {
  min-width: 0;
  display: block;
  white-space: nowrap;
  overflow: hidden;
}

.tool-copy span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 780;
}

.tool-button.is-active {
  border-color: #b8ccff;
  background: var(--blue-soft);
  color: var(--blue-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(--blue);
}

.run-button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--blue);
  color: white;
  font-weight: 780;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 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: #f5f8ff;
  overflow-x: auto;
}

.editor-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 50px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  overflow: visible;
}

.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: #b8ccff;
  background: var(--panel);
  color: var(--blue-ink);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.09);
}

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

.edit-tool {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.edit-tool.compact {
  width: 32px;
  padding: 0;
}

.edit-tool:hover {
  border-color: #b8ccff;
  background: var(--blue-soft);
  color: var(--blue-ink);
}

.find-tool {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.find-tool input {
  width: 150px;
  height: 24px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
}

.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 var(--line);
  background: #eef5ff;
  color: #7c8ba3;
  font:
    13px/1.6 "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono",
    monospace;
  text-align: right;
  user-select: none;
  white-space: pre;
}

.editor-stack {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.035), transparent 46px), var(--code);
}

.code-sync-layer {
  position: absolute;
  inset: 0;
  padding: 18px;
  overflow: hidden;
  pointer-events: none;
  color: transparent;
  font:
    14px/1.6 "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono",
    monospace;
  tab-size: 2;
  white-space: pre;
}

.code-sync-line {
  min-height: 1.6em;
  border-left: 3px solid transparent;
  padding-left: 9px;
}

.code-sync-line.is-current {
  background: rgba(37, 99, 235, 0.055);
  border-left-color: rgba(37, 99, 235, 0.28);
}

.code-sync-line.is-source-active {
  background: rgba(37, 99, 235, 0.14);
  border-left-color: var(--blue);
}

.code-sync-line.is-find-hit {
  background: rgba(245, 158, 11, 0.12);
}

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

#codeEditor::selection {
  background: rgba(37, 99, 235, 0.22);
}

.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: #eef5ff;
}

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

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

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

#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(37, 99, 235, 0.13);
  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 var(--line);
}

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

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

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

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

.prose code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #edf4ff;
  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: #eef5ff;
  font-weight: 800;
}

.mapped-block,
.svg-box,
.mermaid-box {
  transition:
    background 160ms ease,
    box-shadow 160ms ease,
    outline-color 160ms ease;
}

.mapped-block.is-preview-active,
.svg-box.is-preview-active,
.mermaid-box.is-preview-active {
  outline: 2px solid rgba(37, 99, 235, 0.48);
  outline-offset: 4px;
  background: rgba(37, 99, 235, 0.08);
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.06);
}

.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(37, 99, 235, 0.32);
  outline-offset: 2px;
}

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

  .tool-rail {
    max-height: 420px;
  }

  .tool-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    align-items: start;
  }

  .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 {
    max-height: none;
  }

  .tool-groups {
    grid-template-columns: 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;
  }

  .code-sync-layer {
    padding: 14px;
    font-size: 13px;
  }

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