:root {
    --primary-color: #00FF00; /* Razer Neon Green */
    --primary-dark-color: #00CC00;
    --background-color: #0d0d0d;
    --card-background-color: #1a1a1a;
    --text-color: #f0f0f0;
    --secondary-text-color: #888;
    --border-color: #005500;
    --input-background-color: #222;
    --input-border-color: #006600;
    --font-family: 'Padauk', 'Roboto', sans-serif;
    --neon-base-color: #03e9f4; /* For new buttons */
    --danger-color: #ff3b30;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 1rem;
}

main {
    max-width: 800px;
    margin: 2rem auto;
    background-color: var(--card-background-color);
    padding: clamp(1.5rem, 5vw, 2rem);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 0 25px rgba(0, 255, 0, 0.1);
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: clamp(2rem, 8vw, 2.5rem);
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

header p {
    color: var(--secondary-text-color);
    font-size: 1.1rem;
}

.api-key-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.api-key-section > label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 700;
    font-size: 1.1rem;
}

.api-key-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.api-key-inputs {
    display: flex;
    gap: 0.5rem;
    flex: 1 1 auto; /* Allow the wrapper to grow and shrink */
}

#api-key-name-input,
#api-key-input {
    flex: 1; /* Allow inputs to share space equally */
    padding: 0.75rem;
    font-family: var(--font-family);
    font-size: 1rem;
    border-radius: 8px;
    border: 1px solid var(--input-border-color);
    background-color: var(--input-background-color);
    color: var(--text-color);
    transition: border-color 0.3s, box-shadow 0.3s;
}

#api-key-name-input:focus,
#api-key-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 255, 0, 0.25);
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.input-label-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: -1rem; /* Pull textarea closer */
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

label {
    font-weight: 700;
    font-size: 1.1rem;
}

textarea {
    width: 100%;
    padding: 1rem;
    font-family: var(--font-family);
    font-size: 1rem;
    border-radius: 8px;
    border: 1px solid var(--input-border-color);
    resize: vertical;
    transition: border-color 0.3s, box-shadow 0.3s;
    background-color: var(--input-background-color);
    color: var(--text-color);
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 255, 0, 0.25);
}

#generate-btn .spinner, #generate-video-btn .spinner, #feeling-lucky-btn .spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#generate-btn.loading .spinner, #generate-video-btn.loading .spinner, #feeling-lucky-btn.loading .spinner {
    display: block;
}

#generate-btn.loading .btn-text, #generate-video-btn.loading .btn-text, #feeling-lucky-btn.loading .btn-text {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.output-section {
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.result-header h2 {
    font-size: 1.5rem;
}

#copy-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #2a2a2a;
    color: var(--primary-color);
    border: 1px solid var(--input-border-color);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-family);
    transition: background-color 0.3s;
}

#copy-btn:hover {
    background-color: #3a3a3a;
}

#copy-btn svg {
    fill: var(--primary-color);
}

.result-container {
    background-color: #0d0d0d;
    color: #f1f1f1;
    border-radius: 8px;
    padding: 1.5rem;
    overflow-x: auto;
    border: 1px solid var(--input-border-color);
}

pre {
    white-space: pre-wrap;
    word-wrap: break-word;
}

code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95rem;
}

input[type="number"] {
    width: 70px;
    padding: 0.5rem;
    font-family: var(--font-family);
    font-size: 1rem;
    border-radius: 6px;
    border: 1px solid var(--input-border-color);
    text-align: center;
    background-color: #333;
    color: var(--text-color);
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.25);
}

/* --- Custom Options Toggle --- */
.toggle-options-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: -0.5rem; /* Pull it closer to characters section */
    margin-bottom: 1.5rem;
}

.toggle-options-wrapper label {
    font-weight: 500;
    font-size: 1rem;
    color: var(--secondary-text-color);
    cursor: pointer;
    user-select: none; /* Prevent text selection on click */
    transition: color 0.3s;
}

.toggle-options-wrapper:hover label {
    color: var(--primary-color);
}

#toggle-custom-options {
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
    accent-color: var(--primary-color); /* Style the checkmark color */
}

/* Custom Options */
.custom-options {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: none; /* Hidden by default */
    flex-direction: column;
    gap: 1rem;
}

.custom-options legend {
    padding: 0 0.5rem;
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1rem;
}

.option-item {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.option-item label {
    font-weight: 500;
    font-size: 1rem;
    flex-shrink: 0;
}

.custom-options select,
.custom-options input[type="text"],
.custom-options input[type="number"] {
    width: 150px;
    padding: 0.5rem;
    font-family: var(--font-family);
    font-size: 1rem;
    border-radius: 6px;
    border: 1px solid var(--input-border-color);
    background-color: #333;
    color: var(--text-color);
}

.custom-options select:focus,
.custom-options input[type="text"]:focus,
.custom-options input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.25);
}

/* --- Characters Section --- */
.characters-section {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.characters-section legend {
    padding: 0 0.5rem;
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1rem;
}

.character-entry {
    position: relative;
    background-color: var(--background-color);
    border: 1px solid var(--input-border-color);
    border-radius: 8px;
    padding: 1.5rem 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.character-entry .character-header {
    font-weight: 700;
    color: var(--secondary-text-color);
    position: absolute;
    top: 0.5rem;
    left: 1rem;
    font-size: 0.9rem;
}

.character-entry label {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: -0.75rem; /* pull label closer to textarea */
}

.character-entry textarea {
    min-height: 60px;
}

.remove-character-btn {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    transition: color 0.2s;
}

.remove-character-btn:hover {
    color: #ff6b6b;
}


/* --- Neon Button Styles --- */

.btn-neon {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem; /* Slightly smaller padding */
    font-size: 1rem; /* Slightly smaller font */
    font-weight: 700;
    color: var(--neon-base-color);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: 0.5s;
    -webkit-box-reflect: below 1px linear-gradient(transparent, #0005);
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 1.5px; /* Slightly less spacing */
    filter: hue-rotate(270deg);
}

#generate-btn.btn-neon,
#feeling-lucky-btn.btn-neon {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    letter-spacing: 1px;
    -webkit-box-reflect: unset;
}

#add-api-key-btn.btn-primary {
    width: auto; /* Override 100% width */
    padding: 0.75rem 1rem;
    font-size: 1rem;
    height: 44px; /* Match input height */
    flex-shrink: 0;
    flex-grow: 1;
    max-width: 150px;
}

#generate-video-btn.btn-neon {
    margin-top: 1rem;
    width: 100%;
}

.btn-neon:hover:not(:disabled) {
    background: var(--neon-base-color);
    color: #050801;
    box-shadow: 0 0 5px var(--neon-base-color),
                0 0 25px var(--neon-base-color),
                0 0 50px var(--neon-base-color),
                0 0 200px var(--neon-base-color);
}

/* Rainbow Lucky Button Customization */
#feeling-lucky-btn.btn-neon {
    filter: none; /* Remove the single-color filter */
    color: #fff; /* Set text to white for contrast */
}

#feeling-lucky-btn.btn-neon:hover:not(:disabled) {
    background: #000;
    color: #fff;
    box-shadow: 0 0 5px #ff00de,
                0 0 25px #00a2ff,
                0 0 50px #ff00de,
                0 0 100px #00a2ff;
}

#feeling-lucky-btn.btn-neon > span:nth-child(1) {
    background: linear-gradient(90deg, transparent, #ff0000, #ffff00, #00ff00, #0000ff, #ff00ff);
}
#feeling-lucky-btn.btn-neon > span:nth-child(2) {
    background: linear-gradient(180deg, transparent, #ff0000, #ffff00, #00ff00, #0000ff, #ff00ff);
}
#feeling-lucky-btn.btn-neon > span:nth-child(3) {
    background: linear-gradient(270deg, transparent, #ff0000, #ffff00, #00ff00, #0000ff, #ff00ff);
}
#feeling-lucky-btn.btn-neon > span:nth-child(4) {
    background: linear-gradient(360deg, transparent, #ff0000, #ffff00, #00ff00, #0000ff, #ff00ff);
}
/* End Rainbow Button */

.btn-neon:disabled {
    cursor: not-allowed;
    background: #111;
    color: #444;
    filter: grayscale(1);
    -webkit-box-reflect: unset;
}

.btn-neon:disabled > span:not(.btn-text) {
    display: none;
}

.btn-neon > span:not(.btn-text) {
    position: absolute;
    display: block;
}

.btn-neon > span:nth-child(1) {
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--neon-base-color));
    animation: animate1 1s linear infinite;
}

.btn-neon > span:nth-child(2) {
    top: -100%;
    right: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent, var(--neon-base-color));
    animation: animate2 1s linear infinite;
    animation-delay: 0.25s;
}

.btn-neon > span:nth-child(3) {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(270deg, transparent, var(--neon-base-color));
    animation: animate3 1s linear infinite;
    animation-delay: 0.5s;
}

.btn-neon > span:nth-child(4) {
    bottom: -100%;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(360deg, transparent, var(--neon-base-color));
    animation: animate4 1s linear infinite;
    animation-delay: 0.75s;
}

@keyframes animate1 {
    0% { left: -100%; }
    50%, 100% { left: 100%; }
}
@keyframes animate2 {
    0% { top: -100%; }
    50%, 100% { top: 100%; }
}
@keyframes animate3 {
    0% { right: -100%; }
    50%, 100% { right: 100%; }
}
@keyframes animate4 {
    0% { bottom: -100%; }
    50%, 100% { bottom: 100%; } /* Corrected animation */
}

/* --- API Key List --- */
.api-key-list-container {
    margin-top: 1.5rem;
}

.api-key-list-container h3 {
    color: var(--secondary-text-color);
    font-size: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

#api-key-list {
    list-style: none;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.api-key-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--input-background-color);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--input-border-color);
    gap: 0.5rem;
}

.api-key-details {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent long names from breaking layout */
}

.api-key-name {
    font-family: var(--font-family);
    font-weight: 700;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.api-key-masked {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    color: var(--secondary-text-color);
}

.api-key-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.copy-key-btn {
    background: none;
    border: none;
    color: var(--secondary-text-color);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: color 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.copy-key-btn:hover:not(:disabled) {
    color: var(--primary-color);
    background-color: #333;
}

.copy-key-btn svg {
    fill: currentColor;
}

.copy-key-btn:disabled {
    cursor: default;
    color: var(--primary-color);
    font-weight: bold;
    font-size: 1.2rem;
}

.delete-key-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 0.25rem 0.5rem;
    transition: color 0.2s, background-color 0.2s;
    flex-shrink: 0;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.delete-key-btn:hover {
    color: #ff6b6b;
    background-color: rgba(255, 59, 48, 0.1);
}

#clear-keys-btn {
    background: transparent;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    transition: background-color 0.3s, color 0.3s;
}

#clear-keys-btn:hover {
    background-color: var(--danger-color);
    color: #fff;
}

/* --- Video Section --- */
.video-section {
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
    margin-top: 2rem;
}

.video-section h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

#video-status {
    margin-top: 1rem;
    color: var(--secondary-text-color);
    min-height: 24px;
}

#video-result-container {
    margin-top: 1rem;
    text-align: center;
}

#generated-video {
    border-radius: 8px;
    border: 1px solid var(--input-border-color);
    background-color: #000;
    max-width: 100%;
}

#download-video-btn {
    margin-top: 1rem;
    text-decoration: none;
}


/* --- Footer and Animated Text --- */
footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem 0;
}

.animated-credit {
    font-size: 1rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary-color), var(--neon-base-color), var(--primary-color));
    background-size: 200% auto;
    color: #fff;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textShine 4s linear infinite;
}

@keyframes textShine {
    to {
        background-position: 200% center;
    }
}

/* --- Helper and new button styles --- */
.btn-primary {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--background-color);
    background: var(--primary-color);
    border: none;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-radius: 6px;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark-color);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    cursor: not-allowed;
    background: #222;
    color: #666;
}

.btn-secondary {
    background-color: #333;
    color: var(--primary-color);
    border: 1px solid var(--input-border-color);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 700;
    transition: background-color 0.3s, transform 0.2s;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #444;
    transform: translateY(-1px);
}

.btn-secondary:disabled {
    background-color: #222;
    color: #666;
    cursor: not-allowed;
    border-color: #444;
}

#generation-status-container {
    text-align: center;
    margin-top: 1rem;
}

#generation-status-text {
    margin-bottom: 0.75rem;
    color: var(--secondary-text-color);
    font-size: 0.9rem;
}

#stop-generation-btn {
    background-color: var(--danger-color);
    color: #fff;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: background-color 0.3s;
}

#stop-generation-btn:hover {
    background-color: #ff6b6b;
}


@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }
    main {
        margin: 1rem auto;
    }
    
    .api-key-input-wrapper {
        flex-direction: column;
        align-items: stretch;
    }
    
    .api-key-inputs {
        flex-direction: column;
    }
    
    #add-api-key-btn.btn-primary {
        width: 100%;
        max-width: none;
    }

    .option-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    .custom-options select,
    .custom-options input[type="text"],
    .custom-options input[type="number"] {
        width: 100%;
    }
}