/* ==================================================
   OVERLAY
================================================== */
@font-face {
    font-family: "Literata";
    src: url("../fonts/Literata-VariableFont_opsz,wght.woff2") format("woff2");
    font-weight: 300 900;
    font-style: normal;
    font-display: swap;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    opacity: 0;
    visibility: hidden;
    transition: .25s;
    z-index: 998;
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-y: scroll;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: "Literata", serif;
    background: #f8f8f6;
    color: #333;
    font-size: 17px;
    line-height: 1.9;
}

img {
    max-width: 100%;
    display: block;
}

button {
    font: inherit;
}

/* ==================================================
   DRAWER MENU
================================================== */
.drawer {
    position: fixed;
    top: 0;
    left: 0;
    transform: translateX(-100%);
    width: 280px;
    height: 100dvh;
    background: #fff;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform .3s;
    box-shadow: 4px 0 20px rgba(0, 0, 0, .12);
    z-index: 1000;
    padding: 24px;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.drawer h3 {
    font-size: 15px;
    color: #666;
    margin: 24px 0 12px;
}

.drawer hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 18px 0;
}

.drawer nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drawer nav a {
    text-decoration: none;
    color: #333;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background .2s, color .2s;
}

.drawer nav a:hover {
    background: #eef6f3;
}

.drawer nav a.active {
    background: #3d8c73;
    color: #fff;
}

.drawer button {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: none;
    border-radius: 8px;
    background: #f4f4f4;
    cursor: pointer;
    font-size: 15px;
}

.drawer button:hover {
    background: #e9e9e9;
}

/* ==================================================
   TOUCH OPTIMIZATION
================================================== */
#menuButton,
#fontDown,
#fontUp {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ==================================================
   TOP BAR
================================================== */
.topbar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: rgba(248, 248, 246, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #e9e9e9;
    z-index: 900;
}

.topbar a {
    color: #2d665d;
    text-decoration: none;
    font-weight: 600;
}

.topbar button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

/* ==================================================
   KHUNG ĐỌC
================================================== */
.reader {
    width: min(100%, 680px);
    margin: auto;
    padding: 36px 22px 80px;
    transition: font-size .2s;
}

.reader h1 {
    font-size: 34px;
    line-height: 1.35;
    margin-bottom: 28px;
    color: #222;
}

/* ==================================================
   FLOATING PROGRESS
================================================== */
.floating-progress {
    position: sticky;
    top: 57px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 18px;
    background: rgba(248, 248, 246, .95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #ececec;
    z-index: 890;

    /* Trạng thái ẩn */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-100%);
    transition: transform .35s cubic-bezier(.4, 0, .2, 1), opacity .25s ease, visibility .35s;
}

.floating-progress.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.progress-track {
    flex: 1;
    height: 4px;
    background: #ddd;
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: #3d8c73;
    transition: width .15s linear;
}

.progress-text {
    white-space: nowrap;
    font-size: 13px;
    color: #666;
    font-weight: 600;
}

/* ==================================================
   NỘI DUNG
================================================== */
section {
    margin-bottom: 70px;
    scroll-margin-top: 80px;
}

section h2 {
    font-size: 26px;
    line-height: 1.5;
    color: #222;
    margin-bottom: 28px;
    padding-bottom: 18px;
    border-bottom: 1px solid #ececec;
}

section p {
    margin-bottom: 30px;
}

blockquote {
    margin: 40px 0;
    padding: 20px 24px;
    border-left: 4px solid #3d8c73;
    background: #f2f6f4;
    font-style: italic;
}

figure {
    margin: 40px 0;
}

figure img {
    width: 100%;
    border-radius: 8px;
    display: block;
}

figcaption {
    margin-top: 12px;
    text-align: center;
    font-size: 14px;
    color: #888;
}

a {
    color: #2d665d;
}

/* ==================================================
   KẾT THÚC SÁCH
================================================== */
.end-book {
    text-align: center;
    margin-top: 80px;
    padding-top: 40px;
    border-top: 1px solid #ececec;
}

.end-book h2 {
    border: none;
    margin-bottom: 18px;
}

.end-book p {
    margin-bottom: 20px;
}

.end-book a {
    display: inline-block;
    padding: 12px 22px;
    margin: 6px;
    border-radius: 8px;
    background: #2d665d;
    color: white;
    text-decoration: none;
}

/* ==================================================
   FOOTER
================================================== */
footer {
    text-align: center;
    color: #666;
    font-size: 15px;
    padding-bottom: 40px;
}

footer hr {
    border: none;
    border-top: 1px solid #ddd;
    margin-bottom: 20px;
}

footer a {
    color: #2d665d;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* ==================================================
   STUDY BLOCK
================================================== */
.study-block {
    margin: 40px 0;
    padding: 20px;
    border: 1px solid #e6e6e6;
    border-radius: 12px;
    background: #fcfcfb;
}

.study-mode-button {
    position: fixed;
    right: 20px;
    bottom: 80px;
    z-index: 950;
    padding: 12px 18px;
    border: none;
    border-radius: 99px;
    background: #2d665d;
    color: white;
    cursor: pointer;

    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease;

    /* Tối ưu cảm ứng cho nút */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.study-mode-button.show {
    opacity: 1;
    visibility: visible;
}

.study-text {
    display: block;
}

.study-table {
    display: none;
    overflow-x: auto;
}

.study-table table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.study-mode .study-text {
    display: none;
}

.study-mode .study-table {
    display: block;
}

.study-table th,
.study-table td {
    padding: 12px 14px;
    border: 1px solid #ddd;
    vertical-align: middle;
    text-align: left;
}

.study-table th {
    background: #f2f6f4;
    font-weight: 600;
}

.study-note {
    margin-top: 16px;
    color: #777;
    font-size: .95em;
    font-style: italic;
}

.study-repeat {
    font-weight: 600;
    background: #f7faf9;
    white-space: nowrap;
}

.study-muted {
    color: #888;
    font-style: italic;
}

/* ==================================================
   RESPONSIVE / MOBILE
================================================== */
@media (max-width: 768px) {
    body {
        font-size: 16.5px;
    }

    .reader {
        padding: 28px 18px 60px;
    }

    .reader h1 {
        font-size: 30px;
    }

    section h2 {
        font-size: 24px;
    }
}

@media (max-width: 420px) {
    .reader {
        padding: 24px 16px 50px;
    }

    .reader h1 {
        font-size: 26px;
    }

    section h2 {
        font-size: 22px;
    }

    .topbar {
        padding: 10px 16px;
    }

    .floating-progress {
        top: 53px;
        padding: 8px 16px;
        gap: 10px;
    }

    .progress-text {
        font-size: 12px;
    }

    .study-block {
        padding: 16px;
    }

    .study-table th,
    .study-table td {
        padding: 10px;
    }
}