:root {
  --bg-page: #f3f4f6;
  --bg-panel: #ffffff;
  --bg-soft: #f9fafb;
  --border-subtle: #e5e7eb;
  --text-main: #111827;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: rgba(37,99,235,.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --nav-h: 56px;
  --shadow-soft: 0 14px 40px rgba(15,23,42,.06);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont,
               "SF Pro SC","PingFang SC","Microsoft YaHei",sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-main);
  overflow-y: auto;
}

@media (max-width: 900px) {
  body {
    min-width: 1024px;
    overflow-x: auto;
  }
}

/* 顶栏 */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: #000;
  display: flex;
  align-items: center;
  z-index: 1000;
}
.nav-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 18px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand img {
  width: 26px;
  height: 26px;
  display: block;
}
.brand span {
  font-size: 16px;
  font-weight: 800;
  color: #f9fafb;
}
.nav-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* 按钮 */
.btn {
  -webkit-appearance: none;
  appearance: none;
  border-radius: 999px;
  padding: 0 14px;
  height: 32px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: #fff;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s ease;
}
.btn:hover {
  background: var(--bg-soft);
  box-shadow: 0 4px 12px rgba(15,23,42,.08);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
.btn.primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  box-shadow: 0 6px 18px rgba(37,99,235,.22);
}
.btn.ghost {
  background: transparent;
  color: var(--text-main);
  border-color: var(--border-subtle);
}
.nav .btn.ghost {
  color: #e5e7eb;
  border-color: rgba(249,250,251,.26);
}
.nav .btn.ghost:hover {
  background: rgba(249,250,251,.06);
}
.btn.mini {
  height: 26px;
  padding: 0 10px;
  font-size: 11px;
}
.btn.seg {
  background: transparent;
}
.btn.seg.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(37,99,235,.46);
}

/* 主布局 */
.mwrap.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 18px 18px;
  display: grid;
  grid-template-columns: 230px minmax(0,1fr) 340px;
  gap: 16px;
  margin-top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
}

/* 侧边栏 m1 */
.m1 {
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
}
.side-block + .side-block {
  margin-top: 14px;
}
.side-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.tree {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.view-switch {
  display: flex;
  gap: 6px;
}
.side-spacer {
  flex: 1;
}
.side-bottom {
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side-bottom .btn {
  width: 100%;
}
.side-hint {
  font-size: 10px;
  color: var(--text-muted);
}

/* 画布 m2 */
.m2 {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stage-head {
  padding: 8px 12px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-soft);
}
.breadcrumbs {
  font-size: 11px;
  color: var(--text-muted);
}
.canvas {
  flex: 1;
  padding: 10px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
}
#m2-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
  border-radius: var(--radius-md);
}
#m2-code {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  background: #111827;
  color: #e5e7eb;
  padding: 10px;
  margin: 0;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas;
  overflow: auto;
}

/* AI 面板 m3 */
.m3 {
  padding: 12px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
}
.m3-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.ai-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}
.ai-tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}
.ai-tip {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.ai-input {
  width: 100%;
  min-height: 90px;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-soft);
  color: var(--text-main);
  font-size: 12px;
  resize: vertical;
}
.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.ai-log {
  margin-top: 8px;
  padding: 8px;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  border: 1px solid var(--border-subtle);
  font-size: 10px;
  color: var(--text-muted);
  max-height: 150px;
  overflow-y: auto;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.38);
}
.modal-panel {
  position: relative;
  width: 720px;
  max-width: 96vw;
  padding: 14px 14px 10px;
  border-radius: var(--radius-lg);
  background: #fff;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 22px 70px rgba(15,23,42,.20);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}
.modal-close {
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-close:hover {
  color: var(--accent);
}
.tmpl-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 10px;
}
.tmpl-card {
  padding: 8px;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tmpl-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}
.tmpl-preview {
  height: 80px;
  border-radius: 8px;
  background: linear-gradient(to bottom right,#eff6ff,#dbeafe);
  border: 1px solid #d1d5db;
}
.tmpl-preview-blank {
  background: repeating-linear-gradient(
    45deg,
    #f9fafb,
    #f9fafb 4px,
    #e5e7eb 4px,
    #e5e7eb 5px
  );
}
.modal-foot {
  margin-top: 8px;
}
.modal-note {
  font-size: 10px;
  color: var(--text-muted);
}

/* 我的项目 */
.proj-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}
.proj-list {
  list-style: none;
  margin: 8px 0 4px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.proj-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-soft);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
}
.proj-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.proj-ops {
  display: flex;
  gap: 4px;
}
.proj-ops .btn {
  height: 22px;
  padding: 0 8px;
  font-size: 10px;
}

/* 工具 */
.hidden {
  display: none !important;
}