/* styles.css */

/* 1. Design tokens */
:root {
    /* Палітра: graphite + teal, тихий темний редакційний стиль */
    --bg: #0f1216;
    --surface: #161a20;
    --raised: #1d222a;
    --code-bg: #0b0d11;

    --border: #262c35;
    --border-strong: #343b46;

    --heading: #f1f3f6;
    --text: #e3e6ea;
    --text-2: #b4bbc5;
    --muted: #8f98a5;

    --accent: #6cc0b2;
    --accent-strong: #8fd6c9;
    --accent-soft: rgba(108, 192, 178, 0.12);
    --accent-line: rgba(108, 192, 178, 0.35);

    --accent2: #d9a86c;
    --accent2-soft: rgba(217, 168, 108, 0.12);

    --visited: #a9b3c4;
    --selection: rgba(108, 192, 178, 0.28);

    /* Шкала відступів */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* Геометрія */
    --gutter: 16px;
    --container: 1080px;
    --measure: 68ch;
    --radius-sm: 6px;
    --radius: 12px;
    --border-w: 1px;
    --hit: 44px;

    /* Типографіка */
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-head: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --fs-base: 1rem;
    --fs-small: 0.875rem;
    --fs-xs: 0.75rem;
    --lh-body: 1.7;
    --lh-head: 1.3;

    color-scheme: dark;
}

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

html {
    color-scheme: dark;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
    background-color: var(--bg);
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-base);
    font-weight: 400;
    line-height: var(--lh-body);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-wrap: anywhere;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

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

img,
video {
    border-radius: var(--radius);
    filter: brightness(0.94);
}

::selection {
    background: var(--selection);
    color: var(--heading);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
    border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

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

/* 3. Links & lists */
a {
    color: var(--accent);
    text-decoration-line: underline;
    text-decoration-color: var(--accent-line);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
    overflow-wrap: anywhere;
}

a:visited {
    color: var(--visited);
}

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

a:active {
    color: var(--heading);
}

ul,
ol {
    padding-left: 0;
    list-style: none;
}

/* 4. Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-head);
    font-weight: 600;
    line-height: var(--lh-head);
    color: var(--heading);
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
    text-wrap: balance;
}

p {
    overflow-wrap: anywhere;
}

strong,
b {
    font-weight: 600;
    color: var(--heading);
}

em,
i {
    font-style: italic;
}

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

mark {
    background: var(--accent2-soft);
    color: var(--heading);
    padding: 0.05em 0.3em;
    border-radius: var(--radius-sm);
    box-shadow: inset 0 0 0 1px rgba(217, 168, 108, 0.25);
}

abbr[title] {
    text-decoration: underline dotted var(--muted);
    cursor: help;
}

hr {
    border: 0;
    height: var(--border-w);
    background: var(--border);
    margin: var(--space-7) 0;
}

kbd {
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: var(--heading);
    background: var(--raised);
    border: var(--border-w) solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    padding: 0.1em 0.45em;
    white-space: nowrap;
}

code,
kbd,
samp,
pre {
    font-family: var(--font-mono);
}

code {
    font-size: 0.9em;
    background: var(--raised);
    color: var(--heading);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
    border: var(--border-w) solid var(--border);
    overflow-wrap: anywhere;
}

pre {
    background: var(--code-bg);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    overflow-x: auto;
    white-space: pre;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-2);
    max-width: 100%;
    margin-bottom: var(--space-5);
}

pre code {
    background: none;
    border: 0;
    padding: 0;
    font-size: inherit;
    color: inherit;
    overflow-wrap: normal;
    white-space: inherit;
}

/* 5. Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: var(--border-w) solid var(--border);
}

.header-inner {
    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(--hit);
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 1.125rem;
    letter-spacing: 0.02em;
    color: var(--heading);
    text-decoration: none;
}

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

.lang-switcher {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--fs-small);
    font-weight: 500;
}

.lang-switcher a {
    display: inline-flex;
    align-items: center;
    min-height: var(--hit);
    min-width: var(--hit);
    padding: var(--space-2) var(--space-2);
    justify-content: center;
    color: var(--muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    position: relative;
}

.lang-switcher a:visited {
    color: var(--muted);
}

.lang-switcher a:hover {
    color: var(--heading);
    background: var(--raised);
}

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

.lang-switcher a.active::after {
    content: "";
    position: absolute;
    left: var(--space-2);
    right: var(--space-2);
    bottom: 4px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

/* 6. Main layout */
main {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--space-6) var(--gutter) var(--space-7);
}

.article-title {
    font-size: 1.375rem;
    line-height: 1.3;
    font-weight: 600;
    max-width: 40ch;
    margin-bottom: var(--space-5);
    color: var(--heading);
    text-wrap: balance;
}

/* 7. Hero */
.hero {
    display: grid;
    gap: var(--space-5);
    margin-bottom: var(--space-7);
}

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

.hero-content .lead {
    font-size: 1.0625rem;
    line-height: 1.65;
    color: var(--text-2);
    padding-left: var(--space-4);
    border-left: 2px solid var(--accent);
    max-width: var(--measure);
}

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

/* Hero visual */
.hero-visual {
    position: relative;
    width: 100%;
    height: 220px;
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.hero-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
    border-radius: var(--radius);
    filter: brightness(0.9) saturate(0.9);
}

.visual-texture {
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--accent-soft), var(--accent-soft)),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 12px);
}

/* 8. Article content */
.content-body {
    max-width: var(--measure);
    margin-bottom: var(--space-7);
}

.content-body > :first-child {
    margin-top: 0;
}

.content-body p {
    margin: 0 0 var(--space-5);
    color: var(--text);
    font-size: 1rem;
    line-height: var(--lh-body);
}

.content-body h2,
.content-body h3,
.content-body h4 {
    margin-top: var(--space-7);
    margin-bottom: var(--space-4);
}

.content-body h2 {
    font-size: 1.375rem;
    padding-bottom: var(--space-2);
    border-bottom: var(--border-w) solid var(--border);
}

.content-body h3 {
    font-size: 1.125rem;
    color: var(--heading);
}

.content-body h4 {
    font-size: 1rem;
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--text);
}

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

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

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

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

.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 > li {
    margin-bottom: var(--space-2);
    padding-left: var(--space-1);
}

.content-body ol > li::marker {
    color: var(--accent);
    font-weight: 600;
}

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

.content-body li > ul > li::before {
    width: 4px;
    height: 4px;
    background: var(--muted);
}

.content-body ul li strong {
    color: var(--heading);
}

.content-body blockquote {
    position: relative;
    margin: var(--space-6) 0;
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: var(--border-w) solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 1.0625rem;
    font-style: italic;
    line-height: 1.65;
    color: var(--text-2);
}

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

.content-body blockquote cite {
    display: block;
    margin-top: var(--space-3);
    font-size: var(--fs-small);
    font-style: normal;
    color: var(--muted);
}

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

.content-body figure img {
    border: var(--border-w) solid var(--border);
}

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

.content-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius);
    margin: 0 0 var(--space-5);
    font-size: 0.9375rem;
    -webkit-overflow-scrolling: touch;
}

.content-body thead {
    background: var(--raised);
}

.content-body th,
.content-body td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    vertical-align: top;
    border-bottom: var(--border-w) solid var(--border);
    min-width: 8ch;
}

.content-body th {
    color: var(--heading);
    font-weight: 600;
}

.content-body td {
    color: var(--text-2);
}

.content-body tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.015);
}

.content-body tbody tr:hover {
    background: var(--accent-soft);
}

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

/* 9. Related materials */
.related-materials {
    margin-top: var(--space-8);
}

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

.section-header h2 {
    font-size: 1.25rem;
    white-space: nowrap;
}

.divider-line {
    flex-grow: 1;
    height: var(--border-w);
    background: var(--border);
}

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

.card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-5);
    background: var(--raised);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    position: relative;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.card:hover {
    border-color: var(--accent-line);
    background: #20262e;
}

.card:visited {
    color: var(--text);
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
    font-size: 0.8125rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px var(--space-3);
    background: var(--accent-soft);
    color: var(--accent);
    border: var(--border-w) solid var(--accent-line);
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: var(--fs-xs);
    letter-spacing: 0.06em;
}

.badge.accent-badge {
    background: var(--accent2-soft);
    color: var(--accent2);
    border-color: rgba(217, 168, 108, 0.35);
}

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

.card h4 {
    font-size: 1.0625rem;
    line-height: 1.4;
    color: var(--heading);
    transition: color 0.2s ease;
}

.card:hover h4 {
    color: var(--accent-strong);
}

.card p {
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--muted);
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-clamp: 3;
    overflow: hidden;
}

.card-footer {
    display: flex;
    justify-content: flex-end;
    color: var(--muted);
    font-size: var(--fs-small);
    padding-top: var(--space-2);
    border-top: var(--border-w) solid var(--border);
}

/* 10. Footer */
footer {
    margin-top: var(--space-8);
    background: var(--surface);
    border-top: var(--border-w) solid var(--border);
}

.footer-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--space-6) var(--gutter);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    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-4);
}

.footer-center a {
    display: inline-flex;
    align-items: center;
    min-height: var(--hit);
    padding: 0 var(--space-2);
    color: var(--text-2);
    font-size: var(--fs-small);
    text-decoration: none;
    border-radius: var(--radius-sm);
}

.footer-center a:hover {
    color: var(--accent-strong);
    text-decoration: underline;
    text-underline-offset: 0.25em;
}

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

/* 11. Forms & buttons (dark defaults) */
button,
input,
select,
textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: var(--border-w) solid var(--border-strong);
    border-radius: var(--radius-sm);
    min-height: var(--hit);
    padding: var(--space-2) var(--space-3);
    color-scheme: dark;
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
    opacity: 1;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
    border-color: var(--muted);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 1px var(--accent-strong);
}

button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
    cursor: pointer;
    background: var(--raised);
    color: var(--heading);
    font-weight: 600;
    padding: var(--space-2) var(--space-4);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

button:hover,
input[type="button"]:hover,
input[type="submit"]:hover,
input[type="reset"]:hover {
    background: var(--border-strong);
    border-color: var(--muted);
}

button:active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 12. Tablet (>=480px) */
@media (min-width: 480px) {
    :root {
        --gutter: 20px;
    }

    .hero-visual {
        height: 260px;
    }

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

/* 13. Tablet landscape (>=768px) */
@media (min-width: 768px) {
    body {
        font-size: 1.0625rem;
    }

    .header-inner {
        flex-wrap: nowrap;
    }

    .logo {
        font-size: 1.25rem;
    }

    .article-title {
        font-size: 1.625rem;
    }

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

    .hero-visual {
        height: 300px;
    }

    .content-body p {
        font-size: 1.0625rem;
    }

    .content-body h2 {
        font-size: 1.625rem;
    }

    .content-body h3 {
        font-size: 1.25rem;
    }

    .content-body blockquote {
        font-size: 1.125rem;
    }

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

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

/* 14. Desktop (>=1024px) */
@media (min-width: 1024px) {
    :root {
        --gutter: 32px;
    }

    body {
        font-size: 1.125rem;
    }

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

    .article-title {
        font-size: 2rem;
        line-height: 1.25;
    }

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

    .hero-visual {
        height: 100%;
        min-height: 360px;
    }

    .content-body p {
        font-size: 1.125rem;
    }

    .content-body h2 {
        font-size: 1.875rem;
    }

    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: var(--space-5);
    }
}

/* 15. Wide (>=1280px) */
@media (min-width: 1280px) {
    :root {
        --container: 1120px;
    }

    .article-title {
        font-size: 2.125rem;
    }
}

/* 16. Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }
}