.demo-theme-toggle,
.demo-theme-panel {
    font: inherit;
}

.demo-theme-toggle {
    position: fixed;
    z-index: 90;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    border: 1px solid color-mix(in srgb, var(--primary) 34%, var(--line));
    border-right: 0;
    border-radius: 10px 0 0 10px;
    background: color-mix(in srgb, var(--surface) 96%, var(--theme-background));
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0;
    padding: 12px 10px;
    writing-mode: vertical-rl;
}

.demo-theme-toggle:hover,
.demo-theme-toggle:focus-visible {
    border-color: var(--primary);
    color: var(--primary-dark);
}

.demo-theme-toggle:focus-visible,
.demo-theme-panel button:focus-visible,
.demo-theme-panel input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 42%, transparent);
    outline-offset: 2px;
}

.demo-theme-panel {
    position: fixed;
    z-index: 91;
    top: 50%;
    right: 16px;
    width: min(340px, calc(100vw - 32px));
    max-height: min(760px, calc(100vh - 32px));
    overflow: auto;
    transform: translateX(calc(100% + 32px)) translateY(-50%);
    border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface) 98%, var(--theme-background));
    box-shadow: 0 24px 72px rgba(15, 23, 42, 0.22);
    color: var(--text);
    opacity: 0;
    padding: 18px;
    pointer-events: none;
    transition: transform 180ms ease, opacity 180ms ease;
}

.demo-theme-panel.is-open {
    transform: translateX(0) translateY(-50%);
    opacity: 1;
    pointer-events: auto;
}

.demo-theme-panel__head {
    display: grid;
    gap: 6px;
    margin-bottom: 16px;
}

.demo-theme-panel__title {
    font-size: 1.08rem;
    line-height: 1.25;
    margin: 0;
}

.demo-theme-panel__text {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.45;
    margin: 0;
}

.demo-theme-panel__section {
    border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
    display: grid;
    gap: 10px;
    padding-top: 14px;
}

.demo-theme-panel__section + .demo-theme-panel__section {
    margin-top: 14px;
}

.demo-theme-panel__legend,
.demo-theme-panel__label {
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 700;
}

.demo-theme-panel__presets {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.demo-theme-panel__preset,
.demo-theme-panel__button {
    border: 1px solid color-mix(in srgb, var(--line) 88%, transparent);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    min-height: 38px;
    padding: 8px 10px;
}

.demo-theme-panel__preset:hover,
.demo-theme-panel__button:hover {
    border-color: color-mix(in srgb, var(--primary) 46%, var(--line));
    background: color-mix(in srgb, var(--primary) 7%, var(--surface));
}

.demo-theme-panel__preset[aria-pressed="true"] {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
    color: var(--primary-dark);
}

.demo-theme-panel__fields {
    display: grid;
    gap: 10px;
}

.demo-theme-panel__field {
    display: grid;
    gap: 6px;
}

.demo-theme-panel__field-row {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr auto;
}

.demo-theme-panel__color {
    border: 1px solid var(--line);
    border-radius: 8px;
    height: 38px;
    inline-size: 54px;
    padding: 3px;
}

.demo-theme-panel__range {
    accent-color: var(--primary);
    inline-size: 100%;
}

.demo-theme-panel__value {
    color: var(--muted);
    font-size: 0.82rem;
    min-width: 72px;
    text-align: right;
}

.demo-theme-panel__actions {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 1fr;
}

.demo-theme-panel__button--reset {
    color: var(--error-text);
}

@media (max-width: 640px) {
    .demo-theme-toggle {
        bottom: 0;
        right: 16px;
        top: auto;
        transform: none;
        border: 1px solid color-mix(in srgb, var(--primary) 34%, var(--line));
        border-bottom: 0;
        border-radius: 10px 10px 0 0;
        padding: 10px 14px;
        writing-mode: horizontal-tb;
    }

    .demo-theme-panel {
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        max-height: min(82vh, 720px);
        transform: translateY(100%);
        border-bottom: 0;
        border-radius: 14px 14px 0 0;
    }

    .demo-theme-panel.is-open {
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .demo-theme-panel {
        transition: none;
    }
}
