* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #0f172a;
    --secondary: #1e293b;
    --accent: #3b82f6;
    --accent-light: #60a5fa;
    --text: #f1f5f9;
    --text-muted: #cbd5e1;
    --border: #334155;
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --nav-bg: rgba(15, 23, 42, 0.8);
    --nav-bg-solid: rgba(15, 23, 42, 0.97);
    --card-bg: rgba(59, 130, 246, 0.05);
    --card-bg-hover: rgba(59, 130, 246, 0.1);
    --tag-bg: rgba(59, 130, 246, 0.15);
    --panel-bg: #1e293b;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --primary: #f8fafc;
    --secondary: #e2e8f0;
    --accent: #2563eb;
    --accent-light: #1d4ed8;
    --text: #0f172a;
    --text-muted: #475569;
    --border: #cbd5e1;
    --bg-dark: #f8fafc;
    --bg-darker: #ffffff;
    --nav-bg: rgba(255, 255, 255, 0.85);
    --nav-bg-solid: rgba(255, 255, 255, 0.97);
    --card-bg: rgba(37, 99, 235, 0.05);
    --card-bg-hover: rgba(37, 99, 235, 0.1);
    --tag-bg: rgba(37, 99, 235, 0.12);
    --panel-bg: #ffffff;
    color-scheme: light;
}

/* Reading preferences (set as data attributes on <html> by prefs.js) */
:root[data-textsize="large"] { font-size: 112.5%; }
:root[data-textsize="xl"] { font-size: 125%; }

:root[data-font="dyslexic"] body {
    font-family: Verdana, 'Trebuchet MS', Tahoma, sans-serif;
    letter-spacing: 0.03em;
    word-spacing: 0.12em;
}

:root[data-spacing="relaxed"] body { line-height: 1.9; }
:root[data-spacing="relaxed"] .about-content > p,
:root[data-spacing="relaxed"] .work-card p { line-height: 2.1; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, var(--bg-darker) 0%, var(--primary) 100%);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Accessibility: skip link + visible keyboard focus */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 200;
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: 0 0 8px 0;
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    left: 0;
}

a:focus-visible,
button:focus-visible {
    outline: 3px solid var(--accent-light);
    outline-offset: 3px;
    border-radius: 4px;
}

/* Navigation */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: 2px;
}

.nav-toggle {
    display: none;
    font: inherit;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text);
    background: none;
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.65rem;
    cursor: pointer;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.3s ease;
    font-size: 0.95rem;
}

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

/* Hero Section */
.hero {
    padding: 8rem 0;
    text-align: center;
}

.hero-photo {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--accent);
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 30px rgba(59, 130, 246, 0.25);
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--text) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero .subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

.hero-tagline {
    margin-top: 1.5rem;
    font-size: 1.05rem;
    font-style: italic;
    color: var(--accent-light);
}

/* Sound wave: chaos settling into calm */
.sound-wave {
    max-width: 700px;
    margin: 3rem auto 0;
}

.sound-wave svg {
    display: block;
    width: 100%;
    height: 70px;
}

.sound-wave path {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.wave-jagged {
    opacity: 0.9;
    animation: wave-settle-out 7s ease 1s forwards;
}

.wave-smooth {
    opacity: 0;
    animation: wave-settle-in 7s ease 1s forwards;
}

@keyframes wave-settle-out {
    to { opacity: 0; }
}

@keyframes wave-settle-in {
    to { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
    .wave-jagged { display: none; }
    .wave-smooth { opacity: 0.9; animation: none; }
}

/* Stat band */
.stat-band {
    text-align: center;
}

.stat-number {
    font-size: 4.5rem;
    font-weight: 700;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-text {
    max-width: 480px;
    margin: 0.75rem auto 0;
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Pull quote + standalone line */
.pull-quote {
    max-width: 600px;
    margin: 3rem auto;
    text-align: center;
    font-size: 1.35rem;
    font-style: italic;
    line-height: 1.7;
    color: var(--text);
}

.about-content .standalone-line,
.standalone-line {
    margin: 3.5rem 0 1.5rem;
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Tone demo */
.tone-demo .about-content > p {
    text-align: center;
}

.tone-demo-controls {
    text-align: center;
    margin-top: 2.5rem;
}

.tone-button {
    font: inherit;
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text);
    background: rgba(59, 130, 246, 0.08);
    border: 2px solid var(--accent);
    border-radius: 999px;
    padding: 1.1rem 2.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.tone-button:hover {
    background: rgba(59, 130, 246, 0.18);
}

.tone-button.playing {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 45px rgba(59, 130, 246, 0.5);
}

.tone-note {
    margin-top: 1.25rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.7;
}

/* Sections */
.section {
    padding: 5rem 0;
    border-top: 1px solid var(--border);
}

.section h2 {
    font-size: 2.5rem;
    margin-bottom: 3rem;
    text-align: center;
}

/* About Section */
.about-content {
    max-width: 800px;
    margin: 0 auto;
}

.about-content a {
    color: var(--accent-light);
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
}

.about-content a:hover {
    color: var(--accent);
}

.about-content > p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.8;
}

.skills,
.highlights {
    margin: 3rem 0;
}

.skills h3,
.highlights h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--accent);
}

.skill-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.skill-tags span {
    display: inline-block;
    background: var(--card-bg-hover);
    border: 1px solid var(--accent);
    color: var(--accent-light);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.highlights ul {
    list-style: none;
    margin-top: 1rem;
}

.highlights li {
    padding: 0.75rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: var(--text-muted);
}

.highlights li:before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--accent);
}

/* Work Grid */
.work-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.work-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.work-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.work-card:hover {
    border-color: var(--accent);
    background: var(--card-bg-hover);
    transform: translateY(-4px);
}

.work-card h3 {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.work-card p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tags span {
    font-size: 0.8rem;
    background: var(--tag-bg);
    color: var(--accent-light);
    padding: 0.35rem 0.75rem;
    border-radius: 12px;
}

/* Social Section */
.social-section {
    text-align: center;
}

.social-section p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 3rem;
}

.social-links {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.social-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    background: var(--card-bg);
}

.social-btn:hover {
    border-color: var(--accent);
    background: var(--tag-bg);
    color: var(--accent-light);
    transform: translateY(-2px);
}

.social-btn svg {
    width: 20px;
    height: 20px;
}

.social-btn.github {
    --hover-color: #ffffff;
}

.social-btn.linkedin {
    --hover-color: #0a66c2;
}

.social-btn.twitter {
    --hover-color: #1da1f2;
}

.social-btn.email {
    --hover-color: #34d399;
}

.social-btn.coffee:hover {
    border-color: #ff5e5b;
    color: #ff5e5b;
}

.coffee-icon {
    font-size: 1.2rem;
}

/* ClearPage page */
.wordmark {
    margin-bottom: 1.5rem;
}

.wordmark img {
    width: min(420px, 80%);
    height: auto;
}

.cp-mascot {
    width: 180px;
    height: auto;
    margin-bottom: 1rem;
}

.app-icon {
    display: block;
    width: 96px;
    height: 96px;
    margin: 0 auto 1.5rem;
    border-radius: 22%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.cp-illustration {
    display: block;
    width: 200px;
    height: auto;
    margin: 2.5rem auto 0;
    opacity: 0.9;
}

/* Footer */
.legal-links {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.legal-links a {
    color: var(--text-muted);
    text-decoration: none;
}

.legal-links a:hover {
    color: var(--accent);
}

footer {
    background: var(--secondary);
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: 4rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .hero h1 {
        font-size: 2.5rem;
    }

    .hero .subtitle {
        font-size: 1rem;
    }

    .section h2 {
        font-size: 1.8rem;
    }

    .navbar .container {
        position: relative;
    }

    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0;
        background: var(--nav-bg-solid);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links li {
        text-align: center;
    }

    .nav-links a {
        display: block;
        padding: 0.85rem;
        font-size: 1rem;
    }

    .work-grid {
        grid-template-columns: 1fr;
    }

    .social-links {
        gap: 1rem;
    }

    .social-btn {
        flex: 1;
        justify-content: center;
        padding: 0.85rem 1rem;
        font-size: 0.95rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }

    .hero {
        padding: 4rem 0;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .section {
        padding: 3rem 0;
    }

    .section h2 {
        font-size: 1.5rem;
    }

    .skill-tags {
        gap: 0.5rem;
    }

    .skill-tags span {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* Theme-dependent assets: dark-only shown on dark theme, light-only on light */
.light-only { display: none; }
:root[data-theme="light"] .light-only { display: inline; }
:root[data-theme="light"] .dark-only { display: none; }

/* Dark-mode illustrations get a dark backdrop when the theme is light */
:root[data-theme="light"] .cp-illustration {
    background: #0f172a;
    border-radius: 20px;
    padding: 1.25rem;
}

/* Reading preferences widget */
.prefs-toggle {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 150;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: var(--panel-bg);
    color: var(--text);
    font: inherit;
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.prefs-toggle:hover {
    background: var(--card-bg-hover);
}

.prefs-panel {
    position: fixed;
    bottom: 5.25rem;
    right: 1.25rem;
    z-index: 150;
    width: min(320px, calc(100vw - 2.5rem));
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.prefs-panel[hidden] {
    display: none;
}

.prefs-panel h2 {
    font-size: 1.05rem;
    margin-bottom: 1rem;
}

.prefs-panel fieldset {
    border: none;
    margin-bottom: 1rem;
}

.prefs-panel legend {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.prefs-options {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.prefs-options button {
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.85rem;
    cursor: pointer;
}

.prefs-options button[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.prefs-reset {
    font: inherit;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: none;
    border: none;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
}

/* Writing section */
.post-body {
    max-width: 720px;
    margin: 0 auto;
}

.post-body p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    line-height: 1.8;
}

.post-body h2 {
    font-size: 1.5rem;
    text-align: left;
    margin: 2.5rem 0 1rem;
}

.post-body a {
    color: var(--accent-light);
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
}

.post-meta {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.75rem;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Selection */
::selection {
    background: var(--accent);
    color: var(--bg-dark);
}
