/* Reset spacing and sizing */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Smooth anchor scrolling */
html {
    scroll-behavior: smooth;
}

/* Main body style */
body {
    font-family: Arial, sans-serif;
    background: linear-gradient(180deg, #f0f4f8, #ffffff);
    color: #1f2937;
    line-height: 1.7;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Dark mode body */
body.dark-mode {
    background: linear-gradient(180deg, #0f172a, #111827);
    color: #e5e7eb;
}

/* Links */
a {
    text-decoration: none;
    color: inherit;
}

/* Images */
img {
    max-width: 100%;
    display: block;
}

/* Decorative background */
.bg-decor {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}

/* Blob common style */
.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.22;
}

/* Blob one */
.b1 {
    width: 260px;
    height: 260px;
    background: #38bdf8;
    top: 60px;
    left: -70px;
}

/* Blob two */
.b2 {
    width: 300px;
    height: 300px;
    background: #60a5fa;
    top: 35%;
    right: -90px;
}

/* Blob three */
.b3 {
    width: 240px;
    height: 240px;
    background: #a5b4fc;
    bottom: 30px;
    left: 25%;
}

/* Skip link hidden */
.skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
}

/* Skip link visible on focus */
.skip-link:focus {
    left: 20px;
    top: 20px;
    background: #111827;
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    z-index: 9999;
}

/* Announcement bar */
.announcement-bar {
    background: linear-gradient(90deg, #0f172a, #1e3a8a);
    color: #fff;
    padding: 12px 18px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    text-align: center;
    font-size: 0.95rem;
}

/* Announcement bar links */
.announcement-bar a {
    color: #93c5fd;
    font-weight: bold;
}

/* Announcement badge */
.badge {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.18);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* Site header */
header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    min-height: 110px;
}

/* Dark mode header */
body.dark-mode header {
    background: rgba(17, 24, 39, 0.95);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

/* Logo wrapper */
.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    flex-shrink: 0;
    margin: 0;
    padding: 0;
}

/* Fixed logo size */
.logo img {
    width: 200px;
    height: auto;
    max-width: none;
    object-fit: contain;
    display: block;
}

/* Desktop nav */
.main-nav {
    display: flex;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
    min-width: 0;
}

/* Nav list */
.nav-links {
    list-style: none;
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

/* Nav links */
.nav-links li a {
    color: #1f2937;
    font-weight: 600;
    transition: 0.3s ease;
}

/* Dark mode nav links */
body.dark-mode .nav-links li a {
    color: #e5e7eb;
}

/* Nav hover */
.nav-links li a:hover {
    color: #2563eb;
}

/* Mobile site menu button */
.menu-toggle {
    display: none;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.25);
    border: none;
    flex-shrink: 0;
}

/* Site menu icon */
.menu-toggle i {
    font-size: 1.3rem;
    line-height: 1;
}

/* Mobile site sidebar */
.sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    width: 300px;
    height: 100vh;
    background: #111827;
    color: #fff;
    padding: 24px 20px;
    transition: 0.35s ease;
    z-index: 2000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: -10px 0 30px rgba(0,0,0,0.25);
}

/* Mobile site sidebar active */
.sidebar.active {
    right: 0;
}

/* Sidebar close button */
.close-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    margin-bottom: 22px;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
}

/* Sidebar list */
.sidebar ul {
    list-style: none;
    margin-bottom: 24px;
}

/* Sidebar items */
.sidebar ul li {
    margin-bottom: 14px;
}

/* Sidebar links */
.sidebar ul li a {
    color: #fff;
    font-size: 1rem;
}

/* Sidebar social row */
.sidebar-social {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Sidebar social links */
.sidebar-social a {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: 0.3s ease;
}

/* Sidebar social hover */
.sidebar-social a:hover {
    background: #2563eb;
    transform: translateY(-2px);
}

/* Main */
main {
    width: 100%;
}

/* Reader page section */
.reader-section {
    padding: 32px 18px 70px;
}

/* Reader layout */
.reader-wrap {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    align-items: start;
}

/* Desktop chapter sidebar */
.chapter-sidebar {
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(255,255,255,0.7);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    padding: 18px;
    position: sticky;
    top: 110px;
    height: calc(100vh - 110px);
    max-height: calc(100vh - 110px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Dark chapter sidebar */
body.dark-mode .chapter-sidebar {
    background: rgba(17, 24, 39, 0.92);
    border: 1px solid rgba(255,255,255,0.08);
}

/* Sidebar title */
.sidebar-title {
    font-size: 1.2rem;
    margin-bottom: 14px;
    color: #0f172a;
}

/* Dark sidebar title */
body.dark-mode .sidebar-title {
    color: #f8fafc;
}

/* Mobile chapter toggle */
.chapter-toggle {
    display: none;
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.25);
    border: none;
    flex-shrink: 0;
}

/* Chapter toggle icon */
.chapter-toggle i {
    font-size: 1.3rem;
    line-height: 1;
}

/* Mobile chapter panel */
.chapter-mobile-panel {
    position: fixed;
    top: 0;
    left: -340px;
    width: 320px;
    height: 100vh;
    background: #ffffff;
    color: #1f2937;
    padding: 20px 16px 20px;
    transition: 0.35s ease;
    z-index: 2100;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 10px 0 30px rgba(0,0,0,0.18);
    display: none;
}

/* Dark mobile chapter panel */
body.dark-mode .chapter-mobile-panel {
    background: #111827;
    color: #e5e7eb;
}

/* Show mobile chapter panel */
.chapter-mobile-panel.active {
    left: 0;
}

/* Mobile chapter close button */
.chapter-panel-close {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    margin-bottom: 18px;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
}

/* Right content translator row */
.content-translate-row {
    width: 100%;
    margin-bottom: 18px;
}

/* Translate wrapper */
.translate-wrap {
    margin-bottom: 16px;
}

/* Google Translate box on right content */
#google_translate_element,
#google_translate_element_mobile,
#google_translate_element_mobile_panel {
    width: 100%;
    max-width: 100%;
    height: 34px;
    min-height: 34px;
    max-height: 34px;
    background: #ffffff;
    padding: 2px 6px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    display: flex;
    align-items: center;
    overflow: hidden;
}

/* Dark translate widgets */
body.dark-mode #google_translate_element,
body.dark-mode #google_translate_element_mobile,
body.dark-mode #google_translate_element_mobile_panel {
    background: #1f2937;
    border: 1px solid rgba(255,255,255,0.08);
}

/* Keep Google widget visible */
.goog-te-gadget {
    font-size: 0 !important;
    line-height: 0 !important;
    width: 100% !important;
    display: block !important;
}

/* Hide Google default extra text */
.goog-te-gadget > span {
    display: none !important;
}

/* Google dropdown */
.goog-te-combo {
    width: 100% !important;
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    padding: 0 6px !important;
    border-radius: 6px !important;
    border: 1px solid #cbd5e1 !important;
    font-size: 12px !important;
    background: #ffffff !important;
    color: #111827 !important;
    margin: 0 !important;
    display: block !important;
    outline: none !important;
}

/* Dark dropdown */
body.dark-mode .goog-te-combo {
    background: #111827 !important;
    color: #f9fafb !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
}

/* Reader control buttons row */
.reader-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

/* Control button */
.control-btn {
    border: none;
    background: #2563eb;
    color: #fff;
    padding: 10px 8px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s ease;
}

/* Control hover */
.control-btn:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
}

/* Chapter search box */
.chapter-search {
    position: relative;
    margin-bottom: 16px;
}

/* Search input */
.chapter-search input {
    width: 100%;
    padding: 13px 14px 13px 42px;
    border-radius: 14px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 0.96rem;
    outline: none;
    transition: 0.3s ease;
}

/* Search hover */
.chapter-search input:hover {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/* Search focus */
.chapter-search input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

/* Dark search input */
body.dark-mode .chapter-search input {
    background: #111827;
    color: #f8fafc;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Search icon */
.chapter-search i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
}

/* Chapter list */
.chapter-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding-right: 6px;
    -webkit-overflow-scrolling: touch;
}

/* Chapter list items */
.chapter-list > li {
    margin-bottom: 8px;
}

/* Chapter links */
.chapter-list a {
    display: block;
    padding: 11px 12px;
    border-radius: 12px;
    color: #1f2937;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    transition: 0.3s ease;
    font-weight: 600;
}

/* Dark chapter links */
body.dark-mode .chapter-list a {
    background: #0f172a;
    color: #e5e7eb;
    border: 1px solid rgba(255,255,255,0.06);
}

/* Chapter hover */
.chapter-list a:hover {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
}

/* Dark chapter hover */
body.dark-mode .chapter-list a:hover {
    background: #1e3a8a;
    color: #ffffff;
}

/* Active chapter link */
.chapter-list a.active-link {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
}

/* Active chapter dark */
body.dark-mode .chapter-list a.active-link {
    background: #1e3a8a;
    color: #ffffff;
}

/* Subchapter list */
.subchapter-list {
    list-style: none;
    margin-top: 6px;
    padding-left: 16px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

/* Open subchapter list */
.subchapter-list.active {
    max-height: 500px;
}

/* Subchapter items */
.subchapter-list li {
    margin-bottom: 6px;
}

/* Subchapter links */
.subchapter-list a {
    font-size: 0.94rem;
    font-weight: 500;
    padding: 9px 10px;
}

/* Reader content card */
.reader-content {
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(255,255,255,0.7);
    border-radius: 26px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    padding: 28px 26px;
    width: 100%;
    position: relative;
}

/* Dark reader content */
body.dark-mode .reader-content {
    background: rgba(17, 24, 39, 0.92);
    border: 1px solid rgba(255,255,255,0.08);
}

/* Mobile reader tools */
.mobile-reader-tools {
    display: none;
    gap: 12px;
    align-items: stretch;
    justify-content: space-between;
    margin-bottom: 18px;
    flex-wrap: wrap;
    width: 100%;
}

/* Book title */
.book-title {
    font-size: 2rem;
    color: #0f172a;
    margin-bottom: 8px;
}

/* Dark book title */
body.dark-mode .book-title {
    color: #f8fafc;
}

/* Book subtitle */
.book-subtitle {
    color: #475569;
    margin-bottom: 24px;
    font-size: 1rem;
}

/* Dark subtitle */
body.dark-mode .book-subtitle {
    color: #cbd5e1;
}

/* Reading text wrapper */
.reading-text {
    font-size: 18px;
    transition: font-size 0.3s ease;
}

/* Paragraphs */
.reading-text p {
    margin-bottom: 18px;
    color: inherit;
}

/* Hide all chapter blocks by default */
.chapter-block {
    display: none;
    width: 100%;
    min-height: 100%;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* Show active chapter block */
.chapter-block.active-chapter {
    display: block;
}

/* Chapter content heading */
.chapter-block h2 {
    font-size: 1.55rem;
    margin-bottom: 14px;
    color: #1d4ed8;
}

/* Chapter subheading */
.chapter-block h3 {
    font-size: 1.12rem;
    margin: 20px 0 10px;
    color: #0f172a;
    scroll-margin-top: 130px;
}

/* Dark chapter subheading */
body.dark-mode .chapter-block h3 {
    color: #f8fafc;
}

/* Top and bottom chapter navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    flex-wrap: wrap;
}

/* Top chapter nav spacing */
.chapter-nav-top {
    margin-bottom: 24px;
}

/* Bottom chapter nav spacing */
.chapter-nav-bottom {
    margin-top: 24px;
}

/* Previous and next chapter buttons */
.chapter-btn {
    border: none;
    background: #2563eb;
    color: #ffffff;
    padding: 11px 18px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s ease;
}

/* Chapter button hover */
.chapter-btn:hover {
    background: #1d4ed8;
}

/* Disabled chapter button */
.chapter-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* Highlight in chapter list search */
.chapter-hit {
    background: #fde68a;
    color: #111827;
    padding: 1px 2px;
    border-radius: 4px;
}

/* Highlight in reader text search */
.reader-hit {
    background: #facc15;
    color: #111827;
    padding: 1px 2px;
    border-radius: 4px;
}

/* Right side go to top button */
#contentTopBtn {
    position: fixed;
    right: 18px;
    bottom: 78px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: #0f172a;
    color: #ffffff;
    font-size: 1.05rem;
    cursor: pointer;
    display: none;
    z-index: 998;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.28);
}

/* Right side go to top hover */
#contentTopBtn:hover {
    background: #1e3a8a;
}

/* Footer */
footer {
    background: #0f172a;
    color: #e5e7eb;
    padding: 45px 20px 28px;
    margin-top: 40px;
}

/* Footer menu */
.footer-menu {
    max-width: 1150px;
    margin: 0 auto 28px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
}

/* Footer columns */
.footer-menu .column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Footer links */
.footer-menu a {
    color: #cbd5e1;
    transition: 0.3s ease;
}

/* Footer hover */
.footer-menu a:hover {
    color: #60a5fa;
}

/* Footer social row */
.footer-social {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* Footer social links */
.footer-social a {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: 0.3s ease;
}

/* Footer social hover */
.footer-social a:hover {
    background: #2563eb;
    transform: translateY(-2px);
}

/* Footer text */
footer p {
    text-align: center;
    color: #94a3b8;
    font-size: 0.95rem;
}

/* Global go to top button */
#goTopBtn {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.3);
    display: none;
    z-index: 999;
}

/* Global go to top hover */
#goTopBtn:hover {
    background: #1d4ed8;
}

/* Stack layout for medium screens */
@media (max-width: 1100px) {
    .reader-wrap {
        grid-template-columns: 1fr;
    }

    .chapter-sidebar {
        display: none;
    }

    .chapter-mobile-panel {
        display: block;
    }

    .mobile-reader-tools {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        flex-wrap: nowrap;
        margin-bottom: 18px;
        width: 100%;
    }

    .chapter-toggle {
        display: flex;
        width: 52px;
        height: 52px;
        min-width: 52px;
        min-height: 52px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .reader-controls {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
        margin-bottom: 0;
        flex-wrap: nowrap;
        width: auto;
    }

    .control-btn {
        width: 52px;
        height: 52px;
        min-width: 52px;
        min-height: 52px;
        padding: 0;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0;
        flex-shrink: 0;
    }

    .control-btn i {
        font-size: 1.1rem;
        margin: 0;
    }

    .reader-content {
        padding: 22px 20px;
    }

    .chapter-list {
        max-height: 75vh;
        overflow-y: auto;
    }

    .book-title {
        font-size: 1.7rem;
    }
}

/* Site nav responsive */
@media (max-width: 992px) {
    header {
        min-height: auto;
        padding: 8px 14px;
        gap: 12px;
    }

    .main-nav {
        display: none;
    }

    .menu-toggle {
        display: flex;
    }

    .book-title {
        font-size: 1.7rem;
    }

    .logo {
        margin: 0;
        padding: 0;
    }

    .logo img {
        width: 260px;
        height: auto;
    }
}

/* Small devices */
@media (max-width: 768px) {
    header {
        min-height: auto;
        padding: 6px 12px;
        align-items: center;
    }

    .logo {
        margin: 0 !important;
        padding: 0 !important;
        line-height: 0;
    }

    .logo img {
        width: 62vw !important;
        max-width: 300px !important;
        min-width: 180px;
        height: auto !important;
    }

    .reader-section {
        padding: 22px 12px 48px;
    }

    .reader-content {
        padding: 18px 16px;
    }

    .chapter-sidebar {
        display: none;
    }

    .chapter-mobile-panel {
        display: block;
    }

    .mobile-reader-tools {
        display: flex;
    }

    .chapter-toggle {
        display: flex;
    }

    .reader-controls {
        display: flex;
        gap: 8px;
    }

    .control-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }

    .reading-text {
        font-size: 17px;
    }

    .chapter-nav {
        flex-direction: row;
        width: 100%;
    }

    .chapter-btn {
        flex: 1;
        text-align: center;
    }

    .chapter-list {
        max-height: 75vh;
        overflow-y: auto;
    }

    #google_translate_element,
    #google_translate_element_mobile,
    #google_translate_element_mobile_panel {
        height: 32px;
        min-height: 32px;
        max-height: 32px;
    }

    .goog-te-combo {
        height: 26px !important;
        min-height: 26px !important;
        max-height: 26px !important;
        font-size: 11px !important;
    }
}

/* Very small phones */
@media (max-width: 520px) {
    .announcement-bar {
        font-size: 0.88rem;
    }

    header {
        padding: 4px 10px;
        gap: 10px;
    }

    .book-title {
        font-size: 1.45rem;
    }

    .chapter-block h2 {
        font-size: 1.3rem;
    }

    .chapter-mobile-panel {
        width: 290px;
        left: -310px;
    }

    .logo img {
        width: 64vw !important;
        max-width: 260px !important;
        min-width: 165px;
    }

    #google_translate_element,
    #google_translate_element_mobile,
    #google_translate_element_mobile_panel {
        height: 32px;
        min-height: 32px;
        max-height: 32px;
    }

    .goog-te-combo {
        height: 26px !important;
        min-height: 26px !important;
        max-height: 26px !important;
        font-size: 11px !important;
    }
}