:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #6b7686;
  --line: #dde2ea;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --brand-soft: #e8f0fe;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --topbar-h: 54px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }
b { font-weight: 650; }

/* ------------------------------------------------------------ top bar */
.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: #111a27;
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; letter-spacing: .2px; white-space: nowrap; }
.brand b { color: #7aa7ff; font-weight: 500; margin: 0 1px; }
.brand svg { color: #7aa7ff; }
.tabs { display: none; gap: 4px; margin-left: 4px; }
.tab {
  background: transparent; border: 0; color: #aab6c8; padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer;
}
.tab.active { background: #243349; color: #fff; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }

/* ------------------------------------------------------------ buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
  text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: #f4f6f9; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #1d4fd0; }
.btn.ghost { background: transparent; color: inherit; border-color: transparent; }
.topbar .btn.ghost { color: #d5deeb; border-color: #2d3d54; }
.topbar .btn.ghost:hover { background: #1c2a3f; }
.btn.icon { width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 1px solid #2d3d54; background: transparent; color: #d5deeb; }
.btn.icon:hover { background: #1c2a3f; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.btn.danger-ghost { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ------------------------------------------------------------ layout */
.layout { flex: 1; min-height: 0; display: flex; }
.sidebar {
  width: 320px; flex: none; overflow-y: auto; padding: 12px;
  background: var(--bg); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
}
.workspace { flex: 1; min-width: 0; display: flex; gap: 12px; padding: 12px; }
.pane {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 14px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.step {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 700;
}
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.hint.inline { margin: 0 0 0 auto; align-self: center; text-align: right; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12.5px; color: #3a4658; display: flex; justify-content: space-between; gap: 6px; }
.field output { font-weight: 650; color: var(--ink); }
.row { display: flex; align-items: center; gap: 8px; }
.row.gap { margin-top: 4px; }
.row.gap .btn { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }

input[type="range"] { width: 100%; accent-color: var(--brand); margin: 0; }
input[type="number"], select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input[type="color"] { width: 100%; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.upload-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; margin-bottom: 4px; border: 2px dashed #b9c7dd; border-radius: 10px;
  color: var(--brand); font-weight: 600; cursor: pointer; background: var(--brand-soft);
}
.upload-btn:hover { border-color: var(--brand); }

/* ------------------------------------------------------------ toolbar */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfc;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.tool-btn {
  appearance: none; border: 0; background: transparent; font: inherit; font-size: 13px; padding: 6px 11px; cursor: pointer; color: var(--ink);
}
.seg .tool-btn + .tool-btn { border-left: 1px solid var(--line); }
.tool-btn:hover { background: #f0f3f8; }
.tool-btn.active { background: var(--brand); color: #fff; }
.tool-btn.solo { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.tool-btn.solo.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tool-btn:disabled { opacity: .4; cursor: not-allowed; }
.toggles { display: flex; gap: 12px; margin-left: auto; flex-wrap: wrap; }

.canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #e9edf2; }
.canvas-wrap canvas, .canvas-wrap .gl-canvas { position: absolute; inset: 0; display: block; }
.canvas-wrap.dragging { outline: 3px dashed var(--brand); outline-offset: -6px; }
.statusbar { padding: 6px 12px; border-top: 1px solid var(--line); background: #fafbfc; color: var(--muted); font-size: 12px; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(233, 237, 242, .94); text-align: center; padding: 20px; }
.empty-inner { max-width: 340px; color: #46536a; }
.empty-inner svg { color: #8ea3c4; }
.empty-inner h3 { margin: 10px 0 4px; font-size: 18px; color: var(--ink); }
.empty-inner p { margin: 0 0 14px; color: var(--muted); }
.empty-inner .btn { margin: 3px; }

.view-msg {
  position: absolute; inset: 0; z-index: 2; display: grid; place-content: center; text-align: center; padding: 24px;
  color: #51607a; background: linear-gradient(#eef2f7, #dfe6ee); pointer-events: none;
}
.view-msg.error { color: #8a1f1f; pointer-events: auto; }
.view-msg p { max-width: 420px; margin: 8px auto 0; }

/* ------------------------------------------------------------ dialogs & toast */
dialog { border: 0; border-radius: 14px; padding: 20px 22px; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(10, 20, 40, .35); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 40, .45); }
dialog h3 { margin: 0 0 8px; }
dialog ol { padding-left: 20px; margin: 8px 0; }
dialog li { margin: 6px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #111a27; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: min(92vw, 560px); box-shadow: 0 10px 30px rgba(0,0,0,.3);
  transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.banner { background: #fff4d6; color: #5c4400; padding: 10px 14px; border-bottom: 1px solid #f0d27a; font-size: 13px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1099px) {
  .tabs { display: flex; }
  .workspace { padding: 8px; }
  body[data-tab="2d"] .pane-3d { display: none; }
  body[data-tab="3d"] .pane-2d { display: none; }
  .sidebar { width: 280px; }
  .hint.inline { display: none; }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; overflow-y: auto; }
  .sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; flex: none; }
  .workspace { flex: none; height: 78vh; min-height: 420px; }
  body { overflow: auto; }
  .top-actions .btn.ghost { display: none; }
  .brand span { font-size: 16px; }
}
