:root {
  --bg: #1f1f1f;
  --panel: #2a2a2a;
  --text: #e6e6e6;
  --muted: #9aa0a6;
  --accent: #4dabf7;
  --btn: #3a3a3a;
  --btn-hover: #4a4a4a;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

/* Prevent accidental selection/callout on iOS during long-press near canvas */
* { -webkit-tap-highlight-color: transparent; }
html, body, .workspace, .canvas-wrap, canvas, .menubar, .menu, .menu-panel {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Allow selection where it’s appropriate (forms/inputs) */
input, textarea, select, .input, [contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: rgb(15, 48, 15);
  font: 14px/1.35 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
}

.brand {
  margin-right: 8px;
  display: flex;
  align-items: center;
  color: var(--accent);
}

.brand-icon {
  display: block;
  width: 24px;
  height: 24px;
}

.brand-icon:hover {
  filter: drop-shadow(0 0 6px rgba(77, 171, 247, 0.35));
}

.toolbar {
  display: none;
}

.divider {
  width: 1px;
  height: 28px;
  background: #000;
  margin: 0 2px;
}

.group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.btn {
  appearance: none;
  border: 1px solid #000;
  background: var(--btn);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation; /* prevent double-tap zoom on mobile */
}

.icon-btn {
  appearance: none;
  border: 1px solid #000;
  background: var(--btn);
  color: var(--text);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation; /* prevent double-tap zoom */
}

.quick-zoom .btn.small {
  width: 28px;
  height: 24px;
  line-height: 1;
  padding: 0;
  touch-action: manipulation; /* prevent double-tap zoom */
}

.btn:hover {
  background: var(--btn-hover);
}

.btn[aria-pressed="true"] {
  outline: 2px solid var(--accent);
}

.input {
  background: #1a1a1a;
  color: var(--text);
  border: 1px solid #000;
  border-radius: 6px;
  padding: 6px 8px;
}

.input.number {
  width: 80px;
}

.input.range {
  width: 100px;
}

.input.color {
  padding: 0;
  width: 36px;
  height: 32px;
}

.slider {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.slider span {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
    position: fixed;
    top: 100px; /* space for menubar/action bar */
    left: 0;
    right: 0;
    bottom: 0; /* anchor to bottom to fill screen */
    height: calc(100vh - 100px);
    display: grid;
    place-items: center;
    overflow: auto; /* if canvas is larger, allow scroll */
    /* padding: 12px; */
    border-width: medium;
    border-color: #585868;
    border-style: dashed;
}

.canvas-wrap {
  background: #111;
  border: 1px solid #000;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100vw;
  max-height: calc(100vh - 90px);
}

canvas {
  display: block;
  width: min(95vw, 1024px);
  height: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.status-wrap {
  position: fixed;
  left: 12px; /* move to left side */
  right: auto;
  bottom: 18px; /* moved up a bit to avoid edge overlap */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  z-index: 15;
}

.status-bar {
  position: static;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  pointer-events: auto; /* enable clicks for interactive parts */
}

.quick-zoom {
  display: inline-flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 4px 6px;
}

.quick-zoom .btn.small {
  width: 28px;
  height: 24px;
  line-height: 1;
  padding: 0;
  touch-action: manipulation; /* avoid double-tap zoom */
}

/* Action bar select-mode icon toggle */
.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

.action-item.select-toggle {
  padding: 0;
  width: 32px; height: 32px;
  border: 1px solid #000;
  background: var(--btn);
  border-radius: 6px;
  justify-content: center;
}
.action-item.select-toggle:hover { background: var(--btn-hover); }
.action-item.select-toggle input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
  pointer-events: none;
}
.action-item.select-toggle .select-icon { color: var(--text); }
.action-item.select-toggle.active {
  background: #90EE90; /* light green when active */
  border-color: #5ea65e;
}
.action-item.select-toggle.active:hover { background: #98f098; }
.action-item.select-toggle.active .select-icon { color: #0b3d0b; }
.action-item.select-toggle input:checked + .select-icon {
  color: var(--accent);
  filter: drop-shadow(0 0 4px rgba(77,171,247,0.35));
}

/* Normalize lucide icon sizes */
.icon-btn svg,
.action-item.select-toggle .select-icon {
  width: 18px;
  height: 18px;
}

@media (min-width: 900px) {
  .input.range {
    width: 140px;
  }

  canvas {
    width: min(90vw, 1280px);
  }
}

/* Menubar */
.menubar {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap; /* keep all top-level menus on one line */
  overflow-x: auto;  /* allow horizontal scroll if too narrow */
  white-space: nowrap;
}

.menu { flex: 0 0 auto; }

.menu {
  position: relative;
}

.menu>summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  transition: background 120ms ease;
}

.menu>summary::-webkit-details-marker {
  display: none;
}

.menu>summary:hover {
  background: rgba(255, 255, 255, 0.06);
}

.menu>summary:focus-visible {
  outline: none;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.menu[open]>summary {
  background: rgba(255, 255, 255, 0.10);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.menu-panel {
    z-index: 100;
    background-color: black;
    position: fixed;
    top: auto;
    left: 0;
    min-width: 240px;
    max-width: 360px;
    /* background: var(--panel); */
    color: var(--text);
    border: none;
    border-radius: 10px;
    padding: 8px;
    /* box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38), 0 2px 6px rgba(0, 0, 0, 0.2); */
}

/* Horizontal variant for compact menus */
.menu-panel.horizontal {
  /* display: flex; */
  /* flex-wrap: wrap; */
  align-items: center;
  gap: 8px;
  min-width: unset;
  max-width: min(95vw, 1000px);
  white-space: wrap;
  padding: 8px 10px;
}

.menu-panel.horizontal .menu-item {
  padding: 6px 10px;
}

.menu-panel.horizontal hr {
  display: none;
}

.menu-panel.horizontal .menu-hint {
  flex-basis: 100%;
  white-space: normal;
  opacity: 0.85;
}

.menu-item {
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: inline-block;
}

/* In horizontal panels, items should size to content */
.menu-panel.horizontal .menu-item {
  width: auto;
}

.menu-item:hover {
  background: var(--btn-hover);
}

.menu-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}

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

/* Keep checkbox label text on a single line and not constrained */
.menu-row label.menu-check,
.menu-row .menu-item.menu-check {
  width: auto;
  color: var(--text);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  padding: 0 6px;
}

.menu-section {
  border-top: 1px solid #000;
  margin-top: 6px;
  padding-top: 6px;
}

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

.menu-hint {
  margin-top: 6px;
}

.btn.small {
  padding: 4px 8px;
}

/* Text menu helpers */
.menu-text-input { min-width: 180px; }
.menu-row .menu-text-input { flex: 1; }
.menu-check { padding: 0 6px; }

/* Small value badge for inline sliders */
.size-value {
  display: inline-block;
  min-width: 32px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}

/* Size popover */
.size-popover {
  position: fixed;
  right: 12px;
  bottom: 64px;
  min-width: 260px;
  max-width: 320px;
  background: rgba(0,0,0,0.9);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 8px;
  z-index: 25;
}
.size-popover__title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.size-popover__row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}
.size-popover__row.presets { flex-wrap: wrap; }
.size-popover__row.presets .btn.small { padding: 2px 6px; }
.size-popover__error { color: #ffb3b3; font-size: 12px; min-height: 16px; }

/* Top-right select mode control */
.top-right-controls {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 20;
}
.top-right-controls .btn.small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.top-right-controls input[type="checkbox"] {
  margin: 0;
}



.action-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 10px 8px;
  background: var(--panel);
  border-top: 1px solid rgba(255,255,255,0.06);
  position: fixed;
  top: 50px;
  left: 0;
}