/* styles.css */

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

    /* Surfaces: background -> surface -> raised (subtle steps) */
    --bg: #0f1216;
    --surface: #161b22;
    --raised: #1d242d;
    --code-bg: #0b0e12;

    /* Borders */
    --border: #2a323d;
    --border-strong: #3a4350;
    --border-width: 1px;

    /* Text */
    --heading: #eef0f4;
    --text: #e4e7ec;
    --text-2: #bcc3ce;
    --muted: #959eac;

    /* Accents */
    --accent: #d4a25e;
    --accent-strong: #e6b878;
    --accent-2: #9cc3ad;
    --accent-soft: rgba(212, 162, 94, 0.12);
    --accent-line: rgba(212, 162, 94, 0.45);
    --focus: #f3cf8a;

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

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

    --fs-body: 1rem;
    --fs-body-md: 1.0625rem;
    --fs-body-lg: 1.125rem;
    --lh-body: 1.7;
    --lh-heading: 1.3;

    /* Spacing scale: 4/8/12/16/24/32/48/64 */
    --s1: 4px;
    --s2: 8px;
    --s3: 12px;
    --s4: 16px;
    --s5: 24px;
    --s6: 32px;
    --s7: 48px;
    --s8: 64px;

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

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

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

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

::selection {
    background: rgba(212, 162, 94, 0.3);
    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);
}

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

img {
    border-radius: var(--radius);
    filter: brightness(0.92);
}

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

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

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

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

:focus {
    outline: none;
}

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

/* =========================================================
   4. Typography
   ========================================================= */
h1,
h2,
h3,
h4 {
    font-family: var(--font-head);
    font-weight: 600;
    line-height: var(--lh-heading);
    letter-spacing: -0.01em;
    color: var(--heading);
    overflow-wrap: break-word;
    hyphens: auto;
}

ul,
ol {
    list-style: none;
}

p {
    max-width: var(--measure);
}

small {
    font-size: 0.875em;
}

mark {
    background: var(--accent-soft);
    color: var(--heading);
    padding: 0 var(--s1);
    border-radius: var(--radius-sm);
    box-shadow: inset 0 -0.45em 0 rgba(212, 162, 94, 0.22);
}

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

/* =========================================================
   5. Form controls (dark defaults)
   ========================================================= */
input,
textarea,
select,
button {
    font: inherit;
    color: var(--text);
    background: var(--raised);
    border: var(--border-width) solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: var(--s3) var(--s4);
    min-height: var(--touch);
    max-width: 100%;
    color-scheme: dark;
}

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

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

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

textarea {
    min-height: calc(var(--touch) * 2);
    resize: vertical;
}

button,
input[type="button"],
input[type="submit"] {
    cursor: pointer;
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--heading);
    font-weight: 500;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

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

button:active {
    background: rgba(212, 162, 94, 0.26);
}

input:-webkit-autofill,
textarea:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--raised) inset;
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
}

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

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

.logo {
    display: inline-flex;
    align-items: center;
    gap: var(--s3);
    min-height: var(--touch);
    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);
}

.lang-switcher {
    display: flex;
    align-items: center;
    gap: var(--s1);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

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

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

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

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

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

/* =========================================================
   7. Main layout
   ========================================================= */
main {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--s6) var(--gutter) var(--s7);
    min-width: 0;
    flex: 1 0 auto;
}

.article-title {
    font-size: clamp(1.375rem, 1.15rem + 1vw, 2rem);
    line-height: 1.28;
    font-weight: 600;
    max-width: 40ch;
    margin-bottom: var(--s5);
    padding-bottom: var(--s5);
    border-bottom: var(--border-width) solid var(--border);
    text-wrap: balance;
}

/* =========================================================
   8. Hero
   ========================================================= */
.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s5);
    margin-bottom: var(--s7);
    min-width: 0;
}

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

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

.hero-content .lead {
    font-size: var(--fs-body-lg);
    line-height: 1.65;
    color: var(--text-2);
    max-width: var(--measure);
}

.meta-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s2) var(--s3);
    font-size: 0.875rem;
    color: var(--muted);
}

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

/* Hero visual: image container (mobile first) */
.hero-visual {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: var(--code-bg);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
}

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

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

/* =========================================================
   9. Article content
   ========================================================= */
.content-body {
    max-width: var(--measure);
    margin-bottom: var(--s7);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    color: var(--text-2);
}

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

.content-body p {
    max-width: none;
    color: var(--text-2);
}

.content-body h2,
.content-body h3,
.content-body h4 {
    margin-top: var(--s7);
    margin-bottom: var(--s3);
    color: var(--heading);
}

.content-body h2 {
    font-size: 1.5rem;
    padding-top: var(--s2);
}

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

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

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

.content-body em {
    color: var(--heading);
}

.content-body blockquote {
    position: relative;
    margin: var(--s6) 0;
    padding: var(--s5) var(--s5) var(--s5) var(--s5);
    background: var(--surface);
    border: var(--border-width) solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-family: var(--font-head);
    font-size: 1.125rem;
    line-height: 1.6;
    color: var(--text);
}

.content-body blockquote p {
    color: inherit;
}

.content-body blockquote cite {
    display: block;
    margin-top: var(--s3);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-style: normal;
    color: var(--muted);
}

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

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

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

.content-body li {
    margin-top: var(--s2);
    padding-left: var(--s1);
    color: var(--text-2);
}

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

.content-body ul ul,
.content-body ol ol,
.content-body ul ol,
.content-body ol ul {
    margin-top: var(--s2);
    padding-left: var(--s5);
}

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

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

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

.content-body figure img {
    margin: 0 auto;
}

.content-body figcaption {
    margin-top: var(--s3);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--muted);
    text-align: center;
}

/* Inline code */
.content-body code,
.content-body kbd,
code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    overflow-wrap: anywhere;
}

:not(pre) > code {
    background: var(--raised);
    color: var(--accent-strong);
    padding: 1px var(--s2);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-sm);
}

/* Code blocks */
pre {
    position: relative;
    max-width: 100%;
    margin: var(--s6) 0;
    padding: var(--s4) var(--s5);
    background: var(--code-bg);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre;
    tab-size: 4;
}

pre code {
    display: block;
    min-width: max-content;
    font-size: inherit;
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    overflow-wrap: normal;
}

/* Tables */
.content-body table,
table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: separate;
    border-spacing: 0;
    margin: var(--s6) 0;
    font-size: 0.9375rem;
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
}

th,
td {
    padding: var(--s3) var(--s4);
    text-align: left;
    vertical-align: top;
    border-bottom: var(--border-width) solid var(--border);
    min-width: 8ch;
    overflow-wrap: anywhere;
}

th {
    background: var(--raised);
    color: var(--heading);
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.02em;
}

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

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

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

/* =========================================================
   10. Related materials (cards)
   ========================================================= */
.related-materials {
    margin-top: var(--s8);
    min-width: 0;
}

.section-header {
    display: flex;
    align-items: center;
    gap: var(--s4);
    margin-bottom: var(--s5);
}

.section-header h2,
.section-header h3 {
    margin: 0;
    font-size: 1.25rem;
    white-space: nowrap;
    color: var(--heading);
}

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

.cards-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s4);
}

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

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

a.card:visited {
    color: inherit;
}

.card:hover {
    background: var(--raised);
    border-color: var(--border-strong);
}

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

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

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--s3);
    background: 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.08em;
    text-transform: uppercase;
    line-height: 1.6;
}

.badge.accent-badge {
    background: rgba(156, 195, 173, 0.1);
    color: var(--accent-2);
    border-color: rgba(156, 195, 173, 0.4);
}

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

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

.card p {
    flex-grow: 1;
    margin-bottom: var(--s4);
    font-size: 0.9375rem;
    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(--s3);
    border-top: var(--border-width) solid var(--border);
    font-size: 0.875rem;
    color: var(--muted);
}

.card-footer::after {
    content: "→";
    color: var(--accent);
    font-size: 1rem;
    transition: transform 0.2s ease;
}

.card:hover .card-footer::after {
    transform: translateX(3px);
}

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

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

.footer-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--s2) var(--s3);
    font-size: 0.875rem;
    color: var(--muted);
}

.footer-center {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--s2) var(--s5);
}

.footer-center a {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
    padding: 0 var(--s2);
    font-size: 0.9375rem;
    color: var(--text-2);
    text-decoration: none;
    border-radius: var(--radius-sm);
}

.footer-center a:visited {
    color: var(--text-2);
}

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

.dmca-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    min-height: 32px;
    padding: var(--s1) var(--s3);
    border: var(--border-width) solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    color: var(--muted);
    cursor: default;
}

/* =========================================================
   12. Responsive: 480 / 768 / 1024 / 1280
   ========================================================= */
@media (min-width: 480px) {
    :root {
        --gutter: var(--s5);
    }

    .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(--s6);
        --fs-body: var(--fs-body-md);
    }

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

    main {
        padding-top: var(--s7);
    }

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

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

    .article-title {
        font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    }

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

    .footer-center {
        gap: var(--s2) var(--s6);
    }
}

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

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

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

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

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

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

    .article-title {
        font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem);
    }
}

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

/* =========================================================
   13. Touch devices: larger hit areas
   ========================================================= */
@media (pointer: coarse) {
    .lang-switcher a,
    .footer-center a,
    .logo {
        min-height: var(--touch);
    }

    .lang-switcher a {
        min-width: var(--touch);
    }
}

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

    .card:hover .card-footer::after {
        transform: none;
    }
}