/* X-DRAW — chrome styled to match X-GLYPHS / Layout Studio (Linear/Figma dark) */
:root,
[data-ls-theme="original"] {
  color-scheme: dark;
  --bg: #0B0D0F;
  --panel: #111318;
  --panel-2: #171A20;
  --card: #171A20;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.10);
  --text: #FFFFFF;
  --text-dim: rgba(255, 255, 255, 0.65);
  --text-muted: rgba(255, 255, 255, 0.42);
  --hover: rgba(255, 255, 255, 0.05);
  --header-bg: rgba(11, 13, 15, 0.82);
  --paper: #f6f5f2;
  --accent: #FFFFFF;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  letter-spacing: -0.01em;
  -webkit-user-select: none;
  user-select: none;
}

.xd-app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Custom scrollbars — thin, no arrows (match Layout Studio) */
.xd-app *::-webkit-scrollbar { width: 6px; height: 6px; }
.xd-app *::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 999px; }

/* ============================ Header ============================ */
.xd-header {
  flex: 0 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px 0 14px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 90;
}

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

.xd-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.xd-brand__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: #fff;
  color: #000;
}

.xd-brand__name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
}

.xd-brand__beta {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--hover);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.xd-brand__sub {
  padding-left: 12px;
  border-left: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0;
}

.xd-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.xd-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--hover);
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.xd-btn:hover { color: var(--text); background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.16); }
.xd-btn svg { opacity: .9; }

.xd-btn--primary {
  background: #fff;
  color: #000;
  border-color: #fff;
}
.xd-btn--primary:hover { background: #e5e5e5; color: #000; border-color: #e5e5e5; }

/* ======================= Options / context bar ======================= */
.xd-options {
  flex: 0 0 auto;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: rgba(17, 19, 24, 0.72);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.xd-options::-webkit-scrollbar { height: 0; }

/* Keep every control reachable on narrow windows — nothing collapses. */
.xd-field,
.xd-options__sep,
.xd-select,
.xd-chip,
.xd-actions { flex: 0 0 auto; }
.xd-options__spacer { flex: 1 1 auto; min-width: 8px; }

.xd-field {
  display: flex;
  align-items: center;
  gap: 9px;
}

.xd-field > label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.xd-field input[type="range"] {
  width: 108px;
  height: 3px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.xd-field input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--panel-2);
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  cursor: pointer;
}

.xd-field__val {
  min-width: 24px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.xd-options__sep {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.xd-options__spacer { flex: 1; }

.xd-select {
  height: 30px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font: inherit;
  font-size: 12.5px;
  padding: 0 8px;
  cursor: pointer;
  outline: none;
}
.xd-select:hover { border-color: rgba(255,255,255,.18); }

.xd-chip {
  height: 30px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--hover);
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.xd-chip:hover { color: var(--text); background: rgba(255,255,255,.09); }
.xd-chip.is-active { background: #fff; color: #000; border-color: #fff; }

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

.xd-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.xd-iconbtn:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.xd-iconbtn:disabled { opacity: .3; cursor: default; }

/* ==================== Shell: toolrail + workspace ==================== */
.xd-shell {
  flex: 1;
  min-height: 0;
  display: flex;
}

.xd-toolrail {
  flex: 0 0 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.xd-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
}

.xd-tool svg { width: 22px; height: 22px; }
.xd-tool:hover { color: var(--text); background: var(--hover); }
.xd-tool.is-active { background: #fff; color: #000; }

.xd-toolrail__sep {
  width: 26px;
  height: 1px;
  margin: 4px 0;
  background: var(--border);
}

/* ============================ Inspector (left) ============================ */
.xd-inspector {
  flex: 0 0 188px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 16px 14px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.xd-inspector__title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.xd-vfield { display: flex; flex-direction: column; gap: 9px; }

.xd-vfield__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.xd-vfield__head label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
}

.xd-vfield input[type="range"] {
  width: 100%;
  height: 3px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.xd-vfield input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  cursor: pointer;
}

/* ============================ Stage ============================ */
.stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;   /* we handle pan / pinch-zoom ourselves */
  background:
    radial-gradient(120% 120% at 50% 0%, #171A20 0%, #0B0D0F 60%);
}

.stage.panning { cursor: grabbing; }
.stage.pan-ready { cursor: grab; }
.stage.pan-ready #drawCanvas,
.stage.panning #drawCanvas { cursor: inherit; }

.canvas-wrap {
  position: absolute;
  left: 20px;
  top: 20px;
  transform-origin: 0 0;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,.55);
  overflow: hidden;
}

#gridCanvas {
  display: block;
  background: var(--paper);
}

#drawCanvas {
  position: absolute;
  inset: 0;
  background: transparent;
  cursor: crosshair;
  touch-action: none;
}

/* ================= Main column: preview above the worksheet ================= */
.xd-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ============================ Preview panel (top) ============================ */
.preview-panel {
  flex: 0 0 auto;
  position: relative;
  height: 128px;
  min-height: 72px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px 20px 10px;   /* 20px sides align the canvas with the worksheet */
}

.preview-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 20px;
  margin-bottom: 6px;
}

.preview-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-muted);
}

.preview-size {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-size label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.preview-size input[type="range"] {
  width: 120px;
  height: 3px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.preview-size input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  cursor: pointer;
}

#previewCanvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  background: var(--paper);
  border-radius: 4px;
}

.preview-grip {
  position: absolute;
  bottom: -5px;
  left: 0;
  right: 0;
  height: 10px;
  cursor: ns-resize;
  z-index: 5;
}

.preview-grip::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 3px;
  border-radius: 2px;
  background: var(--border-strong);
  transition: background .12s;
}

.preview-grip:hover::after,
.preview-grip.dragging::after { background: rgba(255,255,255,.4); }

/* ============================ Overlays ============================ */
.hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  background: rgba(11,13,15,.85);
  border: 1px solid var(--border-strong);
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity .6s;
  z-index: 4;
}

.hint.fade { opacity: 0; }

.zoom-badge {
  position: absolute;
  right: 14px;
  bottom: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: rgba(11,13,15,.85);
  border: 1px solid var(--border-strong);
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 4;
}
