/* styles.css */

/* =========================================================
   1. Design tokens
   Тема: папір + чорнильно-синій. Світла, спокійна, editorial.
   ========================================================= */
:root {
    /* Палітра */
    --paper: #f5f2ea;          /* основний фон (теплий папір) */
    --paper-deep: #ece7db;     /* вторинні поверхні, бордери-акценти */
    --surface: #faf8f3;        /* header/footer/вставки */
    --card: #ffffff;           /* картки */
    --ink: #1c2230;            /* основний текст */
    --ink-soft: #3a4150;       /* абзаци */
    --muted: #5a6172;          /* мета, дати, підписи (контраст > 4.5:1) */

    --accent: #1f3f74;         /* чорнильно-синій, основний акцент */
    --accent-hover: #142c57;
    --accent-tint: rgba(31, 63, 116, 0.08);
    --accent-line: rgba(31, 63, 116, 0.28);

    --accent2: #7a4a22;        /* теплий коричневий, допоміжний акцент */
    --accent2-tint: rgba(122, 74, 34, 0.09);

    --line: rgba(28, 34, 48, 0.12);      /* тонкі бордери */
    --line-soft: rgba(28, 34, 48, 0.07);

    /* Тіні (м'які й легкі) */
    --shadow-sm: 0 1px 2px rgba(28, 34, 48, 0.05);
    --shadow-md: 0 6px 18px -10px rgba(28, 34, 48, 0.18);
    --shadow-lg: 0 16px 36px -18px rgba(31, 63, 116, 0.22);

    /* Радіуси */
    --radius-sm: 6px;
    --radius: 12px;
    --radius-lg: 18px;

    /* Типографіка */
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-head: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --fs-base: 1.0625rem;      /* 17px mobile */
    --fs-small: 0.875rem;      /* 14px */
    --fs-xs: 0.75rem;          /* 12px */
    --fs-h1: 1.4375rem;        /* 23px mobile */
    --fs-h2: 1.25rem;
    --fs-h3: 1.125rem;

    --lh-body: 1.7;
    --lh-head: 1.3;

    --measure: 68ch;

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;

    --gutter: 1.125rem;        /* бокові поля mobile */
    --container: 1120px;

    --touch: 44px;             /* мін. зона натискання */
    --transition: 0.2s ease;
}

/* =========================================================
   2. Reset & base
   ========================================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background: var(--paper);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: var(--lh-body);
    font-feature-settings: "kern", "liga";
    text-rendering: optimizeLegibility;
    overflow-wrap: break-word;
    position: relative;
}

img,
picture,
video,
canvas,
svg,
iframe {
    display: block;
    max-width: 100%;
    height: auto;
}

iframe {
    width: 100%;
}

/* Легкий "папірний" патерн поверх фону (статичний, без анімацій) */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(900px 500px at 0% 0%, rgba(31, 63, 116, 0.05), transparent 70%),
        radial-gradient(800px 480px at 100% 100%, rgba(122, 74, 34, 0.05), transparent 70%),
        repeating-linear-gradient(0deg, transparent 0 31px, rgba(28, 34, 48, 0.025) 31px 32px);
}

::selection {
    background: var(--accent);
    color: #ffffff;
}

/* =========================================================
   3. Typography
   ========================================================= */
h1,
h2,
h3,
h4 {
    color: var(--ink);
    font-family: var(--font-head);
    font-weight: 700;
    line-height: var(--lh-head);
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
    hyphens: auto;
}

p {
    overflow-wrap: break-word;
}

strong,
b {
    font-weight: 700;
}

em {
    font-style: italic;
}

small {
    font-size: var(--fs-small);
}

ul,
ol {
    list-style: none;
}

/* Посилання */
a {
    color: var(--accent);
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--accent-line);
    text-underline-offset: 0.2em;
    overflow-wrap: anywhere;
    transition: color var(--transition), text-decoration-color var(--transition);
}

a:hover {
    color: var(--accent-hover);
    text-decoration-color: currentColor;
}

a:active {
    color: var(--accent-hover);
}

/* Focus: чітко видно, але без шуму для миші */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

/* =========================================================
   4. Layout helpers
   ========================================================= */
main {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--space-10) var(--gutter) var(--space-12);
    min-width: 0;
}

/* =========================================================
   5. Header
   ========================================================= */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(245, 242, 234, 0.86);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.header-inner {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--space-3) var(--gutter);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2) var(--space-4);
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--touch);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: 0.02em;
    color: var(--ink);
    text-decoration: none;
    min-width: 0;
}

.logo:hover {
    color: var(--accent);
}

.lang-switcher {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--fs-small);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.lang-switcher a {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
    padding: 0 var(--space-2);
    color: var(--muted);
    text-decoration: none;
}

.lang-switcher a::after {
    content: "";
    position: absolute;
    left: var(--space-2);
    right: var(--space-2);
    bottom: 8px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform var(--transition);
}

.lang-switcher a:hover {
    color: var(--accent);
}

.lang-switcher a.active {
    color: var(--ink);
}

.lang-switcher a.active::after,
.lang-switcher a:hover::after {
    transform: scaleX(1);
}

.lang-switcher a.active::after {
    background: var(--accent);
}

/* =========================================================
   6. Article title & hero
   ========================================================= */
.article-title {
    max-width: 30em;
    margin-bottom: var(--space-8);
    font-size: var(--fs-h1);
    font-weight: 700;
    line-height: 1.3;
    color: var(--ink);
    letter-spacing: -0.015em;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.hero {
    display: grid;
    gap: var(--space-6);
    margin-bottom: var(--space-12);
    min-width: 0;
}

.hero > * {
    min-width: 0;
}

.hero-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-4);
}

.hero-content .lead {
    font-family: var(--font-head);
    font-size: 1.0625rem;
    line-height: var(--lh-body);
    color: var(--ink-soft);
    padding-left: var(--space-4);
    border-left: 2px solid var(--accent-line);
    margin-bottom: var(--space-2);
}

.meta-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    font-size: var(--fs-small);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.meta-info > * + *::before {
    content: "·";
    margin-right: var(--space-3);
    color: var(--line);
}

/* Hero visual: одна уніфікована коробка */
.hero-visual {
    position: relative;
    width: 100%;
    height: 240px;
    overflow: hidden;
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.hero-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    border-radius: inherit;
}

/* Декоративна текстура, якщо присутня */
.visual-texture {
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(at 80% 0%, rgba(31, 63, 116, 0.12) 0, transparent 50%),
        radial-gradient(at 0% 100%, rgba(122, 74, 34, 0.12) 0, transparent 50%),
        repeating-linear-gradient(45deg, rgba(28, 34, 48, 0.03) 0 1px, transparent 1px 10px);
}

/* =========================================================
   7. Article content
   ========================================================= */
.content-body {
    max-width: var(--measure);
    margin: 0 auto var(--space-12);
    min-width: 0;
    font-size: var(--fs-base);
}

.content-body > * + * {
    margin-top: 0;
}

.content-body p {
    margin-bottom: var(--space-5);
    color: var(--ink-soft);
    font-size: inherit;
    line-height: var(--lh-body);
}

.content-body h2,
.content-body h3 {
    margin-top: var(--space-10);
    margin-bottom: var(--space-4);
    color: var(--ink);
}

.content-body h2 {
    font-size: var(--fs-h2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--line-soft);
}

.content-body h3 {
    font-size: var(--fs-h3);
    color: var(--accent);
}

.content-body h2:first-child,
.content-body h3:first-child,
.content-body p:first-child {
    margin-top: 0;
}

.content-body a {
    font-weight: 500;
}

.content-body blockquote {
    position: relative;
    margin: var(--space-8) 0;
    padding: var(--space-5) var(--space-5) var(--space-5) var(--space-6);
    background: linear-gradient(90deg, var(--accent2-tint), transparent 85%);
    border-left: 3px solid var(--accent2);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-family: var(--font-head);
    font-style: italic;
    font-size: 1.0625rem;
    line-height: 1.6;
    color: var(--ink);
}

.content-body blockquote p:last-child {
    margin-bottom: 0;
}

.content-body ul,
.content-body ol {
    margin-bottom: var(--space-5);
    padding-left: var(--space-6);
}

.content-body ul {
    list-style: none;
}

.content-body ul li {
    position: relative;
    margin-bottom: var(--space-2);
    padding-left: var(--space-2);
    color: var(--ink-soft);
}

.content-body ul li::before {
    content: "";
    position: absolute;
    left: calc(-1 * var(--space-4));
    top: 0.72em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.content-body ol {
    list-style: decimal;
    color: var(--ink-soft);
}

.content-body ol li {
    margin-bottom: var(--space-2);
    padding-left: var(--space-1);
}

.content-body ul li strong,
.content-body ol li strong {
    color: var(--ink);
}

.content-body hr {
    height: 1px;
    margin: var(--space-10) 0;
    border: 0;
    background: var(--line);
}

.content-body img {
    margin: var(--space-6) auto;
    border-radius: var(--radius);
    border: 1px solid var(--line-soft);
}

.content-body figure {
    margin: var(--space-6) 0;
}

.content-body figcaption {
    margin-top: var(--space-2);
    font-size: var(--fs-small);
    color: var(--muted);
}

/* Inline code */
code,
kbd,
samp {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

:not(pre) > code {
    padding: 0.1em 0.4em;
    background: var(--paper-deep);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    color: var(--ink);
    overflow-wrap: anywhere;
}

/* Code blocks */
pre {
    margin: var(--space-6) 0;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: var(--fs-small);
    line-height: 1.6;
    white-space: pre;
    color: var(--ink);
}

pre code {
    padding: 0;
    background: none;
    border: 0;
    white-space: inherit;
}

/* Tables: горизонтальний скрол на мобільному */
table {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: var(--space-6) 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: var(--fs-small);
    background: var(--card);
}

thead,
tbody,
tr {
    display: table-row-group;
}

tr {
    display: table-row;
}

th,
td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--line-soft);
    overflow-wrap: anywhere;
    min-width: 8ch;
}

th {
    background: var(--paper);
    color: var(--ink);
    font-weight: 700;
    white-space: nowrap;
}

tbody tr:nth-child(even) td {
    background: rgba(28, 34, 48, 0.02);
}

tbody tr:hover td {
    background: var(--accent-tint);
}

tr:last-child td {
    border-bottom: 0;
}

/* =========================================================
   8. Related materials & cards
   ========================================================= */
.related-materials {
    margin-top: var(--space-12);
}

.section-header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.section-header h2,
.section-header h3 {
    flex-shrink: 0;
    font-size: var(--fs-h2);
    margin: 0;
}

.divider-line {
    flex-grow: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--line), transparent);
}

.cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
    min-width: 0;
}

.cards-grid > * {
    min-width: 0;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--space-5);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition),
        box-shadow var(--transition),
        border-color var(--transition);
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-line);
    box-shadow: var(--shadow-md);
}

.card-top {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    font-size: var(--fs-xs);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25em 0.7em;
    background: var(--accent-tint);
    color: var(--accent);
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.4;
}

.badge.accent-badge {
    background: var(--accent2-tint);
    color: var(--accent2);
    border-color: rgba(122, 74, 34, 0.3);
}

.date {
    color: var(--muted);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
}

.card h4 {
    margin-bottom: var(--space-2);
    font-size: 1.1875rem;
    color: var(--ink);
}

.card p {
    flex-grow: 1;
    margin-bottom: var(--space-4);
    font-size: var(--fs-small);
    line-height: 1.6;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-top: var(--space-3);
    border-top: 1px solid var(--line-soft);
    min-height: var(--touch);
}

.card-footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
    font-weight: 600;
    font-size: var(--fs-small);
}

/* Вся картка клікабельна через посилання, якщо воно є */
.card:focus-within {
    border-color: var(--accent-line);
}

/* =========================================================
   9. Footer
   ========================================================= */
footer {
    margin-top: var(--space-16);
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.footer-inner {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--space-8) var(--gutter);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
    text-align: center;
}

.footer-left {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    color: var(--muted);
    font-size: var(--fs-small);
}

.footer-center {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-1) var(--space-5);
}

.footer-center a {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
    color: var(--ink-soft);
    font-size: var(--fs-small);
    font-weight: 500;
    text-decoration-color: var(--accent-line);
}

.footer-center a:hover {
    color: var(--accent);
}

.dmca-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 32px;
    padding: var(--space-1) var(--space-3);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    color: var(--muted);
    cursor: default;
}

/* =========================================================
   10. Breakpoints (mobile-first)
   ========================================================= */

/* ≥ 480px */
@media (min-width: 480px) {
    :root {
        --gutter: 1.25rem;
    }

    .cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .hero-visual {
        height: 280px;
    }
}

/* ≥ 768px */
@media (min-width: 768px) {
    :root {
        --fs-base: 1.0625rem;
        --fs-h1: 1.75rem;
        --fs-h2: 1.375rem;
        --fs-h3: 1.1875rem;
        --gutter: 1.5rem;
    }

    main {
        padding-top: var(--space-12);
    }

    .article-title {
        margin-bottom: var(--space-10);
    }

    .hero {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
        gap: var(--space-10);
        align-items: center;
    }

    .hero-visual {
        height: auto;
        min-height: 340px;
    }

    .content-body p {
        margin-bottom: var(--space-6);
    }

    .content-body ul,
    .content-body ol {
        padding-left: var(--space-8);
    }

    .content-body ul li::before {
        left: calc(-1 * var(--space-5));
    }

    .footer-inner {
        flex-direction: row;
        justify-content: space-between;
        text-align: left;
    }

    .footer-left {
        justify-content: flex-start;
    }

    .footer-center {
        justify-content: flex-end;
    }

    table {
        display: table;
        overflow: visible;
    }

    thead {
        display: table-header-group;
    }

    tbody {
        display: table-row-group;
    }
}

/* ≥ 1024px */
@media (min-width: 1024px) {
    :root {
        --fs-base: 1.125rem;
        --fs-h1: 2rem;
        --fs-h2: 1.5rem;
        --fs-h3: 1.25rem;
        --gutter: 2rem;
    }

    .hero {
        gap: var(--space-12);
    }

    .hero-visual {
        min-height: 400px;
    }

    .hero-content .lead {
        font-size: 1.1875rem;
    }

    .cards-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: var(--space-6);
    }

    .card {
        padding: var(--space-6);
    }
}

/* ≥ 1280px */
@media (min-width: 1280px) {
    :root {
        --container: 1180px;
    }
}

/* =========================================================
   11. Motion preferences
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        animation-delay: 0ms !important;
        scroll-behavior: auto !important;
    }

    .card:hover {
        transform: none;
    }
}