/* ============================================
   Starfield Background
   ============================================ */

/* 1. The Container: Fixed behind all content */
#star-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
    overflow: hidden;
    z-index: -1; /* Pushes it to the back */
}

/* 2. The Layers: Shared properties */
#stars-small, #stars-medium, #stars-large {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
}

/* 3. The Animation: Endless Vertical Scroll */
/* Note: translateY value must match STARFIELD_SCROLL_HEIGHT in utils/starfield.js */
@keyframes animStar {
    from { transform: translateY(0px); }
    to { transform: translateY(-2000px); }
}

/* Layer Specifics (Animations applied here) */
#stars-small {
    width: 1px;
    height: 1px;
    animation: animStar 50s linear infinite;
}

#stars-medium {
    width: 2px;
    height: 2px;
    animation: animStar 100s linear infinite;
}

#stars-large {
    width: 3px;
    height: 3px;
    animation: animStar 150s linear infinite;
}

/* Reduced motion preference support for starfield */
@media (prefers-reduced-motion: reduce) {
    #stars-small, #stars-medium, #stars-large {
        animation: none;
    }
}

/* ============================================
   Design System
   ============================================ */

/* Design tokens keep light/dark theming centralized. */
:root {
    color-scheme: light dark;
    --bg: #ffffff;
    --fg: #1f2933;
    --accent: #2563eb;
    --muted: #64748b;
    --border: #d4d8dd;
    --max-width: 82ch;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--fg);
    background: transparent; /* Allow starfield to show through */
    display: flex;
    flex-direction: column;
}

.noscript-warning {
    margin: 0;
    padding: 1rem;
    background: #fee2e2;
    color: #7f1d1d;
    text-align: center;
}

/* Sticky shell keeps navigation visible for SPA transitions. */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem clamp(1rem, 3vw, 2.5rem);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 600;
    letter-spacing: 0.02em;
}

.brand__accent {
    color: var(--accent);
}

.brand a {
    color: inherit;
    text-decoration: none;
    transition: transform 150ms ease-in-out;
    display: inline-block; /* Needed for transform to apply */
    position: relative;
    animation: brand-glow-pulse 3s ease-in-out infinite;
}

.brand a:hover,
.brand a:focus-visible {
    transform: scale(1.03);
    text-decoration: none;
}

/* ============================================
   Graham Joss Brand Animation
   ============================================ */

/* Flagship glow pulse animation - subtle continuous effect */
@keyframes brand-glow-pulse {
    0%, 100% {
        text-shadow: 
            0 0 4px rgba(37, 99, 235, 0.2),
            0 0 8px rgba(37, 99, 235, 0.1);
        filter: brightness(1);
    }
    50% {
        text-shadow: 
            0 0 8px rgba(37, 99, 235, 0.4),
            0 0 16px rgba(37, 99, 235, 0.2),
            0 0 24px rgba(37, 99, 235, 0.1);
        filter: brightness(1.05);
    }
}

/* Click animation - energetic burst effect */
@keyframes brand-click-burst {
    0% {
        transform: scale(1);
        filter: brightness(1) hue-rotate(0deg);
    }
    15% {
        transform: scale(0.92);
        filter: brightness(1.3) hue-rotate(-10deg);
    }
    30% {
        transform: scale(1.08);
        filter: brightness(1.4) hue-rotate(10deg);
    }
    45% {
        transform: scale(0.98);
        filter: brightness(1.2) hue-rotate(-5deg);
    }
    60% {
        transform: scale(1.04);
        filter: brightness(1.1) hue-rotate(5deg);
    }
    80% {
        transform: scale(0.99);
        filter: brightness(1.05) hue-rotate(0deg);
    }
    100% {
        transform: scale(1);
        filter: brightness(1) hue-rotate(0deg);
    }
}

/* Click ripple effect using pseudo-element */
.brand a::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.4) 0%, transparent 70%);
    transform: translate(-50%, -50%);
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

/* Class added via JavaScript on click */
.brand a.brand--clicked {
    animation: brand-click-burst 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.brand a.brand--clicked::before {
    animation: brand-ripple 0.6s ease-out forwards;
}

@keyframes brand-ripple {
    0% {
        width: 0;
        height: 0;
        opacity: 1;
    }
    100% {
        width: 200%;
        height: 200%;
        opacity: 0;
    }
}

/* Hover shimmer effect for extra polish */
.brand a::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 1;
}

.brand a:hover::after {
    animation: brand-shimmer 0.8s ease-in-out;
}

@keyframes brand-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Horizontal navigation doubles as our active route indicator. */
.site-nav {
    display: flex;
    gap: 1rem;
    font-weight: 500;
}

.site-nav a {
    color: inherit;
    text-decoration: none;
    position: relative;
    padding-bottom: 0.25rem;
}

.site-nav a::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    height: 2px;
    background: transparent;
    transition: background 150ms ease;
}

.site-nav a[data-active="true"] {
    color: var(--accent);
}

.site-nav a[data-active="true"]::after {
    background: var(--accent);
}

.site-nav a:hover::after,
.site-nav a:focus-visible::after {
    background: var(--accent);
}

/* ============================================
   Hamburger Menu Toggle Button
   ============================================ */

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 20;
}

.nav-toggle__bar {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--fg);
    border-radius: 2px;
    transition: transform 250ms ease, opacity 250ms ease;
}

/* Hamburger to X transformation when menu is open */
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(2) {
    opacity: 0;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ============================================
   Responsive Navigation - Mobile First
   ============================================ */

@media (max-width: 768px) {
    .nav-toggle {
        display: flex;
    }

    .site-nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
        padding: 1rem;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        visibility: hidden;
        transition: max-height 300ms ease, opacity 250ms ease, visibility 0ms 300ms;
    }

    .site-nav.nav-open {
        max-height: 300px;
        opacity: 1;
        visibility: visible;
        transition: max-height 300ms ease, opacity 250ms ease, visibility 0ms;
    }

    .site-nav a {
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid var(--border);
    }

    .site-nav a:last-child {
        border-bottom: none;
    }

    .site-nav a::after {
        display: none;
    }

    .site-nav a[data-active="true"] {
        background: rgba(37, 99, 235, 0.08);
        border-radius: 6px;
    }
}

/* Constrain readable width and let sections stack vertically. */
.view-container {
    position: relative;
    flex: 1;
    width: min(100%, calc(var(--max-width) + 2rem));
    margin: 0 auto;
    padding: clamp(2rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) 4rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.view-container section {
    background: rgba(220, 250, 255, 0.85);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: clamp(1.5rem, 4vw, 2.5rem);
    box-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
}

h1, h2, h3 {
    color: #0f172a;
    margin-top: 0;
    line-height: 1.1;
}

p {
    line-height: 1.6;
    color: var(--muted);
    margin-top: 0.75rem;
}

ul, ol {
    margin: 1rem 0 0;
    padding-left: 1.25rem;
    color: var(--fg);
    line-height: 1.6;
}

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

a:hover,
a:focus-visible {
    text-decoration: underline;
}

.card-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* Cards reuse the same surface styling as primary sections. */
.card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    background: white;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: border-color 120ms ease, transform 120ms ease;
}

.card:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
}

.card a {
    align-self: flex-start;
    font-weight: 600;
}

.muted {
    color: var(--muted);
}

/* Dark code blocks emphasise the instructional snippets. */
.code-block {
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 10px;
    overflow-x: auto;
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1rem clamp(1rem, 3vw, 2.5rem);
    font-size: 0.875rem;
    color: var(--muted);
    text-align: center;
}


/* Notes content experience */
.notes-view {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.notes-header h1 {
    margin-bottom: 0;
}

.notes-breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.notes-breadcrumbs a {
    color: inherit;
    text-decoration: none;
    padding: 0.125rem 0.25rem;
    border-radius: 6px;
}

.notes-breadcrumbs a:hover,
.notes-breadcrumbs a:focus-visible {
    background: rgba(37, 99, 235, 0.12);
    color: var(--accent);
}

.notes-breadcrumbs__sep {
    color: var(--border);
}

.notes-backlink {
    align-self: flex-start;
    font-size: 0.875rem;
    color: var(--accent);
    text-decoration: none;
}

.notes-backlink:hover,
.notes-backlink:focus-visible {
    text-decoration: underline;
}

.notes-directory-lists {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.notes-directory-panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.75);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.notes-directory-panel h2 {
    margin: 0;
}

.notes-directory-panel ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.notes-directory-panel li a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.notes-directory-panel li a:hover,
.notes-directory-panel li a:focus-visible {
    text-decoration: underline;
}

.notes-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.notes-content figure {
    margin: 0;
}

/* Excalidraw embeds */
.excalidraw-embed {
    width: 100%;
    min-height: 600px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #ffffff;
    margin: 1rem 0;
}

.excalidraw-loading {
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    font-style: italic;
}

.excalidraw-embed .excalidraw {
    width: 100%;
    height: 100%;
}

/* Projects section styles */
.project-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

.tag {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.875rem;
    color: var(--muted);
    font-weight: 500;
}

.card-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
    flex-wrap: wrap;
}

.project-actions {
    margin: 2rem 0;
}

.button-primary,
.button-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: 6px;
    font-weight: 500;
    text-decoration: none;
    transition: all 150ms ease;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 0.9375rem;
}

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

.button-primary:hover {
    background: #d97706;
    border-color: #d97706;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(234, 88, 12, 0.2);
}

.button-secondary {
    background: transparent;
    color: var(--accent);
    border-color: var(--border);
}

.button-secondary:hover {
    background: var(--bg-subtle);
    border-color: var(--accent);
}

.button-primary svg,
.button-secondary svg {
    width: 16px;
    height: 16px;
}

.breadcrumb {
    margin-bottom: 1rem;
}

.breadcrumb a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.lead {
    font-size: 1.125rem;
    color: var(--muted);
    line-height: 1.7;
    margin: 1rem 0 2rem;
}

.feature-list {
    list-style: none;
    padding: 0;
}

.feature-list li {
    padding: 0.75rem 0;
    padding-left: 1.75rem;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.feature-list li:last-child {
    border-bottom: none;
}

.feature-list li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
}

.home-hero {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 2rem;
}

.home-hero__image img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
}

@media (max-width: 768px) {
    .home-hero {
        grid-template-columns: 1fr;
        text-align: center;
    }
}

/* Splash page with physics engine */
.splash-section {
    position: relative;
    width: 100%;
    min-height: 400px;
    height: 50vh;
    max-height: 500px;
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    box-shadow: inset 0 2px 20px rgba(0, 0, 0, 0.05);
}

.splash-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.splash-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

.splash-canvas:active {
    cursor: grabbing;
}

.splash-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    pointer-events: none;
    padding: 2rem;
}

.splash-title {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    text-shadow: 2px 2px 20px rgba(255, 255, 255, 0.8);
    letter-spacing: -0.02em;
}

.splash-subtitle {
    font-size: clamp(1rem, 3vw, 1.5rem);
    color: var(--muted);
    margin: 0.5rem 0 0;
    font-weight: 500;
    text-shadow: 1px 1px 10px rgba(255, 255, 255, 0.9);
}

.splash-hint {
    position: absolute;
    bottom: 1.5rem;
    font-size: 0.875rem;
    color: var(--muted);
    opacity: 0.7;
    margin: 0;
    text-shadow: 1px 1px 5px rgba(255, 255, 255, 0.9);
}

@media (max-width: 480px) {
    .splash-section {
        min-height: 300px;
        height: 40vh;
    }
    
    .splash-hint {
        display: none;
    }
}

/* Page transition animations */
.view-container.page-transition-leave {
    animation: page-leave 200ms ease-in forwards;
}

.view-container.page-transition-enter {
    animation: page-enter 300ms ease-out forwards;
}

@keyframes page-leave {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Reduced motion preference support */
@media (prefers-reduced-motion: reduce) {
    .view-container.page-transition-leave,
    .view-container.page-transition-enter {
        animation: none;
    }
    
    .view-container.page-transition-leave {
        opacity: 0;
    }
    
    .view-container.page-transition-enter {
        opacity: 1;
    }
}

/* ============================================
   Magnetic Micro-Interactions
   ============================================ */

/* Base styles for magnetic elements - ensure smooth transforms */
.button-primary,
.button-secondary,
.site-nav a,
.brand a,
.card a,
.notes-directory-panel li a,
.notes-backlink,
.breadcrumb a {
    will-change: transform;
    transform: translate(0, 0);
}

/* Disable magnetic effects when user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    .button-primary,
    .button-secondary,
    .site-nav a,
    .brand a,
    .card a,
    .notes-directory-panel li a,
    .notes-backlink,
    .breadcrumb a {
        transform: none !important;
        transition: none !important;
    }
    
    /* Disable brand animations */
    .brand a {
        animation: none !important;
        filter: none !important;
        text-shadow: none !important;
    }
    
    .brand a::before,
    .brand a::after {
        display: none !important;
    }
    
    .brand a.brand--clicked {
        animation: none !important;
    }
}

/* ============================================
   3D Trapdoor Card Effect
   ============================================ */

/* Parent container with perspective for 3D depth */
.trapdoor-card {
    position: relative;
    width: 320px;
    height: 400px;
    perspective: 1000px;
    margin: 0 auto;
    cursor: pointer;
}

/* The inner wrapper preserves 3D context for children */
.trapdoor-card__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

/* The front face (image) - acts as the trapdoor */
.trapdoor-card__front {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    /* Hinge from the left vertical edge for a door-like swing */
    transform-origin: left center;
    /* Default transition (closing): Fast and smooth, no overshoot */
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 2;
    /* Removed background: white to prevent z-fighting */
}

.trapdoor-card__front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    backface-visibility: hidden;
    border-radius: 16px;
    /* Push slightly forward to avoid z-fighting with the back face */
    transform: translateZ(1px);
}

/* The back of the door - visible when opened */
.trapdoor-card__front::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    /* Rotate and push slightly forward (relative to itself) to create thickness */
    transform: rotateY(180deg) translateZ(1px);
    backface-visibility: hidden;
    border-radius: 16px;
}

/* The back face (secret message) - revealed underneath */
.trapdoor-card__back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2e5a8a 100%);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 1;
    /* Push slightly backward to sit behind the door */
    transform: translateZ(-1px);
}

.trapdoor-card__back h3 {
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    color: #ffffff;
}

.trapdoor-card__back p {
    margin: 0;
    font-size: 1rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
}

/* Open state - front swings outward like a door from the left edge */
.trapdoor-card.open .trapdoor-card__front {
    transform: rotateY(-120deg);
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.15);
    /* Opening transition: Slower with a springy overshoot */
    transition: transform 1.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Hint text for user interaction */
.trapdoor-card__hint {
    position: absolute;
    bottom: -2rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.875rem;
    color: var(--muted);
    opacity: 0.7;
    pointer-events: none;
    white-space: nowrap;
}

/* Hide hint when card is open */
.trapdoor-card.open .trapdoor-card__hint {
    opacity: 0;
    transition: opacity 0.6s ease;
}

/* Reduced motion preference support */
@media (prefers-reduced-motion: reduce) {
    .trapdoor-card__front {
        transition: none;
    }
    
    .trapdoor-card.open .trapdoor-card__front {
        transform: rotateY(-90deg);
    }
    
    .trapdoor-card.open .trapdoor-card__hint {
        transition: none;
    }
}
