/* --- General & Reset --- */
:root {
    --primary-color: #230046; /* Entain Dark Purple */
    --primary-hover: #1a0033; /* Darker Purple */
    --background-color: #f8f8f8; /* Light Grey Background */
    --container-bg: #ffffff;
    --text-color: #333;
    --border-color: #ddd;
    --font-family: 'Poppins', sans-serif;
    --accent-main: #E6007E; /* Entain Pink/Magenta */    
    --accent-main-hover: #c4006b; /* Darker Pink/Magenta */
    --accent-main-rgb: 230, 0, 126; /* For rgba() */
}

/* Ladbrokes Theme */
body.theme-ladbrokes {
    --primary-color: #E00000; /* Ladbrokes Red */
    --primary-hover: #b30000; /* Darker Red */
    --accent-main: #FDB913; /* Ladbrokes Gold (less bright) */
    --accent-main-hover: #E4A60A; /* Darker Gold */
    --accent-main-rgb: 253, 185, 19;
}

/* Coral Theme */
body.theme-coral {
    --primary-color: #004699; /* Coral Blue */
    --primary-hover: #003366; /* Darker Blue */
    --accent-main: #8DC63F; /* Coral Green */
    --accent-main-hover: #709e32; /* Darker Green */
    --accent-main-rgb: 141, 198, 63; /* RGB for Coral Green */
}

/* Bwin Theme */
body.theme-bwin {
    --primary-color: #181818; /* Bwin Red */
    --primary-hover: #000; /* Darker Red */
    --accent-main: #FDB913; /* Ladbrokes Gold (less bright) */
    --accent-main-hover: #E4A60A; /* Darker Gold */
    --accent-main-rgb: 253, 185, 19;
}


@font-face {
    font-family: "midnightsans-12black";
    src: url(https://d2vxgxvhgubbj8.cloudfront.net/images/client/11950/fileassets/cstfont-29860253-96335358.ttf);
    font-weight: normal;
    font-style: normal;
}

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

body {
    font-family: var(--font-family);
    /* New background: Radial gradient from violet to black */
    background-color: #000; /* Fallback color */
    background-image: radial-gradient(circle, var(--primary-color), #000000);
    background-attachment: fixed; /* Makes the background static on scroll, improving perceived quality */
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

/* --- Main Container & Header --- */
.container {
    width: 100%;
    max-width: 750px;
    background-color: var(--container-bg);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 2rem;
    text-align: center;
}

header h1 {
    font-size: 2.5rem; /* Slightly reduced for a more refined look */
    margin-bottom: 2rem;
    font-family: "midnightsans-12black", sans-serif;
    color: #fff; /* White text for visibility on dark primary background */
    background-color: var(--primary-color); /* Deep blue background */
    padding: 1rem 1.5rem; /* Padding around the title and logo */
    border-radius: 8px; /* Slightly rounded corners for the background */
    display: flex; /* Use flexbox for alignment */
    align-items: center; /* Vertically align items */
    justify-content: center; /* Center content horizontally */
    text-transform: uppercase; /* Make "CODE GENERATOR" all uppercase */
    gap: 1rem; /* Space between logo and text */
}

#brand-logo {
    height: 1.5rem; /* Default logo height */
    width: auto; /* Maintain aspect ratio */
    transition: height 0.3s ease; /* Smooth transition for size changes */
}

/* Adjust the logo size for branded views for better visual balance. */
body.theme-ladbrokes #brand-logo,
body.theme-coral #brand-logo {
    height: 1.5rem; /* Set logo size for branded views */
}

/* --- Form Styling --- */
#racingForm {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

label {
    font-weight: 600;
    font-size: 0.9rem; /* Reduced font size for a cleaner look */
    text-align: left;
    text-transform: uppercase; /* Professional styling for labels */
    color: #555;
    /* margin-bottom is now handled by the gap in .form-group for top-level elements */
}

/* New group for top-level form elements to control spacing */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 1rem; /* This now controls the space between the label and its control */
}

/* --- Select Dropdown Styling --- */
.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '▼';
    font-size: 1rem;
    color: var(--accent-main); /* Use neutral accent color */
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none; /* Allows clicks to pass through to the select */
}

select {
    width: 100%;    
    padding: 1rem 2.5rem 1rem 1rem; /* Uniform vertical padding, keep right padding for arrow */
    font-size: 1rem;
    font-family: var(--font-family);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
    appearance: none; /* Removes default browser styling */
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

select:focus {
    outline: none;
    border-color: var(--accent-main);
    box-shadow: 0 0 0 3px rgba(var(--accent-main-rgb), 0.25);
}

/* --- New Searchable Select Dropdown --- */
.searchable-select-container {
    position: relative;
}

#searchable-select-input {
    width: 100%;
    padding: 1rem; /* Reduced padding to match other inputs */
    font-size: 1rem;
    font-family: var(--font-family);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#searchable-select-input:focus {
    outline: none;
    border-color: var(--accent-main);
    box-shadow: 0 0 0 3px rgba(var(--accent-main-rgb), 0.25);
}

.searchable-select-options {
    display: none; /* Hidden by default */
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    z-index: 1000;
    max-height: 225px; /* Approx 5 items * 45px per item */
    overflow-y: auto;
}

.searchable-select-options.visible {
    display: block;
}

.searchable-select-option {
    padding: 0.8rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 1rem;
    line-height: 1.5;
}

.searchable-select-option:hover {
    background-color: rgba(var(--accent-main-rgb), 0.1);
}

/* --- Input Legend Styling --- */
.input-legend {
    display: block; /* Make it take its own line */
    font-size: 0.55rem;
    color: #7f8c8d; /* Muted text color, matches old subtitle */
    text-align: left;
    margin-bottom: 0.5rem;
}

/* --- Result Display --- */
.result {
    margin-top: 1.5rem;
    padding: 1rem;    
    background-color: rgba(var(--accent-main-rgb), 0.08);
    border-left: 5px solid var(--accent-main); /* Use Entain pink accent */
    border-radius: 8px; /* Increased border-radius for consistency */
    text-align: left;
    font-weight: 600;
    /* display: none; Removed: The result container is always visible, its content is managed by JS */
}

/* --- Copy Button (positioned like an icon) --- */
.code-copy-button {
    position: absolute; /* Position relative to #code-section */
    /* Default top and right for the first button (copy) */
    top: 0.75rem;
    right: 0.75rem;
    background-color: transparent;
    color: #777; /* Darker grey for better contrast on light background */
    border: none;
    border-radius: 6px;
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s, background-color 0.2s;
    z-index: 10;
}

.code-copy-button:hover {
    color: var(--accent-main);
    background-color: rgba(var(--accent-main-rgb), 0.1);
}

.code-copy-button svg {
    display: block;
}

/* Specific positioning for the preview button */
#preview-button {
    right: 3rem; /* Positioned to the left of the copy button with a small gap */
    /* Calculation: 0.75rem (copy button's right) + 18px (svg width) + 10px (total horizontal padding) + 8px (desired gap) = 12px + 18px + 10px + 8px = 48px = 3rem */
}

/* --- Code Section Styling --- */
#code-section {
    position: relative; /* This is the key: makes this the anchor for the absolute button */
    margin-top: 1.5rem;
    background-color: #f5f2f0; /* Light background for light themes */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-align: left;
    display: none; /* Hidden by default, shown by JavaScript */
    overflow: hidden; /* Ensures border-radius is respected by children */
}

#code-section pre {
    margin: 0;
    padding: 1rem;
    padding-top: 3.5rem; /* Extra top padding for the copy button */
    padding-bottom: 1rem; /* Added padding at the bottom of the code block */
    color: #333; /* Dark text for light themes */
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace; /* Monospace font for code */
    font-size: 0.9rem;
    /* Wrapping is handled by the inner <code> tag to override Prism's styles */
}


/* --- Preview Modal Styling --- */
.modal-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-overlay.visible {
    display: flex;
}

.modal-content {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    width: 100%;
    max-width: 800px; /* Increased max-width */
    height: 90%; /* Increased height */
    max-height: 600px; /* Increased max-height */
    display: flex;
    flex-direction: column;
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-family: "midnightsans-12black", sans-serif;
    text-align: center;
    font-size: 1.5rem;
    text-transform: uppercase; /* Make title uppercase */
}

.preview-note {
    font-size: 0.9rem;
    color: #7f8c8d;
    text-align: center;
    margin-bottom: 1rem;
}

.preview-warning {
    font-size: 0.75rem; /* Smaller font */
    font-style: italic;
    color: #888; /* Lighter, less prominent color */
    text-align: center;
    margin-top: 1rem; /* Add space above it, separating from the iframe */
    margin-bottom: 0; /* No extra space at the bottom */
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2rem;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    transition: color 0.2s ease;
}

.modal-close:hover {
    color: #333;
}

#preview-iframe {
    flex-grow: 1; /* Take up remaining space */
    width: 100%;
    height: 100%; /* Fallback for browsers not supporting flex-grow well on iframes */
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 600px) {
    .container {
        padding: 1.5rem;
    }
    .two-column-layout, .three-column-layout {
        grid-template-columns: 1fr; /* Stack columns on mobile */
    }
}

/* Add space between the main dropdown and the aui-inputs-container */
#dynamic-inputs-container {
    margin-top: 1.5rem;
}

/* --- Dynamic Input Group Styling --- */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0rem;
    /* margin-bottom is handled by grid gap now */
}

/* --- Fieldset for Grouping --- */
fieldset {
    position: relative; /* Needed for absolute positioning of the button */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    text-align: left;
}

.fieldset-clear-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.fieldset-clear-button:hover {
    background-color: rgba(0,0,0,0.1);
}

.fieldset-clear-button svg {
    fill: #888;
    transition: fill 0.2s;
}

.fieldset-clear-button:hover svg {
    fill: #333;
}

fieldset:last-of-type {
    margin-bottom: 0;
}

legend {
    font-weight: 600;
    font-size: 1.1rem;
    padding: 0 0.5rem;
    color: var(--primary-color);
    font-family: "midnightsans-12black", sans-serif;
    text-transform: uppercase;
}

/* --- Layouts for Input Groups --- */
.one-column-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.two-column-layout {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); /* Responsive columns */
    gap: 1rem 1.5rem; /* 1rem row-gap, 1.5rem column-gap */
}

.three-column-layout {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Responsive columns */
    gap: 1rem; /* Adjust the gap between columns and rows as needed */
}

.input-group label[for^="crc-rdn-paragraph-"] {
    margin-bottom: 0.25rem; /* Reduced spacing for paragraph textareas */
}

/* --- Dynamic Input Field Styling (matching select) --- */
.input-group input[type="text"],
.input-group input[type="number"] {
    width: 100%;
    padding: 1rem; /* Uniform padding for all input types */
    font-size: 1rem;
    font-family: var(--font-family);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
    /* appearance: none; Not needed for text/number inputs */
    cursor: text; /* Indicate it's a text input */
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-group input[type="text"],
.input-group input[type="number"],
.input-group textarea {
    width: 100%;
    padding: 1rem; /* Uniform padding for all input types */
    font-size: 1rem;
    font-family: var(--font-family);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
    /* appearance: none; Not needed for text/number inputs */
    cursor: text; /* Indicate it's a text input */
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-group textarea {
    min-height: 5rem; /* Default height for textareas */
    resize: vertical; /* Allow vertical resizing */
    margin-bottom: 1rem; /* Add spacing after the textarea */
}

.input-group input[type="text"]:focus,
.input-group input[type="number"]:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--accent-main);
    box-shadow: 0 0 0 3px rgba(var(--accent-main-rgb), 0.25);
}

#generated-code-display {
    /* This is the <code> tag. It should inherit styles from its parent <pre> */
    background-color: transparent;
    padding: 0;
    border: none;
    /* Force wrapping to override Prism's default 'white-space: pre' */
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

/* --- Radio Button Group Styling --- */
.radio-group {
    display: flex;
    flex-direction: column; /* Stack options vertically */
    gap: 0.75rem; /* Space between radio options */
    align-items: flex-start; /* Align items to the left */
}

.radio-group div {
    display: flex;
    align-items: center; /* Vertically align radio button and label */
    gap: 0.5rem; /* Space between radio button and label */
}

.radio-group input[type="radio"] {
    margin: 0; /* Reset default margin */
    accent-color: var(--accent-main); /* Modern way to color radio buttons */
}

.radio-group label {
    margin-bottom: 0; /* Override default label margin as flex gap handles it */
    font-weight: normal;
    text-transform: none;
    color: var(--text-color);
}

.button {
    background-color: transparent;
    border: 2px solid var(--accent-main);
    color: var(--accent-main);
    padding: 0.8rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.button:hover {
    background-color: var(--accent-main);
    color: #fff;
}