:root {
  /* Colours: light-dark(<light>, <dark>), picked by the active color-scheme */
  color-scheme: light dark;   /* follow the OS preference by default */

  --bg:         light-dark(#f5f5f5, #0f1115);
  --panel:      light-dark(#fff, #151922);
  --text:       light-dark(#1a1a1a, #e8e8e8);
  --divider:    light-dark(#ddd, #2b2f3a);
  --shadow:     light-dark(rgb(0 0 0 / 8%), rgb(0 0 0 / 40%));
  --link:       light-dark(#226a88, #8ac8ff);
  --heading:    light-dark(#c22757, #ff6f9c);
  --heading-h3: light-dark(#a01c3f, #ff4f86);
  --subtext:    light-dark(#544b39, #b3a58a);
  --accent:     light-dark(#c22757, #ff6f9c);

  /* Layout */
  --container-max: 1220px;
  --panel-padding-y: 1.5rem;
  --panel-padding-x: 2rem;
  --panel-gap: 2rem;            /* between header/main/earlier/footer sections */
  --col-gap: 6rem;              /* main - sidebar gap */
  --section-gap: 1rem;          /* columns */
  --entry-gap: 2rem;            /* experience entries */
}

/* Theme toggle: switch to the opposite of the OS preference */
:root:has(#theme-toggle:checked) { color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root:has(#theme-toggle:checked) { color-scheme: light; }
}

/* Fallback for browsers without light-dark() (before ~2024): light theme only */
@supports not (color: light-dark(#000, #fff)) {
  :root,
  :root:has(#theme-toggle:checked) {
    color-scheme: light;

    --bg: #f5f5f5;
    --panel: #fff;
    --text: #1a1a1a;
    --divider: #ddd;
    --shadow: rgb(0 0 0 / 8%);
    --link: #226a88;
    --heading: #c22757;
    --heading-h3: #a01c3f;
    --subtext: #544b39;
    --accent: #c22757;
  }

  /* The toggle can't work without light-dark(); extra class so it beats the later .header-actions rule */
  .resume-header .header-actions { display: none; }
}

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

:target { scroll-margin-top: 1.5rem; }

body {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  margin: 0;
  padding: 2rem 1rem;
}

h1, h2 { color: var(--heading); }
h3 { color: var(--heading-h3); }
h4 { color: var(--subtext); }

h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  color: inherit;
  text-decoration: none;
}
h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover { text-decoration: underline; }

h1 a:focus-visible,
h2 a:focus-visible,
h3 a:focus-visible,
h4 a:focus-visible,
h5 a:focus-visible,
h6 a:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

a:focus:not(:focus-visible) { outline: none; }

h2 .anchor,
h3 .anchor,
h4 .anchor {
  margin-left: 0.4rem;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-weight: normal;
  color: var(--link);
}

h2:hover .anchor,
h2:focus-within .anchor,
h3:hover .anchor,
h3:focus-within .anchor,
h4:hover .anchor,
h4:focus-within .anchor { opacity: 1; }

.resume-header,
.layout,
.panel-section,
.site-footer {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto var(--panel-gap);
  padding: var(--panel-padding-y) var(--panel-padding-x);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow);
}

.layout {
  display: flex;
  flex-direction: column;
  gap: var(--panel-gap);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1fr);
  gap: var(--col-gap);
  align-items: start;
}

.main-content { grid-column: 1; }

.sidebar {
  grid-column: 2;
  padding-left: 2rem;
  border-left: 5px dotted var(--divider);
}

.resume-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2.5rem;
  position: relative;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--bg);
  padding: 8px 12px;
  z-index: 1000;
  text-decoration: none;
  font-weight: bold;
  border-radius: 0 0 4px 4px;
  transition: top 0.3s ease;
}
.skip-link:focus { top: 0; }

.profile-image img {
  display: block;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
}

.header-main { flex: 1; min-width: 200px; }
.header-main h1 { margin: 0 0 0.6rem; font-size: 2.5rem; }
.subtitle { margin: 0; font-size: 1.2rem; color: var(--subtext); }

.contact-info {
  min-width: 250px;
  text-align: left;
  font-size: 16px;
  font-weight: 400;
  line-height: 20px;
  color: var(--subtext);
}
.contact-info p { margin: 0 0 4px; }

.header-actions {
  position: absolute;
  inset: auto 0.5rem 0.5rem auto;
  display: flex;
  gap: 0.5rem;
  z-index: 10;
}

.pillbtn {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--divider);
  border-radius: 9999px;
  box-shadow: 0 1px 3px var(--shadow);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.pillbtn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#theme-toggle:focus-visible + .pillbtn {
  border-color: var(--accent);
  color: var(--accent);
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.main-content section { margin-bottom: var(--section-gap); }

.experience-section { padding-bottom: 0.5rem; }
.experience-entry { margin-bottom: var(--entry-gap); }
.experience-entry h4 { margin: 1em 0 0.2em; }
.experience-entry h4 + ul { margin-top: 0.25rem; }

.experience-header h3 {
  margin: 0;
  font-size: 1.25rem;
}

.experience-meta {
  margin-top: 0.25rem;
  font-size: 0.9rem;
  color: var(--subtext);
}

.experience-entry p { margin: 0.5rem 0; }
.experience-entry ul { margin: 0.5rem 0 0; padding-left: 1.5rem; }

.sidebar section {
  margin-bottom: var(--section-gap);
  padding-bottom: 0.75rem;
}

.sidebar h2 {
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.sidebar h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--subtext);
}

.cert-list {
  padding-left: 1.5rem;
  margin: 0;
}
.cert-list li { margin-bottom: 1rem; }

.cert-list a {
  font-weight: bold;
  color: var(--link);
  text-decoration: none;
}

.cert-list a:hover,
.cert-list a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

.cert-list .issuer,
.cert-list .date {
  font-size: 0.85em;
  color: var(--subtext);
  line-height: 1.4;
}

.site-footer {
  text-align: center;
}

.site-footer nav {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.footer-links li a {
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--link);
  text-decoration: none;
}

.footer-links li a:hover,
.footer-links li a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

.footer-meta {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dotted var(--divider);
}

.footer-meta p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--subtext);
}

/* Screen-reader only (accessible) */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;   /* deprecated, fallback for older browsers */
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* < 768px (mobile) */
@media (max-width: 768px) {
  .resume-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .profile-image { align-self: center; }

  .content-grid {
    grid-template-columns: 1fr;
    gap: var(--section-gap);
  }

  .main-content,
  .sidebar { grid-column: 1; }

  .sidebar {
    border-left: none;
    border-top: 3px dotted var(--divider);
    padding-left: 0;
    padding-top: 1rem;
  }
}

/* > 1600px (ultra wide) */
@media (min-width: 1600px) {
  body { font-size: 1.1rem; }
  .header-main h1 { font-size: 3rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  @page { size: a4; margin: 12mm; }

  /* Always print the light palette, also when the theme toggle is checked */
  :root,
  :root:has(#theme-toggle:checked) {
    color-scheme: light;

    --bg: #fff;
    --panel: #fff;
  }

  body { padding: 0; }

  .resume-header {
    flex-direction: row;
    align-items: center;
  }

  /* Same width as the sidebar column, text aligned with the sidebar text */
  .contact-info {
    flex: 0 0 calc((100% - 2rem) / 3.2);
    min-width: 0;
    padding-left: calc(2px + 1rem);
  }

  .resume-header,
  .layout,
  .panel-section,
  .site-footer {
    box-shadow: none;
    border-radius: 0;
    margin: 0 0 1rem;
    padding: 0;
  }

  .content-grid {
    grid-template-columns: minmax(0, 2.2fr) minmax(200px, 1fr);
    gap: 2rem;
  }

  .sidebar {
    border: 0;
    padding: 0;
    border-left: 2px dotted #ccc;
    padding-left: 1rem;
  }
  .sidebar section + section { margin-top: 6mm; }

  .footer-links,
  .anchor,
  .header-actions { display: none !important; }

  .main-content,
  .sidebar { grid-column: auto; }

  a { color: #000; text-decoration: underline; }

  /* Print external link addresses, except the Credly certificate links */
  a[href^="http"]:not(.cert-list a)::after {
    content: " (" attr(href) ")";
    font-size: 0.9em;
  }

  /* Avoid breaking inside key blocks */
  .experience-entry,
  .experience-entry ul,
  .experience-entry ol,
  .cert-list,
  .cert-list li,
  .sidebar section {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Keep headings with following content */
  h2, h3, h4 {
    break-after: avoid;
    page-break-after: avoid;
  }

  /* Keep first list item with its heading/intro paragraph */
  h2 + p, h3 + p, h4 + p,
  h2 + ul, h3 + ul, h4 + ul,
  h2 + ol, h3 + ol, h4 + ol {
    break-before: avoid;
    page-break-before: avoid;
  }

  p { orphans: 3; widows: 3; }

  .page-break {
    break-before: page;
    page-break-before: always;
  }
}
