:root {
    /* Follow the browser's light/dark setting, and let built-in controls
       (scrollbars, file picker, inputs) follow it too */
    color-scheme: light dark;

    /* Material 3 baseline colour roles (design tokens).
       light-dark(A, B) picks A in light mode and B in dark mode. */
    --primary:                  light-dark(#6750a4, #d0bcff);
    --on-primary:               light-dark(#ffffff, #381e72);
    --primary-container:        light-dark(#eaddff, #4f378b);
    --on-primary-container:     light-dark(#21005d, #eaddff);
    --secondary-container:      light-dark(#e8def8, #4a4458);
    --on-secondary-container:   light-dark(#1d192b, #e8def8);
    --surface:                  light-dark(#fef7ff, #141218);
    --surface-container-low:    light-dark(#f7f2fa, #1d1b20);
    --surface-container:        light-dark(#f3edf7, #211f26);
    --surface-container-high:   light-dark(#ece6f0, #2b2930);
    --surface-container-highest:light-dark(#e6e0e9, #36343b);
    --on-surface:               light-dark(#1d1b20, #e6e0e9);
    --on-surface-variant:       light-dark(#49454f, #cac4d0);
    --outline:                  light-dark(#79747e, #938f99);
    --outline-variant:          light-dark(#cac4d0, #49454f);
    --error-container:          light-dark(#f9dedc, #8c1d18);
    --on-error-container:       light-dark(#410e0b, #f9dedc);
    --success-container:        light-dark(#d4efd0, #1d4d2b);
    --on-success-container:     light-dark(#0b2e13, #d4efd0);

    /* Material elevation levels 1 and 2 */
    --elevation-1: 0 1px 2px rgb(0 0 0 / 0.3), 0 1px 3px 1px rgb(0 0 0 / 0.15);
    --elevation-2: 0 1px 2px rgb(0 0 0 / 0.3), 0 2px 6px 2px rgb(0 0 0 / 0.15);
}

/* The hidden attribute loses against any rule that sets display,
   so make it always win */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 32px 16px 48px;
    min-height: 100dvh;
    /* A soft glow of the brand colour at the top of the page */
    background:
        radial-gradient(900px 420px at 50% -120px,
            color-mix(in srgb, var(--primary-container) 70%, transparent),
            transparent 70%),
        var(--surface);
    color: var(--on-surface);
    font: 1rem/1.5 system-ui, Roboto, "Segoe UI", sans-serif;
}

.icon {
    width: 24px;
    height: 24px;
    flex: none;
    fill: currentColor;
}

/* ---- header ---- */
.hero {
    max-width: 560px;
    margin: 0 auto 24px;
    text-align: center;
    animation: rise 0.5s ease-out both;
}
.hero-icon {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 24px;
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: var(--elevation-2);
}
.hero-icon .icon { width: 40px; height: 40px; }
h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}
.hero-sub {
    margin: 4px 0 0;
    color: var(--on-surface-variant);
}

/* ---- main card ---- */
.card {
    max-width: 560px;
    margin: 0 auto;
    padding: 8px 32px 32px;
    background: var(--surface-container-low);
    border-radius: 28px;
    box-shadow: var(--elevation-1);
    animation: rise 0.5s 0.08s ease-out both;
}
@keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

form { display: flex; flex-direction: column; }

.step { padding-top: 24px; }
.step + .step { margin-top: 24px; border-top: 1px solid var(--outline-variant); }

.step-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 14px;
    font-size: 1rem;
    font-weight: 500;
}
.step-number {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.875rem;
    font-weight: 600;
}

/* ---- filled text fields ---- */
input[type="text"], input[type="url"] {
    display: block;
    width: 100%;
    padding: 16px;
    background: var(--surface-container-highest);
    color: inherit;
    border: none;
    border-bottom: 1px solid var(--outline);
    border-radius: 8px 8px 0 0;
    font: inherit;
}
input[type="text"]:focus, input[type="url"]:focus {
    outline: none;
    border-bottom-color: var(--primary);
    box-shadow: inset 0 -1px 0 var(--primary); /* thickens the underline to 2px */
}
input::placeholder { color: var(--outline); }

input.key-input {
    font: 600 2.25rem ui-monospace, "SF Mono", Menlo, monospace;
    letter-spacing: 0.4em;
    text-indent: 0.4em; /* balances the space letter-spacing adds after the last character */
    text-align: center;
    text-transform: uppercase;
}
input.key-input::placeholder { font-weight: 400; }

.field-label {
    display: block;
    margin: 16px 0 6px;
    font-size: 0.875rem;
    color: var(--on-surface-variant);
}

/* ---- file drop area ---- */
.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 28px 16px;
    border: 2px dashed var(--outline);
    border-radius: 20px;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.dropzone .icon {
    width: 48px;
    height: 48px;
    margin-bottom: 4px;
    color: var(--primary);
}
.dropzone:hover, .dropzone.dragover {
    background: var(--primary-container);
    border-color: var(--primary);
}
.dropzone.dragover { border-style: solid; }
.dropzone:focus-within {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
/* Invisible but still focusable (display: none would break keyboard use) */
.dropzone input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}
.dropzone-title { font-weight: 500; }
.dropzone-hint {
    font-size: 0.875rem;
    color: var(--on-surface-variant);
}
.dropzone-file {
    white-space: pre-line;
    overflow-wrap: anywhere;
    font-size: 0.875rem;
}
/* Once a file is chosen, the area turns into a "file selected" card */
.dropzone:has(.dropzone-file:not(:empty)) {
    border-style: solid;
    border-color: var(--primary);
    background: var(--secondary-container);
    color: var(--on-secondary-container);
}
.dropzone:has(.dropzone-file:not(:empty)) .dropzone-hint { display: none; }
.dropzone-file:not(:empty) {
    margin-top: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--surface-container-low);
    font-weight: 500;
}

/* ---- conversion options ---- */
.options {
    border-radius: 16px;
    background: var(--surface-container);
}
.options summary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    list-style: none; /* hide the default triangle */
    font-weight: 500;
}
.options summary::-webkit-details-marker { display: none; }
.options summary .chevron {
    margin-left: auto;
    transition: transform 0.2s;
}
.options[open] summary .chevron { transform: rotate(180deg); }

.option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    cursor: pointer;
}
.option:last-child { padding-bottom: 14px; }
.option-text { flex: 1; }
.option-name { display: block; font-weight: 500; }
.option-desc {
    display: block;
    font-size: 0.875rem;
    color: var(--on-surface-variant);
}

/* Material switch, drawn on a checkbox */
.switch {
    appearance: none;
    position: relative;
    flex: none;
    width: 52px;
    height: 32px;
    margin: 0;
    border: 2px solid var(--outline);
    border-radius: 16px;
    background: var(--surface-container-highest);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.switch::before { /* the thumb */
    content: "";
    position: absolute;
    top: 50%;
    left: 6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--outline);
    transform: translateY(-50%);
    transition: left 0.2s, width 0.2s, height 0.2s, background 0.2s;
}
.switch:checked {
    background: var(--primary);
    border-color: var(--primary);
}
.switch:checked::before {
    left: 20px;
    width: 24px;
    height: 24px;
    background: var(--on-primary);
}
.switch:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---- submit button, progress, status message ---- */
.send {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 56px;
    margin-top: 20px;
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    border-radius: 999px;
    box-shadow: var(--elevation-1);
    font: inherit;
    font-size: 1.0625rem;
    font-weight: 500;
    cursor: pointer;
    transition: box-shadow 0.2s, filter 0.2s;
}
.send:hover { box-shadow: var(--elevation-2); filter: brightness(1.08); }
.send:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}
.send:disabled {
    opacity: 0.38;
    box-shadow: none;
    cursor: default;
}

#progresswrap { margin-top: 16px; }
progress {
    display: block;
    width: 100%;
    accent-color: var(--primary);
}
#progresslabel {
    margin-top: 6px;
    font-size: 0.875rem;
    text-align: center;
    color: var(--on-surface-variant);
}

#uploadstatus {
    margin-top: 16px;
    padding: 14px 18px;
    border-radius: 16px;
    white-space: pre-line;
    cursor: pointer;
}
#uploadstatus:empty { display: none; }
#uploadstatus.success {
    background: var(--success-container);
    color: var(--on-success-container);
}
#uploadstatus.error {
    background: var(--error-container);
    color: var(--on-error-container);
}

/* ---- privacy note, explanation, footer ---- */
.privacy, .how {
    max-width: 560px;
    margin: 20px auto 0;
    border-radius: 20px;
    animation: rise 0.5s 0.16s ease-out both;
}
.privacy {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--secondary-container);
    color: var(--on-secondary-container);
    font-size: 0.9375rem;
}
.how {
    background: var(--surface-container-low);
    box-shadow: var(--elevation-1);
}
.how summary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    cursor: pointer;
    list-style: none;
    font-weight: 500;
}
.how summary::-webkit-details-marker { display: none; }
.how summary .chevron {
    margin-left: auto;
    transition: transform 0.2s;
}
.how[open] summary .chevron { transform: rotate(180deg); }
.how-body {
    padding: 0 20px 8px;
    font-size: 0.9375rem;
    color: var(--on-surface-variant);
}

footer {
    max-width: 560px;
    margin: 24px auto 0;
    font-size: 0.8125rem;
    text-align: center;
    color: var(--on-surface-variant);
}
a { color: var(--primary); }

@media (max-width: 480px) {
    body { padding: 20px 12px 32px; }
    .card { padding: 4px 20px 24px; border-radius: 24px; }
    input.key-input { font-size: 1.875rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
