/* =============================================
   MemoBible — Design System (Duolingo-inspired)
   ============================================= */

/* ── TOKENS ── */
:root {
    --indigo: #2d3a8c;
    --indigo-light: #4a5aad;
    --indigo-dark: #1e2a6e;
    --indigo-pale: rgba(45,58,140,0.07);
    --gold: #c9a84c;
    --gold-light: #e8c97a;
    --green: #58cc02;
    --green-shadow: #46a302;
    --red: #ea2b2b;
    --red-shadow: #c42020;
    --yellow: #ffc800;
    --yellow-shadow: #cc9f00;
    --bg: #f7f5f0;
    --card: #ffffff;
    --ink: #1f2937;
    --ink-soft: #4b5563;
    --muted: #9ca3af;
    --border: #e5e7eb;
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;

    /* Semantic aliases (Prioridade 1 — refactor) */
    --ink-deep: #1f2937;
    --ink-muted: #6b7280;
    --border-input: #d6dbe6;
    --red-pale: #fef2f2;
    --red-pale-border: #fecaca;
    --red-dark: #991b1b;
    --green-emerald: #10b981;
    --green-deep: #059669;

    /* Gradientes reutilizáveis */
    --grad-indigo: linear-gradient(135deg, var(--indigo) 0%, var(--indigo-light) 100%);
    --grad-indigo-gold: linear-gradient(135deg, var(--indigo) 0%, var(--gold) 100%);
    --grad-gold: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);

    /* Borders e shadows padrão de cards (Prioridade 2) */
    --card-border: 1.5px solid var(--border);
    --card-shadow: 0 4px 14px rgba(10,12,20,0.05);
    --card-shadow-hover: 0 8px 24px rgba(45,58,140,0.10);
    --card-radius: 20px;
}

/* Classe reutilizável de card (Prioridade 2) */
.mb-card {
    background: var(--card);
    border: var(--card-border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    transition: all 0.18s ease;
}
.mb-card:hover {
    border-color: var(--indigo);
    box-shadow: var(--card-shadow-hover);
}

/* ── DARK MODE ── */
body.dark-mode {
    --bg: #0f1117;
    --card: #1a1d2e;
    --ink: #e5e7eb;
    --ink-soft: #d1d5db;
    --muted: #6b7280;
    --border: #2d3148;
    --indigo-pale: rgba(99,120,255,0.1);
    --ink-deep: #e5e7eb;
    --ink-muted: #9ca3af;
    --border-input: #2d3148;
    --red-pale: rgba(234,43,43,0.12);
    --red-pale-border: rgba(234,43,43,0.3);
    --red-dark: #f87171;
    --card-shadow: 0 4px 14px rgba(0,0,0,0.25);
    --card-shadow-hover: 0 8px 24px rgba(99,120,255,0.18);
}

body.dark-mode .site-header {
    background: rgba(15,17,23,0.92);
    border-image: linear-gradient(90deg, #4a5aad, #c9a84c) 1;
}
body.dark-mode .site-brand img {
    filter: invert(1) hue-rotate(180deg) brightness(1.3);
    mix-blend-mode: screen;
}
body.dark-mode .site-footer-brand img {
    filter: invert(1) hue-rotate(180deg) brightness(1.3);
    mix-blend-mode: screen;
}

body.dark-mode .site-footer { background: #1a1d2e; border-color: #2d3148; }
body.dark-mode .bottom-tabs { background: rgba(15,17,23,0.92); border-color: #2d3148; }
body.dark-mode .site-nav { background: #1a1d2e; }

body.dark-mode .site-btn-ghost { color: #d1d5db !important; border-color: #374151; background: rgba(255,255,255,0.04); }
body.dark-mode .site-btn-ghost:hover { color: #a5b4fc !important; border-color: #4a5aad; }

body.dark-mode .streak-badge { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.3); }

body.dark-mode .lang-globe-btn { border-color: #374151; color: #9ca3af; }
body.dark-mode .lang-dropdown { background: #1a1d2e; border-color: #2d3148; }
body.dark-mode .lang-option { color: #d1d5db; }
body.dark-mode .lang-option:hover { background: rgba(99,120,255,0.1); }

body.dark-mode .toast-success { background: #059669; }
body.dark-mode .toast-info { background: #4a5aad; }

body.dark-mode .btn-3d-outline { background: #1a1d2e; color: #d1d5db; border-color: #374151; box-shadow: 0 3px 0 #0f1117; }

body.dark-mode input, body.dark-mode select { background: #1a1d2e; color: #e5e7eb; border-color: #374151; }

/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
html, body { margin: 0; padding: 0; min-height: 100%; }
html { overflow-x: hidden; }

body {
    font-family: 'DM Sans', 'Inter', Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

button, a { touch-action: manipulation; }

a { color: var(--indigo); text-decoration: none; }
a:hover { text-decoration: underline; }


/* ── 3D BUTTON SYSTEM ── */
.btn-3d {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    transition: transform 0.1s;
    padding: 14px 24px;
    font-size: 15px;
    text-decoration: none !important;
}
.btn-3d:active { transform: translateY(3px); }

.btn-3d-green {
    background: var(--green); color: #fff;
    box-shadow: 0 4px 0 var(--green-shadow);
}
.btn-3d-green:active { box-shadow: 0 1px 0 var(--green-shadow); }
.btn-3d-green:hover { color: #fff; }

.btn-3d-indigo {
    background: var(--indigo); color: #fff;
    box-shadow: 0 4px 0 var(--indigo-dark);
}
.btn-3d-indigo:active { box-shadow: 0 1px 0 var(--indigo-dark); }
.btn-3d-indigo:hover { color: #fff; }

.btn-3d-outline {
    background: var(--card); color: var(--ink-soft);
    border: 2px solid var(--border);
    box-shadow: 0 3px 0 #d1d5db;
}
.btn-3d-outline:active { box-shadow: 0 1px 0 #d1d5db; }

/* ── GLOBAL ANIMATIONS ── */
@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.05); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: 200px 0; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes checkDraw {
    to { stroke-dashoffset: 0; }
}

.anim-bounce { animation: bounceIn 0.5s ease-out; }
.anim-slide { animation: slideUp 0.3s ease-out; }
.anim-pulse { animation: pulse 2s infinite; }
.anim-fade { animation: fadeIn 0.3s ease-out; }

/* Staggered children */
.stagger > *:nth-child(1) { animation-delay: 0s; }
.stagger > *:nth-child(2) { animation-delay: 0.05s; }
.stagger > *:nth-child(3) { animation-delay: 0.1s; }
.stagger > *:nth-child(4) { animation-delay: 0.15s; }
.stagger > *:nth-child(5) { animation-delay: 0.2s; }
.stagger > *:nth-child(6) { animation-delay: 0.25s; }
.stagger > *:nth-child(7) { animation-delay: 0.3s; }
.stagger > *:nth-child(8) { animation-delay: 0.35s; }
.stagger > *:nth-child(9) { animation-delay: 0.4s; }
.stagger > *:nth-child(10) { animation-delay: 0.45s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── HEADER ── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 2px solid transparent;
    border-image: linear-gradient(90deg, var(--indigo), var(--gold)) 1;
    padding-top: env(safe-area-inset-top, 0);
}

.site-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-brand { flex: 1; text-decoration: none; padding-left: 0; }
/* horizontal.png has ~15% transparent padding on the left side of the image.
   At 62px height that's ~28px of visual gap. Negative margin compensates so
   the brain icon visually aligns with the left edge of content cards below. */
.site-brand img { height: 62px; display: block; margin-left: -30px; }
.brand-slogan { display: none; }

.site-nav {
    position: fixed; top: 0; right: 0;
    width: 280px; height: 100vh;
    background: var(--card);
    flex-direction: column; align-items: flex-start;
    padding: 80px 24px 32px; gap: 4px;
    box-shadow: -8px 0 30px rgba(0,0,0,0.1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 105;
    display: flex;
}

.site-nav a {
    text-decoration: none;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 10px;
    transition: color 0.15s, background 0.15s;
}

.site-nav a:hover {
    color: var(--indigo);
    background: var(--indigo-pale);
    text-decoration: none;
}

.nav-spacer { width: 6px; }

.streak-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fffbeb;
    color: #d97706;
    border: 2px solid #fde68a;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    animation: pulse 3s infinite;
}

.site-user {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 0;
}

.site-btn {
    display: inline-block;
    background: var(--indigo);
    color: #fff !important;
    padding: 10px 22px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none !important;
    box-shadow: 0 3px 0 var(--indigo-dark);
    transition: transform 0.1s;
}
.site-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--indigo-dark); }

.site-btn-ghost {
    display: inline-block;
    color: var(--indigo) !important;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none !important;
    border: 2px solid var(--indigo);
    transition: all 0.15s;
    background: rgba(45,58,140,0.04);
}
.site-btn-ghost:hover {
    border-color: var(--indigo);
    color: var(--indigo) !important;
    background: var(--indigo-pale);
}

/* ── LANG GLOBE ── */
.lang-globe { position: relative; flex-shrink: 0; }

.lang-globe-btn {
    display: flex; align-items: center; gap: 2px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 6px;
    cursor: pointer;
    color: var(--muted);
    font-family: 'DM Sans', sans-serif;
    font-size: 10px; font-weight: 600;
    transition: all 0.15s;
    opacity: 0.7;
}
.lang-globe-btn:hover { border-color: var(--indigo); color: var(--indigo); opacity: 1; }
.lang-globe-btn svg { flex-shrink: 0; width: 12px; height: 12px; }
.lang-globe-current { letter-spacing: 0.2px; }

.lang-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    padding: 6px; min-width: 160px;
    opacity: 0; visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 200;
}
.lang-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0); }

.lang-option {
    display: flex; align-items: center; gap: 8px;
    width: 100%; background: none; border: none;
    padding: 8px 12px; border-radius: 8px;
    font-size: 14px; font-weight: 500;
    cursor: pointer; color: var(--ink);
    font-family: 'DM Sans', sans-serif;
    transition: all 0.12s; text-align: left;
}
.lang-option:hover { background: var(--indigo-pale); color: var(--indigo); }
.lang-option.active { background: var(--indigo-pale); color: var(--indigo); font-weight: 700; }

/* ── HAMBURGER (desktop hidden, mobile shows if no bottom tabs) ── */
.lang-globe { order: 2; }
.site-version-sel { order: 3; }
.hamburger {
    order: 4;
    display: flex; flex-direction: column; gap: 5px;
    background: none; border: none; cursor: pointer;
    padding: 12px; z-index: 110; touch-action: manipulation;
    min-width: 44px; min-height: 44px; align-items: center; justify-content: center;
}
.hamburger span {
    display: block; width: 22px; height: 2px;
    background: var(--ink-soft); border-radius: 2px;
    transition: all 0.25s;
}
.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ── PAGE CONTENT ── */
.page-content { flex: 1; }

/* ── BOTTOM TAB BAR (mobile, logged in) ── */
.bottom-tabs {
    display: none; /* shown by .has-tabs */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 8px);
}

.bottom-tabs-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 56px;
    max-width: 500px;
    margin: 0 auto;
}

.btab {
    display: flex; flex-direction: column;
    align-items: center; gap: 1px;
    text-decoration: none !important;
    color: var(--muted);
    font-size: 9px; font-weight: 600;
    padding: 4px 6px;
    border-radius: 8px;
    transition: color 0.15s;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
}
.btab:hover { color: var(--indigo); }
.btab.active[data-tab-idx="0"] { color: #2d3a8c; }
.btab.active[data-tab-idx="1"] { color: #6366f1; }
.btab.active[data-tab-idx="2"] { color: #059669; }
.btab.active[data-tab-idx="3"] { color: #c9a84c; }
.btab.active[data-tab-idx="4"] { color: #7c3aed; }
.btab svg { width: 22px; height: 22px; flex-shrink: 0; }
.btab span { display: block; text-overflow: ellipsis; overflow: hidden; max-width: 100%; line-height: 1.2; }

/* ── Bottom tabs always visible for logged-in users ── */
.has-tabs .bottom-tabs { display: block; }
.has-tabs .page-content { padding-bottom: 64px; }

/* ── FOOTER ── */
.site-footer {
    background: var(--card);
    border-top: 1px solid var(--border);
    margin-top: auto;
}
.site-footer-inner {
    max-width: 1100px; margin: 0 auto;
    padding: 18px 20px;
    display: flex; align-items: center;
    justify-content: space-between; gap: 16px;
}
.site-footer-brand img { height: 32px; display: block; }
.site-footer-copy { color: var(--muted); font-size: 12px; }

/* ── TOAST ── */
#toast-container {
    position: fixed; top: 70px; right: 20px;
    z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 20px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600; color: #fff;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    pointer-events: auto;
}
.toast.show { transform: translateX(0); }
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--indigo); }

/* Nav is always hamburger-based */
.site-nav.open { transform: translateX(0); }
.site-nav a { width: 100%; padding: 10px 14px; font-size: 14px; text-decoration: none; color: var(--ink-soft); font-weight: 600; border-radius: 8px; }
.site-nav a:hover { background: rgba(45,58,140,0.06); color: var(--indigo); text-decoration: none; }
.nav-spacer { width: 100%; height: 1px; background: var(--border); margin: 6px 0; }

/* Overlay behind nav menu */
.nav-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.4); z-index:104; }
.nav-overlay.show { display:block; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
    .site-brand { padding-left: 0; }
    .site-brand img { height: 52px; margin-left: -25px; }
    .site-header-inner { height: 56px; padding: 0 18px; }

    .has-tabs .page-content { padding-bottom: 120px; }

    #toast-container { right: 10px; left: 10px; }
    .toast { width: 100%; }
}

@media (max-width: 400px) {
    .site-header-inner { padding: 0 12px; }
}

@media (max-width: 900px) {
    .site-footer-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* ── DESKTOP LAYOUT FIX ── */
/* Pages were originally designed mobile-first with narrow max-width (500-600px).
   On desktop, widen the wrappers AND turn vertical lists into responsive grids
   (2-3 columns) using auto-fit so cards naturally fill the available width.
   Mobile (<= 900px) is untouched. */

@media (min-width: 901px) {
    .page-content { width: 100%; }

    /* Main hub pages — wide layouts that fill the laptop screen */
    .dash,
    .tracks-page,
    .acad,
    .comm,
    .quiz-hub {
        max-width: 1180px !important;
        padding-left: 40px !important;
        padding-right: 40px !important;
        padding-top: 32px !important;
    }

    /* Quiz hub: 4 quiz types in 2-col grid */
    .quiz-hub .quiz-grid {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 14px;
    }

    /* Content pages — readable but wider */
    .acard-page,
    .cl-page,
    .builder,
    .comp,
    .tour-page,
    .perfil-page,
    .tp {
        max-width: 880px !important;
        padding-left: 40px !important;
        padding-right: 40px !important;
        padding-top: 32px !important;
    }

    /* ── DASHBOARD: turn vertical lists into responsive grids ── */
    /* "Other active tracks" list (small cards) */
    .dash > div[style*="display:flex;flex-direction:column;gap:8px"],
    /* Free tracks wrapper inner list */
    .dash > div > div[style*="margin-bottom:8px"]:not(:only-child) { }

    /* Free tracks block — children become a grid */
    .dash > div[style*="margin-bottom:14px"] > a[href^="/memorizar/"] {
        display: flex !important;
    }
    .dash > div[style*="margin-bottom:14px"] {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .dash > div[style*="margin-bottom:14px"] > div[style*="font-size:12px"] {
        grid-column: 1 / -1;
    }

    /* "Other active tracks" small list → 2-col grid */
    .dash > div[style*="flex-direction:column;gap:8px;margin-bottom:12px"] {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 10px;
    }

    /* Completed tracks list (inside the green card) → 2-col grid */
    .dash #doneTracksList {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 8px;
    }

    /* Premium features quick actions: already 2 children, span wider */
    .dash > div[style*="background:linear-gradient(145deg, #1a1d3a 0%"] > div[style*="display:flex;gap:8px"] {
        gap: 14px !important;
    }

    /* Actions row + Community/Ranking row already use flex - just give them more breathing room */
    .dash > div[style*="display:flex;gap:8px;margin-bottom:12px"] {
        gap: 14px !important;
    }

    /* ── TRACKS PAGE: list of all tracks → grid 2-3 columns ── */
    /* Most track listings use anchor children inside a parent div */
    .tracks-page > div > a[href^="/memorizar/"],
    .tracks-page > div > a[href^="/trilha/"] {
        margin-bottom: 0 !important;
    }
    .tracks-page section,
    .tracks-page .track-section,
    .tracks-page > div:not([style*="text-align"]):not([style*="display:flex"]) {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 14px;
        margin-bottom: 18px;
    }

    /* ── ACADEMY HUB: lingua_tracks list and palaces → grid ── */
    .acad > div:not([style*="text-align"]):not([style*="display:flex"]) > a {
        margin-bottom: 0 !important;
    }
    .acad ul,
    .acad > div > div[style*="display:flex;flex-direction:column"] {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 12px;
    }

    /* ── COMUNIDADE: tabs of cards → grid ── */
    .comm > div > div[style*="flex-direction:column"] {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 12px;
    }
}

/* Wider screens get a small bonus */
@media (min-width: 1400px) {
    .dash,
    .tracks-page,
    .acad,
    .comm,
    .quiz-hub {
        max-width: 1280px !important;
    }
}
