:root {
    --bg-color: #ffffff;
    --text-color: #000000;
    --border-color: #e0e0e0;
    --input-bg: #f5f5f5;
    --button-bg: #007bff;
    --button-text: #ffffff;
    --button-hover: #0056b3;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --border-color: #333333;
    --input-bg: #2a2a2a;
    --button-bg: #0056b3;
    --button-text: #ffffff;
    --button-hover: #003d82;
}

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.6;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Header Section */
.header {
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title {
    font-size: 1.75rem;
    font-weight: 600;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 1.2rem;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.theme-toggle:hover {
    background-color: var(--input-bg);
}

.theme-toggle:focus,
.theme-toggle:focus-visible {
    outline: 2px solid var(--button-bg);
    outline-offset: 2px;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Ad Placeholders */
.ad-placeholder {
    background-color: var(--input-bg);
    border: 1px dashed var(--border-color);
    padding: 1rem;
    margin: 1.5rem 0;
    min-height: 90px;
    border-radius: 4px;
    text-align: center;
    color: var(--text-color);
    opacity: 0.5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.ad-header {
    margin: 0;
    min-height: 120px;
    margin-bottom: 1.5rem;
}

.ad-footer {
    border: 1px dashed var(--border-color);
    padding: 1rem;
    text-align: center;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.main-column {
    display: flex;
    flex-direction: column;
    max-width: 900px;
}

.ad-mid {
    margin: 0 0 1.5rem 0;
    min-height: 250px;
}

/* Controls Panel */
.controls-panel {
    background-color: var(--bg-color);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    position: sticky;
    top: 88px;
    align-self: start;
    max-height: calc(100vh - 120px);
    overflow: auto;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
}

.control-group label:not(input + label) {
    font-weight: 500;
    font-size: 0.95rem;
}

.radio-group {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.radio-group input[type="radio"] {
    cursor: pointer;
    accent-color: var(--button-bg);
    width: 18px;
    height: 18px;
    margin: 0;
}

.radio-group label {
    cursor: pointer;
    user-select: none;
    font-weight: normal;
    margin: 0;
    line-height: 1;
}

.control-group input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--button-bg);
    width: 18px;
    height: 18px;
    margin: 0;
    margin-right: 0.5rem;
}

.control-group label[for] {
    cursor: pointer;
    user-select: none;
    font-weight: normal;
    margin: 0;
}

.control-group input[type="number"],
.control-group select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    background-color: var(--input-bg);
    color: var(--text-color);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

.control-group input[type="range"] {
    padding: 0;
    border: none;
    background-color: transparent;
    color: var(--text-color);
    cursor: pointer;
    width: 100%;
    accent-color: var(--button-bg);
}

.control-group span {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.7;
    min-width: 35px;
}

.control-group input[type="number"]:focus,
.control-group select:focus {
    outline: none;
    border-color: var(--button-bg);
    background-color: var(--bg-color);
}

/* Focus states for all interactive elements */
input:focus-visible,
select:focus-visible,
button:focus-visible {
    outline: 2px solid var(--button-bg);
    outline-offset: 2px;
}

/* Output Section */
.output-section {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.output-stats {
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.7;
    padding: 0.5rem 0;
}

.output-container {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1rem;
    min-height: 150px;
    max-height: 350px;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.6;
}

.copy-button {
    align-self: flex-start;
    padding: 0.625rem 1.25rem;
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.2s;
    position: relative;
    z-index: 101;
}

.copy-button:hover {
    background-color: var(--button-hover);
}

.copy-button:active {
    opacity: 0.9;
}

.copy-button:focus,
.copy-button:focus-visible {
    outline: 2px solid var(--button-bg);
    outline-offset: 2px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .output-section {
        padding-bottom: 200px;
    }

    .header-content {
        flex-direction: row;
        gap: 1rem;
        text-align: center;
    }

    .title {
        font-size: 1.5rem;
    }

    .controls-panel {
        gap: 1rem;
    }

    .control-group {
        gap: 0.5rem;
    }

    .radio-group {
        gap: 1rem;
    }

    .output-container {
        max-height: 300px;
    }

    .copy-button {
        width: 100%;
    }

    .ad-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        border-radius: 0;
        z-index: 99;
        min-height: 80px;
    }
    
    /* Responsive: switch back to single column layout on smaller screens */
    .container {
        display: block;
        padding: 1.5rem 1rem;
    }

    .controls-panel {
        position: static;
        max-height: none;
        margin-bottom: 1rem;
    }
}

@media (max-width: 480px) {
    .output-section {
        padding-bottom: 100px;
    }

    .container {
        padding: 1rem 0.75rem;
    }

    .controls-panel {
        padding: 1rem;
    }

    .title {
        font-size: 1.25rem;
    }

    .radio-group {
        flex-direction: row;
        gap: 1rem;
    }
    /* Keep the footer fixed on very small screens but add page padding so
       it doesn't overlap interactive controls (copy button). */
    .ad-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        border-radius: 0;
        z-index: 99;
        min-height: 80px;
    }

    /* Keep the copy button on top of the footer and make it full width for
       easier tapping on narrow devices. */
    .copy-button {
        position: relative;
        z-index: 101;
        width: 100%;
    }
}
