@layer reset, base, theme, layout, components, utilities, print;

/* ============================================
   RESET
   ============================================ */
@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  ul, ol {
    list-style: none;
  }
}

/* ============================================
   BASE
   ============================================ */
@layer base {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  h1, h2, h3 {
    text-wrap: balance;
    line-height: 1.25;
  }

  p, li {
    text-wrap: pretty;
  }

  a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 0.15em;
  }

  img {
    max-width: 100%;
    display: block;
  }
}

/* ============================================
   THEME — Design Tokens
   ============================================ */
@layer theme {
  :root {
    color-scheme: light dark;

    /* --- Neutrals --- */
    --color-text: light-dark(oklch(20% 0 0), oklch(90% 0 0));
    --color-heading: light-dark(oklch(12% 0 0), oklch(95% 0 0));
    --color-muted: light-dark(oklch(45% 0 0), oklch(65% 0 0));
    --color-border: light-dark(oklch(85% 0 0), oklch(22% 0 0));
    --color-bg: light-dark(oklch(100% 0 0), oklch(10% 0.005 260));
    --color-bg-alt: light-dark(oklch(97% 0.015 75), oklch(13% 0.008 260));

    /* --- Amber Accent (dual WCAG strategy) --- */
    /* accent: AA compliant for normal text on bg (>=4.5:1) */
    --color-accent: light-dark(oklch(45% 0.16 70), oklch(80% 0.15 75));
    /* accent-deco: borders, large text only (>=3:1). NEVER for normal text on light bg */
    --color-accent-deco: light-dark(oklch(60% 0.17 75), oklch(72% 0.15 75));
    /* accent-subtle: metric readout backgrounds */
    --color-accent-subtle: light-dark(
      color-mix(in oklch, oklch(60% 0.17 75) 10%, white),
      color-mix(in oklch, oklch(72% 0.15 75) 12%, oklch(10% 0 0))
    );
    /* accent-hover: link hover state (AA on bg and bg-alt) */
    --color-accent-hover: light-dark(oklch(38% 0.14 70), oklch(88% 0.12 75));

    /* --- Semantic Status --- */
    --color-status-active: light-dark(oklch(55% 0.15 145), oklch(72% 0.15 145));
    --color-status-paused: light-dark(oklch(55% 0.02 0), oklch(65% 0.02 0));

    /* --- Typography --- */
    --font-mono: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo,
                 Consolas, monospace;

    --text-3xl: clamp(2rem, 1.5rem + 2.5vw, 2.75rem);
    --text-2xl: clamp(1.75rem, 1.2rem + 2vw, 2.5rem);
    --text-xl: clamp(1.25rem, 1rem + 1.5vw, 1.75rem);
    --text-lg: clamp(1.1rem, 0.95rem + 0.8vw, 1.35rem);
    --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --text-sm: clamp(0.85rem, 0.8rem + 0.25vw, 0.9rem);
    --text-xs: clamp(0.8rem, 0.75rem + 0.25vw, 0.85rem);

    /* --- Spacing --- */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    --section-gap: clamp(2rem, 4vw, 3rem);
    --component-gap: clamp(0.75rem, 1.5vw, 1.25rem);
    --page-padding: clamp(1rem, 3vw, 2rem);
    --header-padding: clamp(1.5rem, 3vw, 2.5rem);

    /* --- Radius --- */
    --radius-xs: 2px;
    --radius-sm: 4px;
    --radius-md: 6px;

    /* --- Shadow opacity (light-dark for color component only) --- */
    --shadow-color: light-dark(oklch(0% 0 0 / 0.06), oklch(0% 0 0 / 0.2));
    --shadow-color-strong: light-dark(oklch(0% 0 0 / 0.1), oklch(0% 0 0 / 0.3));

    /* --- Shadows (use shadow-color for adaptive opacity) --- */
    --shadow-xs: 0 1px 2px 0 var(--shadow-color);
    --shadow-sm: 0 2px 4px -1px var(--shadow-color);
    --shadow-md: 0 4px 8px -2px var(--shadow-color-strong);

    /* --- Motion --- */
    --duration-fast: 100ms;
    --duration-normal: 200ms;
    --duration-slow: 300ms;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  }
}

/* ============================================
   LAYOUT
   ============================================ */
@layer layout {
  body {
    background: var(--color-bg);
    color: var(--color-text);
    transition: background var(--duration-normal) var(--ease-out),
                color var(--duration-normal) var(--ease-out);
  }

  .cv {
    width: min(900px, 100%);
    margin-inline: auto;
    padding-inline: var(--page-padding);
    padding-block: var(--space-8);
    position: relative;
  }

  .cv > main {
    display: flex;
    flex-direction: column;
    gap: var(--section-gap);
  }

  .cv > main > section {
    display: flex;
    flex-direction: column;
    gap: var(--component-gap);
  }
}

/* ============================================
   COMPONENTS
   ============================================ */
@layer components {

  /* --- Header (brand zone) --- */
  .cv-header {
    background: var(--color-bg-alt);
    padding: var(--header-padding);
    margin-bottom: var(--space-6);
    border-bottom: 3px solid var(--color-accent-deco);
    border-radius: var(--radius-sm);
  }

  .cv-name {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--color-heading);
    letter-spacing: -0.03em;
    line-height: 1.15;
  }

  .cv-title {
    font-size: var(--text-lg);
    font-weight: 400;
    color: var(--color-muted);
    margin-top: var(--space-1);
  }

  .cv-contact {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
  }

  .cv-contact li {
    display: flex;
    align-items: center;
    gap: var(--space-1);
  }

  .cv-contact a {
    color: var(--color-accent);
    transition: color var(--duration-fast) var(--ease-out);

    &:hover {
      color: var(--color-accent-hover);
    }
  }

  .cv-contact .separator {
    color: var(--color-border);
    user-select: none;
  }

  /* --- Summary --- */
  .cv-summary {
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--color-text);
    border-left: 3px solid var(--color-accent-deco);
    padding-left: var(--space-4);
  }

  /* --- Metric Readout Bar --- */
  .metrics-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
    background: var(--color-accent-subtle);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-xs);
  }

  .metric {
    padding: var(--space-2) var(--space-3);
    text-align: center;
    border-right: 1px solid var(--color-border);

    &:last-child {
      border-right: none;
    }
  }

  .metric-value {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--color-accent);
    line-height: 1.2;
  }

  .metric-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    margin-top: var(--space-1);
  }

  /* --- Section Titles --- */
  .section-title {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--color-heading);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-left: 3px solid var(--color-accent-deco);
    padding-left: var(--space-3);
  }

  .section-title--secondary {
    border-left-color: var(--color-border);
  }

  /* --- Project Entry --- */
  .project {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .project-featured {
    background: var(--color-bg-alt);
    border-left: 4px solid var(--color-accent-deco);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--duration-fast) var(--ease-out);

    &:hover {
      box-shadow: var(--shadow-sm);
    }
  }

  .project--active {
    border-left-color: var(--color-status-active);
  }

  .project--paused {
    border-left-color: var(--color-status-paused);
  }

  .project-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-2);
  }

  .project-name {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--color-heading);
  }

  .project-status {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-muted);
  }

  .project-desc {
    color: var(--color-text);
    font-size: var(--text-base);
  }

  .project-achievements {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding-left: var(--space-4);
  }

  .project-achievements li {
    list-style: disc;
    font-size: var(--text-base);
    color: var(--color-text);

    &::marker {
      color: var(--color-accent-deco);
    }
  }

  .project-stack {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-accent);
  }

  /* --- Compact Entries (Experience & Education) --- */
  .compact-entries {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .compact-entry {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-3);
  }

  .compact-label {
    font-size: var(--text-base);
    color: var(--color-text);
  }

  .compact-date {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-muted);
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* --- Skills --- */
  .skills-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .skills-category {
    font-size: var(--text-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    margin-bottom: var(--space-1);
  }

  .skills-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding-left: var(--space-4);
  }

  .skills-list li {
    list-style: disc;
    font-size: var(--text-base);
    color: var(--color-text);

    &::marker {
      color: var(--color-accent-deco);
    }
  }


  /* --- Skills Tech Keywords --- */
  .skills-tech {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-muted);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-2);
  }

  /* --- Experience Main Entry --- */
  .experience-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }

  /* --- Compact Row --- */
  .compact-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
  }

  /* --- Languages --- */
  .language-entry {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: baseline;
  }

  .education-detail {
    font-weight: 400;
    font-size: var(--text-sm);
    color: var(--color-muted);
  }

  .language-name {
    font-weight: 600;
    color: var(--color-heading);
  }

  .language-level {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-accent);
  }

  .language-detail {
    font-size: var(--text-sm);
    color: var(--color-muted);
  }

  /* --- Theme Toggle --- */
  .theme-toggle {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    background: var(--color-bg-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xs);
    padding: var(--space-1) var(--space-2);
    cursor: pointer;
    font-size: var(--text-sm);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--duration-fast) var(--ease-out);

    &:hover {
      border-color: var(--color-accent-deco);
    }
  }

  /* --- Focus --- */
  :focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
    position: relative;
    z-index: 1;
  }
}

/* ============================================
   UTILITIES
   ============================================ */
@layer utilities {
  .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;
  }
}

/* ============================================
   PRINT
   ============================================ */
@layer print {
  @page {
    size: A4 portrait;
    margin: 1.5cm 1.8cm;
  }

  @media print {
    :root { color-scheme: light; }

    /* ---- Base sizing ---- */
    html { font-size: 9.5pt; }
    body {
      background: white;
      color: #000;
      font-size: 9.5pt;
      line-height: 1.45;
    }

    /* ---- Layout ---- */
    .cv { max-width: 100%; padding: 0; }
    .cv > main { gap: 1rem; }
    .cv > main > section { gap: 0.6rem; }

    /* ---- Header ---- */
    .cv-header {
      background: transparent;
      padding: 0.4rem 0;
      margin-bottom: 0.8rem;
      border-bottom: 2px solid oklch(45% 0.16 70);
      border-radius: 0;
    }
    .cv-name { font-size: 14pt; color: oklch(12% 0 0); }
    .cv-title { font-size: 9.5pt; margin-top: 3pt; }
    .cv-contact { margin-top: 0.3rem; }

    /* ---- Font sizes ---- */
    .section-title {
      font-size: 10.5pt;
      padding-left: 0.5rem;
      padding-bottom: 0.1rem;
      color: oklch(12% 0 0);
    }
    .project-name { font-size: 10pt; }
    .cv-contact, .project-status, .compact-date { font-size: 8pt; }
    .compact-label { font-size: 9.5pt; }
    .education-detail { font-size: 8pt; }
    .skills-category { font-size: 8.5pt; margin-bottom: 0.2rem; }

    /* Consistent body text */
    .cv-summary,
    .project-desc,
    .project-achievements li,
    .skills-list li { font-size: 9.5pt; }

    /* ---- Metrics bar ---- */
    .metrics-bar { border: 1px solid #999; background: transparent; }
    .metric { padding: 0.25rem 0.5rem; border-right-color: #ccc; }
    .metric-value { font-size: 10pt; color: oklch(45% 0.16 70); }
    .metric-label { font-size: 7pt; margin-top: 0.05rem; }

    /* ---- Skills ---- */
    #skills { margin-top: 0.8rem; }
    .skills-group { gap: 0.2rem; margin-bottom: 0.6rem; }
    .skills-list { gap: 0.15rem; }
    .skills-tech {
      font-size: 7.5pt;
      padding-top: 0.35rem;
      margin-top: 0.35rem;
    }

    /* ---- Projects ---- */
    .project { gap: 0.25rem; }
    .project-achievements { gap: 0.15rem; padding-left: 1.2rem; }
    .project-featured {
      background: transparent;
      padding: 0.4rem 0 0.4rem 0.6rem;
      border-radius: 0;
      border-left-width: 3px;
      margin-bottom: 0.4rem;
    }
    .project-stack { font-size: 8pt; margin-top: 0.2rem; }
    .cv-summary { padding-left: 0.7rem; }

    /* ---- Experience ---- */
    .experience-main { gap: 0.25rem; margin-bottom: 0.4rem; }
    .compact-entries { gap: 0.25rem; }
    .compact-row { display: flex; gap: 2.5rem; }

    /* ---- Page breaks ----
       Page 1: Header + Profil + Compétences
       Page 2: Projets + Expérience + Formation + Langues */
    #projects { break-before: page; }
    .compact-entry, .experience-main, .skills-group,
    .metrics-bar, .project-featured { break-inside: avoid; }
    h2, h3 { break-after: avoid; }
    p, li { orphans: 2; widows: 2; }

    /* ---- Hide non-print ---- */
    .no-print, .theme-toggle { display: none !important; }

    /* ---- Links ---- */
    a[href^="http"]::after {
      content: " (" attr(href) ")";
      font-size: 7pt;
      color: #666;
      word-break: break-all;
    }
    a[href^="mailto"]::after { content: none; }
    .cv-contact a[href^="http"]::after { content: none; }

    /* ---- Cleanup ---- */
    * {
      box-shadow: none !important;
      text-shadow: none !important;
      animation: none !important;
      transition: none !important;
    }

    /* ---- Accent colors ---- */
    .cv-summary, .project-featured, .section-title { border-color: oklch(60% 0.17 75); }
    .project-achievements li::marker, .skills-list li::marker { color: oklch(60% 0.17 75); }
    .cv-contact a, .project-stack { color: #333; }
  }
}
