/* ================================================
   CIENCIA & SCIENCE - Reimagined UI
   A modern, warm, accessible design system
   ================================================ */

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #222633;
    --bg-surface: #14161e;
    --text-primary: #f0f2f5;
    --text-secondary: #9ca3b4;
    --text-muted: #6b7280;
    --accent-violet: #8b5cf6;
    --accent-violet-light: #a78bfa;
    --accent-cyan: #06b6d4;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-blue: #3b82f6;
    --border: #2a2d3a;
    --border-light: #363a4a;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html { scroll-behavior: smooth; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* === PARTICLES BACKGROUND === */
#particles-bg {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.4;
}

/* === TOP BAR === */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15,17,23,0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1.5rem;
}
.top-bar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.top-bar-label {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--accent-violet-light);
    letter-spacing: 0.02em;
}
.streak-display {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-amber);
}
.streak-flame { font-size: 1.1rem; }

/* === HERO === */
.hero {
    position: relative;
    z-index: 1;
    padding: 5rem 1.5rem 4rem;
    text-align: center;
    background: linear-gradient(180deg, rgba(139,92,246,0.12) 0%, transparent 100%);
}
.hero-content { max-width: 720px; margin: 0 auto; }
.hero-badge {
    display: inline-block;
    padding: 0.35rem 1rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-cyan);
    border: 1px solid rgba(6,182,212,0.3);
    background: rgba(6,182,212,0.08);
    margin-bottom: 1.5rem;
}
.hero-title {
    font-family: var(--font-heading);
    font-size: clamp(2.5rem, 7vw, 4.5rem);
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, #f0f2f5 0%, #a78bfa 50%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.ampersand {
    background: linear-gradient(135deg, var(--accent-amber), var(--accent-rose));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.hero-subtitle {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}
.hero-desc {
    font-size: 1rem;
    color: var(--text-muted);
    max-width: 560px;
    margin: 0 auto 2rem;
}
.hero-stats {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.stat-pill {
    padding: 0.5rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 9999px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.stat-pill .stat-num {
    font-weight: 700;
    color: var(--accent-emerald);
}

/* === APP LAYOUT === */
.app-layout {
    position: relative;
    z-index: 1;
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem 3rem;
    gap: 1.5rem;
}

/* === SIDEBAR === */
.sidebar {
    position: sticky;
    top: 56px;
    width: 280px;
    min-width: 280px;
    height: calc(100vh - 56px);
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.sidebar-header h2 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
}
.sidebar-toggle { display: none; background: none; border: none; color: var(--text-primary); font-size: 1.5rem; cursor: pointer; }
.chapter-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.chapter-list li {
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border: 1px solid transparent;
}
.chapter-list li:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}
.chapter-list li.active {
    background: rgba(139,92,246,0.12);
    color: var(--accent-violet-light);
    border-color: rgba(139,92,246,0.25);
    font-weight: 600;
}
.ch-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--border);
    color: var(--text-muted);
    flex-shrink: 0;
}
.chapter-list li.active .ch-num {
    background: var(--accent-violet);
    color: #fff;
}
.ch-check {
    margin-left: auto;
    font-size: 0.85rem;
    opacity: 0;
    transition: var(--transition);
}
.chapter-list li.completed .ch-check { opacity: 1; }

/* Sidebar Footer / Progress Ring */
.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: center;
    margin-top: auto;
}
.progress-ring-container { position: relative; display: inline-block; width: 72px; height: 72px; }
.progress-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring-bg { fill: none; stroke: var(--border); stroke-width: 6; }
.progress-ring-fill { fill: none; stroke: var(--accent-emerald); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 283; stroke-dashoffset: 283; transition: stroke-dashoffset 0.6s ease; }
.progress-ring-text {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent-emerald);
}
.progress-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    z-index: 90;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent-violet);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    align-items: center;
    justify-content: center;
}

/* === MAIN CONTENT === */
.main-content {
    flex: 1;
    min-width: 0;
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
    gap: 1rem;
}
.loader {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-violet);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === CHAPTER HEADER === */
.chapter-header {
    margin-bottom: 2.5rem;
}
.chapter-number {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-violet-light);
    margin-bottom: 0.5rem;
}
.chapter-title {
    font-family: var(--font-heading);
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}
.chapter-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}
.tag-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tag {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tag-violet { background: rgba(139,92,246,0.15); color: var(--accent-violet-light); }
.tag-cyan { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.tag-emerald { background: rgba(16,185,129,0.15); color: var(--accent-emerald); }
.tag-amber { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.tag-rose { background: rgba(244,63,94,0.15); color: var(--accent-rose); }
.tag-blue { background: rgba(59,130,246,0.15); color: var(--accent-blue); }

/* === MODULE SECTIONS (tabs within each chapter) === */
.module-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 2rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.module-tab {
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
}
.module-tab:hover { color: var(--text-secondary); }
.module-tab.active {
    color: var(--accent-violet-light);
    border-bottom-color: var(--accent-violet);
    background: rgba(139,92,246,0.06);
}
.module-panel { display: none; animation: fadeUp 0.35s ease; }
.module-panel.active { display: block; }
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === CARDS === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}
.card:hover {
    border-color: var(--border-light);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.card-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.card-icon { font-size: 1.2rem; }

/* === FLASHCARD WIDGET === */
.fc-container {
    perspective: 1200px;
    margin-bottom: 1.25rem;
}
.fc-card {
    position: relative;
    width: 100%;
    height: 220px;
    cursor: pointer;
    transition: transform 0.6s cubic-bezier(0.4,0,0.2,1);
    transform-style: preserve-3d;
}
.fc-card.flipped { transform: rotateY(180deg); }
.fc-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
}
.fc-front {
    background: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(6,182,212,0.1));
    border: 1px solid rgba(139,92,246,0.3);
}
.fc-back {
    transform: rotateY(180deg);
    background: linear-gradient(135deg, rgba(16,185,129,0.15), rgba(245,158,11,0.1));
    border: 1px solid rgba(16,185,129,0.3);
}
.fc-word {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.fc-cognate-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(245,158,11,0.2);
    color: var(--accent-amber);
    margin-bottom: 0.5rem;
}
.fc-hint { font-size: 0.8rem; color: var(--text-muted); }
.fc-definition {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    max-width: 320px;
}
.fc-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.fc-btn {
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    background: var(--border);
    color: var(--text-primary);
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.fc-btn:hover { background: var(--border-light); }
.fc-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.fc-counter {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* === CONCEPT BLOCKS === */
.concept-block {
    padding: 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border-left: 3px solid;
}
.concept-block h4 {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.concept-block p { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.concept-block .es-text { font-size: 0.8rem; font-style: italic; color: var(--text-muted); }
.concept-block .analogy { font-size: 0.8rem; color: var(--accent-amber); margin-top: 0.35rem; }
.cb-violet { background: rgba(139,92,246,0.08); border-color: var(--accent-violet); }
.cb-cyan { background: rgba(6,182,212,0.08); border-color: var(--accent-cyan); }
.cb-emerald { background: rgba(16,185,129,0.08); border-color: var(--accent-emerald); }
.cb-amber { background: rgba(245,158,11,0.08); border-color: var(--accent-amber); }
.cb-rose { background: rgba(244,63,94,0.08); border-color: var(--accent-rose); }
.cb-blue { background: rgba(59,130,246,0.08); border-color: var(--accent-blue); }

/* === QUIZ === */
.quiz-question {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.quiz-q-text {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.85rem;
}
.quiz-options { display: flex; flex-direction: column; gap: 0.4rem; }
.quiz-opt {
    padding: 0.65rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    width: 100%;
}
.quiz-opt:hover:not(:disabled) {
    border-color: var(--accent-violet);
    background: rgba(139,92,246,0.06);
    transform: translateX(4px);
}
.quiz-opt.correct {
    background: rgba(16,185,129,0.15);
    border-color: var(--accent-emerald);
    color: var(--accent-emerald);
}
.quiz-opt.incorrect {
    background: rgba(244,63,94,0.15);
    border-color: var(--accent-rose);
    color: var(--accent-rose);
}
.quiz-explanation {
    display: none;
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(59,130,246,0.08);
    border-left: 3px solid var(--accent-blue);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.quiz-explanation.visible { display: block; }
.quiz-score {
    text-align: center;
    padding: 1.5rem;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-emerald);
}

/* === MEMORY TRICKS === */
.trick-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}
.trick-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-amber);
    margin-bottom: 0.3rem;
}
.trick-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* === STUDY TIPS / LAB STEMS === */
.tip-item {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.tip-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.1rem; }
.tip-item strong { color: var(--text-primary); }

.stem-block {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.65rem;
}
.stem-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-cyan);
    margin-bottom: 0.3rem;
}
.stem-en { font-size: 0.9rem; color: var(--text-primary); }
.stem-es { font-size: 0.8rem; font-style: italic; color: var(--text-muted); margin-top: 0.15rem; }

/* === REAL WORLD CONNECTIONS === */
.rw-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.rw-card {
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-surface);
}
.rw-card h4 {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.rw-card p { font-size: 0.85rem; color: var(--text-secondary); }

/* === COMPARISON TABLE === */
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.compare-table th {
    padding: 0.75rem;
    text-align: left;
    background: var(--bg-surface);
    border-bottom: 2px solid var(--border);
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--accent-violet-light);
}
.compare-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

/* === FOOTER === */
.site-footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* === RESPONSIVE === */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        z-index: 200;
        transform: translateX(-110%);
        transition: transform 0.3s ease;
        border-radius: 0;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .mobile-menu-btn { display: flex; }
    .app-layout { padding: 0 0.75rem 3rem; }
}
@media (max-width: 600px) {
    .hero { padding: 3rem 1rem 2.5rem; }
    .hero-title { font-size: 2.2rem; }
    .module-tabs { gap: 0; }
    .module-tab { padding: 0.5rem 0.75rem; font-size: 0.72rem; }
    .card { padding: 1.25rem; }
}
