:root{--bg:#0b0e14;--panel:#131722;--border:#21293a;--text:#e6edf3;--muted:#9aa5b1;--accent:#4cc3ff}
*{box-sizing:border-box}html,body{height:100%}body{margin:0;background:linear-gradient(180deg,#0f1320,#0b0e14);color:var(--text);font:14px/1.4 system-ui,-apple-system,Segoe UI,Roboto;overflow-x:hidden}
.app-header{padding:12px 16px}.subtitle{color:var(--muted)}
.app-layout{display:grid;grid-template-columns:520px 1fr;gap:28px;padding:0 16px 24px;align-items:start}
.controls{background:var(--panel);border:1px solid var(--border);border-radius:10px;padding:12px;position:static;max-height:none;overflow-x:hidden;overflow-y:visible;max-width:100%}
fieldset{border:1px solid var(--border);border-radius:8px;padding:10px;margin:0 0 10px}legend{color:var(--muted)}
.field{display:grid;grid-template-columns:120px 1fr 50px;gap:8px;align-items:center;margin-bottom:12px}
.field .readout{color:var(--text);text-align:right;min-width:55px;font-weight:600;font-size:14px;order:3}
/* Editable readout inputs */
.field input.readout{
  background:var(--bg);
  border:1px solid transparent;
  border-radius:4px;
  padding:2px 4px;
  width:55px;
  box-sizing:border-box;
  transition:border-color 0.2s;
}
.field input.readout:hover{border-color:var(--border)}
.field input.readout:focus{border-color:var(--primary);outline:none}
.field input[type=range]{order:2}
/* For range fields that get readouts added dynamically */
.field.range-field{display:grid;grid-template-columns:120px 60px 1fr;gap:8px;align-items:center}
.field.range-field .readout{order:2}
.field.range-field input[type=range]{order:3}
/* Override for fields without range inputs */
.field:not(:has(.readout)):not(.range-field){grid-template-columns:120px 1fr;gap:12px}
/* Tighten label-select pairing for Edge style */
.edge-style-field{grid-template-columns:120px 220px}
#edgeStyle{width:220px}
label{font-weight:600}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:8px}
/* Allow long inputs to wrap within grid to avoid overflow */
.grid2 > div{min-width:0}
.field input[type=number], .field select{min-width:0}
/* Hide numeric mirrors that pair with range sliders */
input#frameSize,
input#frameWidth,
input#frameHeight,
input#ovalWidth,
input#ovalHeight,
input#circleSize,
input#polygonSides,
input#frameThickness{display:none}

/* Palette alignment: two neat columns with tight chips */
.color-inline{grid-template-columns:120px 60px}
.color-inline label{margin-right:8px}
.color-inline input[type=color]{margin-left:0}

/* Colors section alignment */
#form fieldset:nth-of-type(4) .field{grid-template-columns:120px 60px}
input[type=color],input[type=number],select{background:#0e1320;color:var(--text);border:1px solid var(--border);border-radius:6px;padding:6px 8px;width:100%}

/* Range slider styling - 50% larger */
input[type=range]{
  -webkit-appearance:none;
  appearance:none;
  background:var(--border); /* Fallback background for visibility */
  border-radius:3px;
  cursor:pointer;
  width:100%;
  min-width:120px; /* Ensure minimum visibility */
  height:24px; /* 50% larger than default ~16px */
}

/* Range slider track */
input[type=range]::-webkit-slider-track{
  background:var(--border);
  height:6px; /* 50% larger than default ~4px */
  border-radius:3px;
  border:none;
}

input[type=range]::-moz-range-track{
  background:var(--border);
  height:6px;
  border-radius:3px;
  border:none;
}

/* Firefox specific fixes */
input[type=range]::-moz-range-progress{
  background:var(--accent);
  height:6px;
  border-radius:3px;
}

input[type=range]::-moz-focus-outer{
  border:0;
}

/* Range slider thumb */
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  height:18px; /* 50% larger than default ~12px */
  width:18px;
  border-radius:50%;
  background:var(--accent);
  cursor:pointer;
  border:2px solid var(--panel);
  box-shadow:0 2px 4px rgba(0,0,0,0.3);
  margin-top:-6px; /* Center on track */
}

input[type=range]::-moz-range-thumb{
  height:18px;
  width:18px;
  border-radius:50%;
  background:var(--accent);
  cursor:pointer;
  border:2px solid var(--panel);
  box-shadow:0 2px 4px rgba(0,0,0,0.3);
  -webkit-appearance:none;
  appearance:none;
}

/* Focus states */
input[type=range]:focus{
  outline:none;
}

input[type=range]:focus::-webkit-slider-thumb{
  box-shadow:0 0 0 3px rgba(76,195,255,0.3);
}

input[type=range]:focus::-moz-range-thumb{
  box-shadow:0 0 0 3px rgba(76,195,255,0.3);
}
.controls input[type=color]{
  width:40px!important;
  height:28px;
  padding:0;
  background:transparent;
  border:2px solid var(--border);
  border-radius:6px;
  cursor:pointer;
}
.controls .grid2 .field{align-items:center}
.actions{display:flex;gap:8px;flex-wrap:wrap}
.stage-wrap{position:sticky;top:10px;display:flex;flex-direction:column;gap:8px;align-self:start;z-index:1}
#previewContainer{position:relative;align-self:start;display:flex;justify-content:center;align-items:center;padding:16px;width:min(32vw,520px);aspect-ratio:1/1;overflow:hidden;border-radius:10px}
#zoomWrap{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);transform-origin:center center;will-change:transform}
#preview{display:block}
.checker{--a:#dfe2e6;--b:#f3f5f7;background-image:linear-gradient(45deg,var(--a) 25%,transparent 25%),linear-gradient(-45deg,var(--a) 25%,transparent 25%),linear-gradient(45deg,transparent 75%,var(--a) 75%),linear-gradient(-45deg,transparent 75%,var(--a) 75%);background-size:24px 24px;background-position:0 0,0 12px,12px -12px,-12px 0;background-color:var(--b)}
#svg{display:block;width:100%;height:100%}
.hint{position:absolute;right:8px;bottom:8px;background:#0008;color:#fff;padding:4px 6px;border-radius:6px;font-size:12px}

.stage-toolbar{display:flex;flex-direction:column;gap:6px;background:var(--panel);border:1px solid var(--border);border-radius:8px;padding:8px;position:static;width:min(32vw,520px);align-self:start}
.stage-toolbar .field{display:flex;gap:8px;align-items:center;margin-bottom:4px}
.zoom-readout{margin-left:auto;color:var(--muted)}
.stage-toolbar .toolbar-row button{background:#0e1320;color:var(--text);border:1px solid var(--border);border-radius:6px;padding:6px 10px;cursor:pointer}
.stage-toolbar .toolbar-row button:hover{border-color:var(--accent)}
.stage-toolbar .toolbar-row{display:flex;gap:8px;align-items:center}
.stage-toolbar .toolbar-row .zoom-readout{order:2;margin-left:8px}
.stage-toolbar .toolbar-row #resetViewBtn{order:1}
.stage-toolbar input[type=number]{width:80px}

/* Stage toolbar background color control */
.toolbar-row .bg-picker{margin:0;display:flex;align-items:center;gap:8px}
.toolbar-row .bg-picker input[type=color]{
  margin-left:6px;
  width:32px;
  height:28px;
  padding:0;
  border-radius:4px; /* square-ish */
  -webkit-appearance: none;
  appearance: none;
}
.toolbar-row .bg-picker .bg-transp-label{font-size:12px;margin-right:6px}
/* Remove unused swatch (we now use native color input as the chip next to label) */
.toolbar-sep{width:1px;height:18px;background:var(--border);display:inline-block;margin:0 6px}
.toolbar-row .bg-picker label{font-weight:600}

/* Screen reader only class for accessibility */
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}

/* Memory warning styles */
.memory-warning{
  margin-top:5px;
  padding:8px;
  border-radius:4px;
  font-size:11px;
  font-weight:600;
}
.memory-warning.warn{
  background:#ffa50020;
  color:#ff8c00;
  border:1px solid #ff8c0040;
}
.memory-warning.error{
  background:#ff000020;
  color:#ff4444;
  border:1px solid #ff444440;
}

/* Responsive layout */
@media (max-width: 1100px){
  .app-layout{grid-template-columns:1fr}
  #previewContainer{position:static;width:100%}
  .controls{position:static;max-height:none}
}
