* {
    box-sizing: border-box;
}

:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f2f2f2;
    --text: #222222;
    --muted: #6b6b6b;
    --accent: #8b1a1a;
    --accent-soft: #e6cccc;
    --border: #e2e2e2;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
    --font-size: 20px;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    line-height: 1.9;
}

body.dark {
    --bg: #1c1b19;
    --surface: #272522;
    --surface-2: #302d28;
    --text: #e8e0d2;
    --muted: #aaa092;
    --accent: #c8a978;
    --accent-soft: #66563d;
    --border: #49443d;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

.header-inner {
    max-width: 1400px;
    height: 66px;
    margin: auto;
    padding: 0 22px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.site-title {
    color: var(--accent);
    text-decoration: none;
    font-size: 22px;
    font-weight: bold;
    line-height: 1.15;
    flex: 1;
}

.title-line1 {
    margin-left: 0.2em;
}

.title-line2 {
    display: inline;
}

.lotus-icon {
    width: 1.2em;
    height: 1.2em;
    vertical-align: -0.22em;
    color: var(--accent);
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    gap: 7px;
}

.header-actions button,
.menu-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    min-width: 40px;
    height: 38px;
    cursor: pointer;
}

.page-layout {
    max-width: 1400px;
    margin: auto;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    min-height: calc(100vh - 66px);
    transition: grid-template-columns .25s ease;
}

.sidebar {
    border-right: 1px solid var(--border);
    padding: 28px 16px;
    position: fixed;
    top: 66px;
    left: max(0px, calc((100vw - 1400px) / 2));
    width: 320px;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .2s ease;
    z-index: 970;
}

.sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 20px;
    font-weight: bold;
    margin: 0 10px 18px;
    color: var(--accent);
    flex-shrink: 0;
}

.sidebar-close {
    display: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    width: 30px;
    height: 30px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 8, 0.45);
    z-index: 965;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}

body.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
}

/* Desktop: Mục lục ẩn theo mặc định, chỉ hiện khi bấm nút ☰ */
@media (min-width: 801px) {
    .sidebar-overlay {
        display: none;
    }

    .page-layout {
        grid-template-columns: 0 minmax(0, 1fr);
    }

    .sidebar {
        opacity: 0;
        padding: 28px 0;
        border-right: 0;
        pointer-events: none;
    }

    html.sidebar-expanded .page-layout {
        grid-template-columns: 320px minmax(0, 1fr);
    }

    html.sidebar-expanded .sidebar {
        opacity: 1;
        padding: 28px 16px;
        border-right: 1px solid var(--border);
        pointer-events: auto;
    }
}

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar nav a {
    color: var(--text);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 7px;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: var(--surface-2);
    color: var(--accent);
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 12px 12px;
    flex-shrink: 0;
}

.sidebar-contact {
    padding: 0 12px 8px;
    font-size: 13px;
    color: var(--text);
    opacity: 0.7;
    flex-shrink: 0;
}

.sidebar-contact a {
    color: inherit;
    text-decoration: none;
}

.sidebar-contact a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.home-main {
    padding: 60px 24px 120px;
}

.hero {
    max-width: 820px;
    margin: 0 auto 35px;
    text-align: center;
    padding: 70px 25px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 16px;
}

.lotus {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 20px;
}

.lotus.small {
    font-size: 32px;
}

.hero h1,
.sutra-heading h1 {
    font-size: clamp(32px, 5vw, 48px);
    font-weight: normal;
    margin: 0 0 10px;
    color: var(--accent);
}

.hero p {
    color: var(--muted);
    margin-bottom: 32px;
}

.primary-btn {
    display: inline-block;
    padding: 11px 25px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

.intro-card {
    max-width: 820px;
    margin: auto;
    padding: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    text-align: center;
}

.intro-card h2 {
    color: var(--accent);
    font-weight: normal;
}

.intro-card p {
    color: var(--muted);
}

.quick-links {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.quick-links a {
    color: var(--accent);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 8px;
}

.reading-main {
    grid-column: 2;
    padding: 20px 45px 120px;
}

.sutra {
    max-width: 850px;
    margin: auto;
}

.sutra-heading {
    display: none;
}

/* ===== Tiêu đề Kinh ===== */
.kinh-title {
    text-align: center;
    margin-bottom: 40px;
    line-height: 1.8;
}

.kinh-title .main-title {
    font-size: 28px;
    font-weight: bold;
    color: var(--accent);
    letter-spacing: 2px;
}

.kinh-title .sub-title {
    font-size: 22px;
    font-weight: bold;
    color: var(--accent);
    letter-spacing: 1px;
}

.kinh-title .sub-title-2 {
    font-size: 22px;
    font-weight: bold;
    color: var(--accent);
    letter-spacing: 1px;
}

.kinh-title .trans-info {
    font-size: 16px;
    color: var(--muted);
    margin-top: 10px;
}

.kinh-title .trans-info em {
    font-style: italic;
}

.chapter {
    scroll-margin-top: 90px;
    margin-bottom: 30px;
}

.chapter h2 {
    text-align: center;
    color: var(--accent);
    font-size: 27px;
    font-weight: normal;
    margin-bottom: 12px;
    margin-top: 8px;
}

.sutra-text {
    font-size: var(--font-size);
}

.sutra-text p {
    margin: 0 0 0.8em;
    text-align: justify;
    text-justify: inter-word;
    word-spacing: 0.05em;
}

/* Lưu ý: text-align: justify tự động để dòng cuối cùng của mỗi đoạn
   canh trái (không kéo giãn), nên không cần rule riêng cho :last-child. */

/* ===== Câu thơ / kệ: canh trái từng dòng, không kéo giãn 2 bên =====
   Cách dùng trong HTML:
   <div class="poem">
       <p>Sắc Như Lai đoan trang vi diệu,</p>
       <p>Tất cả thế gian chẳng sánh bằng.</p>
       ...
   </div>
*/
.sutra-text .poem {
    margin: 0 0 0.8em;
}

.sutra-text .poem p {
    text-align: left;
    word-spacing: normal;
    margin: 0 0 0.15em;
    padding-left: 2em !important;
}

.sutra-text .poem p:last-child {
    margin-bottom: 0;
}

.placeholder {
    color: var(--muted);
    text-align: center !important;
    padding: 25px 20px;
    border: 1px dashed var(--border);
    border-radius: 10px;
}

/* ===== Audio section ===== */
.audio-section {
    scroll-margin-top: 90px;
    margin-top: 0;
    margin-bottom: 40px;
    padding: 10px 16px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

.audio-title {
    display: none;
}

.playlist {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 6px;
}

.track {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 4px 10px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    min-height: 28px;
}

.track:last-child {
    border-bottom: 0;
}

.track:hover,
.track.active {
    background: var(--surface-2);
    color: var(--accent);
}

.track-number {
    width: 22px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

.audio-player {
    margin-top: 4px;
}

#audioPlayer {
    display: none;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.player-controls button {
    width: 30px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.player-controls .play-btn {
    width: 34px;
    height: 34px;
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-size: 14px;
}

.player-controls .repeat-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.progress-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
}

.progress-wrapper span {
    font-family: Arial, sans-serif;
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
}

.progress-track-wrap {
    position: relative;
    flex: 1;
    min-width: 60px;
    display: flex;
    align-items: center;
}

.progress-wrapper input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
    height: 4px;
}

.seek-tooltip {
    position: absolute;
    bottom: 100%;
    margin-bottom: 9px;
    left: 0;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    font-family: Arial, sans-serif;
    font-size: 11px;
    font-weight: bold;
    padding: 3px 7px;
    border-radius: 5px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
    z-index: 30;
}

.seek-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text);
}

.seek-tooltip.visible {
    opacity: 1;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 80px;
    flex-shrink: 0;
}

.volume-control span {
    font-size: 12px;
}

.volume-control input[type="range"] {
    width: 60px;
    height: 4px;
}

.collapse-player-btn {
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.progress-row {
    display: none;
}

/* ===== Trình phát thu nhỏ (mini player) ===== */
body.player-collapsed .audio-section {
    display: none;
}

body.player-collapsed .reading-main {
    padding-bottom: 100px;
}

.mini-player {
    display: none;
    align-items: center;
    gap: 10px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 960;
    padding: 8px 16px;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(10px);
    box-shadow: 0 -8px 24px rgba(30, 20, 5, 0.1);
}

body.player-collapsed .mini-player {
    display: flex;
}

.mini-expand-btn {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
}

.mini-info {
    flex-shrink: 0;
    max-width: 150px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
    color: var(--accent);
}

.mini-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.mini-controls button {
    width: 30px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mini-play-btn {
    width: 34px !important;
    height: 34px !important;
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
    font-size: 14px !important;
}

.mini-controls .repeat-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.mini-volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 74px;
    flex-shrink: 0;
}

.mini-volume-control span {
    font-size: 12px;
}

.mini-volume-control input[type="range"] {
    width: 56px;
    height: 4px;
}

.mini-progress-row {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
    font-family: Arial, sans-serif;
    font-size: 10px;
    color: var(--muted);
}

.mini-progress-row input {
    width: 100%;
    height: 4px;
}

/* ===== Nút Về đầu trang - nằm trên mini player và trên footer ===== */
.scroll-top-btn {
    display: none;
    position: fixed;
    right: 22px;
    bottom: 50px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--accent);
    color: #fff;
    font-size: 19px;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    z-index: 975;
}

.scroll-top-btn.show {
    display: flex;
}

/* Khi mini player hiển thị, đẩy nút lên trên khung mini player.
   --mini-player-height được JS đo và cập nhật theo chiều cao thực tế,
   vì mini-player có thể xuống dòng (cao hơn) trên màn hình nhỏ. */
body.player-collapsed .scroll-top-btn {
    bottom: calc(var(--mini-player-height, 66px) + 12px);
}

/* ===== Footer - giảm height 70% ===== */
.site-footer {
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px 24px 12px;
    text-align: center;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.site-footer p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    letter-spacing: 0.3px;
}

.footer-hands {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    line-height: 1;
}

.footer-hands span {
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.footer-hands span:hover {
    opacity: 1;
}

/* ===== Mobile: ẩn loa, thanh tiến độ, hiển thị time với dấu / ===== */
@media (max-width: 800px) {
    .site-title {
        font-size: 18px;
    }

    .title-line2 {
        display: block;
        width: fit-content;
    }

    .page-layout {
        display: block;
    }

    .sidebar {
        position: fixed;
        z-index: 970;
        top: 66px;
        left: 0;
        width: min(320px, 85vw);
        height: calc(100vh - 66px);
        background: var(--surface);
        box-shadow: 12px 0 30px rgba(0,0,0,.12);
        transform: translateX(-105%);
        transition: transform .2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .reading-main {
        padding: 16px 17px 120px;
    }

    .home-main {
        padding: 25px 15px 100px;
    }

    .hero {
        padding: 50px 20px;
    }

    .sutra-text {
        font-size: var(--font-size);
    }

    .audio-section {
        padding: 8px 12px 12px;
        margin-bottom: 30px;
    }

    /* Mobile: ẩn icon loa và thanh tiến độ */
    .audio-section .volume-control {
        display: none !important;
    }
    
    .audio-section .progress-wrapper .progress-track-wrap {
        display: none !important;
    }
    
    .audio-section .progress-wrapper {
        min-width: auto;
        gap: 4px;
    }
    
    .audio-section .progress-wrapper span {
        font-size: 10px;
    }
    
    /* Thêm dấu / giữa thời gian */
    .audio-section .progress-wrapper span:first-child::after {
        content: " / ";
        color: var(--muted);
    }

    .controls-row {
        gap: 6px;
    }

    .player-controls button {
        width: 26px;
        height: 24px;
        font-size: 11px;
    }

    .player-controls .play-btn {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .progress-wrapper {
        min-width: 80px;
    }

    .progress-wrapper span {
        font-size: 9px;
    }

    .volume-control {
        width: 60px;
    }

    .volume-control input[type="range"] {
        width: 40px;
    }

    .collapse-player-btn {
        font-size: 11px;
        padding: 3px 8px;
    }

    .sidebar-close {
        display: block;
    }

    /* Nút về đầu trang mobile - mờ 50% và ở trên mini player */
    .scroll-top-btn {
        right: 14px;
        bottom: 40px;
        width: 42px;
        height: 42px;
        font-size: 17px;
        opacity: 0.5;
        transition: opacity 0.2s ease;
    }
    
    .scroll-top-btn:hover,
    .scroll-top-btn:active {
        opacity: 1;
    }

    /* Khi mini player hiển thị, nút về đầu trang nằm trên mini player */
    body.player-collapsed .scroll-top-btn {
        bottom: calc(var(--mini-player-height, 78px) + 10px);
    }

    body.player-collapsed .reading-main {
        padding-bottom: 110px;
    }

    .mini-player {
        flex-wrap: wrap;
        row-gap: 6px;
        padding: 8px 12px 10px;
    }

    .mini-info {
        order: 1;
        max-width: 50%;
        font-size: 12px;
    }

    .mini-expand-btn {
        order: 2;
        margin-left: auto;
    }

    .mini-controls {
        order: 3;
        width: 100%;
        justify-content: center;
        gap: 10px;
    }

    .mini-repeat-btn,
    .mini-volume-control {
        display: none;
    }

    .mini-progress-row {
        order: 4;
        flex-basis: 100%;
    }
    
    .site-footer {
        padding: 6px 16px 10px;
        gap: 10px;
    }
    
    .site-footer p {
        font-size: 12px;
        margin: 0;
    }
    
    .footer-hands {
        font-size: 12px;
        gap: 6px;
    }

    .track {
        padding: 3px 8px;
        font-size: 12px;
        min-height: 24px;
        gap: 8px;
    }

    .track-number {
        width: 18px;
        font-size: 11px;
    }

    .chapter {
        margin-bottom: 24px;
    }
    
    .chapter h2 {
        margin-bottom: 10px;
        margin-top: 6px;
        font-size: 23px;
    }
    
    .sutra-text p {
        margin: 0 0 0.6em;
    }

    .sutra-text .poem p {
        padding-left: 1.6em !important;
    }

    .kinh-title .main-title {
        font-size: 22px;
    }

    .kinh-title .sub-title {
        font-size: 18px;
    }

    .kinh-title .sub-title-2 {
        font-size: 18px;
    }

    .kinh-title .trans-info {
        font-size: 14px;
    }
}

@media (max-width: 450px) {
    .header-actions {
        gap: 3px;
    }

    .header-actions button {
        min-width: 34px;
        padding: 0;
    }

    .site-title {
        font-size: 16px;
    }

    .controls-row {
        gap: 4px;
    }

    .player-controls button {
        width: 24px;
        height: 22px;
        font-size: 10px;
    }

    .player-controls .play-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .progress-wrapper {
        min-width: 60px;
    }

    .progress-wrapper span {
        font-size: 8px;
    }

    .volume-control {
        width: 50px;
    }

    .volume-control input[type="range"] {
        width: 30px;
    }

    .collapse-player-btn {
        font-size: 10px;
        padding: 2px 6px;
    }
    
    .track {
        padding: 2px 6px;
        font-size: 11px;
        min-height: 22px;
        gap: 6px;
    }
    
    .track-number {
        width: 16px;
        font-size: 10px;
    }
    
    .chapter {
        margin-bottom: 18px;
    }
    
    .chapter h2 {
        font-size: 20px;
        margin-bottom: 8px;
        margin-top: 4px;
    }
    
    .sutra-text p {
        margin: 0 0 0.5em;
    }

    .sutra-text .poem p {
        padding-left: 1.4em !important;
    }

    .kinh-title .main-title {
        font-size: 19px;
    }

    .kinh-title .sub-title {
        font-size: 16px;
    }

    .kinh-title .sub-title-2 {
        font-size: 16px;
    }

    .kinh-title .trans-info {
        font-size: 12px;
    }

    .scroll-top-btn {
        right: 12px;
        bottom: 16px;
        width: 38px;
        height: 38px;
        font-size: 15px;
    }

    body.player-collapsed .scroll-top-btn {
        bottom: calc(var(--mini-player-height, 74px) + 8px);
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .site-footer {
        padding: 4px 12px 8px;
        gap: 8px;
    }
    
    .site-footer p {
        font-size: 11px;
    }
    
    .footer-hands {
        font-size: 11px;
        gap: 4px;
    }
}