#search-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
}

#search-modal.open {
    display: block;
}

.search-panel {
    position: relative;
    width: min(640px, calc(100vw - 24px));
    margin: 52px auto 0;
    border-radius: 20px;
    overflow: hidden;
    background: var(--search-panel-bg) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.search-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
}

.search-input-row .ico {
    width: 18px;
    height: 18px;
    color: var(--muted);
}

#search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 18px;
}

#search-results {
    max-height: 40vh;
    overflow-y: auto;
    padding: 0 6px 8px;
}

.search-label {
    padding: 8px 14px;
    font-size: 12px;
    color: var(--muted);
}

.sr {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 12px;
}

.sr>.ico {
    margin-top: 3px;
    color: var(--muted);
}

.sr.on {
    background: var(--hover-bg);
}

.sr-body {
    min-width: 0;
}

.sr .t {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text);
}

.sr .s {
    display: -webkit-box;
    margin-top: 2px;
    font-size: 12.5px;
    line-height: 1.4;
    color: var(--muted);
    overflow: hidden;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.sr .p {
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sr .sep {
    margin: 0 6px;
    opacity: 0.7;
}

.sr .hit {
    font-weight: 700;
    color: var(--text);
}

.search-footer {
    display: flex;
    gap: 18px;
    padding: 12px 20px;
    font-size: 12px;
    color: var(--muted);
    border-top: 1px solid var(--border-subtle);
}

.search-footer .close-hint {
    margin-left: auto;
}

.search-footer kbd {
    margin-right: 4px;
    padding: 1px 5px;
    border-radius: 4px;
    font: 11px var(--font);
}

@media (max-width: 900px) {
    .search-panel {
        margin-top: 50px;
        border-radius: 30px;
    }

    .search-footer {
        display: none;
    }
}

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.sheet-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.sheet-panel {
    position: relative;
    width: min(500px, calc(100vw - 32px));
    background: var(--bg-modal);
    border-radius: 28px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    padding: 32px 28px 28px;
    box-sizing: border-box;
    transform: scale(0.92) translateY(16px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.sheet-overlay.active .sheet-panel {
    transform: scale(1) translateY(0);
}

.sheet-handle-bar {
    display: none;
}

.sheet-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 10px;
    line-height: 1.3;
    text-align: center;
}

.sheet-desc {
    font-size: 14.5px;
    color: var(--muted);
    line-height: 1.6;
    margin: 0 0 24px;
    text-align: center;
}

.sheet-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
}

.sheet-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    border-radius: 100px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text) !important;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none !important;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.sheet-btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.sheet-btn-never {
    padding: 10px 18px;
    border: none;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 100px;
    transition: color 0.15s ease, background 0.15s ease;
}

.sheet-btn-never:hover {
    color: var(--text);
    background: var(--hover-bg);
}

@media (max-width: 900px) {
    .sheet-overlay {
        align-items: flex-end;
    }

    .sheet-panel {
        width: 100%;
        max-width: 100%;
        border-radius: 28px 28px 0 0;
        border-bottom: none;
        padding: 14px 22px 32px;
        transform: translateY(100%);
        transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
        touch-action: none;
        max-height: 90vh;
    }

    .sheet-panel.dragging {
        transition: none !important;
    }

    .sheet-overlay.active .sheet-panel {
        transform: translateY(0);
    }

    .sheet-handle-bar {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 6px 0 16px;
        cursor: grab;
    }

    .sheet-handle {
        width: 40px;
        height: 5px;
        border-radius: 999px;
        background: var(--muted);
        opacity: 0.45;
    }

    .sheet-actions {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }

    .sheet-btn-primary {
        width: 100%;
    }

    .sheet-btn-never {
        width: 100%;
        text-align: center;
    }
}

@media (orientation: landscape) and (max-height: 550px) {
    .sheet-panel {
        max-height: 94vh;
        overflow-y: auto;
        padding: 10px max(24px, env(safe-area-inset-right)) 16px max(24px, env(safe-area-inset-left));
    }

    .sheet-title {
        font-size: 18px;
        margin-bottom: 6px;
    }

    .sheet-desc {
        font-size: 13px;
        margin-bottom: 12px;
        line-height: 1.45;
    }

    .sheet-actions {
        flex-direction: row;
        gap: 10px;
    }

    .sheet-btn-primary,
    .sheet-btn-never {
        width: auto;
        padding: 8px 18px;
        font-size: 13px;
    }
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: transparent;
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    opacity: 0;
    pointer-events: none;
    transition: background 0.42s cubic-bezier(0.2, 0.9, 0.3, 1),
        backdrop-filter 0.42s cubic-bezier(0.2, 0.9, 0.3, 1),
        opacity 0.25s ease;
}

.image-lightbox.active {
    background: var(--bg-modal);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    opacity: 1;
    pointer-events: auto;
}

.lightbox-controls {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    display: flex;
    align-items: center;
    gap: 3px;
    z-index: 2003;
    background: var(--bg-menu);
    border-radius: 100px;
    padding: 3px 6px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1) 0.08s,
        transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) 0.08s;
}

.image-lightbox.active .lightbox-controls {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.lightbox-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.lightbox-btn:hover {
    background: var(--hover-bg);
    color: var(--text);
}

.lightbox-btn svg {
    display: block;
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

.lightbox-img {
    position: fixed;
    object-fit: contain;
    border-radius: 16px;
    transition: top 0.44s cubic-bezier(0.2, 0.9, 0.3, 1),
        left 0.44s cubic-bezier(0.2, 0.9, 0.3, 1),
        width 0.44s cubic-bezier(0.2, 0.9, 0.3, 1),
        height 0.44s cubic-bezier(0.2, 0.9, 0.3, 1),
        border-radius 0.44s cubic-bezier(0.2, 0.9, 0.3, 1),
        transform 0.25s ease;
    z-index: 2002;
    transform-origin: center center;
    will-change: top, left, width, height, transform;
}

main.prose img {
    cursor: zoom-in;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

main.prose img:hover {
    opacity: 0.95;
}

#settings-trigger,
.side-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: none;
    color: var(--muted);
    cursor: pointer;
}

#settings-trigger .ico,
.side-settings .ico {
    width: 18px;
    height: 18px;
}

#settings-trigger:hover,
.side-settings:hover {
    background: var(--hover-bg);
    color: var(--text);
}

.settings-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.st-top,
.st-bottom {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 3;
    isolation: isolate;
}

.st-top::before,
.st-bottom::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    backdrop-filter: blur(18px) saturate(1.2);
    -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

.st-top {
    top: 0;
    padding: 26px 28px 30px;
}

.st-top::before {
    background: linear-gradient(to bottom, var(--bg-menu) 40%, transparent);
    background: linear-gradient(to bottom, color-mix(in srgb, var(--bg-menu) 94%, transparent), color-mix(in srgb, var(--bg-menu) 80%, transparent) 60%, transparent);
    -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
    mask-image: linear-gradient(to bottom, #000 55%, transparent);
}

.st-top .sheet-title {
    margin: 0 0 6px;
    font-size: 20px;
}

.st-top .sheet-desc {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.5;
}

.st-bottom {
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 36px 28px calc(20px + env(safe-area-inset-bottom));
}

.st-bottom::before {
    background: linear-gradient(to top, var(--bg-menu) 40%, transparent);
    background: linear-gradient(to top, color-mix(in srgb, var(--bg-menu) 94%, transparent), color-mix(in srgb, var(--bg-menu) 80%, transparent) 60%, transparent);
    -webkit-mask-image: linear-gradient(to top, #000 55%, transparent);
    mask-image: linear-gradient(to top, #000 55%, transparent);
}

.st-bottom .sheet-btn-primary {
    border: none;
    font-family: inherit;
    cursor: pointer;
}

.st-bottom .sheet-btn-primary.done {
    opacity: 0.85;
}

.st-scroll {
    flex: 1;
    min-height: 0;
    padding: var(--st-top, 110px) 28px var(--st-bottom, 84px);
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.st-group {
    margin-bottom: 18px;
}

.st-heading {
    margin: 0 0 8px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.st-card {
    border-radius: 20px;
    background: var(--hover-bg);
    overflow: hidden;
}

.st-row,
.st-field {
    display: flex;
    gap: 14px;
    padding: 14px 16px;
    border-top: 1px solid var(--border-subtle);
    cursor: default;
}

.st-card>:first-child {
    border-top: none;
}

.st-row {
    align-items: center;
    justify-content: space-between;
}

.st-row.stack {
    flex-direction: column;
    align-items: stretch;
}

label.st-row {
    cursor: pointer;
}

.st-field {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.st-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.st-label {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text);
}

.st-hint {
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--muted);
}

.st-hint.err {
    color: #ef4444;
}

.st-input {
    width: 100%;
    height: 40px;
    padding: 0 16px;
    border: none;
    border-radius: 100px;
    background: var(--search-bg);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease;
}

.st-input::placeholder {
    color: var(--muted);
    opacity: 0.8;
}

.st-input:focus {
    border-color: var(--text);
}

.st-input.bad {
    border-color: #ef4444;
}

.st-swatches {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.st-swatch {
    display: block;
    position: relative;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--sw, var(--hover-bg));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.st-swatch:hover {
    transform: scale(1.12);
}

.st-swatch.on {
    box-shadow: 0 0 0 2px var(--bg-menu), 0 0 0 4px var(--text);
    ;
}

.st-swatch.reset {
    background: linear-gradient(135deg, transparent 46%, var(--muted) 46%, var(--muted) 54%, transparent 54%), var(--search-bg);
    box-shadow: inset 0 0 0 1.5px var(--muted);
}

.st-swatch.reset.on {
    box-shadow: inset 0 0 0 1.5px var(--muted), 0 0 0 2px var(--bg-menu), 0 0 0 4px var(--text);
    ;
}

.st-swatch.custom {
    background: conic-gradient(from 0deg, #ff5c5c, #f4b942, #5fd68f, #8ad1ff, #c084fc, #ff5c5c);
}

.st-swatch.custom input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: none;
    opacity: 0;
    cursor: pointer;
}

.st-seg {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 100px;
    background: var(--search-bg);
}

.st-seg button {
    flex: 1;
    height: 32px;
    padding: 0 10px;
    border: none;
    border-radius: 100px;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.st-seg button:hover {
    color: var(--text);
}

.st-seg button.on {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
}

.st-switch {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 26px;
}

.st-switch input {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.st-track {
    position: absolute;
    inset: 0;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: var(--search-bg);
    transition: background 0.2s ease, border-color 0.2s ease;
}

.st-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease;
}

.st-switch input:checked+.st-track {
    border-color: transparent;
    background: var(--btn-primary-bg);
}

.st-switch input:checked+.st-track::after {
    transform: translateX(18px);
    background: var(--btn-primary-text);
}

.st-switch input:focus-visible+.st-track {
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

@media (min-width: 901px) {
    .settings-panel {
        width: min(540px, calc(100vw - 32px));
        max-height: min(88vh, 780px);
    }
}

@media (max-width: 900px) {
    .st-top {
        padding: 8px 22px 28px;
    }

    .st-scroll {
        padding-left: 22px;
        padding-right: 22px;
    }

    .st-bottom {
        padding: 36px 22px calc(18px + env(safe-area-inset-bottom));
    }

    .st-bottom .sheet-btn-primary {
        flex: 1;
        width: auto;
    }

    .st-bottom .sheet-btn-never {
        flex: 0 0 auto;
        width: auto;
    }
}

@media (orientation: landscape) and (max-height: 550px) {
    .settings-panel {
        max-height: 94vh;
    }

    .st-top {
        padding: 14px 24px 22px;
    }

    .st-top .sheet-title {
        font-size: 17px;
        margin-bottom: 0;
    }

    .st-top .sheet-desc {
        display: none;
    }
}