:root {
  --bg: #0b1020;
  --bg-panel: #141a2b;
  --bg-panel-soft: #1a2238;
  --accent: #3b82f6;
  --accent-soft: rgba(59,130,246,0.15);
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --border: #1f2937;
  --error: #f97373;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #111827 0, #020617 55%);
  color: var(--text);
  display: flex; /* FLEX LAYOUT FOR COLUMNS */
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* SHARED STYLE FOR COL 1 AND COL 2 */
.sidebar-base {
  width: 380px; /* Fixed matching width */
  min-width: 380px;
  padding: 16px 14px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, #020617 0, #020617 35%, #030712 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto; /* Scroll independently */
}

/* COL 3 CONTAINER */
#previews-column {
  flex: 1; /* Take remaining space */
  display: flex;
  flex-direction: row; /* Side-by-side previews */
  padding: 12px 14px;
  gap: 12px;
  min-width: 0; /* Prevents flex overflow issues */
}

/* Make previews split the available space */
#preview-frame {
  flex: 1;
  /* Original styles below */
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #020617 0, #020617 40%, #000 100%);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 40px rgba(0,0,0,0.6);
  position: relative;
  overflow: hidden;
}

#png-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  /* Reusing .panel styles automatically, just added flex sizing */
}

/* --- ORIGINAL STYLING BELOW (Preserved) --- */

h1 {
  font-size: 18px;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

h1 span {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.subtitle {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 10px;
}

.panel {
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 8px 10px 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.panel-header h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
}

.panel-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
  font-size: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field-wide {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

label {
  font-size: 11px;
  color: var(--text-soft);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

label span.value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="number"],
select,
input[type="text"] {
  width: 100%;
  padding: 4px 6px;
  background: var(--bg-panel-soft);
  border: 1px solid #111827;
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
}

input[type="number"]:focus,
select:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

button {
  padding: 6px 10px;
  border-radius: 999px;
  border: none;
  background: radial-gradient(circle at 0 0, #4f46e5, #2563eb);
  color: white;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 10px 25px rgba(37,99,235,0.35);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

#preview {
  background: #020617;
  border-radius: 10px;
  border: 1px solid #111827;
}

.preview-badge {
  position: absolute;
}
/* --- MOBILE / RESPONSIVE OVERRIDES --- */

/* --- MOBILE RESPONSIVENESS (Max-width 950px) --- */
/* --- MOBILE LAYOUT: Fixed Bottom Preview --- */
/* --- MOBILE LAYOUT: Fixed Bottom Preview (Canvas Only) --- */
@media screen and (max-width: 950px) {

  /* 1. LAYOUT: Scrollable Body with space for footer */
  body {
    display: block !important;    /* Switch off Desktop Flexbox */
    height: auto !important;
    overflow-y: auto !important;  /* Enable scrolling */
    overflow-x: hidden !important;
    padding-bottom: 35vh !important; /* Leaves space for the fixed preview */
  }

  /* 2. CONTROLS: Full width, scrollable */
  .sidebar-base {
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    border: none !important;
    overflow: visible !important;
    padding-bottom: 20px !important;
  }
  
  #config-column { order: 1 !important; }
  #actions-column { order: 2 !important; }

  /* 3. FIXED PREVIEW FOOTER */
  #previews-column {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 35vh !important;     /* Takes up bottom 35% of screen */
    
    background: #020617 !important;
    border-top: 1px solid var(--accent) !important;
    z-index: 999 !important;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5) !important;
    
    display: flex !important;
    flex-direction: row !important;
    padding: 8px !important;
    overflow: hidden !important;
  }

  /* 4. HIDE PNG PREVIEW ON MOBILE */
  #png-frame {
    display: none !important; /* <--- This gives the canvas all the space */
  }

  #previews-column .panel-header, 
  #previews-column .preview-badge {
    display: none !important; 
  }

  /* 5. CANVAS FRAME (Full Width) */
  #preview-frame {
    width: 100% !important;
    height: 100% !important;
    flex: none !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  canvas#preview {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
  }

  /* 6. TOUCH TARGETS */
  input[type="range"] { height: 40px !important; }
  
  input[type="text"], 
  input[type="number"], 
  select {
    height: 44px !important;
    font-size: 16px !important;
  }

  button, .small-btn {
    min-height: 44px !important;
    padding: 0 16px !important;
  }
}

/* --- STEPPER CONTROLS (Mobile Friendly Numbers) --- */

/* Wrapper to hold Button - Input - Button */
.stepper-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}

/* The Input itself (modified to fit inside wrapper) */
.stepper-wrapper input[type="number"] {
  flex: 1;              /* Take remaining width */
  text-align: center;   /* Center the number */
  margin: 0;
  appearance: textfield; /* Remove native spinners (Firefox) */
  height: 44px !important; /* Ensure easy touch height */
}

/* Hide native Webkit spinners (Chrome/Safari) */
.stepper-wrapper input[type="number"]::-webkit-inner-spin-button,
.stepper-wrapper input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* The +/- Buttons */
.stepper-btn {
  width: 44px;         /* Nice big touch target */
  height: 44px;
  background: #1f2937;
  border: 1px solid #374151;
  color: #e5e7eb;
  border-radius: 5px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;   /* Prevent text selection while tapping fast */
  touch-action: manipulation; /* Optimise for touch */
}

.stepper-btn:active {
  background: #3b82f6; /* Accent color on press */
  color: white;
  border-color: #3b82f6;
}