:root {
    --primary-color: #4f46e5; 
    --primary-hover: #4338ca;
    --bg-main: #f8fafc;       
    --sidebar-bg: #ffffff;
    --text-dark: #0f172a;     
    --text-muted: #64748b;    
    --border-color: #e2e8f0;
    --emerald-success: #059669;
    --accent-color: #f59e0b;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-dark);
    background-color: var(--bg-main);
    line-height: 1.5;
}

/* =========================================
   1. СТИЛІ ДЛЯ ГОЛОВНОЇ СТОРІНКИ (LANDING)
   ========================================= */

/* Контейнер для центрування контенту */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Шапка головної сторінки */
.site-header {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
}

.main-nav ul {
    display: flex;
    gap: 24px;
    list-style: none;
}

.main-nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    transition: color 0.2s;
}

.main-nav a:hover {
    color: var(--primary-color);
}

/* Перший екран (Hero) */
.hero-section {
    padding: 80px 0 60px;
    text-align: center;
}

.hero-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.badge {
    background-color: #e0e7ff;
    color: var(--primary-color);
    padding: 6px 16px;
    border-radius: 99px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 24px;
    display: inline-block;
}

.hero-section h1 {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 24px;
    color: var(--text-dark);
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 40px;
    max-width: 600px;
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.125rem;
}

/* Модульна сітка інструментів (Bento Grid) */
.tools-section {
    padding: 60px 0;
}

.section-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-align: center;
}

.section-desc {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 48px;
}

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

.tool-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 32px;
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.06);
}

.card-icon {
    font-size: 2.5rem;
    margin-bottom: 20px;
}

.tool-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.tool-card p {
    color: var(--text-muted);
    margin-bottom: 24px;
    flex-grow: 1;
}

.status-badge {
    background-color: #f1f5f9;
    color: #475569;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
}

/* SEO блок та підвал */
.about-platform {
    padding: 80px 0;
    background-color: #ffffff;
    border-top: 1px solid var(--border-color);
}

.about-platform h2 {
    font-size: 1.75rem;
    margin-bottom: 16px;
}

.about-platform p {
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1.7;
    max-width: 800px;
}

.site-footer {
    padding: 32px 0;
    text-align: center;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}


/* =========================================
   2. СТИЛІ ДЛЯ СТОРІНКИ ГЕНЕРАТОРА АНАГРАМ
   ========================================= */

/* Блокуємо скрол тільки для додатку-генератора */
.app-body {
    overflow: hidden;
    height: 100vh;
}

.app-header { 
    padding: 0 2.5rem; 
    background: var(--sidebar-bg); 
    border-bottom: 1px solid var(--border-color); 
    display: flex; 
    align-items: center; 
    gap: 2rem; 
    height: 70px;
}

.back-link { 
    color: var(--text-muted); 
    text-decoration: none; 
    font-weight: 500; 
    transition: color 0.2s; 
}
.back-link:hover { color: var(--primary-color); }

.app-header h1 { 
    font-size: 1.3rem; 
    font-weight: 600; 
    margin: 0;
}

.main-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 70px);
}

.main-layout { 
    display: flex; 
    flex: 1;
    overflow: hidden; 
}

/* Робоча область А4 */
.preview-section { 
    flex: 1; 
    padding: 2.5rem 2rem; 
    overflow-y: auto; 
    display: flex; 
    justify-content: center; 
    background-color: #f1f5f9; 
}

.a4-page {
    width: 210mm;
    height: 297mm;
    min-height: 297mm;
    max-height: 297mm;
    background: white;
    padding: 15mm 20mm; 
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.08);
    border-radius: 4px;
    box-sizing: border-box;
    overflow: hidden; 
}

.document-title { 
    text-align: center; 
    margin-bottom: 12mm; 
    font-size: 20pt;     
    font-weight: 700; 
    letter-spacing: -0.01em;
    color: var(--text-dark);
}

/* Списки анаграм */
.anagram-list {
    display: flex;
    flex-direction: column;
    gap: 4mm; 
}

.anagram-item { 
    display: flex; 
    align-items: center; 
    font-size: 12pt; 
}

.anagram-scrambled { 
    font-weight: 600; 
    width: 60mm; 
    text-transform: uppercase; 
    letter-spacing: 3px; 
    color: var(--text-dark);
}

.anagram-separator { 
    width: 15mm;
    text-align: center;
    color: var(--text-muted); 
    font-weight: 400;
}

/* Системні лінії підкреслення */
.lines-container {
    display: flex;
    gap: 8px; 
    align-items: center;
}

.letter-line {
    width: 24px; 
    height: 24px;
    border-bottom: 2px solid #cbd5e1; 
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 10pt;
    font-weight: 700;
    font-family: monospace;
    transition: border-color 0.15s ease;
}

.answer-char { display: none; }

.show-answers .answer-char {
    display: block; 
    color: var(--emerald-success); 
}
.show-answers .letter-line { border-bottom-color: #a7f3d0; }
.show-answers .document-title { color: var(--emerald-success); }

/* Права панель налаштувань */
.controls-section { 
    width: 380px; 
    background: var(--sidebar-bg); 
    border-left: 1px solid var(--border-color); 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
}

.controls-card { 
    padding: 2rem;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.field-label {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #334155;
    display: block;
}

.form-select, .words-textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #f8fafc;
    color: var(--text-dark);
    transition: all 0.2s;
}

.form-select {
    padding: 0.85rem 1rem;
    font-weight: 500;
    margin-bottom: 1rem;
    cursor: pointer;
}

.words-textarea {
    padding: 1rem;
    min-height: 150px;
    resize: none; 
    line-height: 1.6;
}

.form-select:focus, .words-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

/* Кнопки */
.action-buttons { 
    margin-top: 1.5rem; 
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
}

.btn { 
    padding: 0.85rem 1.5rem; 
    font-size: 0.95rem; 
    font-weight: 600; 
    border-radius: 12px; 
    cursor: pointer; 
    transition: all 0.2s; 
    border: none; 
    width: 100%; 
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
}

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }

.btn-answers { background-color: #0f172a; color: white; }
.btn-answers:hover { background-color: #1e293b; }
.btn-answers.active-mode { background-color: var(--emerald-success); }

.btn-secondary { background-color: #f1f5f9; color: #334155; }
.btn-secondary:hover { background-color: #e2e8f0; }
.btn-outline { background-color: transparent; border: 2px solid var(--border-color); color: #475569; }
.btn-outline:hover { background-color: #f8fafc; }

/* SEO Текст під генератором (прихований від візуальної частини робочої зони, доступний для ботів) */
.seo-text-block {
    display: none; /* Тимчасово ховаємо, щоб не ламав інтерфейс 100vh. Для SEO краще винести його за межі main-layout */
}
.app-body {
    overflow-y: auto; /* Дозволяємо прокрутку сторінки анаграм, якщо там є SEO текст */
}
.app-body .main-content {
    height: auto;
    min-height: calc(100vh - 70px);
}
.app-body .seo-text-block {
    display: block;
    padding: 40px;
    background: #fff;
    max-width: 1000px;
    margin: 0 auto;
}
.app-body .seo-text-block h2, .app-body .seo-text-block h3 { margin-bottom: 15px; margin-top: 20px;}
.app-body .seo-text-block p, .app-body .seo-text-block ul { margin-bottom: 15px; line-height: 1.6; color: var(--text-muted);}
.app-body .seo-text-block ul { padding-left: 20px; }


/* =========================================
   4. АДАПТИВНІСТЬ (Планшети та Телефони)
   ========================================= */

/* Для планшетів та невеликих ноутбуків (до 992px) */
@media (max-width: 992px) {
    /* Знімаємо жорстке обмеження висоти для екрана генератора */
    .app-body {
        height: auto;
        overflow-y: auto;
    }
    .main-content {
        height: auto;
        min-height: calc(100vh - 70px);
    }
    
    /* Перебудовуємо робочу зону: А4 зверху, налаштування знизу */
    .main-layout {
        flex-direction: column;
        overflow: visible;
    }
    
    /* Дозволяємо горизонтальний скрол для аркуша А4, щоб він не стискався */
    .preview-section {
        padding: 1.5rem 1rem;
        justify-content: flex-start;
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch; /* Плавний скрол на iPhone/iPad */
    }
    
    .a4-page {
        flex-shrink: 0; /* Забороняємо аркушу зминатися */
        margin: 0 auto;
    }
    
    /* Панель налаштувань розтягуємо на всю ширину */
    .controls-section {
        width: 100%;
        border-left: none;
        border-top: 2px solid var(--border-color);
        overflow: visible;
    }
}

/* Для мобільних телефонів (до 768px) */
@media (max-width: 768px) {
    /* --- Головна сторінка (Landing) --- */
    .header-container {
        flex-direction: column;
        height: auto;
        padding: 15px 0;
        gap: 15px;
    }
    
    .main-nav ul {
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px;
    }
    
    .hero-section {
        padding: 40px 0 30px;
    }
    
    .hero-section h1 {
        font-size: 2.2rem; /* Менший заголовок */
    }
    
    .hero-subtitle {
        font-size: 1.05rem;
    }
    
    /* Картки інструментів стають в одну колонку */
    .tools-grid {
        grid-template-columns: 1fr;
    }
    
    .about-platform {
        padding: 50px 0;
    }

    /* --- Сторінка генератора --- */
    .app-header {
        flex-direction: column;
        height: auto;
        padding: 15px;
        gap: 10px;
        text-align: center;
    }
    
    .app-header h1 {
        font-size: 1.1rem;
    }
    
    .controls-card {
        padding: 1.5rem 1rem; /* Зменшуємо відступи на телефоні */
    }
    
    /* Трохи зменшуємо рекламні блоки, щоб вони не вилазили за екран */
    .ad-horizontal {
        max-width: 100%;
        height: auto;
        min-height: 50px;
    }
    
    .ad-modal {
        width: 95%;
        padding: 1.5rem;
    }
}

/* Для дуже маленьких телефонів (до 480px) */
@media (max-width: 480px) {
    .btn-large {
        width: 100%; /* Кнопка на всю ширину */
        padding: 14px 20px;
    }
    
    .hero-section h1 {
        font-size: 1.8rem;
    }
}

/* Фікс друку */
/* Фікс друку (Захист від 2-ї сторінки та приховування відповідей) */
@media print {
    @page {
        size: A4 portrait;
        margin: 0 !important; 
    }
    
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        width: 210mm !important;
        height: 296.5mm !important; /* Жорстко обрізаємо висоту */
        max-height: 296.5mm !important;
        overflow: hidden !important; /* Блокуємо появу нових сторінок */
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .app-header, .controls-section, .seo-text-block, .site-footer, .ad-overlay, .ad-placeholder { 
        display: none !important; 
    }
    
    .main-layout, .preview-section { 
        display: block !important; 
        padding: 0 !important; 
        margin: 0 !important; 
        background: #fff !important;
        height: 296.5mm !important;
        width: 210mm !important;
        overflow: hidden !important;
    }

    .a4-page { 
        box-shadow: none !important; 
        border: none !important;
        margin: 0 !important;
        padding: 10mm 20mm !important; 
        width: 210mm !important;
        height: 296.5mm !important; /* Унеможливлює 2-гу сторінку */
        max-height: 296.5mm !important;
        box-sizing: border-box !important;
        page-break-inside: avoid !important;
        page-break-after: avoid !important;
        background: #fff !important;
        overflow: hidden !important;
    }

    /* ЗАЛІЗОБЕТОННЕ ПРИХОВУВАННЯ ВІДПОВІДЕЙ ПРИ ДРУЦІ */
    .answer-char { 
        display: none !important; 
    }
    
    /* Відповіді друкуються ТІЛЬКИ якщо активний режим .show-answers */
    .show-answers .answer-char { 
        display: block !important; 
        color: black !important; /* Чорний колір краще видно на звичайних принтерах */
    }
}

/* ==========================================
   СТИЛІ ДЛЯ РЕКЛАМНОГО ВІКНА (ОВЕРЛЕЙ)
   ========================================== */
.ad-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ad-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.ad-modal {
    background: white;
    padding: 2.5rem;
    border-radius: 24px;
    width: 90%;
    max-width: 450px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.ad-overlay.active .ad-modal {
    transform: translateY(0);
}

.ad-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-dark);
}

.ad-placeholder {
    width: 100%;
    min-height: 250px;
    background: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    margin: 1.5rem 0;
    font-weight: 500;
    overflow: hidden;
}

.ad-timer-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 1.5rem;
}

.ad-timer-text span {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.4rem;
}

.ad-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ad-actions .btn {
    padding: 0.85rem;
}

/* Приховуємо рекламу під час друку */
@media print {
    .ad-overlay { display: none !important; }
}

/* =========================================
   3. РЕКЛАМНІ БЛОКИ (Google AdSense Placeholders)
   ========================================= */

.ad-placeholder {
    background-color: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}

/* Верхній горизонтальний банер */
.ad-horizontal {
    width: 100%;
    max-width: 970px;
    height: 90px;
    margin: 15px auto;
}

/* Сайдбар під кнопками */
.ad-sidebar {
    width: 100%;
    height: 250px;
    margin-top: 20px;
}

/* Реклама всередині SEO тексту */
.ad-article {
    width: 100%;
    height: 120px;
    margin: 25px 0;
}

/* КРИТИЧНО: Приховуємо рекламу при друку на принтері та генерації PDF */
@media print {
    .ad-placeholder {
        display: none !important;
    }
}