html body[data-reader-paper="white"] {
    color-scheme: light;
    --bg: #fffdf8;
    --bg-article: #fffdf8;
    --bg-card: #ffffff;
    --bg-hover: #f3efe7;
    --bg-sidebar: #faf7f0;
    --border: #e7dfd2;
    --border-light: #d9cfc0;
    --text: #26231f;
    --text-muted: #706a61;
    --text-reading: #26231f;
    --fn-bg: #ffffff;
    --editor-bg: #fffdf8;
    --preview-bg: linear-gradient(180deg, #fffdf8, #faf6ee);
    --panel-bg: rgba(255, 253, 248, 0.96);
    --input-bg: #ffffff;
    --shadow-soft: 0 12px 30px rgba(50, 42, 31, 0.10);
    --reader-paper-bg: #fffdf8;
    --reader-paper-text: #26231f;
    --reader-paper-heading: #191714;
    --reader-paper-muted: #706a61;
    --reader-paper-border: #e7dfd2;
}

html body[data-reader-paper="cream"] {
    color-scheme: light;
    --bg: #f4ecd9;
    --bg-article: #f4ecd9;
    --bg-card: #fbf4e5;
    --bg-hover: #eadfc8;
    --bg-sidebar: #eee3cd;
    --border: #dfcfb1;
    --border-light: #cfbb98;
    --text: #3f3528;
    --text-muted: #766851;
    --text-reading: #3f3528;
    --fn-bg: #fbf4e5;
    --editor-bg: #f8f0df;
    --preview-bg: linear-gradient(180deg, #f8f0df, #efe3ca);
    --panel-bg: rgba(244, 236, 217, 0.96);
    --input-bg: #fbf4e5;
    --shadow-soft: 0 12px 30px rgba(63, 53, 40, 0.13);
    --reader-paper-bg: #f4ecd9;
    --reader-paper-text: #3f3528;
    --reader-paper-heading: #2d241b;
    --reader-paper-muted: #766851;
    --reader-paper-border: #dfcfb1;
}

html body[data-reader-paper="sage"] {
    color-scheme: light;
    --bg: #f0f5ed;
    --bg-article: #f0f5ed;
    --bg-card: #f8fbf6;
    --bg-hover: #dfe9dc;
    --bg-sidebar: #e7efe3;
    --border: #d4dfcf;
    --border-light: #bdcbb7;
    --text: #293228;
    --text-muted: #667160;
    --text-reading: #293228;
    --fn-bg: #f8fbf6;
    --editor-bg: #f3f8f1;
    --preview-bg: linear-gradient(180deg, #f3f8f1, #e7efe3);
    --panel-bg: rgba(240, 245, 237, 0.96);
    --input-bg: #f8fbf6;
    --shadow-soft: 0 12px 30px rgba(41, 50, 40, 0.12);
    --reader-paper-bg: #f0f5ed;
    --reader-paper-text: #293228;
    --reader-paper-heading: #182116;
    --reader-paper-muted: #667160;
    --reader-paper-border: #d4dfcf;
}

html body[data-reader-paper="slate"] {
    color-scheme: dark;
    --bg: #1d2228;
    --bg-article: #1d2228;
    --bg-card: #272d34;
    --bg-hover: #303841;
    --bg-sidebar: #181d22;
    --border: #343b44;
    --border-light: #46505b;
    --text: #e2ded6;
    --text-muted: #aaa49a;
    --text-reading: #e2ded6;
    --fn-bg: #272d34;
    --editor-bg: #20262c;
    --preview-bg: linear-gradient(180deg, #20262c, #181d22);
    --panel-bg: rgba(29, 34, 40, 0.96);
    --input-bg: #20262c;
    --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.34);
    --reader-paper-bg: #1d2228;
    --reader-paper-text: #e2ded6;
    --reader-paper-heading: #f2eee7;
    --reader-paper-muted: #aaa49a;
    --reader-paper-border: #343b44;
}

@media (prefers-color-scheme: light) {
    html body[data-reader-paper="default"] {
        color-scheme: light;
        --bg: #fffdf8;
        --bg-article: #fffdf8;
        --bg-card: #ffffff;
        --bg-hover: #f3efe7;
        --bg-sidebar: #faf7f0;
        --border: #e7dfd2;
        --border-light: #d9cfc0;
        --text: #26231f;
        --text-muted: #706a61;
        --text-reading: #26231f;
        --fn-bg: #ffffff;
        --editor-bg: #fffdf8;
        --preview-bg: linear-gradient(180deg, #fffdf8, #faf6ee);
        --panel-bg: rgba(255, 253, 248, 0.96);
        --input-bg: #ffffff;
        --shadow-soft: 0 12px 30px rgba(50, 42, 31, 0.10);
        --reader-paper-bg: #fffdf8;
        --reader-paper-text: #26231f;
        --reader-paper-heading: #191714;
        --reader-paper-muted: #706a61;
        --reader-paper-border: #e7dfd2;
    }
}

@media (prefers-color-scheme: dark) {
    html body[data-reader-paper="default"] {
        color-scheme: dark;
        --bg: #1d2228;
        --bg-article: #1d2228;
        --bg-card: #272d34;
        --bg-hover: #303841;
        --bg-sidebar: #181d22;
        --border: #343b44;
        --border-light: #46505b;
        --text: #e2ded6;
        --text-muted: #aaa49a;
        --text-reading: #e2ded6;
        --fn-bg: #272d34;
        --editor-bg: #20262c;
        --preview-bg: linear-gradient(180deg, #20262c, #181d22);
        --panel-bg: rgba(29, 34, 40, 0.96);
        --input-bg: #20262c;
        --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.34);
        --reader-paper-bg: #1d2228;
        --reader-paper-text: #e2ded6;
        --reader-paper-heading: #f2eee7;
        --reader-paper-muted: #aaa49a;
        --reader-paper-border: #343b44;
    }
}

select {
    color-scheme: light;
}

select option {
    background: var(--bg-card);
    color: var(--text);
}

html body[data-reader-paper="slate"] select {
    color-scheme: dark;
}

.toolbar-paper-setting {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    position: relative;
}

.toolbar-paper-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
}

.toolbar-paper-icon {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    border-radius: 3px;
    border: 1px solid var(--reader-paper-border);
    background: var(--reader-paper-bg);
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--reader-paper-bg) 72%, var(--reader-paper-text));
}

.toolbar-paper-select {
    flex: 0 0 104px;
    min-width: 0;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    padding: 0 8px;
    cursor: pointer;
}

.toolbar-paper-select.is-enhanced {
    display: none;
}

.toolbar-paper-picker {
    position: relative;
    flex: 0 0 122px;
    min-width: 0;
}

.toolbar-paper-trigger {
    width: 100%;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 8px;
    cursor: pointer;
}

.toolbar-paper-trigger:hover,
.toolbar-paper-trigger:focus-visible {
    border-color: color-mix(in srgb, var(--accent-blue-strong) 50%, var(--border));
    outline: none;
}

.toolbar-paper-trigger-label {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.toolbar-paper-trigger-chevron {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    opacity: 0.72;
}

.toolbar-paper-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 174px;
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-bg);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(12px);
    z-index: 60;
}

.toolbar-paper-picker.open .toolbar-paper-menu {
    display: flex;
}

.toolbar-paper-choice {
    width: 100%;
    min-height: 34px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 8px;
    cursor: pointer;
    text-align: left;
}

.toolbar-paper-choice:hover,
.toolbar-paper-choice:focus-visible {
    background: var(--bg-hover);
    outline: none;
}

.toolbar-paper-choice[aria-selected="true"] {
    background: color-mix(in srgb, var(--accent-blue-soft) 42%, transparent);
}

.toolbar-paper-choice-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbar-paper-choice::after {
    content: "";
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border-radius: 999px;
    background: var(--accent-blue);
    opacity: 0;
}

.toolbar-paper-choice[aria-selected="true"]::after {
    opacity: 1;
}

.toolbar-paper-swatch {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border-radius: 5px;
    border: 1px solid color-mix(in srgb, var(--reader-paper-border) 80%, #000000);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.24);
    background:
        radial-gradient(circle at 35% 28%, rgba(255,255,255,0.32), transparent 24%),
        repeating-linear-gradient(135deg, rgba(0,0,0,0.045) 0 1px, transparent 1px 5px),
        var(--reader-paper-bg);
}

.toolbar-paper-swatch[data-paper="default"] {
    background:
        linear-gradient(135deg, var(--bg-article) 0 48%, var(--bg-card) 48% 52%, var(--reader-paper-bg) 52% 100%),
        repeating-linear-gradient(135deg, rgba(0,0,0,0.05) 0 1px, transparent 1px 5px);
}

.toolbar-paper-swatch[data-paper="white"] {
    border-color: #e7dfd2;
    background:
        radial-gradient(circle at 35% 28%, rgba(255,255,255,0.55), transparent 24%),
        repeating-linear-gradient(135deg, rgba(38,35,31,0.045) 0 1px, transparent 1px 5px),
        #fffdf8;
}

.toolbar-paper-swatch[data-paper="cream"] {
    border-color: #dfcfb1;
    background:
        radial-gradient(circle at 35% 28%, rgba(255,255,255,0.46), transparent 24%),
        repeating-linear-gradient(135deg, rgba(63,53,40,0.055) 0 1px, transparent 1px 5px),
        #f4ecd9;
}

.toolbar-paper-swatch[data-paper="sage"] {
    border-color: #d4dfcf;
    background:
        radial-gradient(circle at 35% 28%, rgba(255,255,255,0.46), transparent 24%),
        repeating-linear-gradient(135deg, rgba(41,50,40,0.05) 0 1px, transparent 1px 5px),
        #f0f5ed;
}

.toolbar-paper-swatch[data-paper="slate"] {
    border-color: #343b44;
    background:
        radial-gradient(circle at 35% 28%, rgba(255,255,255,0.12), transparent 24%),
        repeating-linear-gradient(135deg, rgba(255,255,255,0.045) 0 1px, transparent 1px 5px),
        #1d2228;
}

.sidebar-top-search {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    height: 36px;
}

.sidebar-search {
    margin-bottom: 8px;
}

.sidebar-search.sidebar-top-search {
    margin-bottom: 0;
}

.sidebar-search-input {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.78rem;
}

.sidebar-top-search .sidebar-search-input {
    height: 36px;
    margin: 0;
    padding: 7px 11px;
}

.sidebar-search-input::placeholder {
    color: var(--text-muted);
}

.toolbar-history-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    padding: 0;
    margin: 0;
    border-radius: 7px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    appearance: none;
}

.toolbar-history-btn svg {
    width: 18px;
    height: 18px;
    display: block;
}

.toolbar-history-btn svg path {
    stroke: currentColor;
    stroke-width: 1.85;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.toolbar-history-btn:hover:not(:disabled) {
    color: var(--text);
    background: var(--bg-hover);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.toolbar-history-btn:disabled {
    opacity: 0.32;
    cursor: not-allowed;
    background: transparent;
    box-shadow: none;
}

.shortcuts-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
}

.shortcuts-overlay.visible {
    display: flex;
}

.shortcuts-panel {
    position: relative;
    width: min(520px, 90vw);
    max-height: 80vh;
    overflow: auto;
    padding: 28px 32px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
    box-shadow: var(--shadow-soft);
}

.shortcuts-panel h3 {
    margin: 0 0 16px;
    color: var(--text);
    font-size: 1rem;
}

.shortcuts-panel table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text);
    font-size: 0.82rem;
}

.shortcuts-panel td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.shortcuts-panel td:first-child {
    width: 45%;
    color: var(--text-muted);
    font-family: Inter, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: nowrap;
}

.shortcuts-panel .section-label {
    padding-top: 12px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.shortcuts-panel tr:first-child .section-label {
    padding-top: 0;
}

.shortcuts-panel td.section-label {
    border-bottom: 0;
}

.shortcuts-close {
    position: absolute;
    top: 12px;
    right: 16px;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
}

.shortcuts-close:hover {
    color: var(--text);
}

.fn-insert-popup {
    display: none;
    position: fixed;
    z-index: 50;
    width: min(360px, calc(100vw - 24px));
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    box-shadow: 0 4px 20px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.1);
}

.fn-insert-popup.visible {
    display: grid;
    gap: 8px;
}

.popup-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.popup-word {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    font-weight: 750;
}

.popup-ipa {
    color: var(--accent-blue);
    font-size: 0.76rem;
    white-space: nowrap;
}

.popup-lookup {
    display: grid;
    gap: 5px;
}

.popup-definition {
    max-height: 120px;
    overflow: auto;
    color: var(--text);
    font-size: 0.78rem;
    line-height: 1.45;
    white-space: pre-line;
}

.popup-source {
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.2;
}

.popup-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.popup-sep {
    width: 1px;
    height: 18px;
    margin: 0 3px;
    flex-shrink: 0;
    background: var(--border);
}

.fn-insert-popup button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 30px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.12s;
}

.fn-insert-popup button:hover {
    background: var(--bg-hover);
}

.fn-insert-popup button[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    z-index: 100;
    transform: translateX(-50%);
    border-radius: 5px;
    background: #1a1a1a;
    color: #fff;
    padding: 3px 7px;
    font-size: 0.65rem;
    white-space: nowrap;
    pointer-events: none;
}

[data-theme="light"] .fn-insert-popup button[title]:hover::after {
    background: #333;
}

.popup-btn-note {
    flex: 1 1 auto;
    justify-content: center !important;
    gap: 6px;
    padding: 0 10px !important;
    border: 1px solid rgba(59,130,246,0.32) !important;
    background: rgba(59,130,246,0.1) !important;
    color: var(--accent-blue) !important;
    font-size: 0.78rem !important;
    font-weight: 700;
}

.popup-btn-note:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}

.popup-btn-known {
    flex: 1 1 auto;
    gap: 6px;
    padding: 0 10px !important;
    border: 1px solid rgba(16, 185, 129, 0.38) !important;
    background: rgba(16, 185, 129, 0.1) !important;
    color: #059669 !important;
    font-size: 0.78rem !important;
    font-weight: 700;
}

[data-theme="dark"] .popup-btn-known {
    color: #6ee7b7 !important;
}

.popup-btn-bold {
    font-weight: 700;
    font-family: Georgia, serif;
    font-size: 0.9rem;
}

.popup-btn-close {
    color: var(--text-muted) !important;
    font-size: 0.8rem !important;
}
