/* ==========================================================================
   assets/css/style.css — Global Stylesheet for Chinese Learning Platform
   ========================================================================== */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --card: #ffffff;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --error: #dc2626;
    --danger: #ef4444;
    --mandarin: #0284c7;
    --cantonese: #7c3aed;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

/* --------------------------------------------------------------------------
   App Layout & Sidebar (Desktop Default)
   -------------------------------------------------------------------------- */
.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
}

.sidebar {
    width: 320px;
    background: #ffffff;
    border-right: 1px solid var(--border);
    padding: 24px 18px;
    flex-shrink: 0;
    transition: transform 0.3s ease, visibility 0.3s ease;
    z-index: 1001;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 8px 0 16px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header a {
    display: block;
    width: 100%;
    text-align: center;
}

/* Increased Sidebar Logo Sizing */
.sidebar-header img {
    width: 100%;
    max-width: 220px;
    height: auto;
    /*max-height: 120px;*/
    object-fit: contain;
    display: block;
    margin: 0 auto 8px auto;
}

.close-sidebar-btn {
    display: none;
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    font-size: 22px;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.sidebar h2 {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-top: 12px;
    margin-bottom: 12px;
    width: 100%;
}

.nav-group {
    margin-bottom: 28px;
}

.nav-link {
    display: block;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.nav-link:hover {
    background: #f1f5f9;
}

.nav-link.active {
    background: #eff6ff;
    color: var(--primary);
    font-weight: 700;
}

/* Accordion Nav */
.level-accordion {
    margin-bottom: 6px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #ffffff;
}

.level-accordion summary::-webkit-details-marker {
    display: none;
}

.level-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    font-weight: 700;
    font-size: 14px;
    color: #334155;
    cursor: pointer;
    user-select: none;
    background: #f8fafc;
    transition: background 0.15s ease;
}

.level-header:hover {
    background: #f1f5f9;
}

.chevron {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.level-accordion[open] .chevron {
    transform: rotate(180deg);
}

.level-content {
    padding: 6px 0;
    background: #ffffff;
    border-top: 1px solid var(--border);
}

.sub-link {
    display: block;
    padding: 6px 12px 6px 20px;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.4;
}

.sub-link:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.sub-link.active {
    background: #eff6ff;
    color: var(--primary);
    font-weight: 700;
}

/* Mobile Overlay Screen Backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    padding: 40px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* --------------------------------------------------------------------------
   Mobile Top Header Bar (Desktop default: Hidden)
   -------------------------------------------------------------------------- */
.mobile-top-bar {
    display: none;
}

.btn-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* --------------------------------------------------------------------------
   Unified Mobile Breakpoint (<= 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {

    /* Fixed full-width top bar with increased height */
    .mobile-top-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 64px;
        background-color: #ffffff;
        border-bottom: 1px solid #e2e8f0;
        padding: 0 16px;
        z-index: 999;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    }

    /* Increased Mobile Header Logo Sizing */
    .mobile-site-title a img {
        height: 42px !important;
        max-height: 48px !important;
        width: auto !important;
        object-fit: contain;
    }

    /* Hide text below logo in sidebar menu on mobile */
    .sidebar-title-text {
        display: none !important;
    }

    /* Increased Mobile Drawer Logo Sizing */
    .sidebar-header img {
        width: 100%;
        max-width: 240px;
        max-height: 130px !important;
    }

    .btn-menu-toggle {
        display: flex;
        align-items: center;
        gap: 6px;
        background: #f1f5f9;
        border: 1px solid #cbd5e1;
        border-radius: 6px;
        padding: 6px 12px;
        font-size: 16px;
        font-weight: 600;
        color: #0f172a;
        cursor: pointer;
    }

    .mobile-site-title a {
        font-size: 18px;
        font-weight: 700;
        color: #0f172a;
        text-decoration: none;
    }

    .mobile-nav-spacer {
        width: 44px;
        /* Keeps header logo centered opposite toggle button */
    }

    body {
        padding-top: 64px;
        /* Matches increased top bar height */
    }

    .close-sidebar-btn {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    /* Off-screen drawer sidebar for mobile */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 290px;
        height: 100vh;
        overflow-y: auto;
        transform: translateX(-100%);
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.1);
    }

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

    .main-content {
        padding: 20px 16px;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .card {
        cursor: default;
    }

    .modal-overlay.active {
        display: none !important;
    }
}

/* --------------------------------------------------------------------------
   Containers, Cards & Page Content
   -------------------------------------------------------------------------- */
.container {
    max-width: 1050px;
    margin: 40px auto;
    padding: 0 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.header h1 {
    margin: 0;
    font-size: 26px;
    color: #0f172a;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.page-card,
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
    margin-bottom: 24px;
}

.card {
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.meaning {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 16px 0;
    color: #1e293b;
}

.char-details {
    font-size: 13px;
    color: var(--text-muted);
    margin: 16px 0;
}

.char-details strong {
    color: var(--text-main);
}

.btn-char-link {
    display: block;
    text-align: center;
    background: #f1f5f9;
    color: var(--primary) !important;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none !important;
    margin-top: 4px;
    pointer-events: auto !important;
}

.btn-char-link:hover {
    background: #e2e8f0;
}

/* Modal Popup */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
}

.modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: #f1f5f9;
    border: none;
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    color: #64748b;
}

.modal-close-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.modal-target-box {
    width: 280px;
    height: 280px;
    margin: 16px auto;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #fafafa;
}

/* Typography & Content Formatting */
h1 {
    font-size: 32px;
    color: var(--text-main);
    margin-top: 0;
    margin-bottom: 16px;
}

h2 {
    font-size: 20px;
    color: #1e293b;
    margin-top: 28px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

h3 {
    font-size: 18px;
    color: #1e293b;
    margin-top: 0;
    margin-bottom: 16px;
}

p {
    color: #334155;
    font-size: 15px;
    margin-bottom: 16px;
}

p.subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 28px;
}

ul {
    color: #334155;
    font-size: 15px;
    padding-left: 20px;
}

li {
    margin-bottom: 8px;
}

.story-quote {
    background: #eff6ff;
    border-left: 4px solid var(--primary);
    padding: 16px 20px;
    margin: 24px 0;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #1e3a8a;
}

.adsense-wrapper {
    margin: 32px 0;
    padding: 16px;
    background: #f1f5f9;
    border: 1px dashed var(--border);
    border-radius: 8px;
    text-align: center;
}

.adsense-label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
}

/* --------------------------------------------------------------------------
   Buttons & Actions
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s ease;
}

.btn:hover {
    background: var(--primary-hover);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

.btn-arrow {
    background: #e2e8f0;
    color: #334155;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    text-decoration: none;
    font-weight: bold;
}

.btn-danger {
    background: var(--danger);
}

.btn-secondary {
    background: #64748b;
}

.btn-success {
    background: var(--success);
}

.btn-kofi {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background-color: #ff5e5b;
    color: #ffffff !important;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 8px;
    text-decoration: none !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.btn-kofi:hover {
    background-color: #e04b48;
    transform: translateY(-1px);
}

.btn-submit,
.btn-primary {
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    width: 100%;
}

.btn-submit:hover,
.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-audio {
    background: var(--mandarin);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.btn-audio.cantonese {
    background: var(--cantonese);
}

.btn-animate {
    background: #10b981;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: default;
}

/* Badges, Tables & Steps */
.pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.pill {
    background: #f1f5f9;
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 13px;
    color: #334155;
}

.badge-container {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 12px;
    text-transform: uppercase;
}

.badge-level {
    background: #e0f2fe;
    color: #0369a1;
}

.badge-cat {
    background: #fef3c7;
    color: #b45309;
}

.target-box {
    width: 140px;
    height: 140px;
    margin: 0 auto 16px auto;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fafafa;
}

.target-box-lg {
    width: 220px !important;
    height: 220px !important;
    margin: 0 auto 24px auto;
    border-radius: 12px;
}

.seo-data-table,
table {
    width: 100%;
    margin: 15px 0;
    border-collapse: collapse;
    text-align: left;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

th {
    background: #f1f5f9;
    color: #334155;
}

.stroke-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    background: #f1f5f9;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    min-height: 48px;
}

.stroke-step {
    width: 52px;
    height: 52px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.stroke-step-num {
    position: absolute;
    bottom: 2px;
    right: 3px;
    font-size: 9px;
    color: #94a3b8;
    font-weight: 600;
}

/* Form Controls */
.form-group {
    margin-bottom: 18px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group label,
label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

.form-control,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-main);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
}

.form-control:focus,
input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea.form-control {
    resize: vertical;
    min-height: 120px;
}

/* Banners & Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
}

.alert-success {
    background-color: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background-color: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.site-footer {
    text-align: center;
    padding: 28px 16px 8px 16px;
    border-top: 1px solid var(--border);
    margin-top: 48px;
    color: var(--text-muted);
    font-size: 13px;
}

.site-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.site-footer a:hover {
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Cookie Consent Banner
   -------------------------------------------------------------------------- */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #0f172a;
    color: #ffffff;
    padding: 14px 20px;
    z-index: 9999;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
}

.cookie-content {
    max-width: 1050px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.cookie-content p {
    margin: 0;
    font-size: 13px;
    color: #cbd5e1;
    line-height: 1.4;
    flex: 1;
}

.cookie-content a {
    color: #38bdf8;
    text-decoration: underline;
}

.cookie-content .btn {
    white-space: nowrap;
    padding: 8px 16px;
}

@media (max-width: 768px) {
    .cookie-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .cookie-content .btn {
        width: 100%;
    }
}