/* ============================================
   Psy Freelance WebDev - Brutalist Dark Theme
   Per SPECS.md sections 3.1-3.4, 3.6-3.7
   ============================================ */

/* 3.1 Color Palette */
:root {
    --surface-0: #0a0a0a;
    --surface-1: #111111;
    --surface-2: #1a1a1a;
    --surface-3: #222222;
    --text-primary: #e0e0e0;
    --text-secondary: #888888;
    --text-tertiary: #555555;
    --accent: #00ff41;
    --accent-dim: #00cc33;
    --accent-glow: rgba(0, 255, 65, 0.15);
    --accent-secondary: #00e5ff;
    --border: #333333;
    --border-bright: #444444;
    --error: #ff4444;
    --warning: #ffaa00;
    --font-mono: "JetBrains Mono", "IBM Plex Mono", "Fira Code", "Noto Sans Mono TC", monospace;
    --font-sans: "Inter", -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    --radius: 0px;
    --max-width: 1200px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;
    --space-12: 48px;
    --space-16: 64px;
    --space-24: 96px;
    --nav-height: 64px;
}

/* 3.2 Typography */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-mono);
    color: var(--text-primary);
    margin: 0;
}

h1 { font-size: clamp(2.5rem, 6vw, 5rem); font-weight: 700; line-height: 1.1; }
h2 { font-size: clamp(1.5rem, 3vw, 2.5rem); font-weight: 600; line-height: 1.2; }
h3 { font-size: 1.25rem; font-weight: 500; line-height: 1.3; }

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--surface-0);
    margin: 0;
    padding: 0;
}

p { margin: 0 0 var(--space-4) 0; line-height: 1.6; }

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 150ms ease-out;
}
a:hover { color: var(--accent-dim); }

code, pre {
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

pre {
    background: var(--surface-1);
    border: 1px solid var(--border);
    padding: var(--space-4);
    overflow-x: auto;
    border-radius: var(--radius);
}

code { color: var(--accent); }

/* Labels/meta text */
.label, .meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
}

/* Nav links */
.nav-link {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Button text */
.btn-text {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 3.3 Layout System */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-6);
    width: 100%;
}

.section {
    padding-block: var(--space-24);
    border-top: 1px solid var(--border);
    text-align: center;
}

.grid-12 {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--space-6);
}

.main-content {
    min-height: calc(100dvh - var(--nav-height));
    padding-top: var(--nav-height);
}

/* 3.4 Component Design */

/* Buttons */
.btn {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-3) var(--space-6);
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 200ms ease-out;
    position: relative;
    overflow: hidden;
    display: inline-block;
    text-decoration: none;
    text-align: center;
}
.btn:hover {
    background: var(--accent);
    color: var(--surface-0);
}
.btn:active {
    transform: translate(1px, 1px);
}
.btn-secondary {
    border-color: var(--border-bright);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: var(--surface-3);
    color: var(--text-primary);
}

/* Cards */
.card {
    border: 1px solid var(--border);
    background: var(--surface-1);
    padding: var(--space-6);
    border-radius: var(--radius);
    transition: border-color 200ms ease-out;
}
.card:hover {
    border-color: var(--accent);
}

/* Form Inputs */
.form-input {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    background: var(--surface-0);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    width: 100%;
    transition: border-color 150ms ease-out;
    box-sizing: border-box;
}
.form-input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 1px var(--accent);
}
.form-input::placeholder {
    color: var(--text-tertiary);
}

/* No soft shadows, no glassmorphism, no rounded corners */
* {
    box-shadow: none !important;
}

/* Override for focus ring and brutalist press */
.form-input:focus {
    box-shadow: 0 0 0 1px var(--accent) !important;
}

/* 3.6 Language Switcher */
.lang-switcher {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-tertiary);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}
.lang-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 150ms ease-out;
}
.lang-link:hover { color: var(--text-primary); }
.lang-link.active { color: var(--accent); }

/* Navigation */
.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--surface-0);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    display: flex;
    align-items: center;
}
.nav-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-6);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-6);
}
.nav-logo {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
}
.nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-6);
}
.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 150ms ease-out;
    position: relative;
}
.nav-link:hover { color: var(--text-primary); }
.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    border-radius: var(--radius);
}

/* Footer */
.footer {
    border-top: 1px solid var(--border);
    background: var(--surface-0);
    padding: var(--space-12) var(--space-6);
}
.footer-container {
    max-width: var(--max-width);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-6);
}
.footer-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    text-align: center;
}
.footer-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.footer-text {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
}
.footer-link {
    color: var(--accent);
    text-decoration: none;
}
.footer-bottom {
    max-width: var(--max-width);
    margin: var(--space-8) auto 0;
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    text-align: center;
}
.footer-copy {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin: 0;
}

/* Noise overlay - fixed, pointer-events:none, GPU-safe */
.noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Scroll progress bar */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0;
    background: var(--accent);
    z-index: 10000;
    transition: width 100ms linear;
}

/* 3.5.1 Scroll-Reveal */
@media (prefers-reduced-motion: no-preference) {
    .reveal {
        opacity: 0;
        transform: translateY(24px);
        transition: opacity 0.6s ease-out, transform 0.6s ease-out;
        transition-delay: calc(var(--index, 0) * 60ms);
    }
    .reveal.visible {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 3.5.2 Hover-Micro */
@media (prefers-reduced-motion: no-preference) {
    .card {
        transition: border-color 200ms ease-out, transform 200ms ease-out;
    }
    .card:hover {
        border-color: var(--accent);
        transform: translateY(-2px);
    }

    .nav-link::after {
        content: "";
        position: absolute;
        bottom: -2px;
        left: 0;
        width: 0;
        height: 1px;
        background: var(--accent);
        transition: width 200ms ease-out;
    }
    .nav-link:hover::after { width: 100%; }

    /* Button directional fill */
    .btn::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 0;
        height: 100%;
        background: var(--accent);
        transition: width 200ms ease-out;
        z-index: -1;
    }
    .btn:hover::before { width: 100%; }
    .btn:hover {
        color: var(--surface-0);
    }
}

/* 3.5.3 Typography-Motion / Glitch */
@media (prefers-reduced-motion: no-preference) {
    .glitch:hover {
        animation: glitch 200ms steps(2) 1;
    }
    @keyframes glitch {
        0% { text-shadow: 2px 0 var(--accent), -2px 0 var(--error); }
        50% { text-shadow: -2px 0 var(--accent), 2px 0 var(--error); }
        100% { text-shadow: 0 0 transparent; }
    }
}

/* 3.5.4 Page-Transition */
@media (prefers-reduced-motion: no-preference) {
    body {
        animation: fadeIn 300ms ease-out;
    }
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* Terminal boot overlay */
.terminal-boot {
    position: fixed;
    inset: 0;
    background: var(--surface-0);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--accent);
}
.terminal-boot.fade-out {
    animation: bootFade 500ms ease-out forwards;
}
@keyframes bootFade {
    to { opacity: 0; visibility: hidden; }
}

/* 3.5.5 Gallery-Media */
@media (prefers-reduced-motion: no-preference) {
    .gallery-item {
        overflow: hidden;
        position: relative;
    }
    .gallery-item img {
        transition: transform 300ms ease-out;
    }
    .gallery-item:hover img {
        transform: scale(1.05);
    }
    .gallery-overlay {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--surface-0);
        border-top: 1px solid var(--accent);
        padding: var(--space-4);
        transform: translateY(100%);
        transition: transform 300ms ease-out;
    }
    .gallery-item:hover .gallery-overlay {
        transform: translateY(0);
    }
}

/* 3.5.6 Decorative Effects */
.scanline {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 255, 65, 0.02) 2px,
        rgba(0, 255, 65, 0.02) 4px
    );
}

.grid-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.05;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
}

.blinking-cursor {
    display: inline-block;
    color: var(--accent);
    animation: blink 1s step-end infinite;
}
@keyframes blink {
    50% { opacity: 0; }
}

/* 3.5.7 Extended Animations */

/* Marquee */
.marquee {
    overflow: hidden;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: var(--space-4) 0;
    background: var(--surface-1);
}
.marquee-content {
    display: inline-block;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-secondary);
}
@media (prefers-reduced-motion: no-preference) {
    .marquee-content {
        animation: marquee 20s linear infinite;
    }
    @keyframes marquee {
        from { transform: translateX(0); }
        to { transform: translateX(-50%); }
    }
}

/* Accordion image slider */
.accordion-slider {
    display: flex;
    height: 400px;
    gap: 1px;
}
.accordion-strip {
    flex: 1;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: flex 300ms ease-out;
    position: relative;
}
@media (prefers-reduced-motion: no-preference) {
    .accordion-strip:hover {
        flex: 4;
    }
}
.accordion-strip img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Terminal cursor follow */
.terminal-cursor {
    position: fixed;
    left: 0;
    top: 0;
    color: var(--accent);
    opacity: 0.3;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 9000;
    transition: top 100ms ease-out;
}

/* Code rain canvas */
.code-rain {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.05;
}

/* Magnetic button */
.magnetic-btn {
    transition: transform 200ms ease-out;
}

/* 3.7 Responsive Design - Mobile-first, breakpoint 768px */

/* Mobile defaults: nav collapses, grid becomes single column */
@media (max-width: 767px) {
    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        background: var(--surface-0);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: var(--space-4) var(--space-6);
        gap: var(--space-4);
    }
    .nav-links.open {
        display: flex;
    }
    .nav-toggle {
        display: block;
    }
    .grid-12 {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }
    .footer-container {
        grid-template-columns: 1fr;
    }
    .section {
        padding-block: var(--space-12);
    }
    .accordion-slider {
        flex-direction: column;
        height: auto;
    }
    .accordion-strip {
        flex: none;
        height: 60px;
    }
    .accordion-strip:hover {
        flex: none;
        height: 200px;
    }
    /* Disable heavy animations on mobile */
    .code-rain,
    .terminal-cursor,
    .magnetic-btn {
        display: none !important;
    }
}

/* Desktop: 768px and up */
@media (min-width: 768px) {
    .container {
        padding: 0 var(--space-6);
    }
}

/* Touch target minimum 44x44px */
@media (pointer: coarse) {
    .nav-link,
    .btn,
    .lang-link,
    .nav-toggle {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Section transition line (scroll-driven) */
@media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {
        .section::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            height: 1px;
            width: 100%;
            background: var(--accent);
            transform: scaleX(0);
            transform-origin: left;
            animation: sectionLine 1s ease-out;
            animation-timeline: view();
        }
        @keyframes sectionLine {
            from { transform: scaleX(0); }
            to { transform: scaleX(1); }
        }
    }
}

/* Scroll progress bar with CSS scroll timeline */
@supports (animation-timeline: scroll()) {
    .scroll-progress {
        animation: scrollProgress linear;
        animation-timeline: scroll(root);
    }
    @keyframes scrollProgress {
        from { width: 0; }
        to { width: 100%; }
    }
}

/* Reduced motion: disable all animations */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .noise-overlay { display: none; }
    .scanline { display: none; }
    .grid-bg { display: none; }
    .blinking-cursor { animation: none; opacity: 1; }
    .marquee-content { animation: none; }
    .reveal {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* Utility classes */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-accent { color: var(--accent); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.bg-surface-1 { background: var(--surface-1); }
.bg-surface-2 { background: var(--surface-2); }
.border-accent { border-color: var(--accent); }
.full-width { width: 100%; }
.hidden { display: none; }

/* Reading progress bar (blog detail) - CSS scroll-timeline only */
.reading-progress {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    height: 2px;
    width: 0;
    background: var(--accent);
    z-index: 99;
}

@media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: scroll()) {
        .reading-progress {
            width: auto;
            animation: readingProgress linear;
            animation-timeline: scroll(root);
        }
        @keyframes readingProgress {
            from { width: 0; }
            to { width: 100%; }
        }
    }
}
