/* styles.css */

/* ==========================================================================
   1. Design tokens
   ========================================================================== */
:root {
    /* Palette: graphite-slate + muted teal, amber as a secondary accent */
    --bg: #0d1014;
    --surface: #13171d;
    --raised: #191e26;
    --code-bg: #0a0c0f;

    --line: #232a34;
    --line-strong: #2e3744;

    --text: #e3e6eb;
    --text-2: #c2c8d1;
    --muted: #8e97a4;
    --heading: #f1f3f6;

    --accent: #6fbfb2;
    --accent-hover: #9ad8cc;
    --accent-soft: rgba(111, 191, 178, 0.12);
    --accent-line: rgba(111, 191, 178, 0.35);

    --accent2: #d4a373;
    --accent2-soft: rgba(212, 163, 115, 0.14);

    --visited: #b3a488;
    --focus: #a8e6dc;
    --selection: rgba(111, 191, 178, 0.28);

    /* Typography */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --fs-body: 1rem;
    --fs-body-lg: 1.0625rem;
    --fs-small: 0.875rem;
    --fs-xs: 0.75rem;
    --lh-body: 1.7;
    --lh-heading: 1.3;

    /* 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;

    /* Shape */
    --radius: 10px;
    --radius-sm: 6px;
    --border: 1px solid var(--line);

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

    color-scheme: dark;
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background-color: var(--bg);
    color-scheme: dark;
    scrollbar-color: #2a313c var(--bg);
    scrollbar-width: thin;
}

body {
    min-height: 100vh;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    font-weight: 400;
    line-height: var(--lh-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    max-width: 100%;
    overflow-wrap: break-word;
}

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

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #3a4352;
}

ul,
ol {
    list-style: none;
}

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

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

h1 {
    font-family: var(--font-serif);
    font-weight: 700;
}

p,
li,
td,
th,
dd,
dt {
    overflow-wrap: anywhere;
}

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:hover {
    color: var(--accent-hover);
    text-decoration-color: currentColor;
    text-decoration-thickness: 2px;
}

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

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

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

em,
i {
    font-style: italic;
}

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

mark {
    background-color: var(--accent2-soft);
    color: var(--heading);
    padding: 0 var(--s-1);
    border-radius: var(--radius-sm);
}

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

:not(pre) > code {
    background-color: var(--raised);
    color: var(--heading);
    border: var(--border);
    border-radius: var(--radius-sm);
    padding: 0.1em 0.4em;
    font-size: 0.9em;
    overflow-wrap: anywhere;
}

kbd {
    display: inline-block;
    background-color: var(--raised);
    color: var(--heading);
    border: var(--border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    padding: 0 var(--s-2);
    font-size: 0.85em;
    line-height: 1.6;
}

/* ==========================================================================
   4. Forms & buttons
   ========================================================================== */
input,
textarea,
select,
button {
    font: inherit;
    color: var(--text);
    background-color: var(--surface);
    border: var(--border);
    border-radius: var(--radius-sm);
    color-scheme: dark;
}

input,
select,
textarea {
    width: 100%;
    max-width: 100%;
    padding: var(--s-3) var(--s-4);
    min-height: var(--touch);
}

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

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

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

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

button {
    min-height: var(--touch);
    padding: var(--s-2) var(--s-4);
    cursor: pointer;
    background-color: var(--raised);
    border-color: var(--line-strong);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

button:hover {
    background-color: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--heading);
}

button:active {
    background-color: var(--surface);
}

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

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

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

.header-inner {
    max-width: var(--container);
    min-height: 60px;
    margin: 0 auto;
    padding: var(--s-2) 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-family: var(--font-serif);
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: 0.02em;
    color: var(--heading);
}

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

.lang-switcher {
    display: flex;
    align-items: center;
    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-width: var(--touch);
    min-height: var(--touch);
    padding: 0 var(--s-2);
    color: var(--muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

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

.lang-switcher a.active {
    color: var(--accent);
    box-shadow: inset 0 -2px 0 var(--accent);
}

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

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

.article-title {
    font-size: clamp(1.375rem, 1.2rem + 1vw, 2rem);
    line-height: 1.3;
    max-width: 30em;
    margin-bottom: var(--s-6);
    padding-bottom: var(--s-5);
    border-bottom: var(--border);
}

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

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

.hero-content .lead {
    font-size: 1.125rem;
    line-height: 1.65;
    color: var(--text);
    max-width: var(--measure);
}

.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);
}

.hero-visual {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    height: auto;
    overflow: hidden;
    background-color: var(--code-bg);
    border: var(--border);
    border-radius: var(--radius);
}

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

.visual-texture {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(to right, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 32px 32px;
}

/* ==========================================================================
   8. Article content
   ========================================================================== */
.content-body {
    max-width: var(--measure);
    margin-bottom: var(--s-7);
    font-size: var(--fs-body);
}

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

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

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

.content-body h2 {
    font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.625rem);
    padding-bottom: var(--s-2);
    border-bottom: var(--border);
}

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

.content-body h4 {
    font-size: 1rem;
}

.content-body h2 + p,
.content-body h3 + p,
.content-body h4 + p {
    margin-top: 0;
}

.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);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 1.0625rem;
    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(--s-3);
    font-style: normal;
    font-size: var(--fs-small);
    color: var(--muted);
}

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

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

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

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

.content-body li::marker {
    color: var(--accent);
}

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

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

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

.content-body li > p {
    margin-bottom: var(--s-2);
}

.content-body pre {
    position: relative;
    max-width: 100%;
    margin: var(--s-5) 0;
    padding: var(--s-4) var(--s-5);
    background-color: var(--code-bg);
    border: var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: var(--fs-small);
    line-height: 1.6;
    color: var(--text-2);
    white-space: pre;
    tab-size: 4;
}

.content-body pre code {
    display: block;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    font-size: inherit;
    color: inherit;
    overflow-wrap: normal;
    white-space: inherit;
}

.content-body table {
    display: block;
    max-width: 100%;
    margin: var(--s-5) 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: separate;
    border-spacing: 0;
    border: var(--border);
    border-radius: var(--radius);
    font-size: var(--fs-small);
}

.content-body thead,
.content-body tbody,
.content-body tr {
    width: 100%;
}

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

.content-body th {
    background-color: var(--raised);
    color: var(--heading);
    font-weight: 600;
    letter-spacing: 0.01em;
}

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

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

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

.content-body hr,
hr {
    border: 0;
    border-top: var(--border);
    margin: var(--s-7) 0;
}

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

.content-body figure img {
    border-radius: var(--radius);
    filter: brightness(0.94);
    border: var(--border);
}

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

.content-body img {
    border-radius: var(--radius);
    filter: brightness(0.94);
    margin: var(--s-5) 0;
}

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

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

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

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

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

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

a.card:hover {
    color: var(--text);
    text-decoration: none;
    background-color: var(--raised);
    border-color: var(--line-strong);
}

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

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

.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-radius: 999px;
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.4;
}

.badge.accent-badge {
    background-color: var(--accent2-soft);
    color: var(--accent2);
}

.date {
    color: var(--muted);
    font-size: var(--fs-xs);
    letter-spacing: 0.02em;
}

.card h4 {
    margin-bottom: var(--s-2);
    font-size: 1.0625rem;
    color: var(--heading);
    transition: color 0.2s ease;
}

.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);
    color: var(--muted);
    font-size: var(--fs-small);
}

/* ==========================================================================
   10. Footer
   ========================================================================== */
footer {
    margin-top: var(--s-7);
    background-color: var(--surface);
    border-top: var(--border);
}

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

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

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

.footer-center a {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
    padding: 0 var(--s-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-hover);
    background-color: var(--raised);
    text-decoration: underline;
    text-underline-offset: 0.25em;
}

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

/* ==========================================================================
   11. Breakpoints (mobile-first)
   ========================================================================== */
@media (min-width: 480px) {
    :root {
        --gutter: var(--s-5);
    }

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

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

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

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

    .hero-visual {
        aspect-ratio: auto;
        min-height: 320px;
    }

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

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

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

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

@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;
    }
}

@media (min-width: 1024px) {
    :root {
        --fs-body: 1.125rem;
        --fs-body-lg: 1.1875rem;
    }

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

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

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

/* ==========================================================================
   12. Motion preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    a.card:hover,
    .card:hover {
        transform: none;
    }
}