:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #d9dde3;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-weak: rgba(37, 99, 235, 0.12);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
}

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

.menu-bar {
  height: 56px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(#ffffff, #fbfbfd);
}

.app-title {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.menu-menubar {
  display: flex;
  align-items: center;
  gap: 4px;
}

.menu-dropdown {
  position: relative;
}

.menu-top-btn {
  list-style: none;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.menu-top-btn::-webkit-details-marker {
  display: none;
}

.menu-top-btn::marker {
  content: "";
}

.menu-dropdown[open] > .menu-top-btn {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  z-index: 30;
}

.menu-item {
  height: 32px;
  padding: 0 10px;
  width: 100%;
  display: block;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  position: relative;
}

.menu-item:hover:not(:disabled) {
  background: #f1f5f9;
}

.menu-item.is-selected {
  background: var(--accent-weak);
  color: #0b3ea1;
}

.menu-item:disabled {
  opacity: 0.55;
  cursor: default;
}

.menu-submenu {
  position: relative;
  width: 100%;
}

.menu-item-parent {
  padding-right: 24px;
}

.menu-item-parent::after {
  content: "›";
  position: absolute;
  right: 10px;
  color: #64748b;
}

.menu-submenu:hover > .menu-item-parent,
.menu-submenu:focus-within > .menu-item-parent {
  background: #f1f5f9;
}

.menu-subpanel {
  position: absolute;
  left: calc(100% - 4px);
  top: -4px;
  min-width: 190px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  z-index: 40;
}

.menu-submenu::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 0;
  width: 14px;
  height: 100%;
}

.menu-submenu:hover > .menu-subpanel,
.menu-submenu:focus-within > .menu-subpanel,
.menu-submenu.is-open > .menu-subpanel {
  display: flex;
}

.menu-submenu.is-open > .menu-item-parent {
  background: #f1f5f9;
}

.menu-label {
  font-size: 12px;
  color: var(--muted);
}

.menu-select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}

.menu-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}

.menu-btn:hover:not(:disabled) {
  border-color: #b8c2cc;
}

.menu-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.menu-spacer {
  flex: 1;
}

.status-text {
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.legacy-controls {
  display: none;
}

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

.sidebar {
  width: 260px;
  padding: 14px;
  border-right: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#customToolsTitle {
  display: none;
}

#customToolList {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
}

#customToolList:empty {
  display: none;
}

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

.tool-btn {
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  padding: 0 12px;
}

.tool-btn:hover {
  border-color: #b8c2cc;
}

.tool-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.build-tool-btn {
  height: 36px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}

.build-tool-btn:hover {
  border-color: #b8c2cc;
}

.tool-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  min-height: 34px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.hint-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.hint-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.canvas-pane {
  flex: 1;
  min-width: 0;
  position: relative;
  padding: 14px;
}

#canvas {
  width: 100%;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: block;
  touch-action: none;
}

.context-menu {
  position: absolute;
  z-index: 10;
  min-width: 230px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px;
}

.context-menu.is-hidden {
  display: none;
}

.ctx-title {
  font-weight: 700;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.ctx-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0;
}

.ctx-row label {
  font-size: 12px;
  color: var(--muted);
}

.ctx-input {
  flex: 1;
  min-width: 0;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 8px;
  font-size: 13px;
}

.ctx-color {
  width: 46px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 2px;
}

.ctx-range {
  flex: 1;
}

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

.ctx-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.ctx-btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.history-pane {
  width: 280px;
  padding: 14px;
  border-left: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.history-pane.is-collapsed {
  display: none;
}

.history-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-print-btn {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
}

.history-empty {
  font-size: 12px;
  color: var(--muted);
}

.history-list {
  margin: 0;
  padding-left: 26px;
  list-style-position: inside;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  overflow-y: auto;
  flex: 1;
}

.history-list li {
  margin-bottom: 6px;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
