:root {
    --sidebar-width: 280px;
    --toc-width: 220px;
    --header-height: 56px;
    --bg: #ffffff;
    --bg-muted: #f6f8fa;
    --border: #e1e4e8;
    --text: #24292f;
    --text-muted: #57606a;
    --accent: #0969da;
    --accent-soft: #eef6ff;
    --sidebar-active: #eef6ff;
    --code-bg: #f6f8fa;
    --shadow: 0 1px 0 rgba(27, 31, 36, 0.04);
    --mark-bg: #fff8c5;
    --callout-note: #ddf4ff;
    --callout-tip: #dafbe1;
    --callout-warning: #fff8c5;
    --callout-danger: #ffebe9;
    --callout-info: #eef6ff;
    --scrollbar-track: transparent;
    --scrollbar-thumb: rgba(27, 31, 36, 0.16);
    --scrollbar-thumb-hover: rgba(27, 31, 36, 0.28);
}

[data-theme="dark"] {
    --bg: #0d1117;
    --bg-muted: #010409;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #4493f8;
    --accent-soft: #13253b;
    --sidebar-active: #13253b;
    --code-bg: #161b22;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
    --mark-bg: #3d2e00;
    --callout-note: #13253b;
    --callout-tip: #12261e;
    --callout-warning: #3d2e00;
    --callout-danger: #3d1418;
    --callout-info: #13253b;
    --scrollbar-track: transparent;
    --scrollbar-thumb: rgba(230, 237, 243, 0.18);
    --scrollbar-thumb-hover: rgba(230, 237, 243, 0.32);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 15px;
}

html[data-font-size="sm"] {
    font-size: 14px;
}

html[data-font-size="md"] {
    font-size: 15px;
}

html[data-font-size="lg"] {
    font-size: 17px;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    background: var(--bg-muted);
    color: var(--text);
    line-height: 1.7;
    font-size: 1rem;
}

html[dir="ltr"] body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.book {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-inline-start: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 20;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 18px 16px 14px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    min-width: 0;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    align-self: flex-start;
}

.focus-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--bg-muted);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--text);
}

.focus-toggle .fa-duotone {
    font-size: 15px;
}

.focus-toggle.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.site-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.site-title a {
    color: inherit;
    text-decoration: none;
}

.site-title a:hover {
    color: var(--accent);
    text-decoration: none;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--bg-muted);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--text);
}

.theme-toggle .fa-duotone {
    font-size: 15px;
}

.search-box {
    position: relative;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.search-box-icon {
    position: absolute;
    top: 50%;
    inset-inline-start: 28px;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-muted);
    line-height: 1;
    z-index: 1;
}

.search-box-icon .fa-duotone {
    font-size: 14px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px;
    padding-inline-start: 2.35rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    background: var(--bg-muted);
    color: var(--text);
    outline: none;
}

.search-box input:focus {
    border-color: var(--accent);
    background: var(--bg);
}

.search-results {
    position: absolute;
    top: calc(100% - 8px);
    right: 16px;
    left: 16px;
    z-index: 30;
    max-height: 320px;
    overflow: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(27, 31, 36, 0.12);
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus {
    background: var(--bg-muted);
    text-decoration: none;
}

.search-result-title {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.search-result-snippet {
    display: block;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

.search-result-snippet mark {
    background: var(--mark-bg);
    color: inherit;
    padding: 0 2px;
    border-radius: 3px;
}

.search-empty {
    padding: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 12px 10px 32px;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.sidebar-nav::-webkit-scrollbar {
    width: 8px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border: 2px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

.search-results,
.toc-panel,
.toc-drawer {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.search-results::-webkit-scrollbar,
.toc-panel::-webkit-scrollbar,
.toc-drawer::-webkit-scrollbar {
    width: 8px;
}

.search-results::-webkit-scrollbar-track,
.toc-panel::-webkit-scrollbar-track,
.toc-drawer::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.search-results::-webkit-scrollbar-thumb,
.toc-panel::-webkit-scrollbar-thumb,
.toc-drawer::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border: 2px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
}

.search-results::-webkit-scrollbar-thumb:hover,
.toc-panel::-webkit-scrollbar-thumb:hover,
.toc-drawer::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

.nav-section {
    margin-bottom: 4px;
}

.nav-section-header {
    display: flex;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    border-radius: 8px;
}

.nav-section-header:hover {
    background: var(--bg-muted);
}

.nav-toggle {
    order: -1;
}

.nav-section-header .nav-item,
.nav-section-header .nav-section-title {
    flex: 1 1 auto;
    min-width: 0;
    padding-block: 8px;
    padding-inline-end: 12px;
    padding-inline-start: 4px;
    text-align: start;
}

.nav-section-header .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    padding: 0;
}

.nav-toggle .nav-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1em;
    height: 1em;
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.nav-toggle .fa-duotone {
    position: relative;
}

.nav-section.expanded > .nav-section-header .nav-toggle-icon {
    transform: rotate(-90deg);
}

/* Nav chevrons: fa-angle-left suits RTL; mirror for LTR */
html[dir="ltr"] .nav-toggle .nav-toggle-icon {
    transform: scaleX(-1);
}

html[dir="ltr"] .nav-section.expanded > .nav-section-header .nav-toggle-icon {
    transform: scaleX(-1) rotate(-90deg);
}

/* Auth icons: sign-in/out arrows follow reading direction */
html[dir="rtl"] .auth-login-link .fa-duotone,
html[dir="rtl"] .auth-logout-btn .fa-duotone {
    transform: scaleX(-1);
}

.nav-section.collapsed > .nav-section-children {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.nav-section.expanded > .nav-section-children {
    max-height: none;
    opacity: 1;
    overflow: visible;
    pointer-events: auto;
}

.nav-section-children {
    margin-top: 2px;
    margin-inline-start: 12px;
    padding-inline-start: 10px;
    border-inline-start: 1px solid var(--border);
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.nav-section-children .nav-section-children {
    margin-inline-start: 8px;
}

.nav-section-title,
.nav-section-label {
    display: block;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.nav-section-title .site-icon {
    margin-inline-end: 6px;
}

.nav-section-label {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.nav-item {
    display: block;
    padding: 8px 12px;
    padding-inline-start: calc(12px + var(--depth, 0) * 8px);
    margin-bottom: 2px;
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    text-decoration: none;
}

.nav-section-children > .nav-item {
    padding-inline-start: 8px;
}

.nav-item .site-icon {
    margin-inline-end: 6px;
}

.nav-subitem {
    font-size: 13px;
}

.nav-parent.active {
    font-weight: 600;
}

.nav-item:hover {
    background: var(--bg-muted);
    text-decoration: none;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--accent);
    font-weight: 600;
}

.page {
    min-width: 0;
    background: var(--bg-muted);
    display: flex;
    flex-direction: column;
}

.page-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: none;
    align-items: center;
    gap: 12px;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-muted);
    cursor: pointer;
    padding: 0;
    color: var(--text);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.menu-btn .fa-duotone {
    font-size: 15px;
}

.menu-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.page-header strong {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
    font-weight: 700;
}

.page-inner {
    flex: 1;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 32px 36px 80px;
}

.page-top-meta {
    margin-bottom: 16px;
}

.page-top-meta .breadcrumb {
    margin-bottom: 12px;
}

.page-top-meta .page-meta {
    margin-bottom: 0;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.breadcrumb a {
    color: var(--text-muted);
}

.breadcrumb a:hover {
    color: var(--accent);
}

.breadcrumb span:last-child {
    color: var(--text);
    font-weight: 500;
}

.page-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.page-meta-sep {
    opacity: 0.5;
}

.page-meta-link {
    color: var(--accent);
    font-weight: 600;
}

.page-meta-link:hover {
    text-decoration: underline;
}

.page-card h1,
.page-card h2,
.page-card h3,
.page-card h4 {
    scroll-margin-top: 24px;
}

kbd {
    display: inline-block;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}

.search-page-summary {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.search-page-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-page-item {
    display: block;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
}

.search-page-item:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.search-page-title {
    display: block;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 6px;
}

.search-page-snippet {
    display: block;
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
}

.search-page-snippet mark {
    background: var(--mark-bg);
    padding: 0 2px;
    border-radius: 3px;
}

.search-result-item.active {
    background: var(--accent-soft);
}

.back-to-top {
    position: fixed;
    bottom: 28px;
    right: calc(var(--sidebar-width) + 28px);
    z-index: 40;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 48px;
    height: 44px;
    padding: 0 14px 0 12px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    background: linear-gradient(180deg, var(--accent) 0%, #0550ae 100%);
    color: #fff;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(9, 105, 218, 0.4);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

[data-theme="dark"] .back-to-top {
    background: linear-gradient(180deg, #4493f8 0%, #1f6feb 100%);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 28px rgba(31, 111, 235, 0.5);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    box-shadow: 0 12px 32px rgba(9, 105, 218, 0.55);
    transform: translateY(-2px);
}

.back-to-top.visible:hover {
    transform: translateY(-2px);
}

.back-to-top:active {
    transform: translateY(0);
    box-shadow: 0 6px 20px rgba(9, 105, 218, 0.4);
}

.back-to-top-icon {
    font-size: 13px;
    line-height: 1;
}

.back-to-top-label {
    line-height: 1;
    letter-spacing: 0.01em;
}

.toc-fab {
    display: none;
    position: fixed;
    bottom: 24px;
    inset-inline-start: 24px;
    z-index: 40;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.toc-fab .fa-duotone {
    font-size: 16px;
}

.toc-fab:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 6px 20px rgba(9, 105, 218, 0.15);
    transform: translateY(-2px);
}

.toc-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: min(320px, 88vw);
    height: 100vh;
    z-index: 50;
    background: var(--bg);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow: auto;
    padding: 20px 16px 32px;
}

html[dir="rtl"] .toc-drawer {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
}

.toc-drawer.open {
    transform: translateX(0);
}

.toc-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.toc-drawer-header button {
    border: none;
    background: transparent;
    font: inherit;
    cursor: pointer;
    color: var(--text-muted);
}

.toc-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.35);
}

.toc-drawer-backdrop.open {
    display: block;
}

.page-card {
    width: 100%;
    max-width: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 48px;
    box-shadow: var(--shadow);
}

.page-card h1:first-child,
.page-card h2:first-child,
.page-card h3:first-child {
    margin-top: 0;
}

.page-card h1,
.page-card h2,
.page-card h3,
.page-card h4 {
    position: relative;
}

.nav-section:has(.nav-item.active) > .nav-section-header .nav-section-title {
    color: var(--accent);
    font-weight: 700;
}

.heading-actions {
    position: absolute;
    top: 50%;
    left: -3.4em;
    right: auto;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    line-height: 1;
    margin: 0;
    unicode-bidi: isolate;
}

.page-card .heading-rtl > .heading-actions {
    left: auto;
    right: -3.4em;
}

.heading-actions .site-icon {
    display: block;
    font-size: 0.85em;
    line-height: 1;
    vertical-align: baseline;
}

.heading-anchor {
    display: inline-flex;
    align-items: center;
    position: static;
    color: var(--text-muted);
    opacity: 1;
    text-decoration: none;
    font-weight: 400;
    line-height: 1;
    padding: 0 2px;
}

.heading-copy-link {
    display: inline-flex;
    align-items: baseline;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font: inherit;
    font-size: 0.85em;
    line-height: 1;
    padding: 0 2px;
}

.heading-copy-link.copied {
    color: var(--accent);
}

.page-card h1:hover .heading-actions,
.page-card h2:hover .heading-actions,
.page-card h3:hover .heading-actions,
.page-card h4:hover .heading-actions,
.heading-actions:focus-within {
    opacity: 1;
}

@media (max-width: 860px) {
    .heading-actions {
        opacity: 1;
    }
}

.page-card h1:hover .heading-anchor,
.page-card h2:hover .heading-anchor,
.page-card h3:hover .heading-anchor,
.page-card h4:hover .heading-anchor,
.heading-anchor:focus {
    opacity: 1;
}

.page-card h1:first-of-type {
    font-size: 1.6rem;
    line-height: 1.35;
    margin: 0 0 24px;
    padding-bottom: 0;
}

.page-card h1:not(:first-of-type) {
    font-size: 1.3rem;
    line-height: 1.4;
    margin: 64px 0 16px;
    padding-top: 0;
    padding-bottom: 0;
    border-top: none;
    font-weight: 700;
}

.page-card hr:has(+ h1:not(:first-of-type)) {
    display: none;
}

.page-card h2 {
    font-size: 1.15rem;
    margin: 28px 0 12px;
    padding-top: 0;
    font-weight: 700;
}

.page-card h3 {
    font-size: 1.02rem;
    margin: 22px 0 10px;
    font-weight: 600;
}

.page-card p,
.page-card ul,
.page-card ol,
.page-card blockquote,
.page-card table,
.page-card pre,
.page-card .mermaid {
    margin: 16px 0;
}

.page-card ul,
.page-card ol {
    padding-right: 24px;
}

.page-card li {
    margin: 6px 0;
}

.page-card blockquote {
    margin-right: 0;
    padding: 12px 16px;
    border-right: 4px solid var(--accent);
    background: var(--bg-muted);
    color: var(--text-muted);
    border-radius: 8px 0 0 8px;
}

/* Translated content direction follows target language, not UI shell */
.page-card[dir="ltr"],
.page-top-meta[dir="ltr"],
body[data-content-dir="ltr"] .page-card:not([dir="rtl"]),
body[data-content-dir="ltr"] .page-top-meta:not([dir="rtl"]) {
    direction: ltr;
    text-align: left;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.page-card[dir="ltr"] ul,
.page-card[dir="ltr"] ol {
    padding-right: 0;
    padding-left: 24px;
}

.page-card[dir="ltr"] blockquote {
    border-right: none;
    border-left: 4px solid var(--accent);
    border-radius: 0 8px 8px 0;
}

#pageToc[dir="ltr"] .toc-item,
.toc-drawer-nav[dir="ltr"] .toc-item {
    text-align: left;
}

.page-card[dir="ltr"] th,
.page-card[dir="ltr"] td,
html[dir="ltr"] .page-card:not([dir="rtl"]) th,
html[dir="ltr"] .page-card:not([dir="rtl"]) td {
    text-align: left;
}

.page-card[dir="rtl"],
.page-top-meta[dir="rtl"],
body[data-content-dir="rtl"] .page-card:not([dir="ltr"]),
body[data-content-dir="rtl"] .page-top-meta:not([dir="ltr"]) {
    direction: rtl;
    text-align: right;
    font-family: 'Vazirmatn', sans-serif;
}

#pageToc[dir="rtl"] .toc-item,
.toc-drawer-nav[dir="rtl"] .toc-item {
    text-align: right;
}

.page-card[dir="rtl"] th,
.page-card[dir="rtl"] td,
html[dir="rtl"] .page-card:not([dir="ltr"]) th,
html[dir="rtl"] .page-card:not([dir="ltr"]) td {
    text-align: right;
}

.code-block {
    position: relative;
}

.copy-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 4px 10px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.copy-btn.copied {
    color: var(--accent);
}

.page-card pre {
    direction: ltr;
    text-align: left;
    overflow: auto;
    padding: 16px;
    padding-top: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--code-bg);
    margin: 0;
}

.page-card pre code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    background: transparent;
    padding: 0;
}

.page-card :not(pre) > code {
    direction: ltr;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--code-bg);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}

.page-card table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    overflow: auto;
}

.page-card th,
.page-card td {
    border: 1px solid var(--border);
    padding: 10px 12px;
    text-align: start;
}

.page-card th {
    background: var(--bg-muted);
}

.page-card img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.page-card hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 32px 0;
}

.callout {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin: 16px 0;
}

.callout-title {
    font-weight: 700;
    margin-bottom: 8px;
}

.callout-body > :first-child {
    margin-top: 0;
}

.callout-body > :last-child {
    margin-bottom: 0;
}

.callout-note { background: var(--callout-note); }
.callout-tip { background: var(--callout-tip); }
.callout-warning { background: var(--callout-warning); }
.callout-danger { background: var(--callout-danger); }
.callout-info { background: var(--callout-info); }

.mermaid {
    overflow-x: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}

.page-pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 24px;
}

.pager-link {
    display: block;
    padding: 16px 18px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.pager-link:hover {
    border-color: var(--accent);
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(9, 105, 218, 0.08);
    transform: translateY(-1px);
}

[data-theme="dark"] .pager-link:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.pager-empty {
    visibility: hidden;
}

.pager-prev {
    text-align: start;
}

.pager-next {
    text-align: end;
}

.pager-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.pager-title {
    display: block;
    font-weight: 600;
    color: var(--accent);
}

.toc-panel {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    padding: 32px 20px 40px 24px;
    background: var(--bg-muted);
}

.toc-title {
    margin: 0 0 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.toc-filter {
    width: 100%;
    margin-bottom: 12px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    font-size: 12px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.toc-filter:focus {
    border-color: var(--accent);
}

.toc-filter-empty {
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.toc-item.toc-filter-hidden {
    display: none;
}

.toc-item {
    display: block;
    padding: 5px 10px;
    margin: 1px -10px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
    text-decoration: none;
    border-inline-start: 3px solid transparent;
}

.toc-item:hover,
.toc-item.active {
    color: var(--accent);
    text-decoration: none;
}

.toc-item.active {
    font-weight: 600;
    background: var(--accent-soft);
    border-inline-start-color: var(--accent);
}

.toc-h1 {
    font-weight: 600;
    color: var(--text);
}

.toc-h3 {
    margin-inline-start: 14px;
}

.toc-h4 {
    margin-inline-start: 28px;
    font-size: 12px;
}

.toc-empty {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 15;
}

@media (max-width: 1100px) {
    .book {
        grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    }

    .toc-panel {
        display: none;
    }

    .toc-fab {
        display: inline-flex;
    }

    .back-to-top {
        bottom: 84px;
    }
}

body.focus-mode .back-to-top {
    right: 28px;
}

@media (max-width: 860px) {
    .book {
        grid-template-columns: 1fr;
    }

    .page-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        width: min(var(--sidebar-width), 88vw);
        transform: translateX(100%);
        transition: transform 0.2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.open {
        display: block;
    }

    .back-to-top {
        right: 28px;
    }

    .page-inner {
        padding: 20px 16px 48px;
    }

    .page-card {
        padding: 24px 20px;
    }

    .page-pager {
        grid-template-columns: 1fr;
    }
}

/* Homepage */
.page-home .book {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.page-home .toc-panel,
.page-home .toc-fab,
.page-home .toc-drawer,
.page-home .toc-drawer-backdrop {
    display: none !important;
}

.page-home .page-inner {
    padding-top: 24px;
}

.page-home .page-card {
    border: none;
    box-shadow: none;
    padding-top: 0;
    background: transparent;
}

.page-home .continue-reading-banner {
    margin-bottom: 16px;
}

.page-home .home-hero {
    margin-top: 0;
    box-shadow: 0 2px 12px rgba(9, 105, 218, 0.06);
}

[data-theme="dark"] .page-home .home-hero {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.page-home .page-card > h2:first-of-type {
    margin-top: 40px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 1.15rem;
    color: var(--text-muted);
}

.home-hero {
    margin: -8px 0 8px;
    padding: 36px 40px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent-soft) 0%, var(--bg) 55%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.home-hero-badge {
    display: inline-block;
    margin: 0 0 12px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.home-hero-title {
    margin: 0 0 14px;
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    line-height: 1.35;
    font-weight: 700;
    color: var(--text);
}

.home-hero-desc {
    margin: 0 0 24px;
    max-width: 52rem;
    font-size: 1.05rem;
    color: var(--text-muted);
    line-height: 1.8;
}

.home-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.home-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.home-btn:hover {
    text-decoration: none;
}

.home-btn-primary {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
}

.home-btn-primary:hover {
    filter: brightness(1.08);
    color: #fff;
}

.home-btn-secondary {
    background: var(--bg);
    color: var(--accent);
    border: 1px solid var(--border);
}

.home-btn-secondary:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.home-btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px dashed var(--border);
}

.home-btn-ghost:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.home-section {
    margin: 28px 0 36px;
}

.home-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.home-section-title .home-section-icon {
    display: inline-flex;
    font-size: 1.15rem;
    line-height: 1;
}

.home-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.home-card {
    display: flex;
    flex-direction: column;
    padding: 20px 22px;
    border-radius: 12px;
    background: var(--bg-muted);
    border: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.home-card:hover {
    text-decoration: none;
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(9, 105, 218, 0.08);
    transform: translateY(-2px);
}

[data-theme="dark"] .home-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.home-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.home-card-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.home-card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.home-card-desc {
    margin: 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 768px) {
    .home-hero {
        padding: 24px 20px;
    }

    .home-cards {
        grid-template-columns: 1fr;
    }
}

.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 100;
    background: transparent;
    pointer-events: none;
}

.reading-progress span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.12s ease-out;
    border-radius: 0 2px 2px 0;
}

body.focus-mode .sidebar,
body.focus-mode .toc-panel,
body.focus-mode .toc-fab,
body.focus-mode .toc-drawer,
body.focus-mode .toc-drawer-backdrop,
body.focus-mode .sidebar-backdrop {
    display: none !important;
}

body.focus-mode .book {
    grid-template-columns: 1fr;
}

body.focus-mode .page {
    width: 100%;
    max-width: none;
}

body.focus-mode .page-inner {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 32px 48px 80px;
}

body.focus-mode .page-card {
    width: 100%;
    max-width: none;
    box-shadow: none;
    border-radius: 0;
    border-right: none;
    border-left: none;
}

.focus-exit {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 60;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 14px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.focus-exit:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.skip-link {
    position: absolute;
    top: -100px;
    right: 16px;
    z-index: 200;
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    top: 12px;
}

.font-size-control {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-muted);
}

.font-size-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 32px;
    font-weight: 700;
    line-height: 1;
}

.font-size-btn[data-size="sm"] {
    font-size: 11px;
}

.font-size-btn[data-size="md"] {
    font-size: 13px;
}

.font-size-btn[data-size="lg"] {
    font-size: 15px;
}

.font-size-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.shortcuts-hint {
    flex-shrink: 0;
    margin: 8px 12px 16px;
    width: calc(100% - 24px);
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    padding: 8px;
    cursor: pointer;
}

.shortcuts-hint:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.sticky-section-anchor {
    position: sticky;
    top: 12px;
    z-index: 25;
    height: 0;
    margin: 0;
    overflow: visible;
    pointer-events: none;
}

.sticky-section-bar {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: min(720px, calc(100% - 32px));
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg) 96%, transparent);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
    pointer-events: none;
}

.sticky-section-bar[hidden] {
    display: none !important;
}

.sticky-section-anchor:has(.sticky-section-bar:not([hidden])) {
    margin-bottom: 12px;
}

@media (max-width: 860px) {
    .sticky-section-anchor {
        top: calc(var(--header-height) + 8px);
    }
}

.sticky-section-label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.sticky-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toc-panel-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 12px;
}

.toc-panel-head .toc-title {
    margin: 0;
}

.toc-expand-btn {
    display: none;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 4px 10px;
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
}

body.toc-has-subheadings .toc-expand-btn {
    display: block;
}

.toc-expand-btn[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

body.toc-compact:not(.toc-expanded) .toc-item[data-level="3"],
body.toc-compact:not(.toc-expanded) .toc-item[data-level="4"] {
    display: none;
}

.continue-reading-sidebar {
    margin: 0 12px 10px;
}

.continue-reading-link {
    display: block;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--accent-soft);
    text-decoration: none;
    color: inherit;
}

.continue-reading-link:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.continue-reading-label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.continue-reading-title {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
}

.continue-reading-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--accent-soft);
}

.continue-reading-banner strong {
    display: block;
    margin-bottom: 4px;
}

.continue-reading-banner a {
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: filter 0.15s ease;
}

.continue-reading-banner a:hover {
    filter: brightness(1.08);
    text-decoration: none;
    color: #fff;
}

.zoomable-image {
    cursor: zoom-in;
}

.image-lightbox[hidden] {
    display: none !important;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    background: rgba(0, 0, 0, 0.82);
}

.image-lightbox img {
    max-width: min(96vw, 1200px);
    max-height: 82vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.image-lightbox-caption {
    margin: 0;
    color: #fff;
    font-size: 14px;
}

.image-lightbox-close {
    position: absolute;
    top: 20px;
    left: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-radius: 999px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 18px;
}

.shortcuts-modal[hidden] {
    display: none !important;
}

.shortcuts-modal {
    position: fixed;
    inset: 0;
    z-index: 130;
}

.shortcuts-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.shortcuts-modal-panel {
    position: relative;
    width: min(420px, calc(100vw - 32px));
    margin: 10vh auto 0;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.shortcuts-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.shortcuts-modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.shortcuts-modal-header button {
    border: none;
    background: transparent;
    font: inherit;
    cursor: pointer;
    color: var(--text-muted);
}

.shortcuts-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.shortcuts-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.shortcuts-list li:last-child {
    border-bottom: none;
}

.search-section-label {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.search-skeleton-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.search-skeleton-line {
    display: block;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--bg-muted), var(--border), var(--bg-muted));
    background-size: 200% 100%;
    animation: searchSkeleton 1.2s ease infinite;
}

.search-skeleton-title {
    width: 55%;
    margin-bottom: 8px;
}

.search-skeleton-snippet {
    width: 85%;
}

@keyframes searchSkeleton {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

@media print {
    .sidebar,
    .toc-panel,
    .page-header,
    .sidebar-backdrop,
    .theme-toggle,
    .focus-toggle,
    .focus-exit,
    .reading-progress,
    .sticky-section-bar,
    .shortcuts-modal,
    .image-lightbox,
    .shortcuts-hint,
    .font-size-control,
    .continue-reading-sidebar,
    .continue-reading-banner,
    .search-box,
    .page-pager,
    .copy-btn,
    .heading-anchor,
    .back-to-top,
    .toc-fab,
    .toc-drawer,
    .toc-drawer-backdrop {
        display: none !important;
    }

    .book {
        display: block;
    }

    .page-inner {
        padding: 0;
    }

    .page-card {
        border: none;
        box-shadow: none;
        padding: 0;
    }
}

.site-icon {
    display: inline-block;
    width: 1.15em;
    text-align: center;
    vertical-align: -0.12em;
    --fa-primary-color: var(--text);
    --fa-secondary-color: var(--text-muted);
    --fa-secondary-opacity: 0.45;
}

.back-to-top .site-icon {
    color: #fff;
    --fa-primary-color: #fff;
    --fa-secondary-color: rgba(255, 255, 255, 0.55);
    --fa-secondary-opacity: 1;
}

.home-card-icon .site-icon {
    font-size: 1.6rem;
}

.icon-browser {
    margin-top: 24px;
}

.icon-browser-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.icon-browser-search {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.icon-browser-search:focus {
    border-color: var(--accent);
}

.icon-browser-count {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.icon-browser-hint {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.icon-browser-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 10px;
}

.icon-browser-grid.loading {
    opacity: 0.55;
}

.icon-browser-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    text-align: center;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.icon-browser-item:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.icon-browser-item.copied {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.icon-browser-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
}

.icon-browser-preview .fa-duotone {
    --fa-primary-color: var(--text);
    --fa-secondary-color: var(--text-muted);
    --fa-secondary-opacity: 0.45;
}

.icon-browser-name {
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--text);
    word-break: break-all;
}

.icon-browser-label {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.35;
}

.icon-browser-empty,
.icon-browser-error {
    margin: 16px 0 0;
    font-size: 14px;
    color: var(--text-muted);
}

.icon-browser-load-more {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.icon-browser-load-more:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}


/* Login page */
body.page-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg-muted);
}

.login-page {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
}

.login-title {
    margin: 0 0 8px;
    font-size: 1.35rem;
    text-align: center;
}

.login-subtitle {
    margin: 0 0 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.login-error {
    margin: 0 0 16px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--callout-danger);
    color: var(--text);
    font-size: 0.9rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.login-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.login-field input:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

.login-submit {
    margin-top: 4px;
    padding: 11px 16px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.login-submit:hover {
    filter: brightness(1.05);
}

.login-decoy {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

/* Auth bar in sidebar */
.auth-bar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.auth-bar-guest {
    justify-content: flex-start;
}

.auth-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.auth-user {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    height: 36px;
    padding: 0 4px;
    color: var(--text-muted);
}

.auth-user .fa-duotone {
    font-size: 15px;
    flex-shrink: 0;
}

.auth-logout-form {
    margin: 0;
    flex-shrink: 0;
}

.auth-tool-btn,
.auth-admin-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-muted);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    flex-shrink: 0;
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    line-height: 1;
    box-shadow: none;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
}

.auth-tool-btn .fa-duotone,
.auth-admin-link .fa-duotone {
    font-size: 15px;
    pointer-events: none;
}

.auth-tool-btn:hover,
.auth-admin-link:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.auth-logout-btn:hover {
    border-color: #cf222e;
    color: #cf222e;
    background: var(--callout-danger);
}

/* Admin users page */
body.page-admin {
    min-height: 100vh;
    background: var(--bg-muted);
    padding: 24px;
}

.admin-page {
    max-width: 920px;
    margin: 0 auto;
}

.admin-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.admin-header h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
}

.admin-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.admin-back-link {
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
}

.admin-back-link:hover {
    text-decoration: underline;
}

.admin-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 16px;
}

.admin-card h2 {
    margin: 0 0 16px;
    font-size: 1.1rem;
}

.admin-message {
    margin: 0 0 16px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.92rem;
}

.admin-message-success {
    background: var(--callout-tip);
}

.admin-message-error {
    background: var(--callout-danger);
}

.admin-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

.admin-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    flex: 1;
}

.admin-field span {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.admin-field input {
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.admin-btn {
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.admin-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.admin-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.admin-btn-primary:hover {
    filter: brightness(1.05);
    color: #fff;
}

.admin-btn-danger:hover {
    border-color: #cf222e;
    color: #cf222e;
}

.admin-empty {
    margin: 0;
    color: var(--text-muted);
}

.admin-table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    text-align: start;
    vertical-align: middle;
}

.admin-table th {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 600;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-inline-form {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    margin: 0;
}

.admin-inline-form input[type="password"] {
    min-width: 140px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.admin-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.admin-tab {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
}

.admin-tab.active,
.admin-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.admin-form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.admin-field select,
.admin-field input[type="file"] {
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.admin-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    resize: vertical;
}

.admin-textarea-code {
    direction: ltr;
    text-align: left;
    unicode-bidi: plaintext;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}

.admin-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 0.92rem;
}

.admin-checkbox-inline {
    align-self: end;
    min-height: 38px;
}

.admin-badge {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-muted);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.admin-badge-ok {
    background: var(--callout-tip);
    color: var(--text);
}

.admin-badge-error {
    background: var(--callout-danger);
    color: var(--text);
}

.admin-muted {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.admin-nav-tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.admin-nav-tree .admin-nav-tree {
    margin-top: 8px;
    margin-inline-start: 16px;
    padding-inline-start: 12px;
    border-inline-start: 1px solid var(--border);
}

.admin-nav-item {
    margin-bottom: 8px;
}

.admin-nav-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.admin-nav-row-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.admin-nav-actions {
    flex-shrink: 0;
}

.admin-nav-delete-form {
    margin: 0;
}

.admin-btn-sm {
    padding: 6px 10px;
    font-size: 0.82rem;
}

.admin-nav-file {
    direction: ltr;
    unicode-bidi: isolate;
    text-align: left;
    display: inline-block;
    color: var(--text-muted);
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.82rem;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--bg-muted);
    border: 1px solid var(--border);
}

.admin-nav-item-protected .admin-nav-row-main strong {
    color: var(--text);
}

.admin-badge-protected {
    background: var(--callout-info);
    color: var(--text);
}

.admin-page-wide {
    max-width: 1080px;
}

.admin-field-wide {
    grid-column: 1 / -1;
}

.admin-field-badge {
    width: 100%;
}

.admin-input-badge {
    width: 100%;
    padding: 14px 16px;
    font-size: 1.08rem;
    line-height: 1.5;
}

.admin-hint {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.admin-readonly-list {
    margin: 0;
    display: grid;
    gap: 10px;
}

.admin-readonly-list dt {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.admin-readonly-list dd {
    margin: 0 0 8px;
}

.admin-repeat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-muted);
}

.admin-repeat-row-actions {
    display: flex;
    align-items: center;
    padding-bottom: 2px;
}

.admin-repeat-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.admin-catalog-sections {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-catalog-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-muted);
}

.admin-catalog-section-head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
    justify-content: space-between;
}

.admin-catalog-section-head .admin-form-grid {
    flex: 1;
    min-width: 240px;
}

.admin-catalog-files {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
}

.admin-catalog-files-label {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.admin-repeat-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-muted);
}

.admin-repeat-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-content-link:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.lang-switcher {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 14px 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.lang-switcher-label {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.lang-switcher-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.content-fallback-notice {
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--callout-warning, #d4a72c);
    border-radius: 8px;
    background: var(--callout-warning);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.page-edit-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--accent);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.page-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-muted);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
}

.page-edit-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

.page-edit-notice {
    margin: 0;
    color: var(--accent);
    font-size: 0.88rem;
}

.admin-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* Full-height page editor */
body.page-admin-edit {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 100vh;
    padding: 24px;
}

body.page-admin-edit .admin-page-edit {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-width: none;
    width: 100%;
}

body.page-admin-edit .admin-card-editor {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    margin-bottom: 0;
}

body.page-admin-edit .admin-edit-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 12px;
}

body.page-admin-edit .admin-edit-field {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

body.page-admin-edit .admin-edit-form .admin-form-actions {
    flex-shrink: 0;
}

body.page-admin-edit .admin-page-edit-textarea {
    flex: 1;
    min-height: 200px;
    resize: none;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    unicode-bidi: plaintext;
}

html[dir="rtl"] body.page-admin-edit .admin-page-edit-textarea {
    direction: rtl;
    text-align: right;
}

html[dir="ltr"] body.page-admin-edit .admin-page-edit-textarea {
    direction: ltr;
    text-align: left;
}

.page-translate-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--accent);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.page-translate-lang-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.page-translate-lang-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.page-translate-lang-select {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.page-translate-btn {
    padding: 6px 14px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s ease, opacity 0.15s ease;
}

.page-translate-btn:hover {
    filter: brightness(1.08);
    color: #fff;
}

.page-translate-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

.page-translate-original-btn {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
    font-weight: 500;
}

.page-translate-original-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    filter: none;
}

.page-translate-status {
    font-size: 0.85rem;
    min-height: 1.2em;
}

.page-translate-status.is-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.page-translate-status.is-loading::before {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: translate-spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes translate-spin {
    to { transform: rotate(360deg); }
}

.page-translate-status.is-done {
    color: var(--accent);
}

.translate-progress {
    margin: 12px 0 16px;
}

.translate-progress-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--bg-muted);
    overflow: hidden;
}

.translate-progress-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.25s ease;
}

.translate-batch-actions {
    margin-bottom: 16px;
}

.translate-lang-current {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-muted);
}

.translate-lang-current-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.translate-lang-picker {
    margin-top: 8px;
}

.translate-lang-picker-field select {
    min-width: 280px;
}
