:root {
    --bg: #0a0806;
    --surface: #14110e;
    --surface2: #1c1814;
    --gold: linear-gradient(135deg, #c9a227 0%, #e8c97a 50%, #c9a227 100%);
    --gold-solid: #c9a227;
    --gold-light: #f3e5ab;
    --gold-dim: rgba(201, 162, 39, 0.1);
    --purple: #8b5cf6;
    --cream: #f5f1ea;
    --muted: #a39485;
    --border: rgba(201, 162, 39, 0.12);
    --border-strong: rgba(201, 162, 39, 0.25);
    --glass: rgba(20, 17, 14, 0.7);
    --glass-blur: blur(12px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-font-smoothing: antialiased; }
body { background: var(--bg); color: var(--cream); font-family: 'DM Sans', sans-serif; height: 100vh; overflow: hidden; }

.fade-in { animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.overlay { position: fixed; inset: 0; background: var(--bg); z-index: 10000; display: flex; justify-content: center; align-items: center; padding: 20px; }
.card-pro { 
    background: var(--surface); 
    padding: 60px; 
    border-radius: 40px; 
    width: 100%; 
    max-width: 1000px; 
    border: 1px solid var(--border-strong); 
    box-shadow: 0 50px 150px rgba(0,0,0,0.9); 
    text-align: center;
    position: relative;
    overflow: hidden;
}
.card-pro::before {
    content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at center, rgba(201,162,39,0.03) 0%, transparent 70%);
    pointer-events: none;
}

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; margin-top: 50px; }
.btn-opt { 
    background: var(--surface2); 
    border: 1px solid var(--border); 
    padding: 40px; 
    border-radius: 24px; 
    cursor: pointer; 
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}
.btn-opt:hover { 
    border-color: var(--gold-solid); 
    transform: translateY(-12px); 
    background: var(--gold-dim);
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}
.btn-opt i { color: var(--gold-solid); margin-bottom: 25px; display: block; width: 100%; }
.btn-opt h4 { font-family: 'Playfair Display'; font-size: 1.2rem; letter-spacing: 0.5px; }

#hub-screen { display: none; }
.hub-title { font-family: 'Playfair Display'; font-size: 3rem; color: var(--gold-light); margin-bottom: 8px; font-weight: 700; }
.hub-stat { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 4px; font-weight: 500; }

/* APP SHELL */
.app-shell { display: none; height: 100vh; overflow: hidden; }
.sidebar { 
    width: 280px; 
    min-width: 280px; 
    background: var(--glass); 
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    z-index: 100;
}
.view-content { flex: 1; display: flex; flex-direction: column; background: var(--bg); position: relative; overflow: hidden; min-width: 0; }
.brand { font-family: 'Playfair Display'; font-weight: 700; color: var(--gold-light); font-size: 18px; line-height: 1.2; letter-spacing: -0.5px; }

/* SECTIONS */
#writing-section, #cover-section, #illustration-section { 
    display: none; 
    flex-direction: column; 
    height: 100%; 
    overflow: hidden; 
    animation: sectionFade 0.5s ease;
}
@keyframes sectionFade { from { opacity: 0; filter: blur(10px); } to { opacity: 1; filter: blur(0); } }

/* WRITING HEADER */
.writing-header { 
    flex-shrink: 0; 
    padding: 16px 40px; 
    border-bottom: 1px solid var(--border); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: var(--glass); 
    backdrop-filter: var(--glass-blur);
}
.writing-toolbar { 
    flex-shrink: 0; 
    padding: 10px 40px; 
    border-bottom: 1px solid var(--border); 
    background: var(--surface2); 
    display: flex; 
    gap: 12px; 
    align-items: center; 
}

/* SCROLLABLE WRITING AREA */
.editor-scroll { flex: 1; overflow-y: auto; padding: 60px 40px; scroll-behavior: smooth; }
.editor-scroll::-webkit-scrollbar { width: 6px; }
.editor-scroll::-webkit-scrollbar-track { background: transparent; }
.editor-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

/* PAPER */
.paper { 
    width: 100%; 
    max-width: 800px; 
    min-height: calc(100vh - 250px); 
    margin: 0 auto; 
    background: transparent; 
    color: var(--cream); 
    font-family: 'Crimson Pro', serif; 
    font-size: 22px; 
    line-height: 2; 
    outline: none; 
    word-break: break-word; 
    padding-bottom: 100px;
}
.paper:empty::before { content: 'O silêncio é a tela do autor. Comece sua jornada...'; color: rgba(163, 148, 133, 0.25); font-style: italic; pointer-events: none; }

.btn-gold { 
    background: var(--gold); 
    color: #000; 
    border: none; 
    padding: 14px 28px; 
    border-radius: 12px; 
    font-weight: 800; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    font-size: 0.9rem; 
    transition: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.btn-gold:hover { transform: scale(1.05); box-shadow: 0 10px 30px rgba(201,162,39,0.3); filter: brightness(1.1); }

.btn-outline { 
    background: transparent; 
    border: 1px solid var(--border); 
    color: var(--muted); 
    padding: 12px 24px; 
    border-radius: 12px; 
    font-weight: 700; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    font-size: 0.8rem; 
    transition: 0.3s;
}
.btn-outline:hover { border-color: var(--gold-solid); color: var(--gold-light); background: var(--gold-dim); }

.btn-ia { 
    background: var(--purple); 
    color: white; 
    border: none; 
    padding: 14px 28px; 
    border-radius: 12px; 
    font-weight: 800; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    font-size: 0.85rem; 
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.3);
    transition: 0.3s;
}
.btn-ia:hover { transform: translateY(-3px); box-shadow: 0 12px 35px rgba(139, 92, 246, 0.5); }

input, textarea { 
    background: var(--surface2); 
    border: 1px solid var(--border); 
    color: white; 
    padding: 18px; 
    border-radius: 16px; 
    width: 100%; 
    margin-bottom: 15px; 
    outline: none; 
    transition: 0.3s;
    font-family: 'DM Sans', sans-serif;
}
input:focus, textarea:focus { border-color: var(--gold-solid); background: var(--bg); box-shadow: 0 0 20px var(--gold-dim); }

#masterStatus { 
    display: none; 
    position: fixed; 
    top: 30px; 
    right: 30px; 
    background: var(--glass); 
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--purple); 
    color: var(--cream); 
    padding: 14px 35px; 
    border-radius: 50px; 
    font-size: 0.75rem; 
    font-weight: 800; 
    align-items: center; 
    gap: 15px; 
    z-index: 20000; 
    letter-spacing: 2px; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.6); 
}
.spin { width: 16px; height: 16px; border: 3px solid rgba(139, 92, 246, 0.2); border-top: 3px solid var(--purple); border-radius: 50%; animation: rot 0.8s linear infinite; }
@keyframes rot { 100% { transform: rotate(360deg); } }

#toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); background: #059669; color: white; padding: 18px 45px; border-radius: 50px; font-weight: 800; z-index: 30000; display: none; box-shadow: 0 20px 50px rgba(0,0,0,0.5); animation: toastIn 0.5s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes toastIn { from { transform: translate(-50%, 50px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.sidebar { transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1), min-width 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.sidebar.collapsed { width: 0 !important; min-width: 0 !important; border-right: none; }
.hamburger-btn { background: none; border: 1px solid var(--border); color: var(--muted); cursor: pointer; padding: 8px 10px; border-radius: 10px; display: flex; align-items: center; transition: 0.3s; }
.hamburger-btn:hover { border-color: var(--gold-solid); color: var(--gold-light); background: var(--gold-dim); }

.confirm-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(8px); z-index: 50000; display: none; align-items: center; justify-content: center; }
.confirm-box { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 24px; padding: 48px; max-width: 450px; width: 90%; text-align: center; box-shadow: 0 30px 100px rgba(0,0,0,1); }

/* RESPONSIVIDADE MOBILE */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 10000;
        transform: translateX(-100%);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 20px 0 50px rgba(0,0,0,0.5);
    }
    .sidebar.active { transform: translateX(0); }
    
    .writing-header { padding: 12px 20px; }
    .writing-toolbar { padding: 8px 20px; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .editor-scroll { padding: 30px 20px; }
    .paper { font-size: 19px; line-height: 1.8; }
    
    .grid-3 { grid-template-columns: 1fr; }
    .card-pro { padding: 40px 20px; border-radius: 0; height: 100vh; display: flex; flex-direction: column; justify-content: center; }
    .hub-title { font-size: 2.2rem; }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        backdrop-filter: blur(4px);
        z-index: 9000;
    }
    .sidebar-overlay.active { display: block; }
}

/* LEITURA IMERSIVA & TTS */
.reading-mode {
    background: #14110e !important;
    color: #f5f1ea !important;
    font-family: 'Crimson Pro', serif;
    line-height: 1.8;
}

#tts-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(20, 17, 14, 0.8);
    backdrop-filter: blur(15px);
    padding: 10px 20px;
    border-radius: 30px;
    border: 1px solid rgba(201, 162, 39, 0.3);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10001;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#tts-widget:hover {
    transform: translateY(-5px) scale(1.02);
    border-color: var(--gold-solid);
    box-shadow: 0 15px 40px rgba(201,162,39,0.15);
}

.tts-label {
    font-family: 'DM Sans', sans-serif;
    font-size: 10px;
    letter-spacing: 1px;
    font-weight: 700;
    text-transform: uppercase;
}

/* AD SYSTEM v2.0 */
#ea-ad-container.ad-popup {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
}

#ea-ad-container.ad-sidebar {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 10000;
    animation: adSlideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.ad-box {
    background: #1c1814;
    border: 1px solid var(--border-strong);
    padding: 40px;
    border-radius: 30px;
    max-width: 450px;
    width: 90%;
    text-align: center;
    position: relative;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8);
}

.ad-popup .ad-box {
    border: 2px solid var(--accent);
}

.ad-header {
    font-size: 10px;
    letter-spacing: 4px;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 20px;
}

.ad-subtitle {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    color: var(--accent);
    margin-bottom: 15px;
}

.ad-text {
    font-size: 15px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 25px;
}

.ad-btn {
    width: 100%;
    justify-content: center;
    text-decoration: none;
}

.ad-img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 15px;
    margin-bottom: 20px;
    border: 1px solid rgba(201, 162, 39, 0.1);
}

.ad-premium-link {
    display: inline-block;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
    text-decoration: none !important;
    transition: 0.3s;
}

.ad-premium-link:hover {
    letter-spacing: 2px;
    color: #fff;
}

.close-ad {
    position: absolute;
    top: -20px;
    right: -20px;
    width: 50px;
    height: 50px;
    background: #c9a227;
    color: #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 20001;
    border: 3px solid #1c1814;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.close-ad:hover {
    transform: scale(1.15) rotate(90deg);
    background: #fff;
}

.tts-premium-lock {
    opacity: 0.6;
    filter: grayscale(1);
    cursor: pointer;
    position: relative;
}

.tts-premium-lock::after {
    content: 'PREMIUM';
    position: absolute;
    top: -12px;
    right: 5px;
    background: var(--gold);
    color: #000;
    font-size: 8px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 900;
    letter-spacing: 1px;
}

@keyframes adSlideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
