/* ============================================================
   /assets/css/main.css
   Hệ thống thiết kế dùng chung — Mobile-first
   Ưu tiên: đọc lâu không mỏi mắt, thao tác 1 tay, tốc độ tải
   ============================================================ */

/* ===== DESIGN TOKENS ===== */
:root {
    /* Màu nền — giấy ngà ấm, không dùng trắng thuần (đỡ chói) */
    --paper:       #fbf8f3;
    --paper-dim:   #f0ebe2;
    --paper-card:  #ffffff;

    /* Màu chữ — đen ấm, không dùng đen thuần */
    --ink:         #1a1410;
    --ink-soft:    #6b5d4f;
    --ink-faint:   #a89a89;

    /* Đường viền */
    --border:      #e4dccd;
    --border-soft: #ede6d8;

    /* Accent — cam đất nung, đậm và rõ trên mobile */
    --accent:      #b8541f;
    --accent-deep: #7c3a14;
    --accent-soft: #fdf0e6;

    /* Trạng thái */
    --green:  #2d6a3e;
    --green-bg: #e9f5ec;
    --yellow: #9a6a0c;
    --yellow-bg: #fdf3df;
    --red:    #b3261e;
    --red-bg: #fbe9e7;

    /* Bán kính bo góc */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;
    --r-pill: 999px;

    /* Font */
    --font-ui:    -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-read:  Georgia, 'Times New Roman', 'Noto Serif', serif;

    /* Chiều cao thanh điều hướng dưới (mobile) */
    --bottombar-h: 60px;
    --topbar-h: 56px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-ui);
    background: var(--paper);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-deep); }
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; }

/* Vùng chạm tối thiểu 44px cho thao tác ngón tay */
.tap-target { min-height: 44px; min-width: 44px; display: flex; align-items: center; justify-content: center; }

/* ===== TOP BAR (mobile-first, sticky) ===== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--ink);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 14px;
    box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.site-logo {
    font-size: 1.25rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: -.3px;
}
.site-logo span { color: #e8956b; }

.header-search-btn {
    margin-left: auto;
    background: rgba(255,255,255,.1);
    border: none;
    border-radius: var(--r-pill);
    color: #fff;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* Search bar full-screen overlay style cho mobile */
.search-overlay {
    position: fixed;
    inset: 0;
    background: var(--paper);
    z-index: 200;
    display: none;
    flex-direction: column;
    padding: 14px;
}
.search-overlay.active { display: flex; }
.search-overlay form { display: flex; gap: 8px; }
.search-overlay input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    font-size: 1rem;
    background: var(--paper-card);
}
.search-overlay-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--ink-soft);
    padding: 0 4px;
}

/* Desktop nav — ẩn trên mobile, hiện từ tablet trở lên */
.site-nav-desktop { display: none; }
.header-search-desktop { display: none; }

/* ===== BOTTOM NAV (chỉ mobile) — thao tác 1 tay ===== */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    background: var(--paper-card);
    border-top: 1px solid var(--border);
    display: flex;
    height: var(--bottombar-h);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--ink-faint);
    font-size: .68rem;
    font-weight: 600;
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav .icon { font-size: 1.25rem; line-height: 1; }

/* ===== MAIN CONTENT ===== */
.site-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 14px calc(var(--bottombar-h) + 24px);
}

/* ===== FOOTER (ẩn trên mobile vì có bottom nav, hiện desktop) ===== */
.site-footer {
    display: none;
    background: var(--ink);
    color: var(--ink-faint);
    text-align: center;
    padding: 24px;
    font-size: .82rem;
}

/* ===== FLASH MESSAGES ===== */
.flash {
    padding: 12px 16px;
    border-radius: var(--r-md);
    margin-bottom: 14px;
    font-size: .9rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.flash-error   { background: var(--red-bg);   border: 1px solid #f3cbc7; color: var(--red); }
.flash-success { background: var(--green-bg); border: 1px solid #c5e3cd; color: var(--green); }

/* ===== STORY GRID — 2 cột trên mobile, không co quá nhỏ ===== */
.story-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.story-card {
    background: var(--paper-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    overflow: hidden;
    display: block;
    transition: transform .15s, box-shadow .15s;
}
.story-card:active { transform: scale(.97); }
.story-card-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    background: var(--paper-dim);
}
.story-card-cover-placeholder {
    width: 100%; aspect-ratio: 2/3;
    background: linear-gradient(160deg, var(--paper-dim), var(--border-soft));
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
}
.story-card-body { padding: 10px 10px 12px; }
.story-card-title {
    font-size: .88rem;
    font-weight: 700;
    color: var(--ink);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
    margin-bottom: 4px;
}
.story-card-meta { font-size: .76rem; color: var(--ink-soft); }

/* ===== SECTION HEADING ===== */
.section-heading {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--ink);
    border-left: 4px solid var(--accent);
    padding-left: 10px;
    margin-bottom: 14px;
}

/* ===== CATEGORY CHIPS ===== */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-soft);
}
.chip-count { font-size: .72rem; color: var(--ink-faint); }

/* ===== BREADCRUMB — ẩn trên mobile để tiết kiệm không gian ===== */
.breadcrumb { display: none; }

/* ===== STORY DETAIL ===== */
.story-detail-hero {
    display: flex;
    gap: 14px;
    margin-bottom: 18px;
}
.story-detail-cover {
    width: 110px;
    aspect-ratio: 2/3;
    object-fit: cover;
    flex-shrink: 0;
    border-radius: var(--r-md);
    box-shadow: 0 4px 14px rgba(26,20,16,.15);
}
.story-detail-cover-placeholder {
    width: 110px; aspect-ratio: 2/3; flex-shrink: 0;
    background: linear-gradient(160deg, var(--paper-dim), var(--border-soft));
    border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
}
.story-detail-title {
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 8px;
}
.story-detail-meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--r-pill);
    font-size: .72rem;
    font-weight: 700;
}
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-gray   { background: var(--paper-dim); color: var(--ink-soft); }
.badge-blue   { background: #e3ecfb; color: #2151a8; }

.story-description {
    font-size: .88rem;
    color: var(--ink-soft);
    line-height: 1.7;
    background: var(--paper-dim);
    border-left: 3px solid var(--border);
    padding: 12px 14px;
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
    margin-bottom: 16px;
}

/* CTA buttons — full width trên mobile cho dễ chạm */
.btn-cta-row { display: flex; gap: 10px; margin-bottom: 20px; }
.btn-cta {
    flex: 1;
    text-align: center;
    padding: 13px;
    border-radius: var(--r-md);
    font-weight: 700;
    font-size: .92rem;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-cta-primary { background: var(--accent); color: #fff; }
.btn-cta-secondary { background: var(--paper-card); color: var(--accent); border: 1.5px solid var(--accent); }

/* ===== CHAPTER LIST ===== */
.chapter-list {
    background: var(--paper-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    overflow: hidden;
}
.chapter-list-scroll { max-height: 420px; overflow-y: auto; }
.chapter-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 14px;
    border-bottom: 1px solid var(--paper-dim);
    color: var(--ink);
    font-size: .87rem;
    min-height: 48px;
}
.chapter-list a:last-child { border-bottom: none; }
.chapter-list a:active { background: var(--paper-dim); }
.chapter-date { color: var(--ink-faint); font-size: .74rem; white-space: nowrap; margin-left: 10px; }

/* ===== READING PROGRESS BAR — signature element ===== */
.reading-progress {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    background: var(--accent);
    z-index: 150;
    width: 0%;
    transition: width .1s linear;
}

/* ===== CHAPTER READER ===== */
.reader-topbar {
    position: sticky;
    top: 0;
    z-index: 90;
    background: rgba(251,248,243,.96);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--border-soft);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.reader-topbar-title {
    flex: 1;
    font-size: .85rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reader-icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--r-pill);
    background: var(--paper-dim);
    color: var(--ink);
    font-size: 1rem;
    border: none;
    flex-shrink: 0;
}

.chapter-content {
    font-family: var(--font-read);
    font-size: 1.0625rem;
    line-height: 1.95;
    color: var(--ink);
    word-break: break-word;
    padding: 4px 2px 32px;
}

.reader-nav-bottom {
    display: flex;
    gap: 10px;
    padding: 16px 14px calc(var(--bottombar-h) + 16px);
    position: sticky;
    bottom: 0;
}
.reader-nav-btn {
    flex: 1;
    text-align: center;
    padding: 13px;
    border-radius: var(--r-md);
    font-size: .85rem;
    font-weight: 700;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reader-nav-btn.prev { background: var(--paper-card); border: 1.5px solid var(--border); color: var(--ink); }
.reader-nav-btn.next { background: var(--accent); color: #fff; }
.reader-nav-btn.disabled { opacity: .4; pointer-events: none; }

/* Font size control — floating, vị trí dễ chạm 1 tay */
.font-size-control {
    position: fixed;
    bottom: calc(var(--bottombar-h) + 80px);
    right: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 80;
}
.font-size-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    border: none;
    box-shadow: 0 3px 10px rgba(26,20,16,.18);
    font-weight: 800;
    display: flex; align-items: center; justify-content: center;
}
.font-size-btn.plus  { background: var(--accent); color: #fff; font-size: 1rem; }
.font-size-btn.minus { background: var(--paper-card); color: var(--ink); font-size: .85rem; border: 1px solid var(--border); }

/* ===== PAGINATION — touch-friendly ===== */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 20px; justify-content: center; }
.pagination a, .pagination span {
    min-width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: .85rem;
    color: var(--ink);
}
.pagination .active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== FORM ELEMENTS (login, search) ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 6px; }
.form-control {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    font-size: 1rem;
    color: var(--ink);
    background: var(--paper-card);
    min-height: 48px;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ===== TABLET & DESKTOP — từ 768px trở lên ===== */
@media (min-width: 768px) {
    :root { --topbar-h: 64px; }

    .bottom-nav { display: none; }
    .site-main { padding-bottom: 32px; }
    .site-footer { display: block; }
    .breadcrumb {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
        font-size: .82rem;
        color: var(--ink-soft);
        margin-bottom: 16px;
    }
    .breadcrumb a { color: var(--ink-soft); }
    .breadcrumb a:hover { color: var(--accent); }
    .breadcrumb-sep { color: var(--ink-faint); }

    .site-header { padding: 0 24px; }
    .site-logo { font-size: 1.4rem; }
    .header-search-btn { display: none; }
    .site-nav-desktop {
        display: flex;
        gap: 4px;
        margin-left: 32px;
    }
    .site-nav-desktop a {
        color: #d8cfc3;
        font-size: .9rem;
        font-weight: 600;
        padding: 8px 14px;
        border-radius: var(--r-sm);
    }
    .site-nav-desktop a:hover { background: rgba(255,255,255,.08); color: #fff; }
    .header-search-desktop {
        display: flex;
        gap: 8px;
        margin-left: auto;
    }
    .header-search-desktop input {
        padding: 8px 14px;
        border: 1px solid #44392f;
        border-radius: var(--r-sm);
        background: #2a221a;
        color: #f0ebe2;
        font-size: .875rem;
        width: 220px;
    }
    .header-search-desktop input::placeholder { color: var(--ink-faint); }
    .header-search-desktop button {
        padding: 8px 16px;
        background: var(--accent);
        color: #fff;
        border: none;
        border-radius: var(--r-sm);
        font-weight: 700;
        font-size: .875rem;
    }

    .story-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; }

    .story-detail-hero { gap: 24px; }
    .story-detail-cover, .story-detail-cover-placeholder { width: 200px; }
    .story-detail-title { font-size: 1.6rem; }

    .btn-cta-row { display: inline-flex; }
    .btn-cta { flex: none; padding: 12px 28px; }

    .reader-nav-bottom { padding-bottom: 16px; position: static; }
    .font-size-control { bottom: 24px; }

    .chapter-content { font-size: 1.08rem; max-width: 720px; margin: 0 auto; }
}

/* ===== Tôn trọng prefers-reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
