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

:root {
  --bg0: #0d1117;
  --bg1: #161b22;
  --bg2: #21262d;
  --bg3: #30363d;
  --border: #30363d;
  --border-light: #484f58;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #484f58;
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --accent-dim: #1a1040;
  --red: #f87171;
  --green: #3fb950;
  --yellow: #d29922;
  --header-h: 44px;
  --toolbar-w: 52px;
  --panel-w: 300px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background: var(--bg0);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 10px;
  gap: 8px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.btn-header {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-header:hover { background: var(--bg3); border-color: var(--border-light); }
.btn-header:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-header.btn-icon { padding: 4px 7px; }
.btn-header.btn-accent { background: var(--accent); border-color: transparent; color: white; }
.btn-header.btn-accent:hover { background: #7c3aed; }

/* ── Main layout ──────────────────────────────────────────── */
.main {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Left toolbar ─────────────────────────────────────────── */
.toolbar {
  width: var(--toolbar-w);
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  flex-shrink: 0;
  overflow: hidden;
}

.tool-section { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tool-sep { width: 28px; height: 1px; background: var(--border); margin: 4px 0; }
.toolbar-spacer { flex: 1; }

.tool {
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tool:hover { background: var(--bg3); color: var(--text); }
.tool.active { background: var(--accent-dim); color: var(--accent2); border-color: var(--accent); }
.tool-marker.active { border-color: var(--red); color: var(--red); background: #2d1515; }

.color-pickers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-top: 1px solid var(--border);
  width: 100%;
}

.color-swatch-group { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.color-label { font-size: 9px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.04em; }

.color-swatch-wrap { position: relative; width: 28px; height: 28px; }
.color-swatch-wrap input[type=color] {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: none;
}
.color-swatch-preview {
  width: 28px; height: 28px; border-radius: 6px;
  border: 2px solid var(--border-light);
  pointer-events: none;
}

.stroke-width-input {
  width: 36px; text-align: center;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 11px; padding: 2px 2px;
}
.stroke-width-input::-webkit-inner-spin-button { display: none; }

/* ── Canvas area ──────────────────────────────────────────── */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #111418;
}

.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: default;
  background-image:
    linear-gradient(45deg, #1a1d22 25%, transparent 25%),
    linear-gradient(-45deg, #1a1d22 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1d22 75%),
    linear-gradient(-45deg, transparent 75%, #1a1d22 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.canvas-viewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.canvas-viewport svg:first-child {
  display: block;
  box-shadow: 0 4px 32px rgba(0,0,0,0.6);
}

.canvas-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.canvas-hint.visible { opacity: 1; }
.hint-box {
  background: rgba(22,27,34,0.92);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 380px;
  text-align: center;
  backdrop-filter: blur(8px);
}
.hint-title { font-size: 16px; font-weight: 600; color: var(--accent2); margin-bottom: 10px; }
.hint-body { font-size: 13px; color: var(--text2); line-height: 1.6; }
kbd {
  background: var(--bg3); border: 1px solid var(--border-light);
  border-radius: 4px; padding: 1px 5px; font-size: 11px;
  font-family: monospace; color: var(--text);
}

/* ── Status bar ───────────────────────────────────────────── */
.statusbar {
  height: 26px;
  background: var(--bg1);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 0;
  font-size: 11px;
  color: var(--text2);
  flex-shrink: 0;
}
.st-item { padding: 0 6px; white-space: nowrap; }
.st-sep { color: var(--border-light); }
.st-spacer { flex: 1; }
.st-el { color: var(--accent2); }
.st-dim { color: var(--text3); }

/* ── Right panel ──────────────────────────────────────────── */
.panel-right {
  width: var(--panel-w);
  background: var(--bg1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.panel-block {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}

.ai-block { flex: 1; min-height: 0; }
.props-block { max-height: 280px; flex-shrink: 0; }

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

.panel-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.btn-tiny {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text2);
  font-size: 11px;
  padding: 2px 7px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn-tiny:hover { background: var(--bg3); border-color: var(--border); color: var(--text); }
.btn-tiny.btn-danger:hover { background: #2d1515; border-color: var(--red); color: var(--red); }

/* ── Chat ─────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-msg .msg-body {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.55;
  max-width: 100%;
  word-break: break-word;
}

.chat-msg.user { align-items: flex-end; }
.chat-msg.user .msg-body {
  background: var(--accent);
  color: white;
  border-radius: 8px 8px 2px 8px;
}

.chat-msg.assistant .msg-body {
  background: var(--bg2);
  color: var(--text);
  border-radius: 8px 8px 8px 2px;
  border: 1px solid var(--border);
}

.chat-msg.thinking .msg-body {
  color: var(--text2);
  font-style: italic;
}

.chat-msg.error .msg-body {
  background: #2d1515;
  border-color: var(--red);
  color: var(--red);
}

.chat-msg.success .msg-body {
  background: #0d2818;
  border-color: var(--green);
  color: var(--green);
}

.thinking-dots::after {
  content: '';
  animation: dots 1.2s steps(3, end) infinite;
}
@keyframes dots {
  0%   { content: '.'; }
  33%  { content: '..'; }
  66%  { content: '...'; }
  100% { content: ''; }
}

/* ── Markers bar ──────────────────────────────────────────── */
.markers-bar {
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  background: #1c1020;
  flex-shrink: 0;
}
.markers-bar-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.markers-bar-label { font-size: 10px; color: var(--text2); white-space: nowrap; }
.markers-chips { display: flex; flex-wrap: wrap; gap: 3px; flex: 1; }
.marker-chip {
  background: #2d1515;
  border: 1px solid #7f3d3d;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  color: #fca5a5;
  white-space: nowrap;
}

/* ── Chat input ───────────────────────────────────────────── */
.chat-input-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg2);
}

#chat-input {
  background: var(--bg0);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12.5px;
  font-family: inherit;
  resize: none;
  line-height: 1.45;
  transition: border-color 0.15s;
  width: 100%;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
#chat-input::placeholder { color: var(--text3); }

.btn-send {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s;
  align-self: flex-end;
}
.btn-send:hover { background: #7c3aed; }
.btn-send:disabled { background: var(--bg3); color: var(--text2); cursor: not-allowed; }

/* ── Properties panel ─────────────────────────────────────── */
#props-content {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
}

#props-content::-webkit-scrollbar { width: 4px; }
#props-content::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.props-empty {
  color: var(--text3);
  font-size: 11.5px;
  padding: 8px 0;
  font-style: italic;
}

.prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 7px;
}

.prop-label {
  font-size: 11px;
  color: var(--text2);
  white-space: nowrap;
  min-width: 55px;
}

.prop-val-text {
  font-size: 11px;
  color: var(--accent2);
  font-family: monospace;
}

.prop-color-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
}

.prop-color-input {
  width: 24px; height: 24px;
  border: none; border-radius: 4px;
  padding: 0; cursor: pointer;
  flex-shrink: 0;
}

.prop-text-input {
  flex: 1;
  background: var(--bg0);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  font-family: monospace;
}
.prop-text-input:focus { outline: none; border-color: var(--accent); }

.prop-number-input {
  width: 60px;
  background: var(--bg0);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  text-align: right;
}
.prop-number-input:focus { outline: none; border-color: var(--accent); }
.prop-number-input::-webkit-inner-spin-button { display: none; }

.prop-range-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.prop-range {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  outline: none;
}
.prop-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.prop-range-val {
  font-size: 11px;
  color: var(--text2);
  min-width: 30px;
  text-align: right;
}

.prop-divider { height: 1px; background: var(--border); margin: 8px 0; }

.btn-delete-el {
  width: 100%;
  background: #2d1515;
  color: var(--red);
  border: 1px solid #7f3d3d;
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.12s;
}
.btn-delete-el:hover { background: #3d1a1a; }

/* ── Selection overlay ────────────────────────────────────── */
.selection-overlay {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}

/* ── Collapsible AI panel (mobile only) ──────────────────── */
.btn-collapse { display: none; }
#btn-toggle-ai svg { transition: transform 0.2s ease; }
.ai-block.collapsed #btn-toggle-ai svg { transform: rotate(180deg); }

/* ── Touch support ────────────────────────────────────────── */
.canvas-container { touch-action: none; }

/* ── Mobile layout ────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --toolbar-w: 100%; --panel-w: 100%; }

  body { overflow: auto; }

  .main {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .toolbar {
    flex-direction: row;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 8px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .tool-section { flex-direction: row; }
  .tool-sep { width: 1px; height: 28px; margin: 0 4px; }
  .toolbar-spacer { display: none; }

  .color-pickers {
    flex-direction: row;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 4px 8px;
    margin-left: 4px;
    gap: 8px;
  }
  .color-swatch-group { flex-direction: row; align-items: center; gap: 4px; }

  .canvas-area { min-height: 45vh; }

  .panel-right {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 55vh;
    overflow-y: auto;
  }

  .btn-collapse { display: flex; align-items: center; justify-content: center; }

  .ai-block { min-height: 280px; }
  .ai-block.collapsed { min-height: 0; }
  .ai-block.collapsed .chat-messages,
  .ai-block.collapsed .markers-bar,
  .ai-block.collapsed .chat-input-area { display: none; }

  .panel-right.ai-collapsed { max-height: none; overflow: visible; }

  .chat-messages { max-height: 160px; }
  .props-block { display: none; }

  .statusbar { font-size: 10px; }
  .st-el, .st-dim { display: none; }
}
