/* studio 本体（ツールの枠）の見た目。プレビューの中身は theme.css 側。 */
:root {
  --ui-bg: #f6f6f4;
  --ui-panel: #ffffff;
  --ui-line: #e3e2de;
  --ui-text: #23231f;
  --ui-muted: #74736c;
  --ui-accent: #2a5bd7;
  --ui-accent-soft: #e8eefc;
  --ui-danger: #c2361f;
  --ui-radius: 8px;
  --ui-font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --ui-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
  color: var(--ui-text);
  font: 13px/1.5 var(--ui-font);
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--ui-mono); font-size: 0.92em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.spacer { flex: 1; }

/* ---- 上部バー ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-line);
}
.brand { font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.project input {
  width: 220px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-weight: 600;
}
.project input:hover, .project input:focus { border-color: var(--ui-line); background: var(--ui-bg); outline: none; }
.group { display: flex; align-items: center; gap: 6px; }
.group-label { color: var(--ui-muted); margin-right: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: var(--ui-panel);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #c9c8c2; background: #fafaf8; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #efeeea; border-color: transparent; }
.btn-primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
.btn-primary:hover { background: #224bb4; border-color: #224bb4; }
.btn-small { padding: 3px 8px; font-size: 12px; }
.btn-add { width: 100%; justify-content: center; margin-top: 6px; border-style: dashed; color: var(--ui-muted); background: transparent; }
.chip {
  padding: 4px 10px;
  border: 1px solid var(--ui-accent);
  border-radius: 999px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  cursor: pointer;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 3ペイン ---- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(320px, 1fr) minmax(360px, 1.25fr);
}
.sidebar {
  overflow: auto;
  padding: 12px 10px 24px;
  border-right: 1px solid var(--ui-line);
  background: var(--ui-panel);
}
.side-section + .side-section { margin-top: 22px; }
.side-head { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 6px; }
.side-head h2 { margin: 0; font-size: 12px; color: var(--ui-muted); font-weight: 600; letter-spacing: 0.04em; }

.tree { list-style: none; margin: 0; padding: 0; }
.tree-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 4px 6px 4px calc(8px + var(--depth) * 16px);
  border-radius: 6px;
  cursor: pointer;
}
.tree-row::before {
  content: "";
  position: absolute;
  left: calc(var(--depth) * 16px - 4px);
  top: 6px;
  bottom: 6px;
  border-left: 1px solid var(--ui-line);
  display: var(--guide, block);
}
.tree-row[style*="--depth:0"]::before { display: none; }
.tree-row:hover { background: #f3f2ee; }
.tree-row.is-active { background: var(--ui-accent-soft); }
.tree-row.is-active .tree-title { color: var(--ui-accent); }
.tree-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tree-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-path { font-family: var(--ui-mono); font-size: 11px; color: var(--ui-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row.is-dup .tree-path { color: var(--ui-danger); }
.tree-actions { display: none; gap: 1px; }
.tree-row:hover .tree-actions, .tree-row.is-active .tree-actions { display: flex; }
.tree-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ui-muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 22px;
}
.tree-btn:hover { background: #fff; color: var(--ui-text); box-shadow: 0 0 0 1px var(--ui-line); }
.tree-btn[data-act="delete"]:hover, .tree-btn[data-act="delete-part"]:hover { color: var(--ui-danger); }

.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-editor { position: relative; border-right: 1px solid var(--ui-line); background: var(--ui-panel); }

/* エディタの補完メニュー（行頭の / で部品、]( でリンク先） */
.ac-menu {
  position: absolute;
  z-index: 20;
  width: 320px;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}
.ac-menu[hidden] { display: none; }
.ac-group { padding: 8px 8px 2px; font-size: 11px; color: var(--ui-muted); font-weight: 600; letter-spacing: 0.04em; }
.ac-item { display: flex; flex-direction: column; gap: 1px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.ac-item:hover { background: #f3f2ee; }
.ac-item.is-active { background: var(--ui-accent-soft); }
.ac-item.is-active .ac-label { color: var(--ui-accent); }
.ac-label { font-weight: 600; }
.ac-desc, .ac-path { color: var(--ui-muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-path { font-family: var(--ui-mono); }
.ac-desc code { padding: 0 2px; border-radius: 3px; background: #efeeea; }
.ac-foot { position: sticky; bottom: -4px; margin: 4px -4px -4px; padding: 6px 12px; border-top: 1px solid var(--ui-line); background: var(--ui-bg); color: var(--ui-muted); font-size: 11px; }
.pane-head {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ui-line);
  min-height: 52px;
}
.field { display: flex; flex-direction: column; gap: 2px; }
.field > span:first-child { font-size: 11px; color: var(--ui-muted); }
.field input {
  padding: 4px 8px;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: var(--ui-panel);
}
.field input:focus { outline: 2px solid var(--ui-accent-soft); border-color: var(--ui-accent); }
.field-title { flex: 1; }
.field-title input { width: 100%; font-weight: 600; }
.field-slug { flex: 1.1; }
.slug-wrap { display: flex; align-items: center; border: 1px solid var(--ui-line); border-radius: 6px; overflow: hidden; }
.slug-wrap:focus-within { border-color: var(--ui-accent); }
.slug-prefix { padding: 4px 0 4px 8px; font-family: var(--ui-mono); font-size: 12px; color: var(--ui-muted); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.slug-wrap input { border: 0; flex: 1; min-width: 60px; font-family: var(--ui-mono); font-size: 12px; padding-left: 0; }
.slug-wrap input:focus { outline: none; }
.field-note { margin: 0 0 4px; color: var(--ui-muted); }

.editor-tools { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--ui-line); }
.editor-tools select { padding: 4px 6px; border: 1px solid var(--ui-line); border-radius: 6px; background: var(--ui-panel); }
.editor-hint { color: var(--ui-muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#editor {
  flex: 1;
  width: 100%;
  padding: 14px 16px 40vh;
  border: 0;
  resize: none;
  outline: none;
  background: var(--ui-panel);
  font: 13px/1.7 var(--ui-mono);
  tab-size: 2;
}

.preview-head { align-items: center; background: var(--ui-panel); }
.preview-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.preview-scale { color: var(--ui-muted); font-family: var(--ui-mono); font-size: 11px; white-space: nowrap; }
.segmented { display: inline-flex; border: 1px solid var(--ui-line); border-radius: 6px; overflow: hidden; }
.segmented button { padding: 3px 12px; border: 0; background: var(--ui-panel); cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--ui-line); }
.segmented button.is-on { background: var(--ui-text); color: #fff; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #e9e8e3; }
#preview {
  position: absolute;
  top: 0;
  border: 0;
  background: #fff;
  transform-origin: top left;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

/* ---- ダイアログ・通知 ---- */
.dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 20px 22px;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: var(--ui-panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.dialog-wide { width: min(860px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(20, 20, 18, 0.35); }
.dialog h2 { margin: 0 0 8px; font-size: 16px; }
.dialog-note { margin: 0 0 10px; color: var(--ui-muted); }
.dialog textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  font: 13px/1.7 var(--ui-mono);
  resize: vertical;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.dg-meta { margin: 0 0 4px; }
.dg-desc { margin: 0 0 8px; color: var(--ui-muted); }
.dg-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.dg-table th, .dg-table td { padding: 4px 8px; border-bottom: 1px solid var(--ui-line); text-align: left; vertical-align: middle; }
.dg-table thead th { color: var(--ui-muted); font-weight: 600; }
.dg-group th { padding-top: 12px; color: var(--ui-text); background: transparent; }
.dg-table tr.is-missing td { color: #a9a8a1; }
.swatch { display: inline-block; width: 14px; height: 14px; margin-right: 6px; border-radius: 3px; vertical-align: -2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
#design-body { max-height: 64vh; overflow: auto; }

/* 部品一覧（カタログ） */
.dialog-catalog { width: min(1240px, calc(100vw - 32px)); height: min(860px, calc(100vh - 32px)); padding: 0; overflow: hidden; }
.catalog { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100%; }
.catalog-list { overflow: auto; padding: 14px 10px; border-right: 1px solid var(--ui-line); background: var(--ui-bg); }
.catalog-list h3 { margin: 14px 6px 4px; font-size: 11px; color: var(--ui-muted); font-weight: 600; letter-spacing: 0.04em; }
.catalog-list h3:first-child { margin-top: 0; }
.catalog-item {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.catalog-item:hover { background: #ecebe6; }
.catalog-item.is-active { background: var(--ui-accent-soft); color: var(--ui-accent); font-weight: 600; }
.catalog-detail { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.catalog-head { display: flex; align-items: flex-start; gap: 16px; padding: 14px 16px 10px; border-bottom: 1px solid var(--ui-line); }
.catalog-title-wrap { flex: 1; min-width: 0; }
.catalog-head h2 { margin: 0 0 2px; font-size: 16px; }
.catalog-desc { margin: 0; color: var(--ui-muted); }
.catalog-desc code { padding: 0 3px; border-radius: 3px; background: #efeeea; color: var(--ui-text); }
.catalog-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.catalog-code {
  flex: none;
  max-height: 32%;
  margin: 0;
  padding: 10px 16px;
  overflow: auto;
  border-bottom: 1px solid var(--ui-line);
  background: #fbfbf9;
  font: 12.5px/1.65 var(--ui-mono);
  white-space: pre-wrap;
}
.catalog-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #e9e8e3; }
#catalog-preview { position: absolute; top: 0; border: 0; background: #fff; transform-origin: top left; }

.help { max-height: 66vh; overflow: auto; }
.help h3 { margin: 14px 0 6px; font-size: 13px; }
.help section:first-child h3 { margin-top: 0; }
.help table { width: 100%; border-collapse: collapse; }
.help td { padding: 4px 8px; border-bottom: 1px solid var(--ui-line); vertical-align: top; }
.help td:first-child { width: 42%; white-space: nowrap; }
.help ul { margin: 0; padding-left: 1.2em; }

.update-banner {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(760px, calc(100vw - 32px));
  padding: 8px 10px 8px 16px;
  border: 1px solid #c9d6f5;
  border-radius: 10px;
  background: var(--ui-accent-soft);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  transform: translateX(-50%);
}
.update-banner[hidden] { display: none; }
.update-files { margin-left: 6px; color: var(--ui-muted); font-family: var(--ui-mono); font-size: 11px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 50;
  max-width: min(640px, calc(100vw - 32px));
  padding: 8px 14px;
  border-radius: 8px;
  background: #23231f;
  color: #fff;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.has-action { pointer-events: auto; }
.toast-action { margin-left: 8px; padding: 2px 10px; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 999px; background: transparent; color: #fff; cursor: pointer; }
.toast-action:hover { background: rgba(255, 255, 255, 0.15); }
/* 2回押しの確認（armed）。1回目でこの見た目になり、3秒で戻る */
.is-armed { background: var(--ui-danger) !important; border-color: var(--ui-danger) !important; color: #fff !important; }
.drop-hint {
  position: fixed;
  inset: 12px;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--ui-accent);
  border-radius: 16px;
  background: rgba(232, 238, 252, 0.85);
  color: var(--ui-accent);
  font-size: 16px;
  font-weight: 600;
  pointer-events: none;
}
.drop-hint.is-on { display: flex; }

/* ---- 種類（作るときに決める。表示だけ）と新規作成 ---- */
.kind-label { padding: 2px 8px; border: 1px solid var(--ui-line); border-radius: 999px; font-size: 12px; color: var(--ui-muted); white-space: nowrap; }
.dialog-new { width: min(560px, 92vw); }
.new-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0 4px; }
.new-kind { display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--ui-line); border-radius: var(--ui-radius); background: var(--ui-panel); text-align: left; cursor: pointer; font: inherit; }
.new-kind:hover { border-color: var(--ui-accent); background: var(--ui-accent-soft); }
.new-kind-title { font-weight: 700; font-size: 15px; }
.new-kind-desc { font-size: 12px; color: var(--ui-muted); line-height: 1.6; }
.field-check { display: flex; align-items: center; gap: 6px; align-self: flex-end; padding-bottom: 7px; white-space: nowrap; font-size: 12px; color: var(--ui-muted); cursor: pointer; }

/* ---- 確認のパネル（エディタの列と切り替え。design-check.js） ---- */
.workspace.is-check .pane-editor { display: none; }
.pane-check { border-right: 1px solid var(--ui-line); background: var(--ui-panel); }
.pane-check[hidden] { display: none; }
.ck-head { align-items: center; gap: 6px; }
.ck-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ck-title small { color: var(--ui-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ck-head a.btn { text-decoration: none; color: inherit; }
.ck-body { flex: 1; overflow: auto; padding: 4px 14px 24px; }
.ck-empty, .ck-note { color: var(--ui-muted); font-size: 12px; line-height: 1.7; }
.ck-empty { margin-top: 24px; }
.ck-section { padding: 12px 0; border-bottom: 1px solid var(--ui-line); }
.ck-section:last-child { border-bottom: 0; }
.ck-h { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 12px; font-weight: 700; }
.ck-badge { padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.ck-badge.is-pass { background: #e6f4ea; color: #1b7f3b; }
.ck-badge.is-fail { background: #fdecea; color: var(--ui-danger); }
.ck-checks, .ck-colors { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.ck-check { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.ck-check.is-fail { background: #fdecea; }
.ck-pair span { display: inline-grid; place-items: center; width: 32px; height: 22px; border-radius: 4px; border: 1px solid var(--ui-line); font-weight: 700; font-size: 12px; }
.ck-name { font-size: 12px; min-width: 0; }
.ck-name small { display: block; color: var(--ui-muted); font-size: 10px; }
.ck-ratio { font-family: var(--ui-mono); font-size: 12px; white-space: nowrap; }
.ck-check.is-pass .ck-ratio { color: #1b7f3b; }
.ck-check.is-fail .ck-ratio { color: var(--ui-danger); }
.ck-summary { width: 100%; border-collapse: collapse; font-size: 12px; }
.ck-summary th { width: 40%; padding: 3px 0; text-align: left; font-weight: 400; color: var(--ui-muted); }
.ck-summary td { padding: 3px 0; font-family: var(--ui-mono); font-size: 11px; }
.ck-none { color: var(--ui-muted); font-family: var(--ui-font); }
.ck-color { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; font-size: 11px; }
.ck-swatch { width: 26px; height: 18px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.12); }
.ck-value { font-family: var(--ui-mono); color: var(--ui-muted); }
.btn.is-on { background: var(--ui-text); border-color: var(--ui-text); color: #fff; }
.sample-tools { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; }
.sample-tools[hidden] { display: none; }
.sample-tools select { padding: 2px 6px; border: 1px solid var(--ui-line); border-radius: 6px; background: var(--ui-panel); font-size: 12px; }

/* unitcell tools の入口へ戻るリンク（道具をまたいで同じ形。文字色は周りから継ぐ） */
.ut-home { color: inherit; opacity: 0.6; font-size: 12px; font-weight: 400; text-decoration: none; white-space: nowrap; }
.ut-home::after { content: " /"; }
.ut-home:hover { opacity: 1; text-decoration: underline; }
