/* ── Toggle Button ────────────────────────────────────────── */

.reading-prefs-btn {
    position: fixed;
    bottom: 152px;
    right: 35px;
    z-index: 100;
    width: 47px;
    height: 47px;
    box-sizing: border-box;
    border: 1px solid var(--fb-border-accent, var(--fb-blue));
    border-radius: 15%;
    background-color: var(--fb-bg-accent, var(--fb-blue));
    color: var(--fb-text-invert, #fff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: scale(0);
    transform-origin: center;
    transition: opacity 0.3s ease, visibility 0.3s ease, background-color 0.3s ease, transform 0.3s ease, color 0.3s ease;
    box-shadow: var(--fb-shadow-md, 0 4px 6px -1px rgba(0,0,0,0.08));
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.reading-prefs-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.reading-prefs-btn:hover {
    background-color: var(--fb-bg-accent-subtle, var(--fb-blue-low));
    color: var(--fb-text-accent, var(--fb-blue));
    border-color: var(--fb-border-accent, var(--fb-blue));
    box-shadow: var(--fb-shadow-lg, 0 10px 15px -3px rgba(0,0,0,0.08));
}

.reading-prefs-btn:active {
    background-color: var(--fb-blue-high);
    color: var(--fb-text-invert, #fff);
    transition: background-color 0.1s ease, transform 0.1s ease;
}

.reading-prefs-btn.panel-open {
    background-color: var(--fb-bg-accent-subtle, var(--fb-blue-low));
    color: var(--fb-text-accent, var(--fb-blue));
}

.reading-prefs-btn.keyboard-focus {
    outline: var(--fb-focus-ring-width, 2px) solid var(--fb-focus-ring, var(--fb-blue));
    outline-offset: var(--fb-focus-ring-offset, 2px);
}

.reading-prefs-btn svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Panel ────────────────────────────────────────────────── */

.reading-prefs-panel {
    position: fixed;
    bottom: 152px;
    right: 92px;
    z-index: 101;
    width: 280px;
    padding: 1rem;
    background: var(--fb-bg-surface, #fff);
    border: 1px solid var(--fb-border, rgba(0, 0, 0, 0.1));
    border-radius: var(--fb-radius-lg, 0.5rem);
    box-shadow: var(--fb-shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.15));
    opacity: 0;
    visibility: hidden;
    transform: translateX(0.5rem);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.reading-prefs-panel--visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* ── Panel Header ─────────────────────────────────────────── */

.reading-prefs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--fb-border, rgba(0, 0, 0, 0.1));
}

.reading-prefs-title {
    font-size: var(--fb-text-sm, 0.875rem);
    font-weight: 600;
    color: var(--fb-text, inherit);
    margin: 0;
}

.reading-prefs-reset {
    padding: 2px 8px;
    border: none;
    background: transparent;
    color: var(--fb-text-muted, #6b7280);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: var(--fb-radius-sm, 0.25rem);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.reading-prefs-reset:hover {
    background: var(--fb-hover, rgba(0, 0, 0, 0.05));
    color: var(--fb-text, inherit);
}

/* ── Section Divider ──────────────────────────────────────── */

.reading-prefs-divider {
    height: 1px;
    background: var(--fb-border, rgba(0, 0, 0, 0.1));
    margin: 0.75rem 0;
    border: none;
}

/* ── Control Group ────────────────────────────────────────── */

.reading-prefs-group {
    margin-bottom: 0.75rem;
}

.reading-prefs-group:last-child {
    margin-bottom: 0;
}

.reading-prefs-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.375rem;
    font-size: 0.75rem;
    color: var(--fb-text-muted, #6b7280);
}

.reading-prefs-value {
    font-weight: 600;
    color: var(--fb-text, inherit);
    min-width: 2.5rem;
    text-align: right;
}

/* ── Range Slider ─────────────────────────────────────────── */

.reading-prefs-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 20px;
    background: transparent;
    outline: none;
    cursor: pointer;
    margin: 0;
}

.reading-prefs-range::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--fb-border, rgba(0, 0, 0, 0.15));
    border-radius: 2px;
}

.reading-prefs-range::-moz-range-track {
    height: 4px;
    background: var(--fb-border, rgba(0, 0, 0, 0.15));
    border-radius: 2px;
    border: none;
}

.reading-prefs-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -6px;
    background: var(--fb-bg-accent, var(--fb-blue));
    border: 2px solid var(--fb-bg-surface, #fff);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.reading-prefs-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.reading-prefs-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--fb-bg-accent, var(--fb-blue));
    border: 2px solid var(--fb-bg-surface, #fff);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.reading-prefs-range:focus-visible {
    outline: var(--fb-focus-ring-width, 2px) solid var(--fb-focus-ring, var(--fb-blue));
    outline-offset: 2px;
}

/* ── Button Group (font family, text alignment) ──────────── */

.reading-prefs-btngroup {
    display: flex;
    gap: 1px;
    background: var(--fb-border, rgba(0, 0, 0, 0.1));
    border-radius: var(--fb-radius-sm, 0.25rem);
    overflow: hidden;
}

.reading-prefs-btngroup__item {
    flex: 1;
    padding: 0.3rem 0.25rem;
    border: none;
    background: var(--fb-bg-surface, #fff);
    color: var(--fb-text-muted, #6b7280);
    font-size: 0.6875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    text-align: center;
    white-space: nowrap;
    line-height: 1.4;
}

.reading-prefs-btngroup__item:hover {
    background: var(--fb-hover, rgba(0, 0, 0, 0.03));
}

.reading-prefs-btngroup__item.active {
    background: var(--fb-bg-accent, var(--fb-blue));
    color: var(--fb-text-invert, #fff);
}

.reading-prefs-btngroup__item svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -2px;
}

/* ── Content Overrides (via CSS custom properties) ────────── */

.prose.fb-markdown-content.content-body {
    font-size: var(--rp-font-size, 100%);
    line-height: var(--rp-line-height, 1.85);
    font-family: var(--rp-font-family, var(--fb-font-sans));
    letter-spacing: var(--rp-letter-spacing, normal);
    text-align: var(--rp-text-align, left);
}

.prose.fb-markdown-content.content-body p {
    margin-bottom: var(--rp-paragraph-spacing, 1.25em);
}

.sl-content-column,
body.focus-mode .sl-content-column {
    max-width: var(--rp-content-width, var(--fb-content-width));
}

/* ── Mobile ──────────────────────────────────────────────── */

@media (max-width: 1023px) {
    .reading-prefs-btn {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 40px;
        height: 40px;
    }

    .reading-prefs-btn svg {
        width: 20px;
        height: 20px;
    }

    .reading-prefs-panel {
        bottom: auto;
        right: 0.75rem;
        left: 0.75rem;
        top: calc(var(--fb-nav-height, 60px) + 0.5rem);
        width: auto;
    }
}

/* ── Print ───────────────────────────────────────────────── */

@media print {
    .reading-prefs-btn,
    .reading-prefs-panel {
        display: none !important;
    }
}
