/* ==========================================================================
   1. CSS Custom Properties
   ========================================================================== */

:root {
  /* Colors - with sRGB fallback for older browsers */
  --color-light: rgba(225, 235, 238, 1);
  --color-dark: rgb(0, 88, 120);
  --text-color: var(--color-light);
  --bg-color: var(--color-dark);

  /* Typography */
  --font-sans: 'Brockmann', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-size-base: 20px;
  --font-size-sm: 0.875rem;
  --font-size-md: 1.125rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.875rem;
  --line-height-base: 1.5;
  --line-height-relaxed: 1.6;
  --line-height-tight: 1.1;
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;

  /* Opacity */
  --opacity-muted: 0.7;
  --opacity-subtle: 0.8;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  --spacing-section: 4rem;

  /* Layout */
  --max-width-content: 56rem;
  --max-width-reading: 40ch;
  --max-width-narrow: 25ch;
  --max-width-cv-text: 50ch;
  --photo-size: 16rem;

  /* Transitions */
  --transition-fast: 200ms;
}

/* Enhanced color for browsers supporting display-p3 */
@supports (color: color(display-p3 0 0 0)) {
  :root {
    --color-dark: color(display-p3 0 0.346 0.47);
  }
}

/* ==========================================================================
   2. Font Faces
   ========================================================================== */

@font-face {
  font-family: 'Brockmann';
  src: url('/fonts/brockmann/brockmann-regular-webfont.woff2') format('woff2'),
       url('/fonts/brockmann/brockmann-regular-webfont.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Brockmann';
  src: url('/fonts/brockmann/brockmann-medium-webfont.woff2') format('woff2'),
       url('/fonts/brockmann/brockmann-medium-webfont.woff') format('woff');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Brockmann';
  src: url('/fonts/brockmann/brockmann-semibold-webfont.woff2') format('woff2'),
       url('/fonts/brockmann/brockmann-semibold-webfont.woff') format('woff');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Brockmann';
  src: url('/fonts/brockmann/brockmann-bold-webfont.woff2') format('woff2'),
       url('/fonts/brockmann/brockmann-bold-webfont.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   3. Base Styles
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  font-family: var(--font-sans);
  color: var(--text-color);
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  padding: var(--spacing-sm);
  margin: 0;

  @media (min-width: 400px) {
    padding: var(--spacing-md);
  }

  @media (min-width: 600px) {
    padding: var(--spacing-xl);
  }
}

::selection {
  color: var(--bg-color);
  background-color: var(--text-color);
}

/* ==========================================================================
   4. Layout
   ========================================================================== */

main {
  max-width: var(--max-width-content);
  margin-inline: auto;
  padding: var(--spacing-md);

  @media (min-width: 768px) {
    padding: var(--spacing-xl);
  }

  /* Scoped link styles */
  & a {
    color: inherit;
    text-decoration: underline;
    transition: all var(--transition-fast);

    &:hover {
      text-decoration: none;
      background-color: black;
      color: white;
    }
  }
}

.content-grid {
  @media (min-width: 768px) {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--spacing-xl);
    align-items: start;
  }
}

.content-primary {
  @media (min-width: 768px) {
    grid-row: 1;
    grid-column: 1;
  }
}

.content-secondary {
  @media (min-width: 768px) {
    grid-row: 1;
    grid-column: 2;
  }
}

/* ==========================================================================
   5. Typography
   ========================================================================== */

h1 {
  /* Fluid typography: 2rem at 320px → 3.75rem at 768px */
  font-size: clamp(2rem, 1.25rem + 3.3vw, 3.75rem);
  font-weight: var(--font-weight-light);
  line-height: var(--line-height-tight);
  margin-block: var(--spacing-2xl);

  & span {
    color: white;
  }
}

h2,
h3,
h4 {
  margin-block: 0;
}

h2 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-light);
  line-height: var(--line-height-relaxed);
  margin-block-end: var(--spacing-md);
  color: white;
}

h3 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-light);
}

h4 {
  font-size: 1rem;
  font-weight: var(--font-weight-medium);
}

/* ==========================================================================
   6. Bio Section
   ========================================================================== */

.bio-section {
  & p {
    max-width: var(--max-width-narrow);
    margin-block-end: var(--spacing-md);
    font-weight: var(--font-weight-light);
    /* Fluid typography: 1.25rem at 320px → 1.875rem at 768px */
    font-size: clamp(1.25rem, 0.9rem + 1.5vw, 1.875rem);
    line-height: var(--line-height-relaxed);
  }
}

/* ==========================================================================
   7. Profile Photo
   ========================================================================== */

.profile-photo {
  width: var(--photo-size);
  height: var(--photo-size);
  margin: 0;
  margin-block: 1.25rem var(--spacing-xl);

  @media (min-width: 768px) {
    margin-block-end: 0;
    flex-shrink: 0;
  }

  & img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.5rem;
  }
}

/* ==========================================================================
   8. Links Section
   ========================================================================== */

.links-section {
  margin-block-start: var(--spacing-section);

  & ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
  }

  & li {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-light);
  }
}

/* ==========================================================================
   9. CV Section
   ========================================================================== */

.cv-section {
  margin-block-start: var(--spacing-section);

  & > ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
  }
}

.cv-header,
.cv-entry-header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);

  @media (min-width: 400px) {
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
  }
}

.cv-header {
  margin-block-end: var(--spacing-md);
}

.cv-entry {
  margin-block-end: var(--spacing-lg);
}

.cv-entry-header span {
  font-size: var(--font-size-sm);
  opacity: var(--opacity-subtle);
}

.cv-entry-meta {
  font-size: var(--font-size-sm);
  opacity: var(--opacity-muted);
  margin-block-start: var(--spacing-xs);
}

.cv-entry-description {
  margin-block-start: var(--spacing-sm);
  max-width: var(--max-width-cv-text);

  & p {
    font-size: var(--font-size-md);
    line-height: var(--line-height-relaxed);
  }
}

.cv-projects {
  margin-block-start: var(--spacing-md);
  margin-inline-start: var(--spacing-md);
  padding-inline-start: var(--spacing-md);
  list-style: disc;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);

  & p {
    font-size: var(--font-size-sm);
    margin: 0;
  }

  & .project-learned {
    font-style: italic;
    opacity: var(--opacity-muted);
  }
}

/* ==========================================================================
   10. CV Toggle (CSS-only with checkbox hack)
   ========================================================================== */

/* Hide the checkbox input */
.cv-toggle-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Base toggle button styles */
.toggle-button {
  appearance: none;
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-light);
  border: 1px solid white;
  color: white;
  background: transparent;
  border-radius: 9999px;
  padding: var(--spacing-sm) var(--spacing-md);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);

  @media (min-width: 600px) {
    padding: var(--spacing-sm) var(--spacing-xl);
  }

  &:hover {
    background-color: white;
    color: black;
  }

  &:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
  }

  /* Show short text on mobile, full text on wider screens */
  & .toggle-text-short {
    display: inline;

    @media (min-width: 600px) {
      display: none;
    }
  }

  & .toggle-text-full {
    display: none;

    @media (min-width: 600px) {
      display: inline;
    }
  }
}

/* Toggle text visibility based on checkbox state */
.toggle-show { display: inline; }
.toggle-hide { display: none; }

.cv-toggle-input:checked + .cv-header .toggle-show { display: none; }
.cv-toggle-input:checked + .cv-header .toggle-hide { display: inline; }

/* Hide non-featured entries and projects by default */
.cv-entry--hidden { display: none; }
.cv-projects { display: none; }

/* Show when toggle is checked */
.cv-toggle-input:checked ~ ul .cv-entry--hidden { display: block; }
.cv-toggle-input:checked ~ ul .cv-projects { display: flex; }

/* ==========================================================================
   11. Print Styles
   ========================================================================== */

@media print {
  :root {
    --bg-color: white;
    --text-color: black;
    --color-light: black;
  }

  body {
    background-color: white;
    padding: 0;
  }

  h1,
  h2,
  h3,
  h4,
  h1 span {
    color: black;
  }

  main {
    max-width: none;
    padding: 0;

    & a {
      color: black;
      text-decoration: underline;

      &:hover {
        background-color: transparent;
        color: black;
      }

      &::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        opacity: var(--opacity-muted);
      }
    }
  }

  .toggle-button {
    display: none;
  }

  .cv-toggle-input {
    display: none;
  }

  .profile-photo {
    width: 8rem;
    height: 8rem;
  }

  .cv-section {
    break-inside: avoid;
  }

  .cv-entry {
    break-inside: avoid;
  }

  /* Show all entries and projects in print */
  .cv-entry--hidden {
    display: block;
  }

  .cv-projects {
    display: flex;
  }
}
