:root {
    color-scheme: dark;
    --ui-ink: #ffffff;
    --ui-muted: hsla(0, 0%, 100%, 0.6);
    --ui-hairline: hsla(0, 0%, 100%, 0.1);
    --ui-glass: hsla(0, 0%, 100%, 0.08);
    --ui-shadow: hsla(0, 0%, 0%, 0.5);
    --ui-ring: hsla(0, 0%, 100%, 0.9);
    --ui-ring-text: hsla(0, 0%, 0%, 1);
    --form-bg: hsla(0, 0%, 100%, 0.08);
    --form-border: hsla(0, 0%, 100%, 0.1);
    --input-bg: hsla(0, 0%, 0%, 0.2);
    --input-placeholder: hsla(0, 0%, 100%, 0.4);
    --assist-bg: hsla(0, 0%, 100%, 0.08);
    --assist-bg-strong: hsla(0, 0%, 100%, 0.12);
    --assist-card-bg: hsla(0, 0%, 100%, 0.1);
    --assist-ghost-border: hsla(0, 0%, 100%, 0.15);
    --assist-key-bg: hsla(0, 0%, 100%, 0.12);
    --assist-key-border: hsla(0, 0%, 100%, 0.1);
    --assist-shadow: hsla(0, 0%, 0%, 0.3);
    --toast-bg: hsla(0, 0%, 9%, 0.7);
    --toast-border: hsla(0, 0%, 100%, 0.08);
    --toast-fg: hsla(0, 0%, 100%, 0.75);
    --dock-radius: 14px;
    --swatch-radius: 8px;
}

body.ui-light {
    --ui-ink: #111827;
    --ui-muted: hsla(0, 0%, 0%, 0.6);
    --ui-hairline: hsla(0, 0%, 0%, 0.1);
    --ui-glass: hsla(0, 0%, 100%, 0.5);
    --ui-shadow: hsla(0, 0%, 0%, 0.15);
    --ui-ring: hsla(0, 0%, 0%, 0.9);
    --ui-ring-text: hsla(0, 0%, 100%, 1);
    --form-bg: hsla(0, 0%, 100%, 0.4);
    --form-border: hsla(0, 0%, 0%, 0.15);
    --input-bg: hsla(0, 0%, 0%, 0.05);
    --input-placeholder: hsla(0, 0%, 0%, 0.4);
    --assist-bg: hsla(0, 0%, 100%, 0.3);
    --assist-bg-strong: hsla(0, 0%, 100%, 0.4);
    --assist-card-bg: hsla(0, 0%, 100%, 0.25);
    --assist-ghost-border: hsla(0, 0%, 0%, 0.15);
    --assist-key-bg: hsla(0, 0%, 0%, 0.08);
    --assist-key-border: hsla(0, 0%, 0%, 0.08);
    --assist-shadow: hsla(0, 0%, 0%, 0.15);
    --toast-bg: hsla(0, 0%, 100%, 0.85);
    --toast-border: hsla(0, 0%, 0%, 0.1);
    --toast-fg: hsla(0, 0%, 0%, 0.75);
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    background: black;
    transition: background-color 170ms linear;
    font-family:
        "Inter",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

#controls {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: end center;
    padding: clamp(14px, 4vh, 38px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 720ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 720ms;
    z-index: 10;
}

#controls.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity 460ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 0s;
}

.dock-wrap {
    display: grid;
    justify-items: center;
    gap: 12px;
    transform: translateY(20px) scale(0.97);
    filter: blur(10px);
    transition:
        transform 560ms cubic-bezier(0.22, 1, 0.36, 1),
        filter 560ms cubic-bezier(0.22, 1, 0.36, 1);
}

#controls.visible .dock-wrap {
    transform: translateY(0) scale(1);
    filter: blur(0);
}

.dock {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-radius: var(--dock-radius);
    background: var(--ui-glass);
    border: 1px solid var(--ui-hairline);
    box-shadow: 0 16px 32px var(--ui-shadow);
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
}

.swatch {
    position: relative;
    width: 44px;
    height: 44px;
    border: 1px solid hsla(0, 0%, 100%, 0.1);
    border-radius: var(--swatch-radius);
    padding: 0;
    cursor: pointer;
    box-shadow: inset 0 1px 0 hsla(0, 0%, 100%, 0.1);
    transition:
        transform 150ms ease,
        box-shadow 150ms ease,
        border-color 150ms ease;
    background-clip: padding-box;
}

body.ui-light .swatch {
    border: 1px solid hsla(0, 0%, 0%, 0.1);
    box-shadow: inset 0 1px 0 hsla(0, 0%, 100%, 0.5);
}

.swatch.is-active {
    border-color: var(--ui-ring);
    box-shadow: 0 0 0 1px var(--ui-ring);
}

.swatch-black {
    background-color: #000000;
}
.swatch-white {
    background-color: #ffffff;
}
.swatch-red {
    background-color: #ff3b30;
}

.swatch-custom {
    background: hsla(0, 0%, 100%, 0.05);
    color: var(--ui-ink);
    font-size: 20px;
    line-height: 1;
    font-weight: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.ui-light .swatch-custom {
    background: hsla(0, 0%, 0%, 0.05);
}

.swatch-custom span {
    display: inline-block;
    transform: translateY(-1px);
}

.swatch:focus-visible,
.custom-form input:focus-visible,
.apply-btn:focus-visible,
.help-ghost:focus-visible,
.shortcut-action:focus-visible {
    outline: 2px solid var(--ui-ring);
    outline-offset: 2px;
}

.custom-form {
    width: min(92vw, 420px);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--dock-radius);
    background: var(--form-bg);
    border: 1px solid var(--form-border);
    box-shadow: 0 16px 32px var(--ui-shadow);
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    pointer-events: none;
    visibility: hidden;
    transition:
        opacity 320ms ease,
        transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 320ms;
}

.custom-form.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
    transition:
        opacity 320ms ease,
        transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 0s;
}

.color-dot {
    width: 16px;
    height: 16px;
    margin-left: 4px;
    border-radius: 50%;
    border: 1px solid var(--ui-hairline);
    background: black;
}

.custom-form input,
.apply-btn {
    border: 0;
    border-radius: 6px;
    box-sizing: border-box;
    outline: none;
}

.custom-form input {
    min-width: 0;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    background: var(--input-bg);
    border: 1px solid var(--ui-hairline);
    color: var(--ui-ink);
    transition: border-color 150ms ease;
}

.custom-form input:focus {
    border-color: hsla(0, 0%, 100%, 0.3);
}

body.ui-light .custom-form input:focus {
    border-color: hsla(0, 0%, 0%, 0.3);
}

.custom-form input::placeholder {
    color: var(--input-placeholder);
    font-weight: 400;
}

.apply-btn {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--ui-ring-text);
    font-size: 14px;
    font-weight: 500;
    background: var(--ui-ring);
    transition: filter 150ms ease;
    border-radius: 6px;
}

#error {
    min-height: 16px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    color: #ff453a;
    letter-spacing: 0.01em;
    text-align: center;
    opacity: 0;
    transition: opacity 160ms ease;
}

#error.visible {
    opacity: 1;
}

.help-ghost {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 22;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--assist-ghost-border);
    border-radius: 50%;
    background: var(--assist-bg-strong);
    color: var(--ui-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    opacity: 0.8;
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    transition:
        opacity 200ms ease,
        transform 200ms ease,
        color 200ms ease,
        background 200ms ease;
    box-shadow: 0 4px 12px var(--assist-shadow);
}

.help-ghost.active {
    opacity: 1;
    color: var(--ui-ink);
    background: var(--assist-card-bg);
}

.help-card {
    position: fixed;
    right: 24px;
    bottom: 76px;
    z-index: 21;
    width: min(92vw, 190px);
    padding: 16px;
    border-radius: var(--dock-radius);
    border: 1px solid var(--form-border);
    background: var(--assist-card-bg);
    box-shadow: 0 20px 40px var(--assist-shadow);
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    color: var(--ui-ink);
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 240ms ease,
        transform 240ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 240ms;
}

.help-card.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity 240ms ease,
        transform 240ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 0s;
}

.keys {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

.help-credit {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--assist-ghost-border);
    text-align: center;
    font-size: 11px;
    font-weight: 400;
    color: var(--ui-muted);
    opacity: 0.6;
}

.help-credit a {
    color: inherit;
    text-decoration: none;
    transition:
        opacity 150ms ease,
        color 150ms ease;
}

.help-credit a:hover {
    opacity: 1;
    color: var(--ui-ink);
}

.shortcut {
    width: 100%;
    min-height: 40px;
    padding: 6px 8px 6px 10px;
    border-radius: 6px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    box-sizing: border-box;
    cursor: pointer;
    color: var(--ui-ink);
    transition: background 150ms ease;
}

.shortcut:hover {
    background: var(--assist-key-bg);
}

.shortcut-label {
    color: var(--ui-muted);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    text-align: left;
}

.shortcut-key {
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid var(--assist-key-border);
    background: var(--assist-key-bg);
    color: var(--ui-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.1);
}

body.ui-light .shortcut-key {
    box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.05);
}

.shortcut-action {
    appearance: none;
    font: inherit;
    text-align: left;
}

.shortcut-action.active {
    background: var(--assist-key-bg);
}

.shortcut-action.active .shortcut-key {
    border-color: var(--ui-ring);
    color: var(--ui-ring);
}

.hint-toast {
    position: fixed;
    left: 50%;
    bottom: calc(clamp(14px, 4vh, 38px) + 96px);
    transform: translateX(-50%) translateY(8px);
    z-index: 9;
    padding: 10px 24px;
    border-radius: 999px;
    border: 1px solid var(--toast-border);
    background: var(--toast-bg);
    color: var(--toast-fg);
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 900ms ease,
        transform 900ms ease,
        visibility 0s linear 900ms;
    pointer-events: none;
    box-shadow: 0 10px 30px var(--ui-shadow);
}

.hint-toast.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    transition:
        opacity 1800ms ease,
        transform 1800ms ease,
        visibility 0s linear 0s;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.noscript-banner {
    position: fixed;
    inset: auto 14px 14px;
    z-index: 30;
    max-width: min(560px, calc(100vw - 28px));
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--ui-hairline);
    background: var(--assist-bg-strong);
    color: var(--ui-ink);
    font-size: 14px;
    font-weight: 500;
}

@media (hover: hover) and (pointer: fine) {
    .swatch:hover {
        transform: translateY(-2px);
    }

    .help-ghost:hover {
        opacity: 1;
        background: var(--assist-card-bg);
    }

    .apply-btn:hover {
        filter: brightness(1.1);
    }
}

.swatch:active {
    transform: translateY(0);
}

.apply-btn:active {
    transform: translateY(1px);
}

@media (max-width: 540px) {
    .dock {
        gap: 8px;
        padding: 8px;
    }
    .swatch {
        width: 40px;
        height: 40px;
    }
    .custom-form input {
        font-size: 16px;
    }
    .help-card {
        right: 14px;
        bottom: 70px;
        width: min(94vw, 190px);
    }
    .help-ghost {
        right: 14px;
        bottom: 14px;
    }
}
