/* ---- Settings: Overlay & panel ---- */
.settings-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.4s ease, opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-overlay.settings-open {
    pointer-events: auto;
    visibility: visible;
    opacity: 1;
}

.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-overlay.settings-open .settings-backdrop {
    opacity: 1;
}

.settings-panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    height: 100%;
    background: rgba(10, 10, 14, 0.95);
    backdrop-filter: blur(32px);
    -webkit-backdrop-filter: blur(32px);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    transform: translateX(100%);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform;
    display: flex;
    flex-direction: column;
}

.settings-overlay.settings-open .settings-panel {
    transform: translateX(0);
}

.settings-panel-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ---- Settings: Header ---- */
.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 28px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    animation: settingsHeaderIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.settings-overlay.settings-open .settings-header {
    animation-delay: 0.05s;
}

@keyframes settingsHeaderIn {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.settings-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    margin: 0;
    letter-spacing: -0.5px;
}

.settings-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s var(--ease-snap);
}

.settings-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transform: rotate(90deg);
}

/* ---- Settings: Body ---- */
.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px 40px;
    display: flex;
    flex-direction: column;
    gap: 36px;
}

.settings-section {
    animation: settingsSectionIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.settings-overlay.settings-open .settings-section[data-section="performance"] {
    animation-delay: 0.1s;
}

.settings-overlay.settings-open .settings-section[data-section="themes"] { animation-delay: 0.18s; }
.settings-overlay.settings-open .settings-section[data-section="app"] { animation-delay: 0.26s; }
.settings-overlay.settings-open .settings-section[data-section="appearance"] { animation-delay: 0.34s; }
.settings-overlay.settings-open .settings-section[data-section="defaults"] { animation-delay: 0.42s; }
.settings-overlay.settings-open .settings-section[data-section="accessibility"] { animation-delay: 0.5s; }
.settings-overlay.settings-open .settings-section[data-section="data"] { animation-delay: 0.58s; }
.settings-overlay.settings-open .settings-section[data-section="about"] { animation-delay: 0.66s; }

@keyframes settingsSectionIn {
    from {
        opacity: 0;
        transform: translateX(24px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.settings-section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 0 0 16px;
    padding-bottom: 8px;
}

/* ---- Performance options ---- */
.settings-perf-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-perf-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    cursor: pointer;
    text-align: left;
    transition: all 0.35s var(--ease-snap);
    color: var(--text-secondary);
}

.settings-perf-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateX(4px);
}

.settings-perf-btn.active {
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.12);
    border-color: rgba(var(--accent-rgb, 59, 130, 246), 0.4);
    color: white;
    box-shadow: 0 0 24px -6px rgba(var(--accent-rgb, 59, 130, 246), 0.3);
}

.settings-perf-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    font-size: 1.1rem;
    color: var(--accent);
    flex-shrink: 0;
    transition: all 0.35s var(--ease-snap);
}

.settings-perf-btn.active .settings-perf-icon {
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.25);
    color: white;
    transform: scale(1.05);
}

.settings-perf-btn span:nth-child(2) {
    font-weight: 600;
    font-size: 0.95rem;
    color: inherit;
}

.settings-perf-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
    font-weight: 400;
}

.settings-perf-btn.active .settings-perf-hint {
    color: rgba(255, 255, 255, 0.75);
}

/* ---- Theme cards ---- */
.settings-themes-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.settings-theme-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 14px 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.4s var(--ease-snap);
    color: var(--text-secondary);
}

.settings-theme-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateY(-4px) scale(1.02);
    color: white;
}

.settings-theme-card.active {
    border-color: var(--accent);
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.1);
    box-shadow: 0 0 24px -6px rgba(var(--accent-rgb, 59, 130, 246), 0.4);
    color: white;
}

.settings-theme-preview {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    flex-shrink: 0;
    transition: transform 0.35s var(--ease-snap);
}

.settings-theme-card:hover .settings-theme-preview,
.settings-theme-card.active .settings-theme-preview {
    transform: scale(1.1);
}

.settings-theme-preview-custom {
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--accent);
}

.settings-theme-name {
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
}

/* ---- Custom theme ---- */
.settings-custom-theme {
    margin-top: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 18px;
    display: none;
    animation: settingsCustomExpand 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-custom-theme.expanded {
    display: block;
}

@keyframes settingsCustomExpand {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.settings-custom-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.settings-custom-row:last-of-type {
    margin-bottom: 18px;
}

.settings-custom-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 120px;
}

.settings-custom-row input[type="color"] {
    width: 48px;
    height: 48px;
    padding: 4px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: transparent;
    cursor: pointer;
    transition: border-color 0.3s ease, transform 0.25s var(--ease-snap);
}

.settings-custom-row input[type="color"]:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

.settings-custom-hex {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.settings-custom-reset {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.settings-custom-reset:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

/* ---- Settings rows (selects, toggles) ---- */
.settings-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    transition: background 0.25s ease, border-color 0.25s ease;
}

.settings-row:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
}

.settings-row-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.settings-row-right {
    flex-shrink: 0;
}

.settings-select {
    min-width: 140px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.25s ease, background 0.25s ease;
}

.settings-select:hover,
.settings-select:focus {
    border-color: var(--accent);
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.1);
    outline: none;
}

.settings-select-sm {
    min-width: 90px;
}

/* ---- Custom dropdowns (replace native select) ---- */
.custom-dropdown {
    position: relative;
    min-width: 140px;
}

.custom-dropdown-sm {
    min-width: 96px;
}

.custom-dropdown-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: white;
    font-size: 0.88rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: all 0.3s var(--ease-snap);
}

.custom-dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.custom-dropdown.open .custom-dropdown-trigger {
    border-color: rgba(var(--accent-rgb, 59, 130, 246), 0.5);
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.08);
    box-shadow: 0 0 0 1px rgba(var(--accent-rgb, 59, 130, 246), 0.2);
}

.custom-dropdown-value {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-dropdown-chevron {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: var(--text-secondary);
    transition: transform 0.35s var(--ease-snap);
}

.custom-dropdown.open .custom-dropdown-chevron {
    transform: rotate(180deg);
    color: var(--accent);
}

.custom-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    min-width: 100%;
    background: rgba(14, 14, 18, 0.98);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    box-shadow:
        0 24px 48px -12px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    padding: 6px;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.97);
    transform-origin: top;
    transition: opacity 0.25s var(--ease-snap), transform 0.25s var(--ease-snap), visibility 0.25s;
    max-height: 0;
    overflow: hidden;
}

.custom-dropdown.open .custom-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    max-height: 280px;
    overflow-y: auto;
}

.custom-dropdown-option {
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s var(--ease-snap);
}

.custom-dropdown-option:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.custom-dropdown-option.active {
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.15);
    color: var(--accent);
}

.settings-input-num {
    width: 72px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
}

.settings-input-num:focus {
    border-color: var(--accent);
    outline: none;
}

/* Toggle switch ---- */
.settings-toggle {
    width: 48px;
    height: 26px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 13px;
    cursor: pointer;
    padding: 0;
    position: relative;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.settings-toggle:hover {
    background: rgba(255, 255, 255, 0.14);
}

.settings-toggle[data-on="true"] {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 16px -2px rgba(var(--accent-rgb, 59, 130, 246), 0.5);
}

.settings-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.settings-toggle[data-on="true"] .settings-toggle-knob {
    transform: translateX(22px);
}

/* ---- Data & reset actions ---- */
.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s var(--ease-snap);
    position: relative;
}

.settings-action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
}

.settings-action-btn-danger {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.2);
}

.settings-action-btn-danger:hover {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.35);
}

.settings-file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    font-size: 0;
}

/* ---- About ---- */
.settings-about {
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
}

.settings-about-version {
    font-weight: 700;
    font-size: 1rem;
    color: white;
    margin: 0 0 6px;
}

.settings-about-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0 0 14px;
}

.settings-debug-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.settings-debug-row input {
    cursor: pointer;
}

/* ---- Theme transition on app (smooth theme switch) ---- */
html {
    transition: background-color 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
    transition: background-color 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                border-color 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                color 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.5s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* ---- Performance: reduced motion ---- */
body.perf-medium .aurora-bg {
    animation-duration: 45s;
}

body.perf-low .aurora-bg {
    animation: none;
    opacity: 0.9;
}

body.perf-low [data-hero],
body.perf-low [data-stash-hero],
body.perf-low [data-rdd-hero] {
    animation-duration: 0.35s;
}

body.perf-medium [data-hero],
body.perf-medium [data-stash-hero],
body.perf-medium [data-rdd-hero] {
    animation-duration: 0.5s;
}

/* ---- Accessibility: reduced motion (user preference) ---- */
body.reduced-motion .aurora-bg { animation: none; }
body.reduced-motion [data-hero],
body.reduced-motion [data-stash-hero],
body.reduced-motion [data-rdd-hero],
body.reduced-motion .portal-card,
body.reduced-motion .script-card,
body.reduced-motion .nav-indicator,
body.reduced-motion .navbar,
body.reduced-motion .brand-capsule,
body.reduced-motion .nav-dock,
body.reduced-motion .settings-trigger {
    animation-duration: 0.2s !important;
}
body.reduced-motion * {
    animation-duration: 0.15s !important;
    transition-duration: 0.15s !important;
}

/* ---- App: compact layout ---- */
body.layout-compact .navbar { padding: 18px 32px; }
body.layout-compact .smooth-scroll-wrapper { padding-top: 70px; }
body.layout-compact .nav-btn { padding: 10px 18px; font-size: 0.8rem; }
body.layout-compact .home-wrap { padding-top: 70px; }
body.layout-compact .stash-wrap { padding-top: 70px; }
body.layout-compact .rdd-wrap { padding-top: 70px; }

/* ---- Accessibility: focus outline ---- */
body.focus-outline *:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

body.focus-outline *:focus:not(.settings-toggle):not(.settings-file-input) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---- Accessibility: high contrast ---- */
body.high-contrast {
    --glass-border: rgba(255, 255, 255, 0.2);
}
body.high-contrast .nav-btn.active { font-weight: 700; }
body.high-contrast .portal-card { border-color: rgba(255, 255, 255, 0.12); }
body.high-contrast .script-card { border-color: rgba(255, 255, 255, 0.1); }

/* ---- Color scheme: light (when colorScheme is light or system + prefers-light) ---- */
html.color-scheme-light {
    --bg-depth: #e8e8ec;
    --bg-surface: #f0f0f4;
    --text-primary: #0f0f12;
    --text-secondary: #505060;
    --glass: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.08);
}
html.color-scheme-light body { color: var(--text-primary); }
html.color-scheme-light .settings-panel { background: rgba(255, 255, 255, 0.98); }
html.color-scheme-light .settings-section-title { color: var(--text-secondary); }
html.color-scheme-light .settings-row-label { color: var(--text-primary); }
html.color-scheme-light .settings-title { color: var(--text-primary); }

/* ---- Corner radius presets ---- */
body.radius-subtle .brand-capsule,
body.radius-subtle .nav-dock,
body.radius-subtle .portal-card,
body.radius-subtle .script-card,
body.radius-subtle .rdd-panel { border-radius: 12px; }
body.radius-subtle .stash-cats,
body.radius-subtle .settings-toggle { border-radius: 10px; }

body.radius-rounded .brand-capsule { border-radius: 16px; }
body.radius-rounded .nav-dock { border-radius: 100px; }
body.radius-rounded .portal-card { border-radius: 28px; }
body.radius-rounded .script-card { border-radius: 28px; }
body.radius-rounded .rdd-panel { border-radius: 28px; }
body.radius-rounded .stash-cats { border-radius: 100px; }
body.radius-rounded .settings-toggle { border-radius: 14px; }
