/* Reader settings panel (slide-up sheet) + footnote modal. */

/* --- Settings panel --------------------------------------------------------- */

.settings-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    max-width: var(--measure);
    margin: 0 auto;
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;

    /* In Telegram fullscreen the WebView's own env() inset can read 0 while
         Telegram reports a real one (--tg-inset-bottom, set by reader.js). */
    padding: 16px 16px calc(16px + max(env(safe-area-inset-bottom), var(--tg-inset-bottom, 0px)));
    transform: translateY(100%);
    transition: transform 0.2s ease;
}

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

/* Drag affordance: a grabber bar at the top of the sheet. */
.settings-panel::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    margin: -4px auto 12px;
    border-radius: 2px;
    background: var(--line);
}

/* Dim backdrop; click/tap outside the sheet closes it. */
.settings-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgb(0 0 0 / 35%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}
.settings-row:first-child { border-top: none; }

.settings-label {
    color: var(--ink-soft);
    font-size: 14px;
}

.seg {
    display: flex;
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.seg button {
    background: transparent;
    border: none;
    color: var(--ink-soft);
    font: inherit;
    font-size: 14px;
    padding: 6px 10px;
    white-space: nowrap;
    cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button svg { display: block; }

/* --- Dropdown (font, column width) ---
 * For option sets too wide to sit beside their label as a seg. The list is our
 * own markup rather than a native <select>: Telegram's WebView opens that as an
 * OS picker that ignores the reader's theme. reader.js keeps the trigger label
 * and .selected in sync, and flips the list upward (.drop-up) when the row sits
 * too close to the bottom of the viewport for it to open down. */
.dropdown {
    position: relative;
    min-width: 9rem;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    padding: 6px 10px;
    cursor: pointer;
}

/* Chevron, drawn in CSS to keep the sheet free of another inline SVG. */
.dropdown-trigger::after {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--ink-soft);
    border-bottom: 1.5px solid var(--ink-soft);
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.15s ease;
}
.dropdown.open .dropdown-trigger { border-color: var(--accent); }
.dropdown.open .dropdown-trigger::after { transform: translateY(1px) rotate(-135deg); }

.dropdown-options {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 25;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
}
.dropdown.open .dropdown-options { display: block; }

.dropdown.drop-up .dropdown-options {
    top: auto;
    bottom: calc(100% + 4px);
    box-shadow: 0 -8px 24px rgb(0 0 0 / 18%);
}

.dropdown-option {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--ink-soft);
    font: inherit;
    font-size: 14px;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
}
.dropdown-option + .dropdown-option { border-top: 1px solid var(--line); }

.dropdown-option.selected {
    background: var(--accent);
    color: var(--accent-ink);
}

.seg button.active {
    background: var(--accent);
    color: var(--accent-ink);
}

.stepper {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

/* stylelint-disable-next-line no-descending-specificity --
     .seg and .stepper are separate components; no element matches both, so the
     source order between them can't cause a cascade surprise. */
.stepper button {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    font: inherit;
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.stepper .stepper-value {
    color: var(--ink);
    font-size: 14px;
    min-width: 4ch;
    text-align: center;
}

/* --- Footnote modal --------------------------------------------------------- */

.fn-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgb(0 0 0 / 50%);
}
.fn-modal[hidden] { display: none; }

.fn-modal-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--olive);
    border-radius: 12px;
    padding: 16px 18px;
    max-width: 420px;
    color: var(--olive);
    font-style: italic;
    font-size: 15px;
    line-height: 1.6;
}
