:root {
    --bg-dark: #161c27;
    --primary: #379dd8;
    --error: #e86f6f;
    --text: #e2e8f0;
    --muted: #9aa4b2;
    --border: #4d545f;
    --radius: 20px;
    --font: Roboto, system-ui, Segoe UI, Arial, sans-serif;
    --form-max: 820px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
    zoom: 1.1;
}

body::-webkit-scrollbar {
    display: none;
}

body {
    background: var(--bg-dark);
    color: var(--text);
    font-family: var(--font);
    display: block;
}

header {
    width: 100%;
    max-width: var(--form-max);
    margin: 10px auto 6px;
    text-align: center;
}

header pre {
    display: grid;
    font-size: 1.5rem;
    justify-content: center;
    align-content: center;
    text-align: center;
    margin: 0;
}

main.container {
    width: 100%;
    max-width: var(--form-max);
    margin: 0 auto;
    padding: 12px 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.container--stretch {
    align-items: stretch;
}

.row--left {
    justify-content: flex-start;
}

.gap-12 {
    gap: 12px;
}

.mt-8 {
    margin-top: 8px;
}

.is-hidden {
    display: none !important;
}

#tunName {
    min-width: 180px;
}

.full {
    width: 100%;
    max-width: var(--form-max);
}

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: var(--form-max);
}

label {
    font-size: 14px;
    color: var(--text);
}

.toolbar {
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
}

.toolbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.api-link {
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
    text-decoration: none;
    opacity: .7;
    padding: 2px 4px;
    border-radius: 8px;
    transition: opacity .15s ease, color .15s ease, background-color .15s ease;
}

.api-link:hover {
    opacity: 1;
    color: var(--primary);
}

.api-link:focus-visible {
    opacity: 1;
    color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(55, 157, 216, .15);
    background: rgba(55, 157, 216, .06);
}

.toolbar .core-toggle {
    width: auto;
    flex: 1 1 auto;
    max-width: none;
}

.chevron-toggle {
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text);
    height: 40px;
    padding: 0 6px;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.chevron-toggle svg {
    transition: transform .15s ease;
}

.chevron-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.chevron-toggle:hover {
    color: var(--primary);
    background: rgba(55, 157, 216, .06);
}

.chevron-toggle:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 3px rgba(55, 157, 216, .15);
}

.settings-panel {
    width: 100%;
    max-width: var(--form-max);
    overflow: hidden;
    max-height: 260px;
    opacity: 1;
    transform: translateY(0);
    transition: max-height .18s ease-in-out, opacity .18s ease-in-out, transform .18s ease-in-out;
    padding: 0 20px;
}

.settings-panel--collapsed {
    max-height: 0;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
}

.settings-panel__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 8px;
}

.settings-panel__field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}

.file-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

#asciiHeader {
    cursor: pointer;
    position: relative;
}

.api-link--header {
    position: absolute;
    right: 18px;
    bottom: 12px;
    transform: none;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .25);
    backdrop-filter: blur(6px);
}

@media (max-width: 520px) {
    .api-link--header {
        bottom: 10px;
        right: 12px;
    }
}

.snowfall {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    z-index: 70;
    overflow: hidden;
}

.snowfall__flake {
    position: absolute;
    top: -12px;
    border-radius: 999px;
    --snowfall-sway: 20px;
    --snowfall-size: 16px;
    --snowfall-opacity: 0.7;
    width: var(--snowfall-size);
    height: var(--snowfall-size);
    opacity: var(--snowfall-opacity);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
    animation-name: snowfall-float;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.snowfall__glyph {
    font-size: var(--snowfall-size);
    line-height: 1;
    color: rgba(255, 255, 255, 0.95);
    font-family: Arial, sans-serif;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.25);
}

@keyframes snowfall-float {
    0% {
        transform: translate3d(0, -20px, 0);
    }
    50% {
        transform: translate3d(var(--snowfall-sway, 20px), 50vh, 0);
    }
    100% {
        transform: translate3d(0, calc(100vh + 40px), 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .snowfall {
        display: none;
    }
}

.input, select, textarea {
    background: var(--bg-dark);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    width: 100%;
    max-width: var(--form-max);
}

.input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(55, 157, 216, .2);
}

.input-loading {
    position: relative;
    border-color: rgba(55, 157, 216, .9);
    box-shadow: 0 0 0 1px rgba(55, 157, 216, .75),
    0 0 14px 3px rgba(55, 157, 216, .55),
    0 0 26px 8px rgba(55, 157, 216, .35);
    animation: inputGlow 1.4s linear infinite;
}

@keyframes inputGlow {
    0% {
        box-shadow: 0 0 0 1px rgba(55, 157, 216, .55),
        0 0 10px 2px rgba(55, 157, 216, .4),
        0 0 18px 5px rgba(55, 157, 216, .25);
    }
    50% {
        box-shadow: 0 0 0 1px rgba(55, 157, 216, 1),
        0 0 18px 4px rgba(55, 157, 216, .75),
        0 0 32px 10px rgba(55, 157, 216, .5);
    }
    100% {
        box-shadow: 0 0 0 1px rgba(55, 157, 216, .55),
        0 0 10px 2px rgba(55, 157, 216, .4),
        0 0 18px 5px rgba(55, 157, 216, .25);
    }
}

@media (prefers-reduced-motion: reduce) {
    .input-loading {
        animation: none;
    }
}

#links.input-error,
textarea.input-error,
input.input-error,
select.input-error {
    border-color: var(--error) !important;
    box-shadow: 0 0 0 3px rgba(232, 111, 111, .25) !important;
}

#links.input-error:hover,
#links.input-error:focus {
    border-color: var(--error) !important;
    box-shadow: 0 0 0 3px rgba(232, 111, 111, .3) !important;
}

#links {
    height: 165px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    resize: vertical;
}

#links::-webkit-scrollbar {
    display: none;
}

#out {
    height: 340px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    scrollbar-width: none;
    -ms-overflow-style: none;
    width: 100%;
    max-width: var(--form-max);
}

#out::-webkit-scrollbar {
    display: none;
}

.button-row {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: var(--form-max);
}

.btn-primary, input[type="submit"] {
    background: transparent;
    color: white;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 10px 16px;
    cursor: pointer;
}

input[type="submit"]:active, button:active {
    transform: scale(0.95);
}

input[type="submit"][disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.circle-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.core-toggle {
    --core-count: 3;
    --core-index: 0;
    position: relative;
    width: 100%;
    max-width: calc(var(--form-max) - 120px);
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(var(--core-count), 1fr);
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.core-toggle .labels {
    position: relative;
    z-index: 2;
    display: contents;
}

.core-toggle .labels span {
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    color: white;
}

.core-toggle .knob {
    position: absolute;
    z-index: 1;
    top: 2px;
    bottom: 2px;
    width: calc((100% / var(--core-count)) - 4px);
    border-radius: 999px;
    background: rgba(55, 157, 216, 0.25);
    border: 1px solid var(--primary);
    transition: left .2s ease;
    left: calc((100% / var(--core-count)) * var(--core-index) + 2px);
}

.custom-checkbox {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-dark);
    transition: all 0.2s ease;
    min-width: fit-content;
    -webkit-tap-highlight-color: transparent;
}

.custom-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.custom-checkbox .checkmark {
    position: relative;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: var(--bg-dark);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.custom-checkbox input[type="checkbox"]:checked + .checkmark {
    background: var(--primary);
    border-color: var(--primary);
}

.custom-checkbox input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.custom-checkbox input[type="checkbox"]:focus + .checkmark {
    box-shadow: 0 0 0 2px rgba(55, 157, 216, 0.3);
}

.custom-checkbox span {
    font-size: 13px;
    font-weight: 400;
    color: var(--text);
}

.custom-checkbox:active {
    transform: scale(0.97);
}

.settings-panel__chips .custom-checkbox {
    border-radius: 999px;
    border-width: 1px;
    border-color: transparent;
    background: rgba(148, 163, 184, 0.12);
    padding: 7px 14px;
    gap: 6px;
    min-width: 0;
}

.settings-panel__chips .custom-checkbox .checkmark {
    display: none;
}

.settings-panel__chips .custom-checkbox span {
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
}

.settings-panel__chips .custom-checkbox:has(input[type="checkbox"]:checked) {
    background: var(--primary);
    border-color: var(--primary);
    color: #0b1120;
}

.settings-panel__chips .custom-checkbox:has(input[type="checkbox"]:checked) span {
    color: #ffffff;
}

.settings-panel__chips .custom-checkbox.is-active {
    background: var(--primary);
    border-color: var(--primary);
}

.settings-panel__chips .custom-checkbox.is-active span {
    color: #ffffff;
}

.hidden {
    display: none !important;
}

#errorText {
    line-height: 24px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

@media (hover: hover) and (pointer: fine) {
    .input:hover,
    textarea:hover,
    select:hover {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(55, 157, 216, .15);
    }

    .btn-primary:hover,
    input[type="submit"]:hover {
        background: var(--primary);
        color: white;
    }

    .circle-btn:hover {
        background: var(--primary);
        color: white;
    }

    .custom-checkbox:hover {
        border-color: var(--primary);
        background: rgba(55, 157, 216, 0.1);
    }

    .settings-panel__chips .custom-checkbox:hover {
        border-color: var(--primary);
        background: rgba(55, 157, 216, 0.16);
    }
}

@media (max-width: 600px) {
    html, body {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        position: relative !important;
        width: 100vw;
        zoom: 1;
    }

    header {
        max-width: 100%;
        margin: 8px auto 4px;
    }

    header pre {
        margin: 0;
        font-size: 0.65rem;
    }

    main.container {
        max-width: 100%;
        padding: 8px 12px 14px;
        gap: 10px;
    }

    .core-toggle {
        height: 42px;
    }

    .core-toggle .labels span {
        font-size: 14px;
    }

    .core-toggle .knob {
        top: 3px;
        bottom: 3px;
        width: calc((100% / var(--core-count)) - 6px);
    }

    .input {
        font-size: 14px;
        padding: 10px 12px;
        max-width: 100%;
    }

    textarea {
        width: 100% !important;
        font-size: 13px;
    }

    #links {
        height: 120px;
    }

    #out {
        height: 260px;
    }

    .button-row {
        max-width: 100%;
    }

    input[type="submit"] {
        padding: 10px 14px;
        font-size: 14px;
    }

    .circle-btn {
        width: 40px;
        height: 40px;
    }

    .settings-panel {
        width: 100vw;
        max-width: 100vw;
        margin-left: calc(50% - 50vw);
        margin-right: calc(50% - 50vw);
        padding-left: 0;
        padding-right: 0;
    }

    .settings-panel__field {
        padding: 0 12px;
    }

    .settings-panel__chips {
        position: relative;
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        margin: 4px 0 8px;
        padding: 0 12px;
        gap: 8px;
        scroll-snap-type: x mandatory;
        scroll-padding: 0 12px;
        scrollbar-width: none;
        touch-action: pan-x;
        overscroll-behavior-x: contain;
        background:
            linear-gradient(90deg, var(--bg-dark) 0%, transparent 100%) 0 0 / 18px 100% no-repeat,
            linear-gradient(270deg, var(--bg-dark) 0%, transparent 100%) 100% 0 / 18px 100% no-repeat;
        background-attachment: local, local;
    }

    .settings-panel__chips::-webkit-scrollbar {
        display: none;
    }

    .settings-panel__chips .custom-checkbox {
        flex: 0 0 auto;
        scroll-snap-align: start;
        scroll-snap-stop: normal;
        white-space: nowrap;
    }
}