:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --line: #d5dde5;
  --line-dark: #aab7c4;
  --text: #17212b;
  --muted: #627180;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --danger: #b42318;
  --blue: #245d82;
  --shadow: 0 14px 34px rgba(20, 35, 50, 0.12);
  --radius: 8px;
  --sans: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

body:not(.advanced-mode) .advanced-only {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: center;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  padding: 10px 16px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong,
.brand-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.view-tabs,
.screen-meta,
.source-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.tool-button,
.primary-button,
.mini-button,
.view-tab,
.palette button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 11px;
  white-space: nowrap;
}

.tool-button:hover,
.mini-button:hover,
.palette button:hover,
.view-tab:hover {
  border-color: var(--line-dark);
  background: #f1f5f7;
}

.tool-button.is-active {
  border-color: var(--accent);
  background: #e5f4f2;
  color: #073f3b;
  font-weight: 800;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.mini-button {
  min-height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.mini-button.danger {
  border-color: #f0c2bd;
  color: var(--danger);
}

.file-action {
  display: inline-flex;
  align-items: center;
}

.file-action input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.ide-workspace {
  display: grid;
  grid-template-columns: 236px minmax(520px, 1fr) 300px;
  gap: 12px;
  min-height: 0;
  padding: 12px;
}

body.advanced-mode .ide-workspace {
  grid-template-columns: 284px minmax(480px, 1fr) 320px;
}

.left-rail,
.right-rail,
.editor-area {
  min-height: 0;
}

.left-rail,
.right-rail {
  display: grid;
  gap: 12px;
}

.left-rail {
  grid-template-rows: auto minmax(220px, 1fr) auto;
}

.panel,
.editor-area {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  overflow: hidden;
}

.panel {
  display: grid;
  min-height: 0;
}

.panel.grow {
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 9px 12px;
}

.panel-head.small {
  min-height: 36px;
  padding: 7px 0 8px;
  border-bottom: 0;
  background: transparent;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
}

.palette {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px;
}

body.advanced-mode .palette {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.palette button {
  width: 100%;
  text-align: left;
  font-weight: 700;
  min-height: 40px;
  cursor: grab;
}

.palette button:active {
  cursor: grabbing;
}

.tree-view,
.model-summary {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.tree-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 4px 7px;
  text-align: left;
}

.tree-item:hover {
  background: #f4f7f9;
}

.tree-item.is-selected {
  border-color: #94c9c4;
  background: #e5f4f2;
}

.tree-item .tag {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
}

.tree-item .name {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-summary {
  display: grid;
  gap: 6px;
}

.model-chip {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
  padding: 7px 8px;
}

.model-chip strong {
  display: block;
  font-size: 12px;
}

.model-chip span {
  color: var(--muted);
  font-size: 12px;
}

.editor-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  padding: 8px 10px;
}

.view-tab {
  min-width: 78px;
}

.view-tab.is-active {
  border-color: var(--accent);
  background: #e5f4f2;
  color: #073f3b;
  font-weight: 800;
}

.screen-meta {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.screen-meta span {
  overflow: hidden;
  max-width: 220px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-pane {
  display: none;
  min-height: 0;
}

.view-pane.is-active {
  display: grid;
}

.canvas-scroll {
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(120, 140, 160, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(120, 140, 160, 0.08) 1px, transparent 1px),
    #e9eef3;
  background-size: 20px 20px;
  padding: 28px;
}

.design-canvas {
  min-width: 360px;
  min-height: 260px;
  border: 1px solid #bcc9d5;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ex-node {
  position: relative;
  min-width: 0;
  min-height: 28px;
  border: 1px solid transparent;
}

.ex-node:hover {
  border-color: #91c7c2;
}

.ex-node.is-selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  overflow: visible;
}

.ex-node.is-dragging {
  opacity: 0.45;
}

.ex-node.is-drop-target {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(36, 93, 130, 0.35);
}

.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  z-index: 8;
  width: 13px;
  height: 13px;
  border: 2px solid #fff;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 1px 5px rgba(20, 35, 50, 0.22);
  cursor: nwse-resize;
}

.ex-group {
  display: grid;
  gap: 8px;
  min-height: 64px;
  background: #fbfcfd;
  padding: 10px;
}

.ex-group::before {
  content: attr(data-label);
  position: absolute;
  top: 2px;
  right: 6px;
  color: #8a98a7;
  font-family: var(--mono);
  font-size: 10px;
}

.ex-output {
  display: flex;
  align-items: center;
  min-height: 28px;
  color: #2e3d4a;
  font-weight: 700;
}

.ex-control,
.ex-button {
  display: flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid #c8d4df;
  border-radius: 6px;
  background: #fff;
  color: #2a3642;
  padding: 0 9px;
}

.ex-control.muted {
  color: #82909d;
}

.ex-button {
  justify-content: center;
  border-color: var(--accent);
  background: #e8f5f3;
  color: #073f3b;
  font-weight: 800;
}

.ex-textarea {
  min-height: 72px;
  align-items: flex-start;
  padding-top: 7px;
}

.ex-grid {
  display: grid;
  min-height: 150px;
  border: 1px solid #bdcad6;
  background: #fff;
  overflow: hidden;
}

.ex-grid-head,
.ex-grid-row {
  display: grid;
  grid-auto-columns: minmax(96px, 1fr);
  grid-auto-flow: column;
}

.ex-grid-head span,
.ex-grid-row span {
  min-height: 30px;
  border-right: 1px solid #d5dde5;
  border-bottom: 1px solid #d5dde5;
  padding: 7px 8px;
  font-size: 12px;
}

.ex-grid-head span {
  background: #edf3f6;
  color: #2e3d4a;
  font-weight: 800;
}

.ex-grid-row span {
  color: #9aa6b1;
}

.unknown-node {
  display: flex;
  align-items: center;
  min-height: 30px;
  border: 1px dashed #bdcad6;
  border-radius: 6px;
  color: var(--muted);
  padding: 0 8px;
  font-family: var(--mono);
  font-size: 12px;
}

.source-toolbar {
  justify-content: space-between;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  padding: 6px 10px;
  color: var(--muted);
}

body:not(.advanced-mode) .editor-toolbar {
  justify-content: flex-end;
}

.source-editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  background: #101820;
  color: #eef6fb;
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}

.right-rail {
  grid-template-rows: minmax(0, 1fr);
}

.inspector-panel {
  grid-template-rows: auto auto auto auto minmax(160px, 1fr);
}

.type-pill {
  border-radius: 999px;
  background: #e9eef3;
  color: var(--muted);
  padding: 3px 9px;
  font-family: var(--mono);
  font-size: 12px;
}

.inspector {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 12px;
}

.inspector label,
.raw-editor label {
  display: grid;
  gap: 5px;
}

.inspector span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.inspector input,
.raw-editor textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
  color: var(--text);
  outline: 0;
}

.inspector input {
  height: 34px;
  padding: 0 9px;
}

.inspector input:focus,
.raw-editor textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-move {
  border-top: 1px solid var(--line);
  padding: 0 12px 12px;
}

.move-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.move-pad button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
  color: var(--text);
}

.move-pad button:hover {
  border-color: var(--line-dark);
  background: #f1f5f7;
}

.grid-column-panel {
  display: none;
  border-top: 1px solid var(--line);
  padding: 0 12px 12px;
}

.grid-column-panel.is-visible {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 160px;
}

.grid-column-editor {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.grid-column-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 72px 30px;
  gap: 6px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 8px;
}

.grid-column-row label {
  display: grid;
  gap: 4px;
}

.grid-column-row span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.grid-column-row input {
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 7px;
}

.grid-column-row button {
  width: 30px;
  height: 30px;
  border: 1px solid #f0c2bd;
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
}

.raw-editor {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  border-top: 1px solid var(--line);
  padding: 0 12px 12px;
}

.raw-editor textarea {
  min-height: 130px;
  resize: none;
  padding: 10px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  padding: 11px 13px;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .ide-workspace {
    grid-template-columns: 220px minmax(420px, 1fr);
  }

  body.advanced-mode .ide-workspace {
    grid-template-columns: 240px minmax(420px, 1fr);
  }

  .right-rail {
    grid-column: 1 / -1;
  }

  .inspector-panel {
    grid-template-rows: auto auto 220px;
  }
}

@media (max-width: 820px) {
  .topbar,
  .ide-workspace {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .left-rail {
    grid-template-rows: auto 260px auto;
  }
}
