/* ============================================================
   app.css — стилі сторінок-генераторів у дизайн-системі головної.
   Змінні старої версії перенаправлено на токени base.css,
   тому стилі окремих інструментів (css/{tool}.css) теж гармонізуються.
   Підключається ТІЛЬКИ на сторінках zavdannya/*.php.
   ============================================================ */

:root {
    --primary-color: var(--brand);
    --primary-hover: var(--brand-600);
    --bg-main: var(--bg);
    --sidebar-bg: var(--card);
    --text-dark: var(--ink);
    --text-muted: var(--muted);
    --border-color: var(--line);
    --emerald-success: #059669;
    --accent-color: var(--sun);
}

/* ---------- Заголовок сторінки ---------- */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    max-width: var(--container);
    margin-inline: auto;
    padding: 20px 20px 12px;
    background: none;
    border: none;
    height: auto;
}
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1.5px solid var(--line);
    background: var(--card);
    color: var(--muted);
    font-weight: 600;
    font-size: .88rem;
    text-decoration: none;
    transition: border-color .15s, color .15s, transform .15s;
}
.back-link:hover { border-color: var(--brand); color: var(--brand-600); transform: translateX(-2px); }
.app-header h1 {
    font-size: clamp(1.2rem, 2.6vw, 1.6rem);
    font-weight: 800;
    letter-spacing: -.01em;
    margin: 0;
}

/* ---------- Робоча область ---------- */
.app-body { height: auto; overflow: visible; background: var(--bg); }
.main-content { display: flex; flex-direction: column; height: auto; min-height: calc(100vh - 210px); }
.main-layout { display: flex; flex: 1; overflow: visible; }

.preview-section {
    flex: 1;
    padding: 8px 24px 36px;
    overflow-y: auto;
    display: flex;
    justify-content: safe center;
    background: radial-gradient(560px 280px at 70% 0%, rgba(17, 202, 160, .08), transparent 70%);
}

.a4-page {
    width: 210mm;
    height: 297mm;
    min-height: 297mm;
    max-height: 297mm;
    background: white;
    padding: 15mm 20mm;
    box-shadow: var(--shadow-lg);
    border-radius: 6px;
    box-sizing: border-box;
    overflow: hidden;
    transition: box-shadow .25s ease;
}
.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: 400px;
    background: transparent;
    border-left: none;
    overflow: visible;
    display: flex;
    flex-direction: column;
}
.controls-card {
    margin: 8px 24px 36px 0;
    padding: 24px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: auto;
}
.field-label {
    font-size: .9rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
    color: var(--ink);
    display: block;
}
.form-select, .words-textarea {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fbfdfc;
    color: var(--ink);
    transition: border-color .18s, box-shadow .18s, background .18s;
}
.form-select { padding: 0.8rem 1rem; font-weight: 600; margin-bottom: 1rem; cursor: pointer; }
.words-textarea { padding: 1rem; min-height: 150px; resize: vertical; line-height: 1.6; }
.form-select:focus, .words-textarea:focus {
    outline: none;
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(17, 202, 160, .14);
}
.form-select:hover, .words-textarea:hover { border-color: #cfdcd8; }

/* Поля без власних класів (напр., грамоти) — у стилі дизайн-системи */
.controls-card input:not([class]):not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
.controls-card textarea:not([class]),
.controls-card select:not([class]) {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    padding: .7rem .9rem;
    background: #fbfdfc;
    font: inherit;
    color: var(--ink);
    transition: border-color .18s, box-shadow .18s, background .18s;
}
.controls-card input:not([class]):focus,
.controls-card textarea:not([class]):focus,
.controls-card select:not([class]):focus {
    outline: none;
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(17, 202, 160, .14);
}

.action-buttons { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 0.6rem; }
.divider { height: 1px; background-color: var(--line); margin: 0.5rem 0; }

/* Універсальне поле введення (діапазони, імена, дати) */
.form-input {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    font-size: 1rem;
    font-weight: 600;
    background: #fbfdfc;
    color: var(--ink);
    transition: border-color .18s, box-shadow .18s, background .18s;
}
.form-input:focus {
    outline: none;
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(17, 202, 160, .14);
}

/* Кнопки — у стилі головної (пілюлі, м'які тіні) */
.btn {
    padding: 0.8rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 999px;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease;
    border: 2px solid transparent;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 6px 16px -6px rgba(17, 202, 160, .55);
}
.btn-primary:hover { background: var(--brand-600); transform: translateY(-1px); }
.btn-answers { background: var(--ink); color: #fff; }
.btn-answers:hover { background: #244552; }
.btn-answers.active-mode { background: var(--emerald-success); }
.btn-secondary { background: var(--brand-050); color: var(--brand-600); }
.btn-secondary:hover { background: #d3f5ea; }
.btn-outline { background: var(--card); border-color: var(--line); color: var(--muted); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand-600); }

/* SEO-текст під генератором */
.seo-text-block { display: none; }
.app-body .seo-text-block {
    display: block;
    padding: 32px 36px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 1000px;
    margin: 0 auto 40px;
}
.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(--muted); }
.app-body .seo-text-block ul { padding-left: 20px; }

/* ---------- Плавна поява згенерованих завдань ---------- */
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > * {
    animation: rise .35s ease both;
}
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(2) { animation-delay: .03s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(3) { animation-delay: .06s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(4) { animation-delay: .09s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(5) { animation-delay: .12s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(6) { animation-delay: .15s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(7) { animation-delay: .18s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(8) { animation-delay: .21s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(9) { animation-delay: .24s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(10) { animation-delay: .27s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(11) { animation-delay: .3s; }
:where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > *:nth-child(n+12) { animation-delay: .33s; }

/* ---------- Адаптивність ---------- */
@media (max-width: 992px) {
    .app-body { height: auto; overflow-y: auto; }
    .main-content { height: auto; min-height: calc(100vh - 70px); }
    .main-layout { flex-direction: column; overflow: visible; }
    .preview-section {
        padding: 8px 16px 24px;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .a4-page { flex-shrink: 0; margin: 0 auto; }
    .controls-section { width: 100%; border-left: none; overflow: visible; }
    .controls-card { margin: 0 16px 24px; }
}
@media (max-width: 768px) {
    .app-header { padding: 14px 16px 8px; gap: 10px; }
    .app-header h1 { font-size: 1.15rem; }
    .controls-card { padding: 1.25rem 1rem; }
    .ad-horizontal { max-width: 100%; height: auto; min-height: 50px; }
    .ad-modal { width: 95%; padding: 1.5rem; }
}

/* ---------- Друк (геометрія аркуша незмінна) ---------- */
@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;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 10mm 20mm !important;
        width: 210mm !important;
        height: 296.5mm !important;
        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;
        animation: none !important;
    }
    :where(#anagram-list, #math-grid, #words-grid, #pyramids-grid, #spysuvannya-grid, #pages-container) > * { animation: none !important; }
    .answer-char { display: none !important; }
    .show-answers .answer-char { display: block !important; color: black !important; }
}

/* ---------- Рекламне вікно (оверлей) ---------- */
.ad-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(23, 49, 59, 0.45);
    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: var(--shadow-lg);
    transform: translateY(20px) scale(.98);
    transition: transform 0.3s ease;
}
.ad-overlay.active .ad-modal { transform: translateY(0) scale(1); }
.ad-title { font-size: 1.3rem; font-weight: 800; color: var(--ink); }
.ad-placeholder {
    width: 100%;
    min-height: 250px;
    background: var(--bg);
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    margin: 1.5rem 0;
    font-weight: 500;
    overflow: hidden;
}
.ad-timer-text { font-size: 1.1rem; font-weight: 500; color: var(--ink); margin-bottom: 1.5rem; }
.ad-timer-text span { color: var(--brand-600); font-weight: 800; 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; } }

/* ---------- Рекламні слоти ---------- */
.ad-placeholder {
    background-color: var(--bg);
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    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; }
.ad-article { width: 100%; height: 120px; margin: 25px 0; }
@media print { .ad-placeholder { display: none !important; } }