:root {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --border: #ddd;
  --accent: #3b6ff0;
  --text: #222;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.hidden { display: none !important; }

#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #666;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#drawing-name {
  border: 1px solid transparent;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 4px;
  min-width: 160px;
}
#drawing-name:hover, #drawing-name:focus {
  border-color: var(--border);
  background: #fafafa;
}

.save-status {
  font-size: 0.8rem;
  color: #888;
}

.user-name {
  font-size: 0.85rem;
  color: #666;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.9rem;
}
.icon-btn:hover { background: #f0f2f8; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: 110%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  min-width: 140px;
  z-index: 20;
  overflow: hidden;
}
.dropdown-menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.9rem;
}
.dropdown-menu button:hover { background: #f0f2f8; }

#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#toolbar {
  width: 84px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 14px 8px;
  overflow-y: auto;
}

.tool-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  border-bottom: 1px solid #eee;
  padding-bottom: 12px;
}
.tool-group:last-child { border-bottom: none; }

.group-label {
  font-size: 0.7rem;
  color: #999;
}

.tool-btn, .width-btn, .proj-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px;
  width: 100%;
  cursor: pointer;
  font-size: 1rem;
}
.proj-btn { font-size: 0.75rem; }
.tool-btn.active, .width-btn.active, .proj-btn.active {
  border-color: var(--accent);
  background: #eaf0ff;
}

#color-swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 100%;
}
.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.swatch.active { border-color: var(--accent); }

#color-custom {
  width: 100%;
  border: none;
  height: 26px;
  cursor: pointer;
}

#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #fbfbfd;
  cursor: crosshair;
}
#canvas-wrap.pan-mode { cursor: grab; }
#canvas-wrap.erase-mode { cursor: cell; }
#canvas-wrap.panning { cursor: grabbing; }

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.grid-line { stroke: #d0d2dc; stroke-width: 0.5; }
.grid-dot { fill: #c7c9d6; }

.iso-line { stroke-linecap: round; }
.iso-line.erase-hover { stroke: #ff4d4f !important; opacity: 0.6; }
.preview-line { stroke: var(--accent); stroke-dasharray: 4 3; opacity: 0.8; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-content {
  background: var(--panel);
  border-radius: 10px;
  width: min(480px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 14px 18px; overflow-y: auto; }

.new-drawing-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.new-drawing-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.new-drawing-row button {
  padding: 8px 14px;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

#drawings-list { list-style: none; margin: 0; padding: 0; }
#drawings-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 6px;
  border-bottom: 1px solid #eee;
}
#drawings-list .d-name { cursor: pointer; font-weight: 500; }
#drawings-list .d-name:hover { color: var(--accent); }
#drawings-list .d-meta { font-size: 0.75rem; color: #999; margin-left: 8px; }
#drawings-list .d-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  margin-left: 6px;
}

@media print {
  #topbar, #toolbar, .modal { display: none !important; }
  #canvas-wrap { position: static !important; }
}