@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&display=swap');

/* Dark theme (default) */
:root, :root[data-theme="dark"]{
    --black: #0a0908;    /* page background */
    --gunmetal: #22333b; /* panels / surface */
    --almond: #eae0d5;   /* primary text (light) */
    --khaki: #c6ac8f;    /* accent */

    --bg: var(--black);
    --surface: var(--gunmetal);
    --accent: var(--khaki);
    --text: var(--almond);
    --surface-text: var(--almond);
    /* dynamic viewport variable (dvh/dvw) */
    --vh: 100dvh;
    --radius: 8px;
}

/* Light theme - swapped color palette */
:root[data-theme="light"]{
    --almond: #eae0d5;     /* page background (was text) */
    --khaki: #c6ac8f;      /* panels / surface (was accent) */
    --black: #0a0908;      /* primary text (was background) */
    --gunmetal: #22333b;   /* accent (was surface) */

    --bg: var(--almond);
    --surface: var(--khaki);
    --accent: var(--gunmetal);
    --text: var(--black);
    --surface-text: var(--black);
    --vh: 100dvh;
    --radius: 8px;
}

/* Base layout + typography */
body{
    margin:0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing:antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

header{
    margin: 1rem 0;
    padding: 0.6rem 1rem;
}

article{
    background: var(--surface);
    color: var(--surface-text);
    margin: 1rem 2rem;
    padding: 1rem;
    border-radius: var(--radius);
    /* Baseline 2024: @starting-style for entry animations */
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s ease, transform 0.5s ease, box-shadow 220ms ease, transform 220ms ease;
    transition-behavior: allow-discrete;
}

/* Baseline 2024: @starting-style - defines initial state when element enters DOM */
@starting-style {
    article {
        opacity: 0;
        transform: translateY(20px);
    }
}

/*
 * BASELINE 2024 FEATURE DESCRIPTION: @starting-style and transition-behavior
 * 
 * This implementation uses @starting-style and transition-behavior: allow-discrete, 
 * two CSS features that became part of Baseline 2024. The @starting-style at-rule 
 * allows you to define the initial state of an element when it first enters the DOM, 
 * enabling smooth entry animations without requiring JavaScript. When combined with 
 * transition-behavior: allow-discrete, it allows transitions on discrete properties 
 * like display and content-visibility. In this portfolio, articles fade in and slide 
 * up smoothly when the page loads, and navigation links fade in gracefully, creating 
 * a polished user experience that was previously difficult to achieve with pure CSS.
 */

h1,h2,h3{ 
    text-align:center; 
    color: var(--text); 
    font-family: 'Lora', Georgia, 'Times New Roman', Times, serif; 
}

picture,picture img{ 
    display:block; 
    margin:0.5rem auto; 
    max-width:100%; height:auto; 
    border-radius:6px; 
}

header nav ul{ 
    display:flex; gap:6rem; 
    align-items:center; 
    justify-content:center; 
    margin:0; 
    padding:0; 
    list-style:none; 
}

header nav a{ 
    color: var(--accent, #c6ac8f); 
    text-decoration:none; 
    padding:0.35rem 0.6rem; 
    border-radius:6px; 
    font-weight:600;
    /* Baseline 2024: Entry animation setup */
    opacity: 1;
    transition: background-color 180ms ease, transform 140ms ease, color 150ms ease, opacity 0.4s ease;
    transition-behavior: allow-discrete;
}

/* Baseline 2024: @starting-style for navigation links */
@starting-style {
    header nav a {
        opacity: 0;
    }
}

header nav a:hover, header nav a:focus{ 
    background: rgba(234,224,213,0.08); 
    outline:none; 
}

a{ 
    color: var(--accent, #c6ac8f); 
}

footer{ 
    padding:1rem; 
    text-align:center; 
    color: rgba(234,224,213,0.75);
    /* Demonstrate Baseline 2024 feature: color-mix() - subtle accent background */
    background: color-mix(in srgb, var(--accent, #c6ac8f) 8%, var(--bg, #0a0908) 92%);
}

@media (max-width:640px){ 
    header nav ul{ 
        gap:0.6rem; flex-wrap:wrap; 
    } 
}

code, pre{ 
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, 'Courier New', monospace;
 }

/* Subtle transitions to improve perceived polish */
/* Note: article and header nav a already have transitions defined with @starting-style */

form fieldset, .contact-card{
    transition: box-shadow 220ms ease, transform 220ms ease;
}

.contact-card:hover, form fieldset:hover, article:hover{
    transform: translateY(-6px);
    box-shadow: 0 14px 30px rgba(96, 95, 95, 0.55);
}

picture img{
    transition: transform 220ms ease, box-shadow 220ms ease;
}

picture img:hover{
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 10px 24px rgba(0,0,0,0.45);
}

@media (prefers-reduced-motion: reduce) {
    header nav a,
    article,
    picture img {
        transition: none !important;
        transform: none !important;
    }
}


form fieldset{
    background: var(--surface);
    color: var(--surface-text);
    border: none;
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: 0 8px 20px rgba(2,6,8,0.6);
    margin: 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

form legend{ 
    color: var(--text); 
    font-weight: 700;
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

/* Labels stack on top of inputs */
form label{ 
    color: var(--text); 
    font-weight: 600;
    display: block;
    margin-bottom: 0.5rem;
}

/* Input and textarea styling */
form input[type="text"],
form input[type="email"],
form input[type="tel"],
form textarea{
    width: 100%;
    padding: 0.75rem;
    background: rgba(234, 224, 213, 0.05);
    border: 2px solid rgba(234, 224, 213, 0.15);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s ease, background 0.2s ease;
    box-sizing: border-box;
}

form input[type="text"]:focus,
form input[type="email"]:focus,
form input[type="tel"]:focus,
form textarea:focus{
    outline: none;
    border-color: var(--accent);
    background: rgba(234, 224, 213, 0.08);
}

form textarea{
    resize: vertical;
    min-height: 100px;
}

/* Submit button */
button[type="submit"]{
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 12px rgba(198, 172, 143, 0.3);
}

button[type="submit"]:hover{
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(198, 172, 143, 0.4);
}

button[type="submit"]:active{
    transform: translateY(0);
}

/* Output elements for error and info messages */
form output{
    display: block;
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    min-height: 1rem;
}

output[name="error"]{
    background: rgba(255, 107, 107, 0.15);
    border: 1px solid rgba(255, 107, 107, 0.4);
    color: #ff6b6b;
}

output[name="info"]{
    background: rgba(77, 171, 247, 0.15);
    border: 1px solid rgba(77, 171, 247, 0.4);
    color: #4dabf7;
}

/* Hide empty output elements */
output:empty{
    display: none;
}

.contact-card{
    background: var(--surface);
    color: var(--surface-text);
    border-radius: var(--radius);
    padding: 1rem;
    border: none;
    box-shadow: 0 8px 20px rgba(2,6,8,0.6);
    margin: 1rem 1rem;
    h3 {
        margin-top: 0;
    }
    .lead {
        font-size: 0.95rem;
    }
}

/* Demonstrate Baseline 2024 feature: color-mix() for wider gamut blending (EC) */
/* This class serves as an additional demonstration; color-mix() is also used in footer */
.demo-color-mix {
  background: color-mix(in srgb, var(--accent, #c6ac8f) 12%, transparent);
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
}

/* Demonstrate new :has() selector (EC) - style articles that contain a picture */
article:has(picture) {
  /* Adds subtle indicator when article contains images; preserves current look */
  position: relative;
}

/* Explicit responsive breakpoints for phone / tablet / desktop */
@media (max-width: 479px) {
  /* Phone */
  header nav ul {
    gap: 0.6rem;
  }
  article {
    margin: 1rem 0.5rem;
  }
}

@media (min-width: 480px) and (max-width: 1023px) {
  /* Tablet */
  header nav ul {
    gap: 2rem;
  }
}

@media (min-width: 1024px) {
  /* Desktop */
  header nav ul {
    gap: 6rem;
  }
}

/* Form validation styling */
form input:invalid:not(:placeholder-shown):not(:focus),
form textarea:invalid:not(:placeholder-shown):not(:focus){
    border-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.08);
}

form input:valid:not(:placeholder-shown),
form textarea:valid:not(:placeholder-shown){
    border-color: rgba(34, 197, 94, 0.4);
}

/* ============================================
   Theme Toggle 
   ============================================ */

#theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--accent);
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

#theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

#theme-toggle:active {
    transform: scale(0.95);
}

#theme-toggle:focus {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Light theme adjustments */
:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="light"] #theme-toggle {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

:root[data-theme="light"] footer {
    background: color-mix(in srgb, var(--accent) 15%, var(--bg) 85%);
}

/* Smooth transitions for theme switching */
body,
header,
main,
footer,
article,
form fieldset,
.contact-card,
input,
textarea,
button {
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ==========================
     View Transition API styles
     - provide root animation and opt-in named regions
     - respect prefers-reduced-motion
     ========================== */
/* Opt pages into browser-handled cross-document transitions (MPA-style) */
@view-transition {
    navigation: auto;
}
@media (prefers-reduced-motion: no-preference) {
    /* Encourage the UA to capture named regions by assigning view-transition-name */
    header { view-transition-name: header; }
    main { view-transition-name: main; }
    footer { view-transition-name: footer; }

    /* Root-level animations (fallback if per-region snapshots are not produced) */
    ::view-transition-old(root) {
        animation: vt-root-out 420ms cubic-bezier(.22,.9,.32,1) both;
    }
    ::view-transition-new(root) {
        animation: vt-root-in 420ms cubic-bezier(.22,.9,.32,1) both;
    }

    /* Gentle per-region fades/translates when user agent has captured them */
    ::view-transition-old(group(header)) {
        animation: vt-header-out 360ms ease both;
    }
    ::view-transition-new(group(header)) {
        animation: vt-header-in 360ms ease both;
    }

    ::view-transition-old(group(main)) {
        animation: vt-main-out 420ms ease both;
    }
    ::view-transition-new(group(main)) {
        animation: vt-main-in 420ms ease 60ms both;
    }

    @keyframes vt-root-out {
        from { transform: translateY(0); opacity: 1; }
        to   { transform: translateY(-6px) scale(.998); opacity: 0.0; }
    }
    @keyframes vt-root-in {
        from { transform: translateY(8px) scale(.998); opacity: 0; }
        to   { transform: translateY(0); opacity: 1; }
    }

    @keyframes vt-header-out { from { transform: translateY(0); opacity:1 } to { transform: translateY(-6px); opacity:0 } }
    @keyframes vt-header-in  { from { transform: translateY(6px); opacity:0 } to { transform: translateY(0); opacity:1 } }
    @keyframes vt-main-out   { from { transform: translateY(0); opacity:1 } to { transform: translateY(-8px); opacity:0 } }
    @keyframes vt-main-in    { from { transform: translateY(10px); opacity:0 } to { transform: translateY(0); opacity:1 } }
}

@media (prefers-reduced-motion: reduce) {
    /* Disable view transition animations for users who prefer reduced motion */
    ::view-transition-old(root), ::view-transition-new(root),
    ::view-transition-old(group(header)), ::view-transition-new(group(header)),
    ::view-transition-old(group(main)), ::view-transition-new(group(main)) {
        animation: none !important;
    }
}

/* ==========================
     Project Card Grid Layout
     - Uses CSS Grid for responsive card layout
     - CSS Variables for project-card customization
     ========================== */

/* CSS Variables for project-card styling */
:root {
    --card-bg: var(--surface);
    --card-border: 1px solid rgba(234, 224, 213, 0.15);
    --card-radius: 12px;
    --card-padding: 1.5rem;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --card-shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.4);
    --card-gap: 1rem;
    
    --card-title-size: 1.5rem;
    --card-title-weight: 700;
    --card-title-color: var(--text);
    
    --card-text-color: var(--surface-text);
    --card-text-size: 1rem;
    
    --card-meta-size: 0.875rem;
    --card-meta-color: rgba(234, 224, 213, 0.7);
    
    --card-image-radius: 8px;
    --card-image-bg: rgba(234, 224, 213, 0.05);
    
    --tag-bg: rgba(198, 172, 143, 0.2);
    --tag-color: var(--accent);
    --tag-radius: 16px;
    --tag-size: 0.875rem;
    
    --link-color: var(--accent);
    --link-hover-color: var(--text);
    --link-weight: 600;
    --link-size: 1rem;
    
    --transition-speed: 0.3s;
}

/* Light theme adjustments for project cards */
:root[data-theme="light"] {
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --card-shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.15);
    --card-border: 1px solid rgba(34, 51, 59, 0.15);
    --card-meta-color: rgba(10, 9, 8, 0.6);
    --tag-bg: rgba(34, 51, 59, 0.1);
    --card-image-bg: rgba(10, 9, 8, 0.03);
}

/* Projects Grid Container */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 4rem;
    padding: 4rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Responsive adjustments for grid */
@media (max-width: 640px) {
    .projects-grid {
        grid-template-columns: 1fr;
        gap: 2.5rem;
        padding: 2rem;
        margin: 1rem;
    }
}

@media (min-width: 641px) and (max-width: 1023px) {
    .projects-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 2.5rem;
    }
}

@media (min-width: 1024px) {
    .projects-grid {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    }
}

/* ==========================
     Data Load Buttons
     ========================== */

.data-load-btn {
    background: var(--accent);
    color: var(--bg);
    border: 2px solid var(--accent);
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 4px 12px rgba(198, 172, 143, 0.3);
    font-family: inherit;
}

.data-load-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(198, 172, 143, 0.4);
}

.data-load-btn:active {
    transform: translateY(0);
}

.data-load-btn:focus {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.data-load-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#load-status {
    min-height: 1.5rem;
    font-style: italic;
}

#load-status.success {
    color: #22c55e;
}

#load-status.error {
    color: #ef4444;
}

#load-status.loading {
    color: var(--accent);
}

/* ==========================
     CRUD Operations Styling
     ========================== */

.crud-form-section {
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.crud-form {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.crud-form fieldset {
    border: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
}

.crud-form legend {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    background: rgba(234, 224, 213, 0.05);
    border: 2px solid rgba(234, 224, 213, 0.15);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s ease, background 0.2s ease;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(234, 224, 213, 0.08);
}

.form-group small {
    display: block;
    font-size: 0.875rem;
    color: var(--card-meta-color);
    margin-top: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg);
    box-shadow: 0 4px 12px rgba(198, 172, 143, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(198, 172, 143, 0.4);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 2px solid var(--accent);
}

.btn-secondary:hover {
    background: rgba(198, 172, 143, 0.1);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Form status messages */
#form-status {
    display: block;
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 1rem;
    min-height: 1rem;
}

#form-status.success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.4);
    color: #22c55e;
}

#form-status.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

#form-status:empty {
    display: none;
}

/* CRUD List Section */
.crud-list-section {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    margin: 0;
}

.list-status {
    text-align: center;
    font-size: 1rem;
    margin: 2rem 0;
    padding: 1rem;
    border-radius: 6px;
}

.list-status.success {
    color: #22c55e;
}

.list-status.info {
    color: var(--accent);
    font-style: italic;
}

.list-status:empty {
    display: none;
}

/* Card wrapper with action buttons */
.card-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--surface);
    border-radius: 0 0 var(--card-radius) var(--card-radius);
    margin-top: -0.5rem;
}

.btn-edit,
.btn-delete {
    flex: 1;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
}

.btn-edit {
    background: #3b82f6;
    color: white;
}

.btn-edit:hover {
    background: #2563eb;
    transform: translateY(-2px);
}

.btn-delete {
    background: #ef4444;
    color: white;
}

.btn-delete:hover {
    background: #dc2626;
    transform: translateY(-2px);
}

.btn-edit:active,
.btn-delete:active {
    transform: translateY(0);
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .crud-form {
        padding: 1.5rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .crud-list-section {
        padding: 1rem;
    }
}
