:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #d9dce1;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2f6fdb;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 'Hiragino Sans', 'Yu Gothic', 'Meiryo', sans-serif;
}

button, select, input { font: inherit; color: inherit; }

button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 16px; }
.bar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chk { display: flex; align-items: center; gap: 4px; }

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr 260px;
}

aside {
  overflow-y: auto;
  padding: 12px;
  background: var(--panel);
}
#palette { border-right: 1px solid var(--line); }
#props { border-left: 1px solid var(--line); }

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

#search { width: 100%; margin-bottom: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.part[hidden], details[hidden] { display: none; }
summary .count { margin-left: 4px; color: var(--muted); font-weight: 400; font-size: 12px; }

.group-title { margin: 16px 0 6px; padding: 3px 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; color: #ffffff; background: var(--muted); border-radius: 4px; }
.group-title:first-child { margin-top: 0; }
.group-title[hidden] { display: none; }
details { margin-bottom: 8px; }
summary { padding: 4px 0; font-weight: 600; cursor: pointer; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding-top: 4px; }
.part {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  font-size: 12px;
}
.part svg { width: 100%; height: 64px; }

#stage {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}
#zoom-reset { position: absolute; top: 10px; right: 14px; padding: 2px 10px; font-size: 12px; opacity: 0.9; }
#canvas {
  width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  background: #dfe3e8; /* シートの外側 (縮小したときに見える). シートは白で, 枠線と影がある */
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  touch-action: none;
  user-select: none;
}

/* Shift を押している間は, कैनवास全体でつかむ形のカーソル (Shift+ドラッグでシートを動かせる). 動かしている間は, つかんでいる形 */
#canvas.pan-ready, #canvas.pan-ready * { cursor: grab !important; }
#canvas.panning, #canvas.panning * { cursor: grabbing !important; }

.hint { color: var(--muted); margin: 0; }
.field { margin-bottom: 14px; }
.field > label, .field > .label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.pair { display: flex; align-items: center; gap: 8px; }
.pair input[type=range] { flex: 1; min-width: 0; }
.pair input[type=number] { width: 64px; }
.field input[type=text] { width: 100%; padding: 4px 6px; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.swatch { width: 22px; height: 22px; padding: 0; border-radius: 50%; }
input[type=color] { width: 36px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.danger { color: #b3261e; }

#msg {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#msg.show { opacity: 1; }
#msg.error { background: #b3261e; }

@media (max-width: 800px) {
  body { height: auto; }
  main { display: flex; flex-direction: column; }
  main > * { min-width: 0; }
  #stage { order: 1; padding: 12px 16px; }
  #props { order: 2; border-left: 0; border-top: 1px solid var(--line); }
  #palette { order: 3; border-right: 0; border-top: 1px solid var(--line); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.wl-btn { padding: 2px 6px; min-width: 38px; border-radius: 4px; border-color: transparent; color: #ffffff; font-size: 11px; text-shadow: 0 0 2px rgba(0, 0, 0, 0.6); }
.field select { width: 100%; padding: 4px 6px; }
.pair button { padding: 4px 10px; }
.doc-name { margin-left: 8px; font-size: 13px; font-weight: 400; color: var(--muted); }

dialog {
  width: min(560px, calc(100% - 32px));
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 6px; font-size: 16px; }
#save-list { list-style: none; margin: 10px 0; padding: 0; max-height: 50vh; overflow-y: auto; }
#save-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.save-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.save-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-meta { color: var(--muted); font-size: 12px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 8px; }
