/* Light theme (default) */
:root {
    --bg-color: #f5f5f5;
    --container-bg: #fff;
    --text-color: #333;
    --border-color: #ccc;
    --error-color: #dc3545;
    --shadow: rgba(0,0,0,0.1);
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --container-bg: #2d2d2d;
        --text-color: #e0e0e0;
        --border-color: #555;
        --error-color: #ef4444;
        --shadow: rgba(0,0,0,0.3);
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

.container {
    background: var(--container-bg);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow);
    transition: background-color 0.3s, box-shadow 0.3s;
}

h1 {
    margin: 0 0 30px 0;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.3s;
}

.upload-area:hover, .upload-area.dragover {
    border-color: #0071e3;
}

input[type="file"] {
    display: none;
}

.preview-thumbnail {
    max-width: 200px;
    max-height: 100px;
    object-fit: cover;
    margin: 0 auto;
    display: block;
}

.controls {
    margin: 20px 0;
    display: grid;
    gap: 15px;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-width: 0;
}

.control-label {
    flex: 1;
}

.control-row-stack {
    display: grid;
    gap: 8px;
    min-width: 0;
}

label {
    display: block;
    margin-bottom: 2px;
    font-weight: 500;
    color: var(--text-color);
}

.label-description {
    font-size: 0.85em;
    font-weight: normal;
    color: var(--text-color);
    opacity: 0.7;
    margin: 0;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    accent-color: #0071e3;
}

input[type="range"] {
    accent-color: #0071e3;
}

.period-inputs {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.period-inputs input[type="range"] {
    width: 130px;
    min-width: 0;
}

.period-inputs input[type="number"] {
    width: 5em;
}

#periodPreviewWrap {
    display: grid;
    gap: 8px;
}

#periodPreview {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    background: #000;
    image-rendering: auto;
}

.period-match {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85em;
    opacity: 0.8;
}

.period-meter {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    overflow: hidden;
}

#periodMatchBar {
    height: 100%;
    width: 0%;
    background: #0071e3;
    transition: width 0.06s linear;
}

input[type="number"] {
    width: 6em;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--container-bg);;
    color: var(--text-color);
    font-size: 14px;
    box-sizing: border-box;
}

input[type="number"]:focus {
    outline: none;
    border-color: #0071e3;
}

#queueMessage {
    margin: 10px 0;
}

#errorMessage {
    color: var(--error-color);
    margin: 10px 0;
}

#result {
    text-align: center;
}

#resultImage {
    width: 100%;
    margin: 12px 0;
}

button {
    background-color: #0071e3;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 400;
    padding: 8px 15px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

button:hover:not(:disabled):not(.remove-btn):not(.swap-btn) {
    background-color: #0076df;
}

button:active:not(:disabled) {
    background-color: #006edb;
}

button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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

footer {
    text-align: center;
    margin-top: 30px;
    font-size: 14px;
    opacity: 0.7;
}

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

footer a:hover {
    text-decoration: underline;
}

.file-pair-preview {
    display: flex;
    align-items: center;
    gap: 20px;
    justify-content: center;
    padding-top: 5px;
}

.file-preview {
    text-align: center;
    flex: 1;
    max-width: 150px;
    transition: transform 0.3s ease;
}

.file-preview .image-wrapper {
    position: relative;
    display: inline-block;
}

.file-preview img {
    width: 150px;
    height: 80px;
    object-fit: cover;
    margin-bottom: 5px;
    display: block;
}

.file-preview p {
    font-size: 0.9em;
    margin: 5px 0;
    word-wrap: break-word;
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #666;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    transition: background-color 0.2s;
}

.remove-btn:hover {
    background-color: #dc3545;
}

.single-file-preview {
    display: inline-block;
    max-width: 100%;
}

.single-file-preview .image-wrapper {
    position: relative;
    display: inline-block;
}

.single-file-preview p {
    font-size: 0.9em;
    margin: 5px 0;
    word-wrap: break-word;
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
}

.swap-btn {
    background-color: #666;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
    flex-shrink: 0;
    z-index: 10;
}

.swap-btn:hover {
    background-color: #0071e3;
    transform: scale(1.1);
}

.swap-btn:active {
    transform: scale(0.95);
}

select {
    width: auto;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--container-bg);
    color: var(--text-color);
    font-size: 14px;
    box-sizing: border-box;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
    padding-right: 40px;
}

select:focus {
    outline: none;
    border-color: #0071e3;
}

hr {
    width: 100%;
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 0;
}

details {
    margin: 24px 0;
}

details summary {
    cursor: pointer;
    font-weight: 500;
    padding: 10px;
    background-color: var(--bg-color);
    border-radius: 8px;
    user-select: none;
}

details summary:hover {
    background-color: var(--border-color);
}

.api-content {
    margin-top: 20px;
}

.api-content h3 {
    font-size: 1.1em;
    margin: 20px 0 10px 0;
}

.api-content h3:first-child {
    margin-top: 10px;
}

.api-content pre {
    background-color: var(--bg-color);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
}

.api-content code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.9em;
}

.api-content ul {
    margin: 10px 0;
    padding-left: 25px;
}

.api-content li {
    margin: 5px 0;
}

.api-content p {
    margin: 10px 0;
}
