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

body {
    color-scheme: dark;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: #1a1a1a;
    color: #e0e0e0;
    font-family: sans-serif;
    padding: 2rem;
}

h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #aaa;
}

.card {
    background: #242424;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
    max-width: 1180px;
}

label {
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #888;
    display: block;
    margin-bottom: 0.4rem;
}

input[type="file"],
input[type="text"],
textarea {
    width: 100%;
    padding: 0.65rem 0.8rem;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;

    &:focus {
        border-color: #5b9bd5;
    }
}

textarea {
    resize: vertical;
    line-height: 1.5;
    min-height: 360px;
}

.row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.morph-row {
    justify-content: flex-start;
}

.rule-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1 1 100%;
}

.rule-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.rule-action-button {
    flex: 0 0 auto;
    min-width: 2.4rem;
    padding-inline: 0;
    font-size: 1rem;
}

.morph-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 100%;
    margin-bottom: 0.1rem;
}

.morph-heading label {
    width: auto;
    margin-bottom: 0;
}

.inline-label {
    color: #bbb;
    font-size: 0.95rem;
    white-space: nowrap;
}

.word-input {
    flex: 1 1 140px;
    min-width: 0;
}

.status {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 24px;
    font-size: 0.88rem;
    color: #888;
    width: auto;

    &[data-state="ready"] {
        color: #7fc6a4;
    }

    &[data-state="error"] {
        color: #d88972;
    }

    .spinner {
        width: 14px;
        height: 14px;
        border: 2px solid #444;
        border-top-color: #5b9bd5;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
        display: none;
    }

    &[data-busy="true"] .spinner {
        display: inline-block;
    }
}

.advanced-settings {
    border: 1px solid #333;
    border-radius: 8px;
    background: #1d1d1d;
    overflow: hidden;

    summary {
        cursor: pointer;
        list-style: none;
        padding: 0.9rem 1rem;
        color: #bcbcbc;
        font-size: 0.82rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;

        &::-webkit-details-marker {
            display: none;
        }
    }

    &[open] summary {
        border-bottom: 1px solid #333;
    }
}

.advanced-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.checkbox-row {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.96rem;
    color: #ddd;

    input {
        margin: auto 0.2rem;
    }

    small {
        display: block;
        margin-top: 0.18rem;
        color: #8d8d8d;
        font-size: 0.82rem;
        line-height: 1.45;
    }
}

.output-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.preview-pane {
    display: flex;
    flex-direction: column;
}

.actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.controls-actions {
    justify-content: flex-start;
}

button {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition:
        filter 0.15s,
        opacity 0.15s,
        background-color 0.15s,
        filter 0.15s;
    background: #5b9bd5;
    color: #fff;
    font-weight: 600;

    &.secondary {
        background: #3a3a3a;
        color: #ccc;
        border: 1px solid #555;
        font-weight: 400;
    }

    &:hover:not(:disabled) {
        filter: brightness(1.15);
    }

    &:active:not(:disabled) {
        filter: brightness(0.9);
    }

    &:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }
}

.help {
    width: 100%;
    max-width: 1180px;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;

    .help-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 0.9rem;
    }

    .help-intro {
        display: flex;
        align-items: baseline;
        column-gap: 1rem;
        border: 1px solid #313131;
        border-radius: 10px;
        padding: 1rem 1.1rem;
        color: #9a9a9a;
        font-size: 0.88rem;
        line-height: 1.55;

        .help-kicker {
            flex: 0 0 auto;
            font-size: 0.74rem;
            text-transform: uppercase;
            letter-spacing: 0.18em;
            color: #d3b46f;
        }

        .help-copy {
            max-width: 54rem;
        }
    }

    .help-card {
        flex: 1 1 17rem;
        border: 1px solid #313131;
        border-radius: 10px;
        padding: 1rem 1.1rem;
        color: #9a9a9a;
        font-size: 0.88rem;
        line-height: 1.55;

        h2 {
            font-size: 0.78rem;
            text-transform: uppercase;
            letter-spacing: 0.12em;
            color: #c2c2c2;
            margin-bottom: 0.65rem;
        }

        a {
            color: #9cc4eb;
            text-decoration: none;

            &:hover {
                text-decoration: underline;
            }
        }

        ul,
        ol {
            padding-left: 1.2rem;
        }
    }
}

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

@media (max-width: 640px) {
    body {
        justify-content: flex-start;
        padding: 1rem;
    }

    .card {
        padding: 1.2rem;
    }

    .help-intro {
        flex-direction: column;
        gap: 0.45rem;
    }

    .morph-row {
        align-items: stretch;
    }

    .morph-heading {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .morph-row button {
        width: 100%;
    }

    .actions button {
        width: 100%;
    }

    .preview-grid {
        grid-template-columns: 1fr;
    }
}
