/* ============================================
   ALTOREAD V2 — COMPLETE DESIGN SYSTEM
   Bold, vibrant, modern. Not bland.
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Playfair+Display:wght@700&display=swap');

/* ============================================
   TOKENS
   ============================================ */
:root {
    /* LIGHT THEME — Bold & Vibrant */
    --bg:           #eef0ff;
    --surface:      #ffffff;
    --surface2:     #e0e3ff;
    --border:       #b8bdf0;
    --text:         #0a0b1a;
    --text-muted:   #545880;
    --primary:      #4338ca;
    --primary-h:    #3730a3;
    --accent:       #0891b2;
    --success:      #059669;
    --danger:       #dc2626;
    --warn:         #d97706;
    /* NAVBAR gets its own vivid tokens in light mode */
    --nav-bg:       #4338ca;
    --nav-text:     #ffffff;
    --nav-muted:    rgba(255,255,255,0.72);
    --nav-border:   rgba(255,255,255,0.15);
    --modal-bg:     rgba(10,11,26,0.7);
    --radius:       12px;
    --radius-lg:    20px;
    --radius-pill:  999px;
    --shadow-sm:    0 1px 4px rgba(67,56,202,.1);
    --shadow-md:    0 4px 24px rgba(67,56,202,.15);
    --shadow-lg:    0 12px 48px rgba(67,56,202,.22);
    --transition:   all 0.25s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
    --bg:           #0a0f1e;
    --surface:      #111827;
    --surface2:     #1e293b;
    --border:       #2d3a4a;
    --text:         #f1f5f9;
    --text-muted:   #94a3b8;
    --primary:      #818cf8;
    --primary-h:    #6366f1;
    --accent:       #22d3ee;
    --nav-bg:       #0f1629;
    --nav-text:     #f1f5f9;
    --nav-muted:    #94a3b8;
    --nav-border:   #2d3a4a;
    --modal-bg:     rgba(0,0,0,0.82);
    --shadow-sm:    0 1px 4px rgba(0,0,0,.3);
    --shadow-md:    0 4px 24px rgba(0,0,0,.4);
    --shadow-lg:    0 12px 48px rgba(0,0,0,.5);
}

/* ============================================
   RESET
   ============================================ */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior:smooth; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
}
a  { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.container { width:100%; max-width:1200px; margin:0 auto; padding:0 1.5rem; }


/* ============================================
   NAVBAR — vivid indigo background in light,
   deep navy in dark
   ============================================ */
.navbar {
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    box-shadow: 0 2px 20px rgba(67,56,202,.25);
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    gap: 1rem;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-shrink: 0;
}
.brand img {
    height: 34px;
    width: 34px;
    border-radius: 8px;
    object-fit: contain;
    background: rgba(255,255,255,0.15);
    padding: 3px;
}
.brand-text {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--nav-text);
}
.highlight { color: #fbbf24; } /* amber stands out on both themes */

/* Desktop nav links */
.nav-links {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.nav-links a {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--nav-muted);
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-pill);
    transition: var(--transition);
}
.nav-links a:hover {
    color: var(--nav-text);
    background: rgba(255,255,255,0.15);
}

/* Language select */
#user-lang-select {
    appearance: none;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: var(--nav-text);
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
    padding: 0.35rem 2rem 0.35rem 0.85rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 16px;
    transition: var(--transition);
}
#user-lang-select:focus { outline: none; }
#user-lang-select option { background: #4338ca; color: #fff; }

/* Theme toggle */
.btn-icon {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: var(--nav-text);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}
.btn-icon:hover { background: rgba(255,255,255,0.28); }

/* Hamburger */
.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 4px;
    background: none;
    border: none;
}
.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--nav-text);
    border-radius: 2px;
    transition: var(--transition);
}

/* Mobile nav drawer */
.mobile-nav {
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    animation: slideDown 0.2s ease;
}
.mobile-nav.open { display: flex; }
.mobile-nav a {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    transition: var(--transition);
}
.mobile-nav a:hover { background: var(--surface2); color: var(--primary); }
.mobile-nav-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem 0.25rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}
#user-lang-select-mobile {
    flex: 1;
    appearance: none;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
}

@keyframes slideDown { from{opacity:0;transform:translateY(-8px)} to{opacity:1;transform:translateY(0)} }
@keyframes fadeUp    { from{opacity:0;transform:translateY(22px)} to{opacity:1;transform:translateY(0)} }
@keyframes fadeIn    { from{opacity:0} to{opacity:1} }
@keyframes slideUp   { from{opacity:0;transform:translateY(30px) scale(.96)} to{opacity:1;transform:translateY(0) scale(1)} }


/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    min-height: calc(100vh - 64px);
    padding: 2rem 0;
}


/* ============================================
   ADS
   ============================================ */
.ad-placeholder {
    width: 100%;
    max-width: 728px;
    height: 90px;
    margin: 1.5rem auto;
    background: var(--surface);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}


/* ============================================
   HOMEPAGE HERO
   ============================================ */
.hero {
    text-align: center;
    padding: 4rem 1.5rem 3rem;
    background: linear-gradient(145deg, #4338ca 0%, #0891b2 100%);
    border-radius: var(--radius-lg);
    margin-bottom: 2.5rem;
    position: relative;
    overflow: hidden;
    color: #fff;
}
.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='30' cy='30' r='1.5' fill='rgba(255,255,255,0.08)'/%3E%3C/svg%3E") repeat;
    pointer-events: none;
}
.hero h1 {
    font-size: clamp(1.9rem, 5vw, 3.4rem);
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1.1;
    margin-bottom: 1rem;
    color: #fff;
    position: relative;
}
.hero h1 span { color: #fbbf24; -webkit-text-fill-color: #fbbf24; }
.hero p {
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: rgba(255,255,255,0.82);
    max-width: 500px;
    margin: 0 auto;
    position: relative;
}
[data-theme="dark"] .hero {
    background: linear-gradient(145deg, #1e1b4b 0%, #0c4a6e 100%);
}


/* ============================================
   CATEGORY GRID
   ============================================ */
.section-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
    padding-right: 1.5rem;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

/* Card accent palette */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    animation: fadeUp 0.4s ease both;
    border-top: 3px solid var(--primary);
    box-shadow: var(--shadow-sm);
}
.card:nth-child(2n)  { border-top-color: #0891b2; }
.card:nth-child(3n)  { border-top-color: #7c3aed; }
.card:nth-child(4n)  { border-top-color: #059669; }
.card:nth-child(5n)  { border-top-color: #d97706; }
.card:nth-child(1) { animation-delay:.05s } .card:nth-child(2) { animation-delay:.1s }
.card:nth-child(3) { animation-delay:.15s } .card:nth-child(4) { animation-delay:.2s }
.card:nth-child(5) { animation-delay:.25s } .card:nth-child(6) { animation-delay:.3s }
.card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
}

.card-img {
    width: 100%;
    height: 150px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-content { padding: 1.25rem; }
.card-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary);
    background: rgba(67,56,202,0.1);
    padding: 0.18rem 0.6rem;
    border-radius: var(--radius-pill);
    margin-bottom: 0.5rem;
}
.card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.3rem; }
.card-meta  { font-size: 0.8rem; color: var(--text-muted); }


/* ============================================
   ARTICLE PAGE — DESKTOP 2-COL LAYOUT
   ============================================ */
.article-page-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2.5rem;
    align-items: start;
}

/* Left column — reading content */
.article-main {}

.article-wrapper {
    max-width: 100%;
}

.article-meta-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.tag {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary);
    background: rgba(67,56,202,0.1);
    padding: 0.25rem 0.85rem;
    border-radius: var(--radius-pill);
}

.article-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.5px;
    margin-bottom: 1.25rem;
}

/* Level switcher */
.level-switcher {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
    background: var(--surface2);
    padding: 0.3rem;
    border-radius: var(--radius-pill);
    width: fit-content;
}
.btn-level {
    padding: 0.45rem 1.2rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    font-family: inherit;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-level.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px rgba(67,56,202,.4);
}
.btn-level:hover:not(.active) { background: var(--border); color: var(--text); }

/* Audio */
.audio-player-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}
audio { width: 100%; }

/* Reading area */
.reading-content {
    font-size: 1.1rem;
    line-height: 2;
    color: var(--text);
    margin-bottom: 2rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary);
}
.reading-content .level-content { animation: fadeIn 0.3s ease; }
.reading-content span.word {
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s;
}
.reading-content span.word:hover {
    background: rgba(67,56,202,0.12);
    color: var(--primary);
}

/* Right sidebar */
.article-sidebar {
    position: sticky;
    top: 84px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.sidebar-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border-top: 3px solid var(--primary);
}

.sidebar-card h3 {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary);
    margin-bottom: 1rem;
}

/* Print btn */
.print-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 1.25rem;
}
.print-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Read tip */
.read-tip {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: var(--surface2);
    border-left: 3px solid var(--accent);
    margin-bottom: 4.5rem;
}


/* ============================================
   FLOATING TEXT CONTROLS
   ============================================ */
.floating-controls {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-pill);
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 150;
    white-space: nowrap;
}
.fc-label {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}
.fc-divider { width:1px; height:24px; background:var(--border); flex-shrink:0; }
.btn-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface2);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    outline: none;
}
.btn-circle:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.color-swatches { display: flex; gap: 0.4rem; align-items: center; }
.color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.color-swatch:hover, .color-swatch.active { border-color: var(--primary); transform: scale(1.25); }


/* ============================================
   TRANSLATION MODAL
   ============================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-bg);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}
.modal.active { display: flex; }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s cubic-bezier(0.34,1.56,0.64,1);
    border-top: 4px solid var(--primary);
}
.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 30px;
    height: 30px;
    background: var(--surface2);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--text-muted);
    transition: var(--transition);
    outline: none;
}
.close-modal:hover { background: var(--danger); color: #fff; }
.modal-word-display { margin-bottom: 1.25rem; }
#modal-word {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    display: block;
    margin-bottom: 0.3rem;
}
.definition { font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; }
#loading-spinner { display: none; font-size: 0.85rem; color: var(--text-muted); padding: 0.5rem 0; }
.translation-result {
    display: none;
    margin-top: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(67,56,202,.08), rgba(8,145,178,.08));
    border: 1px solid rgba(67,56,202,.2);
    border-radius: var(--radius);
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary);
    text-align: center;
}
.btn-translate-lang {
    padding: 0.4rem 0.25rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text);
    transition: var(--transition);
    text-align: center;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.btn-translate-lang:hover { background: rgba(67,56,202,.1); border-color: var(--primary); color: var(--primary); }
.btn-translate-lang.active { background: var(--primary); border-color: var(--primary); color: #fff; }


/* ============================================
   ADMIN PANEL
   ============================================ */
.admin-container { max-width: 820px; margin: 0 auto; }
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-weight: 600; font-size: 0.9rem; }
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67,56,202,.15); }
textarea.form-control { min-height: 120px; resize: vertical; }
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    transition: var(--transition);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: var(--shadow-md); }


/* ============================================
   FOOTER
   ============================================ */
.footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}


/* ============================================
   PRINT
   ============================================ */
@media print {
    .navbar, .footer, .ad-placeholder, .print-btn,
    .level-switcher, .audio-player-container,
    .floating-controls, .article-sidebar { display: none !important; }
    body { background: #fff; color: #000; }
    .reading-content { box-shadow: none; border: none; padding: 0; }
    .article-page-grid { grid-template-columns: 1fr; }
}


/* ============================================
   RESPONSIVE — TABLET 900px
   ============================================ */
@media (max-width: 900px) {
    .article-page-grid { grid-template-columns: 1fr; }
    .article-sidebar { position: static; }
    .category-grid { grid-template-columns: repeat(2, 1fr); }
    /* Show inline ad on tablet/mobile */
    #inline-ad { display: flex !important; }
}


/* ============================================
   RESPONSIVE — MOBILE 640px
   ============================================ */
@media (max-width: 640px) {
    .container { padding: 0 1rem; }

    /* Navbar – hide desktop, show hamburger */
    .nav-links  { display: none; }
    .hamburger  { display: flex; }
    .nav-container { height: 58px; }

    /* Hero */
    .hero { padding: 2.5rem 1rem 2rem; border-radius: var(--radius); }

    /* Cards – single column */
    .category-grid { grid-template-columns: 1fr; gap: 1rem; }

    /* Article */
    .article-title { font-size: 1.65rem; }
    .reading-content { padding: 1.25rem; font-size: 1rem; }
    .level-switcher { width: 100%; }
    .btn-level { flex: 1; text-align: center; padding: 0.5rem 0.25rem; font-size: 0.82rem; }

    /* Floating controls – bottom drawer */
    .floating-controls {
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-left: none; border-right: none; border-bottom: none;
        justify-content: center;
        padding: 0.85rem 1.25rem;
        gap: 0.85rem;
    }
    .fc-label { display: none; }

    /* Modal – bottom sheet */
    .modal { align-items: flex-end; }
    .modal-content {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        position: fixed;
        bottom: 0;
        max-width: 100%;
        margin: 0;
        border-top: 4px solid var(--primary);
    }

    /* Ad */
    .ad-placeholder { height: 60px; }
}
