:root {
  --bg: #0e0f13;
  --panel: #16181f;
  --panel-2: #1d2029;
  --line: #2a2e3a;
  --text: #e7e9ee;
  --muted: #8b90a0;
  --accent: #6366f1;
  --accent-hover: #7c7ff5;
  --danger: #ef4444;
  --canvas-bg: #2a2e3a;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .3px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-size: 15px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: #262a36; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { filter: brightness(1.08); }
.btn.danger:disabled { background: var(--panel-2); border-color: var(--line); color: var(--muted); cursor: not-allowed; filter: none; }
.btn.block { width: 100%; }
.btn.tiny { padding: 4px 8px; font-size: 14px; line-height: 1; }

/* Workspace layout */
.workspace { flex: 1 1 auto; display: flex; min-height: 0; }

/* Toolbar */
.toolbar {
  width: 60px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 0;
  flex: 0 0 auto;
}
.tool {
  position: relative;
  width: 42px;
  height: 42px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .12s, color .12s, border-color .12s;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.tool:hover { color: var(--text); background: var(--panel-2); }
.tool.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.tool kbd {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 8.5px;
  font-family: var(--font);
  color: var(--muted);
  background: transparent;
}
.tool.active kbd { color: rgba(255,255,255,.7); }

/* Canvas */
.canvas-area {
  flex: 1 1 auto;
  position: relative;
  display: grid;
  place-items: center;
  background:
    repeating-conic-gradient(var(--canvas-bg) 0% 25%, #313643 0% 50%) 0 0 / 24px 24px;
  overflow: auto;
  min-width: 0;
}
#canvas {
  /* Concrete size is set by fitCanvas() in app.js so the element box always
     matches the 900:640 viewBox ratio (no letterboxing, WYSIWYG export). */
  width: 720px;
  height: 512px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
  border-radius: 2px;
  background: #fff;
  touch-action: none;
  flex: 0 0 auto;
}
#canvas.tool-pen,
#canvas.tool-rect,
#canvas.tool-ellipse { cursor: crosshair; }
#canvas.tool-select { cursor: default; }

.hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  white-space: nowrap;
}
.hint.show { opacity: 1; }

/* Properties panel */
.panel {
  width: 248px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 0 0 auto;
  overflow-y: auto;
}
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.color-row { display: flex; align-items: center; gap: 8px; }

input[type="color"] {
  width: 38px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }

.hex {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
}
.hex:focus { outline: none; border-color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--line);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--line);
}

.divider { height: 1px; background: var(--line); }

.panel-foot { margin-top: auto; }
#selection-info { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Overlay selection chrome */
.sel-outline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.pen-preview { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.pen-anchor { fill: #fff; stroke: var(--accent); stroke-width: 1.5; }
.pen-anchor.first { fill: var(--accent); }
