
/* Basic Reset & Mobile-First Styling */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    line-height: 1.5; background-color: #222831; /* Darker slate blue */ color: #eeeeee;
    display: flex; flex-direction: column; min-height: 100vh;
}

/* Header */
header {
    background-color: #1a1f26; padding: 0.8rem 1rem; text-align: center;
    position: sticky; top: 0; z-index: 10; border-bottom: 1px solid #3a424d;
}
header h1 { font-size: 1.2rem; color: #00adb5; /* Teal accent */ }

/* Preview Area */
.preview-container {
    width: 100%; max-width: 500px; margin: 1rem auto; position: relative;
    background-color: #393E46; /* Mid-grey */ aspect-ratio: 16 / 9; display: flex;
    align-items: center; justify-content: center; overflow: hidden; border-radius: 8px;
}
.preview-container img {
    display: block; max-width: 100%; max-height: 100%; object-fit: contain; background-color: var(--preview-bg, #393E46); /* Use CSS var for dynamic BG */
}
.preview-container .spinner {
    border: 4px solid rgba(238, 238, 238, 0.3); border-radius: 50%;
    border-top: 4px solid #00adb5; width: 40px; height: 40px;
    animation: spin 1s linear infinite; position: absolute; display: none;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }


/* Form & Controls Area */
main { padding: 0 1rem 6rem; flex-grow: 1; }
#imgForm {
    display: flex; flex-direction: column; gap: 1.5rem;
    max-width: 500px; margin: 0 auto;
}

/* --- Element Selector --- */
.element-selector-section {
    background-color: #1a1f26; /* Darker contrast */
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 1rem; /* Space below selector */
}
.element-selector-header {
     display: flex;
     justify-content: space-between;
     align-items: center;
     margin-bottom: 0.75rem;
}
 .element-selector-header label {
     margin: 0; /* Remove default label margin */
     font-weight: 600;
     color: #aaa; /* Lighter label */
     font-size: 0.9rem;
 }
#add-element-button {
    background-color: #00adb5; color: #fff; border: none; border-radius: 50%;
    width: 30px; height: 30px; font-size: 1.5rem; line-height: 30px;
    cursor: pointer; text-align: center; font-weight: bold;
    transition: background-color 0.2s ease;
}
#add-element-button:hover { background-color: #007f86; }

.element-selector-container {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto; /* Allow horizontal scroll */
    padding-bottom: 0.5rem; /* Space for scrollbar if needed */
     -ms-overflow-style: none;  /* IE and Edge */
     scrollbar-width: none;  /* Firefox */
}
 .element-selector-container::-webkit-scrollbar { display: none; /* Chrome, Safari, Opera */ }

.element-pill {
    display: flex;
    align-items: center;
    background-color: #393E46; /* Pill background */
    color: #eeeeee;
    padding: 0.4rem 0.8rem;
    border-radius: 15px; /* More rounded */
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap; /* Prevent wrapping */
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid transparent;
    position: relative; /* For positioning delete button */
}
.element-pill.active {
    background-color: #00adb5; /* Highlight color */
    color: #1a1f26; /* Dark text on highlight */
    font-weight: bold;
    border-color: #007f86;
    box-shadow: 0 0 5px rgba(0, 173, 181, 0.5);
}
.delete-element-btn {
    background: rgba(0, 0, 0, 0.4);
    color: #ddd;
    border: none;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    cursor: pointer;
    margin-left: 0.5rem;
    font-weight: bold;
    transition: background-color 0.2s ease, color 0.2s ease;
}
 .delete-element-btn:hover {
    background: rgba(255, 0, 0, 0.7);
    color: #fff;
 }


/* Input Styling */
label { display: block; margin-bottom: 0.3rem; font-weight: 600; color: #ccc; font-size: 0.9rem; }
input[type="text"], input[type="url"], input[type="number"], textarea, select {
    width: 100%; padding: 0.8rem 0.6rem; border: 1px solid #393E46;
    background-color: #2a3038; color: #e0e0e0; border-radius: 5px;
    font-size: 1rem; margin-bottom: 0.5rem;
}
textarea { min-height: 80px; resize: vertical; }
/* Hide native color input appearance */
input[type="color"] {
     appearance: none; -webkit-appearance: none; -moz-appearance: none;
     width: 30px; /* Match swatch size */ height: 30px; /* Match swatch size */
     padding: 0; border: none; background: transparent;
     vertical-align: middle; cursor: pointer; border-radius: 50%;
}
 input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
 input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
 input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }

/* --- Visual Color Swatches --- */
.color-swatches { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem;}
.color-swatch {
    width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
    border: 2px solid #555; /* Default border */ transition: border-color 0.2s ease, transform 0.1s ease;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem; /* For emojis */
    position: relative; /* For custom color input positioning */
    background-color: var(--swatch-bg, #444); /* Use CSS var for background */
}
 .color-swatch:hover { transform: scale(1.1); }
 .color-swatch.active { border-color: #fff; box-shadow: 0 0 5px #fff; /* Highlight active swatch */ }
 /* Style for the custom color input trigger */
 .color-swatch-custom {
     position: relative;
     border-color: #777;
     overflow: hidden; /* Hide the actual input visually */
 }
 .color-swatch-custom input[type="color"] {
     position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; /* Make it clickable but invisible */
 }

/* --- Text Alignment Segmented Control --- */
.alignment-buttons { display: flex; border: 1px solid #393E46; border-radius: 5px; overflow: hidden; }
.alignment-buttons button {
    flex-grow: 1; background-color: #2a3038; border: none; color: #ccc;
    padding: 0.6rem 0.5rem; cursor: pointer; font-size: 0.9rem; transition: background-color 0.2s ease, color 0.2s ease;
    border-left: 1px solid #393E46; /* Separator */
}
.alignment-buttons button:first-child { border-left: none; }
.alignment-buttons button.active { background-color: #00adb5; color: #1a1f26; font-weight: bold;}

/* --- Collapsible Details --- */
details { border: 1px solid #393E46; border-radius: 5px; overflow: hidden; background-color: #2a3038; margin-bottom: 1rem; }
details summary {
    padding: 0.8rem 1rem; background-color: #313842; cursor: pointer;
    font-weight: 600; list-style: none; /* Remove default marker */ position: relative;
}
details summary::before { /* Custom marker */
    content: '▼';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    transition: transform 0.2s ease-in-out;
}
details[open] summary { border-bottom: 1px solid #393E46; }
details[open] summary::before { transform: translateY(-50%) rotate(180deg); }
details .details-content { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }

/* Control Groups & Stepper */
.control-group { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; /* Align items at bottom */ }
.control-group > div { flex-grow: 1; flex-basis: 45%; /* Default basis */ min-width: 120px; } /* Allow wrapping */
.stepper { display: flex; align-items: center; }
.stepper input[type="number"] { width: 60px; text-align: center; margin: 0 0.3rem; padding: 0.5rem 0.2rem; appearance: textfield; -moz-appearance: textfield; }
.stepper input[type="number"]::-webkit-inner-spin-button, .stepper input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .stepper-btn { font-size: 1.2rem; padding: 0.3rem 0.6rem; background-color: #444; color: #fff; border: none; border-radius: 5px; cursor: pointer; line-height: 1; }
.inline-label { margin-right: 0.5rem; font-weight: normal; font-size: 0.9rem; color: #aaa; display: inline-block; margin-bottom: 0.3rem; }

/* Font Selector Styling */
.font-selector select { /* Styles for better appearance if needed */ }

/* Generate Button */
.generate-button-container {
    position: fixed; bottom: 0; left: 0; right: 0; padding: 0.8rem 1rem;
    background-color: rgba(26, 31, 38, 0.9); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    border-top: 1px solid #3a424d; z-index: 5;
}
.generate-button {
    display: block; width: 100%; padding: 0.9rem 1rem; background-color: #00adb5;
    color: #1a1f26; border: none; border-radius: 8px; font-size: 1.1rem; font-weight: bold;
    cursor: pointer; transition: background-color 0.2s ease; max-width: 500px; margin: 0 auto;
}
.generate-button:hover, .generate-button:focus { background-color: #007f86; }

/* Helper class */
.hidden { display: none !important; }

/* Input group specific styling */
.input-group-half { flex-basis: 45%; /* Make two fit side-by-side */ }

/* Styling for Developer Info Section */
#jsonPayloadDisplay, #directLinkDisplay {
    font-family: "Courier New", Courier, monospace;
    font-size: 0.85rem;
    background-color: #1e232b; /* Slightly darker than normal inputs */
    color: #c0c0c0; /* Lighter text for readability */
    border: 1px solid #393E46;
    word-break: break-all; /* Ensure long URLs wrap nicely in input */
}
#jsonPayloadDisplay {
    min-height: 150px; /* Provide ample space for JSON */
    white-space: pre; /* Preserve formatting */
    overflow-x: auto; /* Allow horizontal scroll for long lines */
}
#directLinkDisplay {
    margin-bottom: 0; /* Remove default margin if any from global input styles */
}





:root{
  --bg:#222831; --panel:#1a1f26; --panel2:#2a3038; --b:#3a424d; --accent:#00adb5;
  --left:clamp(220px,22vw,280px); --right:clamp(280px,28vw,360px); --g:12px;
}
body{background:var(--bg);}
header{position:sticky;top:0;border-bottom:1px solid var(--b)}
.app-grid{
  display:grid;grid-template-columns:var(--left) 1fr var(--right);
  grid-template-rows:auto 1fr;grid-template-areas:
    "header header header"
    "left   center right";
  height:100vh;overflow:hidden;
}
.app-header{grid-area:header}
.app-left{grid-area:left;background:var(--panel);border-right:1px solid var(--b);overflow:auto}
.app-center{grid-area:center;min-width:0;display:flex;flex-direction:column;gap:8px;padding:12px;overflow:auto}
.app-right{grid-area:right;background:var(--panel);border-left:1px solid var(--b);overflow:auto}

.left-wrap,.right-wrap{padding:12px;display:flex;flex-direction:column;gap:12px}
.section-title{font-size:.9rem;color:#aaa;font-weight:600;margin-bottom:6px}

/* Preview modes */
.preview-container{max-width:none;width:100%;aspect-ratio:auto;min-height:40vh;background:
  conic-gradient(#0000 25%,#00000011 0) 0 0/16px 16px, var(--preview-bg,#393E46);
  border:1px solid var(--b);border-radius:8px}
.preview-tools{display:flex;gap:8px;align-items:center}
.tool-btn{
  background:var(--panel2);border:1px solid var(--b);border-radius:8px;
  padding:8px 10px;cursor:pointer;color:#eee;font-size:.9rem
}
.tool-btn[aria-pressed="true"]{background:var(--accent);color:#112}

.preview--fit .preview-container img{width:100%;height:100%;object-fit:contain;max-width:none;max-height:none}
.preview--fill .preview-container img{width:100%;height:100%;object-fit:cover;max-width:none;max-height:none}
.preview--1x  .preview-container{overflow:auto}
.preview--1x  .preview-container img{width:auto;height:auto;max-width:none;max-height:none}

/* Left: quick actions + element pills */
.quick-actions{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.qbtn{background:var(--panel2);border:1px solid var(--b);border-radius:8px;padding:10px;
  font-size:.85rem;color:#eee;cursor:pointer}
.qbtn:active{transform:translateY(1px)}
.elements-box{background:var(--panel2);border:1px solid var(--b);border-radius:10px;padding:10px}
.element-pill{user-select:none}

/* Right: keep your existing controls styling; just container frames */
.card{background:var(--panel2);border:1px solid var(--b);border-radius:10px;padding:10px}

/* Generate fixed bar stays */
.generate-button-container{left:var(--left);right:var(--right)}

/* Mobile drawers */
@media (max-width: 960px){
  .app-grid{grid-template-columns:1fr;grid-template-rows:auto auto 1fr;grid-template-areas:
    "header" "center" "center";}
  .app-left,.app-right{
    position:fixed;top:48px;bottom:0;width:min(92vw,420px);z-index:20;
    transform:translateX(-110%);transition:transform .2s ease;box-shadow:0 8px 30px #0008
  }
  .app-right{right:0;left:auto;transform:translateX(110%)}
  .app-left.open{transform:translateX(0)}
  .app-right.open{transform:translateX(0)}
  .drawer-toggles{position:fixed;top:56px;left:8px;right:8px;display:flex;justify-content:space-between;z-index:25}
  .toggle-btn{background:var(--panel);border:1px solid var(--b);border-radius:10px;padding:8px 10px;color:#eee}
  .generate-button-container{left:0;right:0}
}
