/* --- Apple HIG Inspired UI --- */
:root {
    --accent-color: #74BF47; /* Mid-light-green for all UI elements */
    --bg-color: #f6f6f6;
    --card-bg-color: #ffffff;
    --text-color: #1d1d1f;
    --secondary-text-color: #6e6e73;
    --separator-color: #e5e5e5;
    --control-bg-color: #7676801f; /* Light gray for control backgrounds */
}

/* --- ADDED: Dark Mode Color Variables --- */
body[data-theme="dark"] {
    --bg-color: #1c1c1e;
    --card-bg-color: #2c2c2e;
    --text-color: #f2f2f7;
    --secondary-text-color: #8e8e93;
    --separator-color: #38383a;
    --control-bg-color: #7676803d;
}

#theme-icon::before {
    font-size: 16px;
    content: '☼'; /* Default: sun icon */
}

body[data-theme="dark"] #theme-icon::before {
    content: '☾'; /* Moon icon when in dark mode */
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* ADDED: Smooth transition for theme change */
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    position: relative; /* ADDED: For positioning the theme toggle */
}

/* --- ADDED: Dark Mode Toggle Styles --- */
.theme-switch-wrapper {
    position: absolute;
    top: 28px;
    right: 25px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
}
.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--control-bg-color);
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.slider.round { border-radius: 28px; }
.slider.round:before { border-radius: 50%; }

body[data-theme="dark"] .slider:before {
    background-color: #444;
}
input:checked + .slider {
    background-color: var(--accent-color);
}
input:checked + .slider:before {
    transform: translateX(22px);
}
/* --- End of Dark Mode Toggle Styles --- */


/* --- Header: Logo & Padding --- */
.header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px; /* Reduced padding */
}

#app-logo {
    height: 80px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.subtitle {
    text-align: center;
    color: var(--secondary-text-color);
    margin-bottom: 24px; /* Reduced padding */
}

.main-content {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 20px;
    align-items: start;
}

.sidebar {
    background: var(--card-bg-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    position: sticky;
    top: 20px;
    transition: background-color 0.3s ease; /* ADDED: Transition */
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.rule-label {
    font-size: 0.9rem;
    color: var(--secondary-text-color);
    margin-left: 8px;
    font-weight: normal;
}

/* --- Segmented Controls (for Radio Buttons) --- */
.segmented-control {
    display: flex;
    background-color: var(--control-bg-color);
    border-radius: 8px;
    padding: 3px;
    width: 100%;
}

.segmented-control input[type="radio"] {
    display: none; /* Hide the actual radio button */
}

.segmented-control label {
    flex: 1;
    padding: 6px 0;
    margin: 0;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--secondary-text-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
}

.segmented-control input[type="radio"]:checked + label {
    background-color: var(--card-bg-color);
    color: var(--text-color);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.color-picker-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.text-color-grid {
    display: flex;
    gap: 6px;
}

.text-color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--separator-color);
    transition: all 0.2s ease;
}
.text-color-option:hover {
    transform: scale(1.1);
}
.text-color-option.selected {
    border-color: var(--accent-color);
}

.color-picker {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 35px;
    height: 35px;
    border: none;
    cursor: pointer;
    background-color: transparent;
    padding: 0;
}
.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}
.color-picker::-webkit-color-swatch {
    border: 1px solid var(--separator-color);
    border-radius: 8px;
}
.color-picker::-moz-color-swatch {
    border: 1px solid var(--separator-color);
    border-radius: 8px;
}

/* --- Sliders (Range Inputs) --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--control-bg-color);
    border-radius: 4px;
    outline: none;
    margin-top: 5px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: #FFF;
    cursor: pointer;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1); /* Added border for visibility */
    box-shadow: 0 1px 3px rgba(0,0,0,0.15); /* Adjusted shadow */
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: #FFF;
    cursor: pointer;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1); /* Added border for visibility */
    box-shadow: 0 1px 3px rgba(0,0,0,0.15); /* Adjusted shadow */
}

/* ADDED: Slider thumb style for dark mode */
body[data-theme="dark"] input[type="range"]::-webkit-slider-thumb {
    background: #e0e0e0;
    border-color: rgba(255,255,255,0.1);
}
body[data-theme="dark"] input[type="range"]::-moz-range-thumb {
    background: #e0e0e0;
    border-color: rgba(255,255,255,0.1);
}

.select-input, .text-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--separator-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg-color);
    color: var(--text-color); /* ADDED: ensure text color changes */
    transition: background-color 0.3s ease, color 0.3s ease; /* ADDED: Transition */
}

.select-input:focus, .text-input:focus {
     border-color: var(--accent-color);
     outline: none;
     box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.2);
}

/* --- START: Styles for Clear Text Button --- */
.input-with-clear {
    position: relative;
}
.text-input {
    padding-right: 30px; /* Make space for the clear button */
}
.clear-btn {
    position: absolute;
    right: 1px;
    top: 1px;
    bottom: 1px;
    width: 35px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    color: var(--secondary-text-color);
    display: none; /* Hidden by default */
    place-items: center;
}
.clear-btn:hover {
    color: var(--text-color);
}
 /* --- END: Styles for Clear Text Button --- */

/* CHANGE: Updated file upload button styles */
.file-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px; /* CHANGE: Reduced gap for a "single space" feel */
    width: 100%;
    padding: 10px;
    border: 1px solid var(--separator-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--control-bg-color);
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-color);
}

/* ADDED: Styles for Logo Upload Group */
.input-group-with-action {
    display: flex;
    align-items: center;
    gap: 8px;
}
.input-group-with-action .file-upload-btn {
    flex-grow: 1;
}
.remove-btn {
    width: 35px;
    height: 35px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid var(--separator-color);
    background: var(--card-bg-color);
    color: var(--secondary-text-color);
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.remove-btn:hover {
    background-color: var(--control-bg-color);
    color: #ff3b30;
    border-color: rgba(255, 59, 48, 0.5);
}

.background-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.background-option {
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Prevent gradient from spilling */
}

.background-option:hover {
    transform: scale(1.05);
}

.background-option.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.3);
}

.background-option.custom {
    background: var(--control-bg-color);
    font-size: 12px; font-weight: 600; color: var(--secondary-text-color);
}
.background-option.custom svg {
    width: 20px;
    height: 20px;
    transition: display 0.2s;
}

/* CHANGE: New styles for custom color pickers UI */
.custom-color-picker-group {
    margin-top: 10px;
    display: none; /* Hidden by default, shown when custom is selected */
    align-items: center;
    justify-content: space-around;
    gap: 10px;
    background-color: var(--control-bg-color);
    padding: 8px;
    border-radius: 8px;
}
.custom-color-picker-group.visible {
    display: flex;
}
.custom-color-picker-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
}
.custom-color-picker-display {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    border: 2px solid var(--separator-color);
    cursor: pointer;
}
.custom-color-picker-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}


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

.text-style-btn {
    flex-grow: 1; padding: 6px 10px;
    border: 1px solid var(--separator-color);
    background: var(--card-bg-color);
    border-radius: 6px; cursor: pointer; font-size: 14px;
}

.text-style-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.center-column {
    display: flex; flex-direction: column; gap: 20px;
}

.buttons {
    display: flex; 
    gap: 10px; 
    justify-content: center;
    position: relative;
}

#clearScreenshotBtn {
    position: absolute;
    right: 0;
    top: 0;
    background: #b75555;
    color: white;
    font-size: 22px;
    font-weight: 400;
    padding: 8px 18px; 
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
/* CHANGE: Added hover animation */
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.btn:active {
    transform: scale(0.98) translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

#copyBtn { background: var(--accent-color); color: white; }
#saveBtn { background: var(--accent-color); color: white; }
#resetBtn { background: var(--separator-color); color: var(--text-color); }


.preview-area {
    background: var(--card-bg-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    min-height: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease; /* ADDED: Transition */
}

.drop-zone {
    border: 2px dashed var(--separator-color);
    border-radius: 12px;
    padding: 60px 20px;
    text-align: center;
    color: var(--secondary-text-color);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.drop-zone:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.drop-zone.dragover {
    border-color: var(--accent-color);
    background-color: rgba(52, 199, 89, 0.05);
    color: var(--accent-color);
}

.preview-container { position: relative; display: inline-block; }
.screenshot-frame { position: relative; transition: all 0.3s ease; }

#screenshotImage {
    transition: box-shadow 0.3s ease;
    display: block;
    /* --- FIXED: Added responsive scaling for mobile --- */
    max-width: 100%;
    height: auto;
}

.screenshot-text { position: absolute; color: #FFFFFF; padding: 0; margin: 0; pointer-events: none; }
.logo-image-preview { position: absolute; height: auto; pointer-events: none; }
.hidden { display: none; }

@media (max-width: 1024px) {
    .main-content { grid-template-columns: 1fr; }
    .preview-area { order: 1; }
    .sidebar-left { order: 2; }
    .sidebar-right { order: 3; }
    .sidebar { position: relative; top: auto; }
    .center-column { order: 1; }
}

/* ADDED: Footer Styles */
footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--secondary-text-color);
    font-size: 0.9rem;
}

footer p {
    display: inline-flex;
    align-items: center;
    gap: 12px; /* Space between text and icons */
}

footer a {
    color: var(--secondary-text-color);
    display: inline-flex;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--text-color);
}

footer svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Annotation Controls - using segmented control style */

/* Inline annotation settings */
.annotation-settings {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.annotation-setting {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.annotation-setting label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--secondary-text-color);
    margin: 0;
}

/* Annotation color grid - same style as text color */
.annotation-color-grid {
    display: flex;
    gap: 6px;
}

.annotation-color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--separator-color);
    transition: all 0.2s ease;
}

.annotation-color-option:hover {
    transform: scale(1.1);
}

.annotation-color-option.selected {
    border-color: var(--accent-color);
}

/* Annotation overlay for drawing */
.annotation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.annotation-overlay.drawing {
    pointer-events: all;
    cursor: crosshair;
}

/* Annotation action buttons */
.annotation-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--separator-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--control-bg-color);
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-color);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-secondary:hover {
    background: var(--primary-bg);
    border-color: var(--primary-color);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary svg {
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .preview-area {
        min-height: 350px;
    }
    #clearScreenshotBtn {
            display: none;
        }
}