: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}.app-header.compact{padding:8px 16px}.app-header.compact h1{margin:0 0 4px;font-size:1.4em}.app-header.compact .subtitle{margin:0;font-size:0.9em}.subtitle{color:var(--muted)}
.app-layout{display:grid;grid-template-columns:560px 1fr;gap:24px;padding:0 12px 16px;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 in the Grid section */
input#columns,
input#rows,
input#cellSize,
input#cellWidth,
input#cellHeight,
input#circleCellSize,
input#circleDiameter,
input#gridThickness{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}
#circleColors .field{grid-template-columns:180px 1fr}
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}
.keyboard-shortcuts{background:var(--panel);border:1px solid var(--border);border-radius:6px;padding:8px 12px;font-size:12px;color:var(--muted);text-align:center;margin:0 auto;max-width:fit-content}
.keyboard-shortcuts strong{color:var(--text)}
.keyboard-shortcuts span{color:var(--text);font-weight:500}
#previewContainer{position:relative;align-self:start;display:flex;justify-content:center;align-items:center;padding:16px;width:min(58vw,920px);min-height:60vh;overflow:hidden;border-radius:10px;cursor:grab}
#zoomWrap{position:absolute;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}

/* Modular cell selection styles */
.cell-interactive{cursor:pointer;transition:all 0.2s ease}
.cell-interactive:hover{stroke:#4cc3ff;stroke-width:3px;stroke-opacity:0.9}
.cell-selected{stroke:#4cc3ff;stroke-width:4px}
.cell-unselected{opacity:0.7}
.cell-add-zone{cursor:pointer}
.cell-add-zone:hover rect{fill:#e8e8e8 !important; opacity:0.8 !important}

/* Cell control styling */
.inline-btn{background:#0e1320;color:var(--text);border:1px solid var(--border);border-radius:4px;padding:2px 8px;cursor:pointer;font-size:12px}
.inline-btn:hover{background:var(--accent);color:#000}

.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(34vw,540px);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}

/* Frame style parameter groups default hidden; toggled by JS */
#curvedParams, #chamferParams, #elongatedParams, #artdecoParams, #toriiParams, #asiantoriiParams, #romanParams, #studdedParams, #vanityParams, #styleFrameThControls{display:none}


/* 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}
}

/* Column-based system styles */
.column-control {
  margin-bottom: 6px;
}

.column-control .field {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.column-control label {
  min-width: 120px;
  font-size: 13px;
  color: var(--text);
}

.column-control .readout {
  width: 45px;
  padding: 2px 6px;
  font-size: 12px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
}

.column-control input[type="range"] {
  flex: 1;
  margin: 0 8px;
}

.remove-column {
  background: var(--danger, #e53e3e);
  color: white;
  border: none;
  border-radius: 3px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  min-width: auto;
  flex-shrink: 0;
}

.remove-column:hover {
  background: var(--danger-hover, #c53030);
}

.column-cell {
  cursor: pointer;
}

.column-cell:hover {
  opacity: 0.8;
}

.column-cell.selected, .section-cell.selected {
  stroke: #4cc3ff !important;
  stroke-width: 4px !important;
}

.attached-section {
  margin-bottom: 8px;
  padding: 10px;
  background: var(--bg-secondary, rgba(255,255,255,0.05));
  border-radius: 6px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent, #4cc3ff);
}

.attached-section .field {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.attached-section label {
  min-width: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.section-columns, .section-rows {
  width: 50px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
}

.section-columns:focus, .section-rows:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.remove-section {
  background: var(--danger, #e53e3e);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  margin-left: auto;
}

.remove-section:hover {
  background: var(--danger-hover, #c53030);
}

/* Section attachment buttons */
#add-top-section, #add-bottom-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  margin-right: 8px;
}

#add-top-section:hover, #add-bottom-section:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
}

.section-buttons {
  flex-direction: column;
  align-items: flex-start !important;
  gap: 6px !important;
}

.section-buttons label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.button-group {
  display: flex;
  gap: 8px;
}

.button-group button {
  margin-right: 0 !important;
}

.section-cell {
  cursor: pointer;
}

.section-cell:hover {
  opacity: 0.9;
}

.top-section {
  fill: #e6f3ff;
}

.bottom-section {
  fill: #fff0e6;
}

