/* styles.css */

/* 1. Design tokens */
:root {
    /* Palette: paper + forest ink, terracotta accent */
    --paper: #f5f1e8;
    --paper-2: #ebe5d6;
    --surface: #fffdf9;
    --ink: #1f2a24;
    --ink-soft: #2e3a33;
    --muted: #5a625b;
    --accent: #2c5a44;
    --accent-hover: #1f4433;
    --accent-2: #8c4a2f;
    --accent-2-tint: rgba(140, 74, 47, 0.09);
    --accent-tint: rgba(44, 90, 68, 0.09);
    --line: rgba(31, 42, 36, 0.14);
    --line-soft: rgba(31, 42, 36, 0.08);
    --focus: #8c4a2f;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, 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;

    /* Spacing scale */
    --s-1: 0.25rem;
    --s-2: 0.5rem;
    --s-3: 0.75rem;
    --s-4: 1rem;
    --s-5: 1.25rem;
    --s-6: 1.5rem;
    --s-7: 2rem;
    --s-8: 3rem;
    --s-section: clamp(2.5rem, 6vw, 4.5rem);
    --gutter: 1.25rem;
    --container: 1100px;
    --measure: 68ch;

    /* Radii & elevation */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(31, 42, 36, 0.05);
    --shadow-md: 0 10px 28px -14px rgba(31, 42, 36, 0.18);

    --transition: 180ms ease;
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background-color: var(--paper);
    background-image:
        linear-gradient(rgba(31, 42, 36, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(31, 42, 36, 0.035) 1px, transparent 1px);
    background-size: 44px 44px;
    color: var(--ink-soft);
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    overflow-wrap: anywhere;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

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

iframe {
    width: 100%;
    border: 0;
}

table {
    border-collapse: collapse;
    max-width: 100%;
}

input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

ul,
ol {
    list-style: none;
}

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

p {
    text-wrap: pretty;
}

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

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

::selection {
    background: var(--accent-tint);
    color: var(--ink);
}

/* Links */
a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    text-decoration-color: rgba(44, 90, 68, 0.4);
    transition: color var(--transition), text-decoration-color var(--transition);
}

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

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

/* Focus */
:focus {
    outline: none;
}

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

/* 4. Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(245, 241, 232, 0.88);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line-soft);
}

.header-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--s-2) var(--gutter);
    min-height: 56px;
    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-2);
    min-height: 44px;
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
    color: var(--ink);
    text-decoration: none;
}

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

.lang-switcher {
    display: flex;
    align-items: center;
    gap: var(--s-1);
    font-family: var(--font-mono);
    font-size: var(--fs-small);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

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

.lang-switcher a:hover {
    color: var(--accent);
    background: var(--accent-tint);
}

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

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

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

.article-title {
    font-size: 1.2rem;
    line-height: 1.35;
    max-width: var(--measure);
    margin-bottom: var(--s-6);
    padding-bottom: var(--s-5);
    border-bottom: 1px solid var(--line);
    font-weight: 700;
}

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

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

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

.hero-content .lead {
    font-size: 1.0625rem;
    line-height: var(--lh-body);
    color: var(--ink);
    max-width: var(--measure);
    margin-bottom: var(--s-2);
}

.meta-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-2) var(--s-3);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    letter-spacing: 0.03em;
    color: var(--muted);
}

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

/* Hero visual (image frame) */
.hero-visual {
    position: relative;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
}

.visual-texture {
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(at 85% 0%, rgba(44, 90, 68, 0.14) 0px, transparent 55%),
        radial-gradient(at 0% 100%, rgba(140, 74, 47, 0.12) 0px, transparent 55%),
        repeating-linear-gradient(45deg, rgba(31, 42, 36, 0.03) 0 1px, transparent 1px 12px);
}

.hero-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    border-radius: 0;
}

/* 7. Article content */
.content-body {
    max-width: var(--measure);
    margin-bottom: var(--s-section);
    font-size: 1rem;
    line-height: var(--lh-body);
    color: var(--ink-soft);
}

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

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

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

.content-body h2 {
    font-size: 1.3rem;
    padding-bottom: var(--s-2);
    border-bottom: 1px solid var(--line-soft);
}

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

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

.content-body a {
    text-decoration-thickness: 1px;
}

.content-body blockquote {
    position: relative;
    margin: var(--s-7) 0;
    padding: var(--s-5) var(--s-5) var(--s-5) var(--s-6);
    background: linear-gradient(90deg, var(--accent-2-tint), transparent 85%);
    border-left: 3px solid var(--accent-2);
    border-radius: 0 var(--r-md) var(--r-md) 0;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--ink);
}

.content-body blockquote p {
    margin: 0;
    color: var(--ink);
}

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

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

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

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

.content-body ul li,
.content-body ol li {
    margin-bottom: var(--s-2);
    padding-left: var(--s-1);
    color: var(--ink-soft);
}

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

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

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

.content-body code:not(pre code) {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0.1em 0.4em;
    background: var(--paper-2);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-sm);
    color: var(--accent-2);
    overflow-wrap: anywhere;
}

.content-body pre {
    margin: var(--s-6) 0;
    padding: var(--s-4) var(--s-5);
    background: #f1ecdf;
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--ink);
    overflow-x: auto;
    white-space: pre;
    -webkit-overflow-scrolling: touch;
}

.content-body pre code {
    font-family: inherit;
    font-size: inherit;
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
}

/* Tables: scroll on small screens instead of breaking layout */
.content-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--s-6) 0;
    font-size: var(--fs-small);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    background: var(--surface);
}

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

.content-body th {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink);
    background: var(--paper-2);
}

.content-body tbody tr:nth-child(even) {
    background: rgba(235, 229, 214, 0.35);
}

.content-body tbody tr {
    transition: background-color var(--transition);
}

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

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

/* 8. Related materials */
.related-materials {
    margin-top: var(--s-section);
    min-width: 0;
}

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

.section-header h2,
.section-header h3 {
    flex-shrink: 0;
    font-size: 1.25rem;
    margin: 0;
}

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

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

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--s-5);
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition),
        box-shadow var(--transition),
        border-color var(--transition);
}

.card:hover {
    transform: translateY(-2px);
    border-color: rgba(44, 90, 68, 0.3);
    box-shadow: var(--shadow-md);
}

.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: 4px 10px;
    background: var(--accent-tint);
    color: var(--accent);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.badge.accent-badge {
    background: var(--accent-2-tint);
    color: var(--accent-2);
}

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

.card h4 {
    margin-bottom: var(--s-2);
    font-size: 1.1rem;
    line-height: 1.35;
    color: var(--ink);
}

.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;
    margin-top: auto;
    padding-top: var(--s-3);
    border-top: 1px solid var(--line-soft);
    opacity: 0.75;
    transition: opacity var(--transition);
}

.card:hover .card-footer {
    opacity: 1;
}

.card-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-size: var(--fs-small);
    font-weight: 600;
}

/* 9. Footer */
footer {
    flex-shrink: 0;
    margin-top: auto;
    background: var(--paper-2);
    border-top: 1px solid var(--line);
}

.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;
    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;
    gap: var(--s-1) var(--s-5);
}

.footer-center a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--ink);
    font-size: var(--fs-small);
    text-decoration: underline;
    text-underline-offset: 0.25em;
}

.footer-center a:hover {
    color: var(--accent);
}

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

/* 10. Breakpoints (mobile-first) */
@media (min-width: 480px) {
    :root {
        --gutter: 1.25rem;
    }

    body {
        font-size: 1.0625rem;
    }

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

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

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

@media (min-width: 768px) {
    :root {
        --gutter: 1.75rem;
    }

    body {
        font-size: 1.0625rem;
    }

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

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

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

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

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

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

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

@media (min-width: 1024px) {
    :root {
        --gutter: 2rem;
    }

    body {
        font-size: 1.125rem;
    }

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

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

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

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

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

/* 11. Reduced motion */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::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 {
        transform: none;
    }
}