:root {
  --ui: 34px;
  /* 最小高さ */
  --gap: 6px;
  --headerH: 48px;
  /* JSで実高に更新 */
  --bg-primary: #f6f6f6;
  --bg-secondary: #fafafa;
  --bg-elevated: #ffffff;
  --border-color: #dddddd;
  --text-color: #222222;
  --muted-color: #666666;
  font-synthesis-weight: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
  overflow: hidden;
  color: var(--text-color);
}

/* ← 固定高さをやめて自動高さ。折り返しやオーバーフローに強くする */
header {
  min-height: var(--ui);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
  overflow: visible;
}

footer {
  min-height: var(--ui);
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
  overflow: hidden;
  border-top: 1px solid var(--border-color);
  border-bottom: none;
}

#systems {
  max-height: 60px;
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  white-space: normal;
  flex: 1 1 auto;
  padding-bottom: 2px;
  min-width: 0;
}

.toolbar-command-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-color);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.toolbar-command-button:hover {
  background: rgba(66, 133, 244, 0.1);
  border-color: rgba(66, 133, 244, 0.32);
  box-shadow: 0 2px 6px rgba(66, 133, 244, 0.12);
}

.toolbar-command-button:active {
  background: rgba(66, 133, 244, 0.18);
  border-color: rgba(66, 133, 244, 0.48);
}

.toolbar-command-button:focus-visible {
  outline-offset: 3px;
}

.toolbar-row {
  display: flex;
  align-items: stretch;
  gap: var(--gap);
  flex-wrap: wrap;
  width: 100%;
}

.toolbar-inline-group {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
}

.toolbar-spacer {
  flex: 1 1 auto;
}

.tool-dropdown {
  position: relative;
  display: flex;
  align-items: stretch;
}

.tool-dropdown > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-color);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.tool-dropdown > summary::-webkit-details-marker {
  display: none;
}

.tool-dropdown[open] > summary {
  background: rgba(66, 133, 244, 0.12);
  border-color: rgba(66, 133, 244, 0.4);
}

.tool-dropdown-panel {
  position: absolute;
  inset: calc(100% + 6px) auto auto 0;
  min-width: clamp(280px, 32vw, 520px);
  max-width: min(520px, calc(100vw - 16px));
  max-height: min(60vh, 420px);
  overflow: auto;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.18);
  display: grid;
  gap: 12px;
  z-index: 1000;
  transform: none;
}

.tool-dropdown-panel[data-align='right'] {
  left: auto;
  right: 0;
}

.tool-dropdown-panel[data-align='center'] {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.tool-section {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

/* ← グリッドの行高も auto に変更（以前は var(--ui) で固定だった） */
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

#stage {
  position: relative;
  background: var(--bg-primary);
  overflow: hidden; /* scrollを削除 */
  display: flex;
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

#stage > * {
  min-height: 0;
}

.side-panel.is-collapsed {
  display: none !important;
}

.side-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-width: 150px;
  max-width: 500px;
  position: relative;
  z-index: 2;
}

.tool-accordion {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.accordion-section {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.accordion-section[open] > summary {
  border-bottom: 1px solid var(--border-color);
}

.accordion-section summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 12px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  gap: 8px;
}

.accordion-section summary::-webkit-details-marker {
  display: none;
}

.accordion-content {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tool-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-preview canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
  height: auto;
}

.tool-preview button {
  align-self: flex-end;
  min-width: 0;
  padding: 4px 10px;
  font-size: 12px;
}

.tool-accordion {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.accordion-section {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.accordion-section[open] > summary {
  border-bottom: 1px solid var(--border-color);
}

.accordion-section summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 12px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  gap: 8px;
}

.accordion-section summary::-webkit-details-marker {
  display: none;
}

.accordion-content {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tool-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-preview canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
  height: auto;
}

.tool-preview button {
  align-self: flex-end;
  min-width: 0;
  padding: 4px 10px;
  font-size: 12px;
}

.panel-header {
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid var(--border-color);
}

.panel-footer {
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.04);
  border-top: 1px solid var(--border-color);
}

.layer-properties {
  display: none;
  padding: 6px 4px 0;
  font-size: 12px;
  color: #333;
}

.layer-properties h4 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.layer-property-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.layer-property-row strong {
  font-size: 12px;
}

.vector-layer-controls {
  display: none;
  gap: 4px;
  grid-template-columns: minmax(0, auto) 1fr;
  align-items: center;
  margin-bottom: 6px;
}

.vector-layer-controls label {
  font-weight: 600;
  font-size: 11px;
}

.vector-layer-controls input[type='number'] {
  width: 90px;
}

.vector-layer-controls input[type='text'] {
  width: 100%;
}

.vector-layer-controls button {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.panel-body {
  flex: 1;
  overflow: scroll;
  padding: 8px;
}

.side-panel.no-tool-props .panel-body {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.prop-empty {
  color: #666;
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

.prop-empty-note {
  color: #666;
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 8px;
}

.prop-item {
  margin-bottom: 12px;
}

.prop-item:last-child {
  margin-bottom: 0;
}

.prop-hint {
  color: #777;
  font-size: 11px;
  line-height: 1.4;
  margin-top: 4px;
}

.tool-meta {
  margin-bottom: 12px;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted-color);
  font-size: 12px;
  line-height: 1.5;
}

.tool-meta-title {
  font-weight: 600;
  color: #333;
  margin-bottom: 6px;
}

.tool-meta-row {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.tool-meta-label {
  font-weight: 600;
  flex: 0 0 auto;
}

.tool-meta-value {
  flex: 1 1 auto;
}

.tool-meta-row + .tool-meta-row {
  margin-top: 4px;
}

.prop-palette-section {
  margin-top: 12px;
}

.palette-hint {
  color: #777;
  font-size: 11px;
  margin-bottom: 6px;
}

.palette-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.palette-swatch {
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  transition: transform 0.12s ease;
}

.palette-swatch:hover {
  transform: scale(1.05);
}

.palette-swatch:focus-visible {
  outline: 2px solid #4285f4;
  outline-offset: 2px;
}

.palette-json {
  width: 100%;
  min-height: 72px;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    'Liberation Mono', 'Courier New', monospace;
  resize: vertical;
}

.palette-json.error {
  border-color: #c62828;
  background: #ffebee;
}

.palette-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.palette-actions button {
  min-width: 0;
  padding: 4px 10px;
}

#leftPanel {
  border-right: 1px solid var(--border-color);
  width: 200px;
}

#layerPanel {
  border-left: 1px solid var(--border-color);
  width: 250px;
}

.layer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.layer-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px;
  background: var(--bg-elevated);
}

.layer-filter {
  min-width: 0;
  padding: 4px 10px;
  font-size: 12px;
  border: none;
  background: transparent;
  color: var(--muted-color);
  border-radius: 4px;
  cursor: pointer;
}

.layer-filter.is-active {
  background: rgba(66, 133, 244, 0.15);
  color: var(--text-color);
  font-weight: 600;
}

.layer-search {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--bg-elevated);
}

.layer-search input[type='search'] {
  border: none;
  background: transparent;
  outline: none;
  font-size: 12px;
  min-width: 160px;
}

.layer-action-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.panel-resizer {
  cursor: col-resize;
  flex: 0 0 4px;
  position: relative;
  background: transparent;
  transition: background 0.2s ease;
  touch-action: none;
  z-index: 2;
}

.panel-resizer.is-collapsed {
  display: none;
}

.panel-resizer.is-collapsed {
  display: none;
}

.panel-resizer::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 40px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.15);
  transform: translate(-50%, -50%);
  transition: background 0.2s ease;
}

.panel-resizer:hover,
.panel-resizer.active {
  background: rgba(100, 150, 255, 0.1);
}

.panel-resizer:hover::before,
.panel-resizer.active::before {
  background: rgba(100, 150, 255, 0.55);
}

body.panel-resize-active {
  cursor: col-resize;
  user-select: none;
}

body.panel-resize-active * {
  cursor: col-resize !important;
}

#canvasArea {
  position: relative;
  overflow: scroll; /* スクロールを中央エリアに移動 */
  background: var(--bg-primary);
  flex: 1 1 auto;
  min-width: 0;
  contain: layout style paint;
  overscroll-behavior: contain;
  z-index: 0;
}

#canvasArea::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#canvasArea::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}


/* canvas要素の配置調整 */
canvas {
  position: absolute;
  inset: 0;
  image-rendering: pixelated;
  z-index: 0;
  transform: translateZ(0);
  will-change: transform;
}

#overlay {
  pointer-events: none;
  z-index: 1;
}

#editorLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  transform-origin: 0 0;
  will-change: transform;
}

button {
  height: 32px;
  min-width: 60px;
  padding: 4px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

select,
input[type="color"],
input[type="number"] {
  height: 32px;
}

.tool {
  min-width: 50px;           /* ツールボタンの最小幅 */
  padding: 4px 8px;
  flex: 0 0 auto;            /* サイズ固定 */
  white-space: nowrap;       /* 折り返し禁止 */
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid #4285f4;
  outline-offset: 2px;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.sep {
  width: 1px;
  height: 22px;
  background: #e2e2e2;
  margin: 0 4px;
}

#status {
  font-size: 12px;
  color: var(--muted-color);
}

.active {
  outline: 2px solid #4a90e2;
}

/* 調整パネルをヘッダの実高に追従。 z-indexで最前面へ */
#adjustPanel {
  position: fixed;
  right: 12px;
  top: calc(var(--headerH) + 8px);
  width: 320px;
  max-height: min(80vh, 640px);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 10px;
  display: none;
  z-index: 999;
  /* ← いちばん上 */
}

#adjustPanel h3 {
  margin: 4px 0 8px;
  font-size: 14px;
}

#adjustPanel .row {
  justify-content: space-between;
}

#adjustPanel label {
  font-size: 12px;
  color: #333;
}

#adjustPanel input[type="range"] {
  width: 160px;
  height: 20px;
}

.adjust-preview {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  justify-content: space-between;
}

.adjust-preview canvas {
  width: 140px;
  height: 100px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
}

#adjustPanel .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

#fileInput {
  display: none;
}

.badge {
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

/* 必須: テキスト編集ボックスの見た目と配置 */
.text-editor {
  position: absolute;
  /* ← これが無いと left/top が効かない */
  min-width: 40px;
  min-height: 24px;
  padding: 4px 6px;
  outline: 1px dashed #4a90e2;
  background: transparent;
  white-space: pre-wrap;
  color: #000;
  font: 16px/1.4 system-ui, sans-serif;
  /* 初期フォント */
  pointer-events: auto;
  user-select: text;
}

#layerPanel .panel-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#layerList,
.layer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 4px 8px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.layer-item.active {
  background: #b3d7ff;
}

.layer-item .handle {
  cursor: move;
  user-select: none;
}

.layer-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.layer-meta-top {
  display: flex;
  gap: 6px;
  align-items: center;
}

.layer-meta-top span.layer-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-meta-bottom {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--muted-color);
}

.layer-meta-bottom span {
  white-space: nowrap;
}

.layer-item input[type="range"] {
  width: 90px;
}

.layer-item-controls {
  display: grid;
  grid-auto-flow: row;
  justify-items: end;
  align-items: center;
  gap: 6px;
}

.layer-item-controls select {
  min-width: 120px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.layer-list .layer-empty {
  text-align: center;
  padding: 12px 8px;
  color: var(--muted-color);
  font-size: 12px;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
}

.footer {
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.footer-right {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
}

.footer-badge {
  white-space: nowrap;
}

.layout-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-color);
}

.layout-control select {
  height: 28px;
  padding: 2px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-color);
  font-size: 12px;
}

.footer-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 14px;
  height: 32px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-color);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.footer-button:hover {
  background: rgba(66, 133, 244, 0.08);
  border-color: rgba(66, 133, 244, 0.32);
  box-shadow: 0 2px 6px rgba(66, 133, 244, 0.12);
}

.footer-button:active {
  background: rgba(66, 133, 244, 0.16);
  border-color: rgba(66, 133, 244, 0.48);
}

.footer-button:focus-visible {
  outline-offset: 3px;
}

.shortcut-hint {
  font-size: 12px;
  color: var(--muted-color);
}

.shortcut-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 18, 18, 0.45);
  backdrop-filter: blur(2px);
}

.shortcut-overlay[hidden] {
  display: none;
}

.tool-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 420;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 18, 18, 0.45);
  backdrop-filter: blur(2px);
}

.tool-search-overlay[hidden] {
  display: none;
}

.tool-search-panel {
  width: min(560px, 94vw);
  max-height: min(88vh, 600px);
  border-radius: 14px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-color);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tool-search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-color);
}

.tool-search-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.tool-search-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-color);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.tool-search-close:hover {
  background: rgba(66, 133, 244, 0.12);
  border-color: rgba(66, 133, 244, 0.32);
}

.tool-search-close:active {
  background: rgba(66, 133, 244, 0.2);
  border-color: rgba(66, 133, 244, 0.48);
}

.tool-search-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 24px 24px;
}

.tool-search-label {
  margin: 0;
  font-size: 12px;
  color: var(--muted-color);
}

.tool-search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-color);
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.tool-search-input::placeholder {
  color: var(--muted-color);
}

.tool-search-input:focus-visible {
  outline: none;
  border-color: rgba(66, 133, 244, 0.55);
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.2);
  background: var(--bg-elevated);
}

.tool-search-hint {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted-color);
}

.tool-search-results {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(52vh, 360px);
  overflow: auto;
}

.tool-search-item {
  margin: 0;
}

.tool-search-button {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-color);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.tool-search-button:hover,
.tool-search-button:focus-visible {
  border-color: rgba(66, 133, 244, 0.48);
  background: rgba(66, 133, 244, 0.08);
  box-shadow: 0 1px 4px rgba(66, 133, 244, 0.12);
}

.tool-search-button.is-active {
  border-color: rgba(66, 133, 244, 0.6);
  background: rgba(66, 133, 244, 0.15);
  box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

.tool-search-name {
  font-weight: 700;
  font-size: 14px;
}

.tool-search-meta {
  font-size: 12px;
  color: var(--muted-color);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-search-empty {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted-color);
  text-align: center;
}

.shortcut-overlay-panel {
  width: min(720px, 92vw);
  max-height: min(90vh, 640px);
  background: var(--bg-elevated);
  color: var(--text-color);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.shortcut-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border-color);
}

.shortcut-overlay-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.shortcut-overlay-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-color);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.shortcut-overlay-close:hover {
  background: rgba(66, 133, 244, 0.12);
  border-color: rgba(66, 133, 244, 0.32);
}

.shortcut-overlay-close:active {
  background: rgba(66, 133, 244, 0.2);
  border-color: rgba(66, 133, 244, 0.48);
}

.shortcut-overlay-body {
  padding: 20px 24px 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.shortcut-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shortcut-section h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.shortcut-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted-color);
}

.shortcut-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.shortcut-list-item {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  display: grid;
  gap: 4px;
}

.shortcut-list-item dt {
  margin: 0;
  font-weight: 700;
  font-size: 13px;
}

.shortcut-list-item dd {
  margin: 0;
  font-size: 12px;
  color: var(--muted-color);
}

.shortcut-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.shortcut-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 1;
}

.shortcut-table th,
.shortcut-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.shortcut-table tbody tr:hover {
  background: rgba(66, 133, 244, 0.08);
}

.shortcut-table th {
  font-weight: 700;
}

.shortcut-empty {
  padding: 16px 12px;
  text-align: center;
  color: var(--muted-color);
}

@media (max-width: 1200px) {
  .tool-dropdown > summary {
    min-width: 96px;
    font-size: 12px;
  }

  .tool {
    min-width: 40px;
    padding: 4px 6px;
    font-size: 11px;
  }

  #systems {
    max-height: 90px;
  }

  .tool-dropdown-panel {
    min-width: clamp(240px, 46vw, 420px);
    max-width: min(420px, calc(100vw - 16px));
  }
}

@media (max-width: 768px) {
  #leftPanel,
  #layerPanel {
    width: 180px;
  }

  .side-panel {
    min-width: 120px;
  }

  #adjustPanel {
    width: min(92vw, 320px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .shortcut-overlay {
    padding: 16px;
  }

  .shortcut-overlay-header {
    padding: 16px 18px 14px;
  }

  .shortcut-overlay-body {
    padding: 16px 18px 20px;
    gap: 20px;
  }
}

@media (max-width: 768px) {
  .layout-control {
    width: 100%;
    justify-content: flex-start;
  }

  .layout-control select {
    width: min(220px, 100%);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-elevated: #2a2a2a;
    --border-color: #404040;
    --text-color: #e0e0e0;
    --muted-color: #bbbbbb;
  }

  body {
    background: var(--bg-primary);
    color: var(--text-color);
  }

  header,
  footer {
    background: var(--bg-secondary);
    border-color: var(--border-color);
  }

  .panel-header,
  .panel-footer,
  .tool-meta {
    background: rgba(255, 255, 255, 0.05);
  }

  .tool-dropdown > summary {
    background: var(--bg-secondary);
  }

  .tool-dropdown-panel {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  }

  .layer-item.active {
    background: rgba(65, 131, 215, 0.45);
  }

  .accordion-section {
    background: var(--bg-secondary);
  }

  .accordion-section summary {
    background: rgba(255, 255, 255, 0.05);
  }

  .shortcut-overlay {
    background: rgba(0, 0, 0, 0.6);
  }

  .tool-search-overlay {
    background: rgba(0, 0, 0, 0.6);
  }

  .tool-search-panel {
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6);
  }

  .tool-search-button:hover,
  .tool-search-button:focus-visible {
    background: rgba(138, 180, 248, 0.16);
    border-color: rgba(138, 180, 248, 0.48);
  }

  .tool-search-button.is-active {
    background: rgba(138, 180, 248, 0.24);
    border-color: rgba(138, 180, 248, 0.64);
  }

  .shortcut-table tbody tr:hover {
    background: rgba(66, 133, 244, 0.24);
  }
}
