* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #1f2937;
  background: #f1f5f9;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  flex-wrap: wrap;
  z-index: 5;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  color: #5b21b6;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 6px;
}
.brand .logo { color: #14b8a6; font-size: 20px; }
.tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.toolbar button {
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
}
.toolbar button:hover { background: #eef2ff; border-color: #c7d2fe; }
.toolbar button.active { background: #6366f1; color: #fff; border-color: #6366f1; }
.toolbar button.primary { background: #0ea5e9; color: #fff; border-color: #0ea5e9; }
.toolbar button.primary:hover { background: #0284c7; }
.toolbar button.danger { background: #fff; color: #dc2626; border-color: #fecaca; }
.toolbar button.danger:hover { background: #fef2f2; }

.sep { width: 1px; height: 22px; background: #e2e8f0; margin: 0 2px; }
.zoom-label { font-size: 12px; color: #64748b; min-width: 44px; text-align: center; }

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-color: #f8fafc;
  background-image:
    linear-gradient(rgba(148,163,184,.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148,163,184,.18) 1px, transparent 1px);
  background-size: 24px 24px;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.editor {
  position: absolute;
  z-index: 10;
  background: #fff;
  border: 2px solid #6366f1;
  border-radius: 10px;
  padding: 10px 12px;
  color: #111;
  font-family: inherit;
  font-size: 15px;
  line-height: 22px;
  outline: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.editor.hidden { display: none; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: rgba(30,41,59,.88);
  color: #fff;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- layout + sidebar ---------- */
.layout {display: flex; flex: 1; min-height: 0;}
.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  border-bottom: 1px solid #eef2f7;
}
.sidebar-title {font-weight: 700; color: #5b21b6; font-size: 14px;}
.toolbar button.mini {
  padding: 5px 9px;
  font-size: 12px;
}
.toolbar button.mini.primary {background: #6366f1; color: #fff; border-color: #6366f1;}
.toolbar button.mini.primary:hover {background: #4f46e5;}

.file-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: .12s;
}
.file-item:hover {background: #f1f5f9;}
.file-item.active {background: #eef2ff; box-shadow: inset 2px 0 0 #6366f1;}
.fname {
  flex: 1;
  font-size: 13px;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fa {display: flex; gap: 4px; opacity: 0; transition: .12s;}
.file-item:hover .fa, .file-item.active .fa {opacity: 1;}
.fa button {
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
}
.fa button:hover {background: #e2e8f0; color: #334155;}
.fa button.del:hover {background: #fee2e2; color: #dc2626;}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}
