* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', 'Yu Gothic UI', sans-serif;
  background: #111827;
  color: #f3f4f6;
  min-height: 100vh;
  margin: 0;
  padding: 20px;
  line-height: 1.6;
}

h2 {
  color: #00d9ff;
  text-shadow: 0 0 10px rgba(0, 217, 255, 0.5);
  margin-bottom: 20px;
  font-size: 28px;
}

.toolbar {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.divider {
  border-left: 1px solid #374151;
  height: 28px;
  margin: 0 8px;
}

label {
  color: #9ca3af;
  font-size: 13px;
}

input[type="number"] {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid #4b5563;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  font-size: 13px;
}

input[type="number"]:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #3b82f6;
}

button {
  padding: 6px 12px;
  font-size: 13px;
  background: #111827;
  border: 1px solid #4b5563;
  border-radius: 6px;
  color: #f3f4f6;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

button:hover {
  background: #1f2937;
  border-color: #6b7280;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #1e40af;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

/* パレット */
#palette {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
  background: #1f2937;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #374151;
}

.palette-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.palette-group-label {
  font-size: 12px;
  color: #9ca3af;
  padding-left: 2px;
}

.palette-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.palette-item {
  width: 48px;
  height: 48px;
  border: 2px solid #4b5563;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  color: #0f172a;
  font-weight: 600;
}

.palette-item:hover {
  transform: scale(1.1);
  border-color: #6b7280;
}

.palette-item.selected {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px #111827, 0 0 12px rgba(59, 130, 246, 0.5);
  transform: scale(1.15);
}

.palette-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  font-size: 10px;
  color: #e5e7eb;
  background: rgba(17, 24, 39, 0.28);
  border-radius: 4px;
  text-align: center;
  padding: 2px 3px;
  white-space: nowrap;
}

.palette-item.selected .palette-label {
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.15);
}

/* マップコンテナ */
#map-wrapper {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
  max-height: 65vh;
  margin-bottom: 12px;
  position: relative;
}

#map {
  display: grid;
  width: fit-content;
  transform-origin: top left;
  background-image: repeating-conic-gradient(#374151 0% 25%, #1f2937 0% 50%);
  background-size: 20px 20px;
}

#map.show-grid {
  gap: 1px;
  background-color: rgba(75, 85, 99, 0.5);
}

.tile {
  width: 16px;
  height: 16px;
  cursor: crosshair;
  transition: filter 0.05s;
}

.tile:hover {
  filter: brightness(1.3);
}

.tile.selected-area {
  box-shadow: none;
}

.tile.selected-edge-top {
  border-top: 2px solid rgba(59, 130, 246, 0.9);
}

.tile.selected-edge-right {
  border-right: 2px solid rgba(59, 130, 246, 0.9);
}

.tile.selected-edge-bottom {
  border-bottom: 2px solid rgba(59, 130, 246, 0.9);
}

.tile.selected-edge-left {
  border-left: 2px solid rgba(59, 130, 246, 0.9);
}

.tile.shape-preview {
  background-image: linear-gradient(rgba(96, 165, 250, 0.32), rgba(96, 165, 250, 0.32));
  box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.95);
}

/* ステータスバー */
.status-bar {
  display: flex;
  gap: 16px;
  padding: 8px 12px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  color: #9ca3af;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-item span {
  color: #60a5fa;
}

/* 出力エリア */
.output-section {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 12px;
  margin-top: 12px;
}

.output-section h3 {
  margin: 0 0 8px 0;
  color: #60a5fa;
  font-size: 14px;
}

#output {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 12px;
  max-height: 200px;
  overflow: auto;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  color: #86efac;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ツールボタン */
.tool-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.tool-btn.selected {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #1e40af;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* ズームコントロール */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

#zoomLevel {
  min-width: 50px;
  text-align: center;
  color: #e5e7eb;
  font-size: 12px;
}

/* ショートカットモーダル */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 20px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h3 {
  margin: 0 0 16px 0;
  color: #f3f4f6;
  font-size: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}

.modal-close:hover {
  color: #f3f4f6;
}

.shortcut-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #374151;
  font-size: 13px;
  color: #d1d5db;
}

.shortcut-item:last-child {
  border-bottom: none;
}

.shortcut-key {
  background: #111827;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 11px;
  color: #60a5fa;
  border: 1px solid #4b5563;
}

/* コンテキストメニュー */
.context-menu {
  display: none;
  position: fixed;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 4px 0;
  min-width: 160px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  z-index: 2000;
}

.context-menu.show {
  display: block;
}

.context-menu-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  color: #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.context-menu-item:hover {
  background: #374151;
}

.context-menu-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.context-menu-divider {
  height: 1px;
  background: #374151;
  margin: 4px 0;
}

.menu-shortcut {
  font-size: 11px;
  color: #6b7280;
  margin-left: 16px;
}

/* スクロールバー */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #1f2937;
}

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

::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* ヘルプリンク */
.help-link {
  font-size: 11px;
  color: #6b7280;
  margin-top: 8px;
}

.help-link a {
  color: #60a5fa;
  cursor: pointer;
}

.help-link a:hover {
  text-decoration: underline;
}
