:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #1b1d22;
  color: #e5e7eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.14), transparent 28%),
    linear-gradient(180deg, #1a1c20 0%, #111317 100%);
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #323743;
  background: linear-gradient(180deg, #23262d 0%, #1a1c21 100%);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.03);
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-tools h2 {
  margin: 0;
  font-size: 0.72rem;
  color: #94a3b8;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.brand {
  padding: 10px 14px;
  border-radius: 10px;
  background: linear-gradient(180deg, #2b3039 0%, #1f232b 100%);
  border: 1px solid #3a404d;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tool-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
  height: calc(100vh - 96px);
}

.palette {
  padding: 18px;
  background: linear-gradient(180deg, #23262d 0%, #1a1c21 100%);
  border-right: 1px solid #323743;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.03);
  height: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid #373d49;
  border-radius: 14px;
  background: linear-gradient(180deg, #2a2f38 0%, #20242b 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.panel h2 {
  margin: 0;
  font-size: 0.95rem;
  color: #cbd5e1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tool-button {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 56px;
  min-height: 50px;
  padding: 8px 6px 6px;
  border: 1px solid #444b58;
  border-radius: 10px;
  background: linear-gradient(180deg, #343a46 0%, #272c35 100%);
  color: #e5e7eb;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  flex: 0 0 auto;
}

.tool-button:hover {
  transform: translateY(-1px);
  border-color: #5d6677;
  background: linear-gradient(180deg, #3b4250 0%, #2d333d 100%);
}

.tool-button.active {
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.4);
  background: linear-gradient(180deg, #24476f 0%, #1f3550 100%);
}

.tool-icon {
  font-size: 1rem;
  line-height: 1;
}

.tool-label {
  font-size: 0.65rem;
  line-height: 1;
  color: #cbd5e1;
}

.tool-shortcut {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  padding: 1px 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.35);
  font-size: 0.62rem;
  color: #cbd5e1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border: 1px solid #444b58;
  border-radius: 10px;
  background: linear-gradient(180deg, #343a46 0%, #272c35 100%);
  color: #e5e7eb;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  user-select: none;
}

.checkbox-button:hover {
  background: linear-gradient(180deg, #3b4250 0%, #2d333d 100%);
  border-color: #5d6677;
}

.checkbox-button input[type="checkbox"] {
  display: none;
}

.checkbox-button input[type="checkbox"]:checked + .checkbox-icon {
  color: #60a5fa;
}

.checkbox-icon {
  font-size: 1rem;
  line-height: 1;
  transition: color 0.12s ease;
}

.checkbox-label {
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}

.action-buttons {
  display: flex;
  gap: 6px;
}

.action-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid #444b58;
  border-radius: 10px;
  background: linear-gradient(180deg, #343a46 0%, #272c35 100%);
  color: #e5e7eb;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.action-button:hover {
  transform: translateY(-1px);
  border-color: #5d6677;
  background: linear-gradient(180deg, #3b4250 0%, #2d333d 100%);
}

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

.action-button:disabled:hover {
  transform: none;
  border-color: #444b58;
  background: linear-gradient(180deg, #343a46 0%, #272c35 100%);
}

.action-icon {
  font-size: 1rem;
  line-height: 1;
}

.action-label {
  font-size: 0.68rem;
  line-height: 1;
  color: #cbd5e1;
  white-space: nowrap;
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.88rem;
  color: #d1d5db;
}

.field input,
.field select,
.actions button {
  font: inherit;
}

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #4b5563;
  border-radius: 10px;
  background: #14181e;
  color: #f9fafb;
}

.field input:disabled {
  background: #11151a;
  color: #6b7280;
}

.field input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 3px;
  border: 1px solid #4b5563;
  border-radius: 10px;
  background: #14181e;
}

.field input[type="range"] {
  width: 100%;
  accent-color: #60a5fa;
}

.preset-palette {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.swatch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--swatch);
  color: #e5e7eb;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  overflow: visible;
}

.swatch:hover {
  transform: scale(1.1);
  border-color: #60a5fa;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.swatch-chip {
  display: none;
}

.swatch-meta {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  gap: 3px;
  min-width: max-content;
  padding: 10px 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, #2a2f38 0%, #20242b 100%);
  border: 1px solid #60a5fa;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 20;
}

.swatch-meta::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #60a5fa;
}

.swatch:hover .swatch-meta {
  display: flex;
}

.swatch-name {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  color: #f3f4f6;
}

.swatch-code {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.3;
  white-space: nowrap;
}

.swatch.active {
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.5);
}

.swatch.active:hover {
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.5), 0 4px 16px rgba(0, 0, 0, 0.5);
}

.actions {
  display: grid;
  gap: 9px;
}

.actions button {
  border: 1px solid #48505e;
  border-radius: 10px;
  padding: 11px 13px;
  background: linear-gradient(180deg, #343a46 0%, #272c35 100%);
  color: #f3f4f6;
  cursor: pointer;
}

.actions button:hover {
  background: linear-gradient(180deg, #3d4452 0%, #2d333d 100%);
}

.actions button:disabled {
  background: #3a3f48;
  border-color: #3a3f48;
  color: #9ca3af;
  cursor: not-allowed;
}

.hint {
  margin: auto 0 0;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid #373d49;
  background: rgba(42, 47, 56, 0.9);
  color: #cbd5e1;
  line-height: 1.7;
  font-size: 0.88rem;
}

.stage {
  min-width: 0;
  min-height: calc(100vh - 96px);
  padding: 24px;
  overflow: auto;
}

.canvas-viewport {
  position: relative;
  width: max(1600px, calc(100vw - 420px));
  height: max(1200px, calc(100vh - 144px));
  transform-origin: top left;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
  border: 1px solid #4b5563;
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  cursor: crosshair;
}

canvas.grid-background {
  background:
    linear-gradient(45deg, #f9fafb 25%, #eef2f7 25%, #eef2f7 50%, #f9fafb 50%, #f9fafb 75%, #eef2f7 75%, #eef2f7 100%);
  background-size: 20px 20px;
}

.canvas-text-editor {
  position: absolute;
  display: none;
  min-width: 120px;
  padding: 0;
  border: 1px solid #60a5fa;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  color: #111827;
  font: 24px/1 sans-serif;
  resize: none;
  overflow: hidden;
  outline: none;
  white-space: pre;
  z-index: 5;
  box-sizing: border-box;
  line-height: 1;
}

body.select-mode canvas {
  cursor: default;
}
