:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-muted: #f7f9fc;
  --text: #142033;
  --muted: #5d6b82;
  --line: #d7dfeb;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --error: #b42318;
  --error-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --success: #027a48;
  --shadow: 0 18px 40px rgba(16, 24, 40, 0.08);
  --radius: 18px;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.09), transparent 26%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
  font-family: var(--sans);
}

body {
  padding: 18px;
}

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

.app-shell {
  display: grid;
  gap: 16px;
  height: calc(100vh - 36px);
}

.toolbar,
.editor-pane,
.preview-pane,
.bottom-panel {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(215, 223, 235, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  padding: 14px 18px;
  align-items: center;
}

.toolbar__brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toolbar__logo {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.toolbar__tagline,
.toolbar__status,
.pane-header__meta,
.message-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.toolbar button,
.toolbar select {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 12px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.toolbar button:hover,
.toolbar select:hover {
  border-color: var(--accent);
  background: #f8fbff;
  transform: translateY(-1px);
}

.toolbar__select,
.toolbar__checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(380px, 42%) 1fr;
  gap: 16px;
}

.editor-pane,
.preview-pane,
.bottom-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.pane-header h1,
.bottom-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.editor-shell {
  position: relative;
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 64px 1fr;
  overflow: hidden;
  background: #f9fbfd;
  border-radius: 0 0 var(--radius) var(--radius);
}

.editor-lines,
#sourceEditor,
#editorHighlight {
  font-family: var(--mono);
  line-height: 1.65;
  font-size: 14px;
  tab-size: 2;
  white-space: pre;
}

.editor-lines {
  overflow: hidden;
  padding: 18px 10px 18px 16px;
  text-align: right;
  color: #8b97ab;
  background: linear-gradient(180deg, #f4f7fb 0%, #edf3f9 100%);
  border-right: 1px solid var(--line);
  user-select: none;
}

#editorHighlight,
#sourceEditor {
  grid-column: 2;
  grid-row: 1;
  padding: 18px 18px 32px;
}

#editorHighlight {
  margin: 0;
  overflow: auto;
  color: transparent;
  pointer-events: none;
}

#editorHighlight .kw { color: #0f3b9e; }
#editorHighlight .num { color: #9a3412; }
#editorHighlight .str { color: #047857; }
#editorHighlight .com { color: #7c8699; }
#editorHighlight .id { color: #7e22ce; }

#sourceEditor {
  resize: none;
  border: none;
  outline: none;
  color: transparent;
  caret-color: var(--text);
  background: transparent;
  overflow: auto;
}

.preview-shell {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  background: linear-gradient(180deg, #f9fbff 0%, #f2f6fb 100%);
  border-radius: 0 0 var(--radius) var(--radius);
}

.preview-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.8;
}

.preview-grid.is-hidden {
  display: none;
}

.preview-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.preview-stage.is-dragging {
  cursor: grabbing;
}

.svg-mount {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
}

.svg-mount svg {
  display: block;
  max-width: none;
  overflow: visible;
}

.svg-mount [data-entity-id][data-coord-mode] {
  cursor: pointer;
}

.svg-mount [data-entity-id][data-coord-mode]:hover {
  filter: drop-shadow(0 0 8px rgba(29, 78, 216, 0.18));
}

.visual-editor {
  position: absolute;
  right: 16px;
  bottom: 16px;
  max-width: 280px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(29, 78, 216, 0.15);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  color: var(--text);
  z-index: 5;
}

.visual-editor__title {
  font-weight: 700;
  font-size: 0.95rem;
}

.visual-editor__meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.visual-editor.is-active {
  border-color: rgba(29, 78, 216, 0.35);
  background: rgba(239, 246, 255, 0.96);
}

.bottom-panel {
  min-height: 240px;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 10px 14px 0;
}

.tab {
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 12px 12px 0 0;
  color: var(--muted);
}

.tab.is-active {
  background: var(--panel-muted);
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom-color: transparent;
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  background: var(--panel-muted);
  margin: 0 14px 14px;
  border: 1px solid var(--line);
  border-radius: 0 16px 16px 16px;
  overflow: auto;
}

.panel.is-active {
  display: block;
}

.panel-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
}

.message-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.message-list li {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.message-list li.error {
  background: var(--error-soft);
  border-color: rgba(180, 35, 24, 0.2);
}

.message-list li.warning {
  background: var(--warning-soft);
  border-color: rgba(181, 71, 8, 0.2);
}

.message-list button {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 0;
  cursor: pointer;
}

.code-block {
  margin: 0;
  padding: 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 12px 14px;
  background: rgba(20, 32, 51, 0.96);
  color: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1000;
}

@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 46vh) minmax(320px, 46vh);
  }

  .bottom-panel {
    min-height: 220px;
  }
}

@media (max-width: 780px) {
  body {
    padding: 8px;
  }

  .app-shell {
    height: auto;
    min-height: calc(100vh - 16px);
  }

  .toolbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .toolbar__actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    margin-right: -4px;
  }

  .toolbar__actions::-webkit-scrollbar {
    height: 6px;
  }

  .toolbar__actions::-webkit-scrollbar-thumb {
    background: rgba(93, 107, 130, 0.24);
    border-radius: 999px;
  }

  .toolbar button,
  .toolbar select {
    white-space: nowrap;
    padding: 8px 10px;
  }

  .panel-columns {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
  }

  .editor-pane,
  .preview-pane {
    min-height: 320px;
  }

  .pane-header {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
  }

  .editor-shell {
    grid-template-columns: 48px 1fr;
  }

  .editor-lines,
  #sourceEditor,
  #editorHighlight {
    font-size: 13px;
  }

  .editor-lines {
    padding: 14px 8px 14px 10px;
  }

  #editorHighlight,
  #sourceEditor {
    padding: 14px 14px 24px;
  }

  .preview-shell {
    min-height: 360px;
  }

  .tabs {
    overflow-x: auto;
    padding: 8px 10px 0;
  }

  .tab {
    white-space: nowrap;
  }

  .panel {
    margin: 0 10px 10px;
  }

  .bottom-panel {
    min-height: 180px;
  }

  .visual-editor {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
}
