/* styles.css */

/* 1. Theme tokens: dark slate + amber, sage as secondary */
:root {
    color-scheme: dark;

    /* Surfaces */
    --bg: #101216;
    --surface: #161a20;
    --surface-raised: #1d222b;
    --code-bg: #0b0d11;

    /* Borders */
    --border: #262c36;
    --border-strong: #343b48;
    --border-width: 1px;

    /* Text */
    --heading: #f1f3f6;
    --text: #e2e5ea;
    --text-soft: #c3c8d0;
    --muted: #9aa2ae;

    /* Accent (primary) */
    --accent: #d9a441;
    --accent-hover: #e6b65a;
    --accent-ink: #1a1307;
    --accent-soft: rgba(217, 164, 65, 0.12);
    --accent-line: rgba(217, 164, 65, 0.3);

    /* Accent (secondary, used sparingly) */
    --accent-2: #8fbfae;
    --accent-2-soft: rgba(143, 191, 174, 0.12);

    /* Focus */
    --focus: #f1f3f6;

    /* Spacing scale */
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;
    --s-8: 64px;

    /* Radii */
    --radius-sm: 6px;
    --radius: 12px;

    /* Typography */
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --fs-body: 1rem;
    --lh-body: 1.7;
    --fs-h1: clamp(1.25rem, 1.05rem + 0.9vw, 2rem);
    --fs-h2: clamp(1.125rem, 1rem + 0.6vw, 1.5rem);
    --fs-h3: clamp(1.0625rem, 0.98rem + 0.4vw, 1.25rem);
    --fs-small: 0.875rem;
    --fs-xs: 0.75rem;

    /* Layout */
    --container: 1120px;
    --measure: 72ch;
    --gutter: var(--s-4);
    --touch: 44px;
}

@media (min-width: 480px) {
    :root {
        --gutter: var(--s-5);
    }
}

@media (min-width: 1024px) {
    :root {
        --fs-body: 1.0625rem;
        --gutter: var(--s-6);
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scrollbar-width: thin;
    scrollbar-color: #343b48 var(--bg);
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-main);
    font-size: var(--fs-body);
    font-weight: 400;
    line-height: var(--lh-body);
    min-height: 100vh;
    min-width: 0;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

::selection {
    background: rgba(217, 164, 65, 0.35);
    color: var(--heading);
}

::-moz-selection {
    background: rgba(217, 164, 65, 0.35);
    color: var(--heading);
}

/* Dark scrollbars (WebKit / Blink) */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: #444c5b;
}

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

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

hr {
    border: 0;
    border-top: var(--border-width) solid var(--border);
    margin: var(--s-7) 0;
}

/* 3. Typography */
p,
li,
td,
th,
blockquote,
dd,
dt,
figcaption,
a {
    overflow-wrap: anywhere;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--heading);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
    text-wrap: balance;
}

h1 {
    font-size: var(--fs-h1);
    line-height: 1.3;
}

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

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

h4 {
    font-size: 1.0625rem;
}

p {
    margin-bottom: var(--s-5);
}

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

em,
i {
    font-style: italic;
}

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

mark {
    background: var(--accent-soft);
    color: var(--heading);
    padding: 0 var(--s-1);
    border-radius: var(--radius-sm);
    box-shadow: inset 0 -0.4em 0 rgba(217, 164, 65, 0.22);
}

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

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

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

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

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

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

/* Lists (base) */
ul,
ol {
    padding-left: var(--s-5);
}

ul {
    list-style: none;
}

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

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

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    border-color: var(--accent);
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

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

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

button:active,
input[type="button"]:active,
input[type="submit"]:active {
    background-color: var(--accent);
}

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

/* 5. Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: rgba(16, 18, 22, 0.96);
    border-bottom: var(--border-width) solid var(--border);
}

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

.logo {
    display: inline-flex;
    align-items: center;
    gap: var(--s-3);
    min-height: var(--touch);
    font-weight: 700;
    font-size: 1.0625rem;
    letter-spacing: 0.04em;
    color: var(--heading);
    text-decoration: none;
}

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

.lang-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1);
    font-size: var(--fs-small);
    font-weight: 500;
}

.lang-switcher a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch);
    min-width: var(--touch);
    padding: 0 var(--s-3);
    color: var(--muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    border: var(--border-width) solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

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

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

.lang-switcher a.active,
.lang-switcher a[aria-current="true"] {
    color: var(--accent);
    border-color: var(--accent-line);
    background-color: var(--accent-soft);
}

/* 6. Main layout */
main {
    flex: 1 0 auto;
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--s-7) var(--gutter) var(--s-8);
}

.article-title {
    max-width: 30ch;
    margin-bottom: var(--s-6);
    font-size: var(--fs-h1);
    line-height: 1.3;
    color: var(--heading);
    padding-left: var(--s-4);
    border-left: 3px solid var(--accent);
}

/* 7. Hero */
.hero {
    display: grid;
    gap: var(--s-6);
    margin-bottom: var(--s-7);
    min-width: 0;
}

.hero-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--s-4);
    min-width: 0;
}

.hero-content .lead {
    font-size: 1.125rem;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: var(--s-2);
}

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

.meta-info > * + *::before {
    content: "/";
    margin-right: var(--s-3);
    color: var(--border-strong);
}

/* Hero visual (single definition) */
.hero-visual {
    position: relative;
    width: 100%;
    height: 260px;
    overflow: hidden;
    border-radius: var(--radius);
    border: var(--border-width) solid var(--border);
    background-color: var(--code-bg);
    min-width: 0;
}

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

/* Decorative texture (optional element) */
.visual-texture {
    width: 100%;
    height: 100%;
    background-image:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 12px);
    background-color: var(--surface);
}

@media (min-width: 480px) {
    .hero-visual {
        height: 320px;
    }
}

@media (min-width: 900px) {
    .hero {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
        gap: var(--s-7);
        align-items: center;
    }

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

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

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

.content-body p {
    margin-bottom: var(--s-5);
    color: var(--text-soft);
}

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

.content-body h2 {
    padding-bottom: var(--s-3);
    border-bottom: var(--border-width) solid var(--border);
}

.content-body h3 {
    margin-top: var(--s-6);
    color: var(--heading);
}

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

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

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

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

.content-body ol {
    list-style: decimal;
}

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

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

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

.content-body li > ul > li::before {
    background-color: transparent;
    border: 1px solid var(--accent);
    width: 5px;
    height: 5px;
}

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

.content-body blockquote {
    position: relative;
    margin: var(--s-6) 0;
    padding: var(--s-5) var(--s-5) var(--s-5) var(--s-5);
    background-color: var(--surface);
    border: var(--border-width) solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
    font-size: 1.0625rem;
    color: var(--muted);
}

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

.content-body blockquote cite {
    display: block;
    margin-top: var(--s-3);
    font-style: normal;
    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-color: var(--surface-raised);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--heading);
    overflow-wrap: anywhere;
}

/* Code blocks */
pre {
    margin-bottom: var(--s-5);
    padding: var(--s-4);
    background-color: var(--code-bg);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    max-width: 100%;
    line-height: 1.6;
    tab-size: 4;
    -webkit-overflow-scrolling: touch;
}

pre code {
    display: block;
    padding: 0;
    background: none;
    border: 0;
    color: var(--text);
    font-size: 0.875rem;
    white-space: pre;
    overflow-wrap: normal;
}

kbd {
    display: inline-block;
    padding: 0 var(--s-2);
    min-width: 1.6em;
    text-align: center;
    background-color: var(--surface-raised);
    border: var(--border-width) solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    color: var(--heading);
    line-height: 1.6;
}

/* Tables */
table {
    display: block;
    max-width: 100%;
    width: max-content;
    min-width: 100%;
    margin-bottom: var(--s-5);
    overflow-x: auto;
    border-collapse: collapse;
    border-spacing: 0;
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
    font-size: var(--fs-small);
    -webkit-overflow-scrolling: touch;
}

thead,
tbody,
tfoot,
tr {
    display: table;
    width: 100%;
    table-layout: auto;
}

th,
td {
    padding: var(--s-3) var(--s-4);
    text-align: left;
    vertical-align: top;
    border-bottom: var(--border-width) solid var(--border);
    color: var(--text-soft);
}

th {
    background-color: var(--surface-raised);
    color: var(--heading);
    font-weight: 600;
}

tbody tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.015);
}

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

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

caption {
    caption-side: bottom;
    padding-top: var(--s-2);
    font-size: var(--fs-xs);
    color: var(--muted);
    text-align: left;
}

/* Figures */
figure {
    margin: var(--s-6) 0;
}

figure img {
    border: var(--border-width) solid var(--border);
    filter: brightness(0.94);
}

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

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

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

.section-header h2,
.section-header h3 {
    margin: 0;
    white-space: nowrap;
}

.divider-line {
    flex: 1 1 auto;
    min-width: var(--s-6);
    height: var(--border-width);
    background-color: var(--border);
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: var(--s-4);
    min-width: 0;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--s-5);
    background-color: var(--surface);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.card:hover {
    background-color: var(--surface-raised);
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

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

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--s-1) var(--s-2);
    background-color: var(--accent-soft);
    color: var(--accent);
    border: var(--border-width) solid var(--accent-line);
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.2;
}

.badge.accent-badge {
    background-color: var(--accent-2-soft);
    color: var(--accent-2);
    border-color: rgba(143, 191, 174, 0.3);
}

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

.card h4 {
    margin-bottom: var(--s-2);
    font-size: 1.0625rem;
    line-height: 1.4;
    color: var(--heading);
}

.card h4 a {
    color: inherit;
    text-decoration: none;
}

.card h4 a:hover {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.card p {
    flex-grow: 1;
    margin-bottom: var(--s-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(--s-3);
    border-top: var(--border-width) solid var(--border);
    font-size: var(--fs-small);
    color: var(--muted);
}

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

/* 10. Footer */
footer {
    margin-top: auto;
    background-color: var(--surface);
    border-top: var(--border-width) solid var(--border);
}

.footer-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--s-6) var(--gutter);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-4);
    text-align: center;
}

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

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

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

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

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

/* 11. Breakpoints: layout refinements */
@media (min-width: 480px) {
    .footer-inner {
        padding: var(--s-6) var(--gutter);
    }
}

@media (min-width: 600px) {
    .footer-inner {
        flex-direction: row;
        justify-content: space-between;
        text-align: left;
    }

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

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

    .cards-grid {
        gap: var(--s-5);
    }
}

@media (min-width: 768px) {
    main {
        padding-top: var(--s-8);
    }

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

@media (min-width: 1024px) {
    .card {
        padding: var(--s-6);
    }

    .content-body h2,
    .content-body h3 {
        margin-top: var(--s-8);
    }
}

@media (min-width: 1280px) {
    :root {
        --container: 1200px;
    }
}

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

    .card:hover {
        transform: none;
    }
}