/* Reset and base styles */
* {
    box-sizing: border-box;
}

html {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1.6;
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    .progress-bar {
        transition: none !important;
    }
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Color tokens */
:root {
    --primary-color: #1a1a1a;
    --bg-color: #ffffff;
    --text-color: #1a1a1a;
    --text-light: #666666;
    --border-color: #e0e0e0;
    --accent-color: #0066cc;
    --hover-bg: #f5f5f5;
    --callout-bg: #f8f9fa;
    --callout-border: #dee2e6;
}

[data-theme="dark"] {
    --primary-color: #ffffff;
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --text-light: #b0b0b0;
    --border-color: #333333;
    --accent-color: #4d9fff;
    --hover-bg: #2d2d2d;
    --callout-bg: #2d2d2d;
    --callout-border: #404040;
}

/* Layout */
.wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Header */
header {
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    position: relative !important;
    top: auto !important;
    z-index: 100;
    transform: none !important;
    backdrop-filter: none !important;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

.site-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
}

.site-title a {
    color: var(--text-color);
    text-decoration: none;
}

nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 2rem;
}

nav a {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

nav a:hover,
nav a:focus,
nav a[aria-current] {
    color: var(--accent-color);
}

/* Main content */
main {
    margin: 3rem 0;
    padding-top: 1rem;
    position: relative;
    z-index: 1;
}

/* Article layout */
article {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    max-width: 1000px;
    margin: 0 auto;
}

@media (min-width: 1100px) {
    .article-body-container {
        display: grid;
        grid-template-columns: 2fr 300px;
        gap: 3rem;
        align-items: start;
    }
    
    .rail {
        position: sticky;
        top: 120px;
    }
}

/* Article header */
.article-header {
    max-width: 900px;
    margin: 0 auto;
    padding-top: 2rem;
}

.article-header h1 {
    font-size: 2.5rem;
    line-height: 1.2;
    margin: 0 0 1rem 0;
    font-weight: bold;
    color: var(--text-color);
}

.standfirst {
    font-size: 1.25rem;
    line-height: 1.5;
    color: var(--text-light);
    margin: 0 0 1.5rem 0;
    font-style: italic;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.meta > span {
    display: flex;
    align-items: center;
}

.meta > span:not(:last-child)::after {
    content: "•";
    margin-left: 1rem;
    color: var(--border-color);
}

/* Images */
.hero-image {
    margin: 2rem 0;
}

.hero-image img,
.inline-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
}

.hero-image figcaption {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
    font-style: italic;
}

.inline-image {
    margin: 1.5rem 0;
}

/* Article body */
.article-body {
    max-width: 900px;
    margin: 0 auto;
}

.article-body h2 {
    font-size: 1.75rem;
    line-height: 1.3;
    margin: 2.5rem 0 1rem 0;
    font-weight: bold;
    color: var(--text-color);
}

.article-body h2:first-child {
    margin-top: 1rem;
}

.article-body p {
    margin: 0 0 1.5rem 0;
    max-width: 80ch;
}

/* Callouts */
.callout {
    background-color: var(--callout-bg);
    border-left: 4px solid var(--accent-color);
    padding: 1.5rem;
    margin: 2rem 0;
    border-radius: 0 4px 4px 0;
    font-size: 0.95rem;
}

.callout strong {
    color: var(--accent-color);
    display: block;
    margin-bottom: 0.5rem;
}

/* Progress bar */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 1000;
    background-color: var(--accent-color);
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.1s ease;
    z-index: 1000;
}

/* Share */
.share-section {
    margin: 3rem 0 2rem 0;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
}

.share-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.share-button {
    background: var(--hover-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.share-button:hover,
.share-button:focus {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.share-panel {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    margin-top: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.share-panel h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
}

.share-url {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.share-url input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}

.share-url button {
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Comments */
.comments-section {
    margin: 2rem 0;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
}

.comments-trigger {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.comments-trigger:hover,
.comments-trigger:focus {
    background-color: #0052a3;
}

.comment-count {
    opacity: 0.8;
}

.comments-container {
    margin-top: 2rem;
}

.comment {
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 0;
}

.comment:last-child {
    border-bottom: none;
}

.comment-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.comment-author {
    font-weight: 600;
    color: var(--text-color);
}

.comment-text {
    line-height: 1.5;
}

/* Recirculation */
.recirc {
    background: var(--callout-bg);
    border-radius: 8px;
    padding: 2rem;
}

.recirc h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.25rem;
    color: var(--text-color);
}

.recirc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.recirc-item {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.recirc-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.recirc-link {
    text-decoration: none;
    color: var(--text-color);
    display: block;
}

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

.recirc-image {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.75rem;
}

.recirc-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    margin: 0 0 0.5rem 0;
    transition: color 0.2s ease;
}

.recirc-teaser {
    font-size: 0.9rem;
    color: var(--text-light);
    line-height: 1.4;
    margin: 0;
}

/* Newsletter */
.newsletter {
    background: var(--callout-bg);
    border: 1px solid var(--callout-border);
    border-radius: 8px;
    padding: 2rem;
    margin: 3rem 0;
    text-align: center;
}

.newsletter h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.25rem;
}

.newsletter form {
    display: flex;
    gap: 0.5rem;
    max-width: 400px;
    margin: 0 auto;
}

.newsletter input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}

.newsletter button {
    padding: 0.75rem 1.5rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

/* Footer */
footer[role="contentinfo"] {
    background: var(--hover-bg);
    border-top: 1px solid var(--border-color);
    margin-top: 4rem;
    padding: 2rem 0;
}

.footer-nav ul {
    list-style: none;
    margin: 0 0 1rem 0;
    padding: 0;
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.footer-nav a {
    color: var(--text-light);
    text-decoration: none;
    font-size: 0.9rem;
}

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

footer p {
    margin: 0;
    color: var(--text-light);
    font-size: 0.9rem;
}

/* CMP Banner */
.cmp-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.cmp-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    gap: 1rem;
    flex-wrap: wrap;
}

.cmp-message {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-color);
}

.cmp-buttons {
    display: flex;
    gap: 0.5rem;
}

.cmp-button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.cmp-button.primary {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.cmp-button:hover {
    background: var(--hover-bg);
}

.cmp-button.primary:hover {
    background: #0052a3;
}

.cmp-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.cmp-modal-content {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.cmp-modal h3 {
    margin: 0 0 1.5rem 0;
}

.cmp-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
}

.cmp-toggle:last-child {
    border-bottom: none;
}

.cmp-switch {
    position: relative;
    width: 50px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.cmp-switch.active {
    background: var(--accent-color);
}

.cmp-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.cmp-switch.active::after {
    transform: translateX(26px);
}

.cmp-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Focus styles */
*:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

button:focus,
a:focus {
    outline-offset: 4px;
}

/* Hidden elements */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Responsive */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }
    
    .wrap {
        padding: 0 1rem;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .article-header h1 {
        font-size: 2rem;
    }
    
    .standfirst {
        font-size: 1.1rem;
    }
    
    .meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .meta > span:not(:last-child)::after {
        display: none;
    }
    
    .cmp-content {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .newsletter form {
        flex-direction: column;
    }
    
    nav ul {
        gap: 1rem;
    }
    
    article {
        max-width: 100%;
    }
    
    .article-header,
    .article-body {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .wrap {
        padding: 0 0.75rem;
    }
    
    .article-header h1 {
        font-size: 1.75rem;
    }
    
    .share-buttons {
        justify-content: center;
    }
    
    .share-url {
        flex-direction: column;
    }
}