/* styles.css */

/* 1. Theme tokens */
:root {
    color-scheme: dark;

    /* Palette: graphite + teal + soft amber */
    --bg: #0f1116;
    --surface: #161a22;
    --raised: #1d222c;
    --code-bg: #0b0d12;

    --text: #e3e6ec;
    --heading: #eef1f5;
    --text-soft: #c2c8d2;
    --muted: #9aa3b2;

    --accent: #5fb8ae;
    --accent-strong: #7fcdc4;
    --accent-soft: rgba(95, 184, 174, 0.14);
    --accent2: #d6a86b;
    --accent2-soft: rgba(214, 168, 107, 0.14);

    --border: rgba(227, 230, 236, 0.09);
    --border-strong: rgba(227, 230, 236, 0.16);
    --focus: #8fd6ce;

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

    /* Radii */
    --r-sm: 6px;
    --r: 12px;
    --r-lg: 16px;

    /* Typography */
    --font-body: -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;
    --fs-small: 0.875rem;
    --fs-xs: 0.75rem;
    --lh-body: 1.7;
    --lh-heading: 1.3;

    --container: 1120px;
    --measure: 68ch;
    --gutter: clamp(16px, 4vw, 24px);
    --hit: 44px;
}

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

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

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

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

::selection {
    background: rgba(95, 184, 174, 0.35);
    color: var(--heading);
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #4a5262;
}

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

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

ul,
ol {
    list-style: none;
}

button,
input,
select,
textarea {
    font: inherit;
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    color-scheme: dark;
}

button,
input[type="button"],
input[type="submit"] {
    min-height: var(--hit);
    padding: var(--s-2) var(--s-4);
    cursor: pointer;
    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 {
    background-color: var(--raised);
    border-color: var(--accent);
    color: var(--heading);
}

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

input,
select,
textarea {
    padding: var(--s-2) var(--s-3);
    width: 100%;
}

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

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

:focus {
    outline: none;
}

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

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

p {
    text-wrap: pretty;
}

a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: rgba(95, 184, 174, 0.4);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
    overflow-wrap: anywhere;
}

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

a:visited {
    color: #a9b8c9;
}

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

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

em,
i {
    font-style: italic;
}

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

kbd {
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: var(--heading);
    background: var(--raised);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
    padding: 1px 6px;
}

hr {
    border: 0;
    height: 1px;
    background: var(--border-strong);
    margin: var(--s-8) 0;
}

/* 4. Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 17, 22, 0.92);
    border-bottom: 1px 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-3) var(--s-6);
}

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

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

.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;
    min-height: var(--hit);
    min-width: var(--hit);
    justify-content: center;
    padding: var(--s-2) var(--s-3);
    color: var(--muted);
    text-decoration: none;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
}

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

.lang-switcher a.active {
    color: var(--accent);
    border-color: rgba(95, 184, 174, 0.35);
    background: var(--accent-soft);
}

/* 5. Layout */
main {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--s-8) var(--gutter) var(--s-12);
}

.article-title {
    max-width: 30ch;
    margin-bottom: var(--s-6);
    font-size: clamp(1.25rem, 1.05rem + 1vw, 1.75rem);
    font-weight: 600;
    line-height: 1.3;
    color: var(--heading);
}

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

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

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

.hero-content .lead {
    font-size: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
    line-height: 1.7;
    color: var(--text-soft);
    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%;
    height: 260px;
    overflow: hidden;
    background: var(--code-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
}

.hero-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    border-radius: var(--r-lg);
    filter: brightness(0.92);
}

.visual-texture {
    width: 100%;
    height: 100%;
    background-image: repeating-linear-gradient(
        135deg,
        rgba(227, 230, 236, 0.025) 0 1px,
        transparent 1px 12px
    );
}

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

.content-body > * + * {
    margin-top: var(--s-4);
}

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

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

.content-body h2 {
    font-size: clamp(1.125rem, 1rem + 0.6vw, 1.375rem);
    padding-bottom: var(--s-3);
    border-bottom: 1px solid var(--border);
}

.content-body h3 {
    font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);
    color: var(--heading);
}

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

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

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

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

.content-body li {
    padding-left: var(--s-1);
}

.content-body li + li {
    margin-top: var(--s-2);
}

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

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

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

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

.content-body blockquote p + p {
    margin-top: var(--s-3);
}

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

.content-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--accent2);
    background: var(--raised);
    padding: 1px var(--s-1);
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.content-body pre {
    margin-top: var(--s-6);
    margin-bottom: var(--s-6);
    padding: var(--s-4);
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--r);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    white-space: pre;
}

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

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

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

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

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

.content-body tbody tr:nth-child(even) {
    background: rgba(227, 230, 236, 0.02);
}

.content-body tbody tr:hover {
    background: rgba(227, 230, 236, 0.045);
}

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

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

.content-body figure img {
    border: 1px solid var(--border);
    border-radius: var(--r);
}

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

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

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

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

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

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

.card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--s-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.card:hover {
    border-color: var(--border-strong);
    background: var(--raised);
    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-4);
    font-size: var(--fs-xs);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--s-1) var(--s-2);
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid rgba(95, 184, 174, 0.25);
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.2;
}

.badge.accent-badge {
    background: var(--accent2-soft);
    color: var(--accent2);
    border-color: rgba(214, 168, 107, 0.3);
}

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

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

.card p {
    flex-grow: 1;
    margin-bottom: var(--s-4);
    font-size: var(--fs-small);
    line-height: 1.65;
    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;
    font-size: var(--fs-small);
    color: var(--muted);
}

.card-footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--hit);
    padding: 0 var(--s-2);
}

/* 9. Footer */
footer {
    margin-top: var(--s-12);
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.footer-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--s-8) 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);
    font-size: var(--fs-small);
    color: var(--muted);
}

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

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

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

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

/* 10. Breakpoints */
@media (min-width: 480px) {
    .cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

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

@media (min-width: 768px) {
    .article-title {
        font-size: clamp(1.375rem, 1.1rem + 1.2vw, 2rem);
    }

    .hero-visual {
        height: 340px;
    }

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

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

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

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

@media (min-width: 1024px) {
    .article-title {
        font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    }

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

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

/* 11. Reduced motion */
@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;
    }

    .card:hover {
        transform: none;
    }
}