/* ==========================================================================
   James Malvern — portfolio
   Plain CSS. Mobile-first. Dark mode follows the operating system.
   Understated academic style: hairlines, whitespace, one restrained accent.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Light theme (default) */
  --bg: #fcfcfa;              /* warm off-white */
  --text: #1a1a18;
  --muted: #5c5c54;
  --rule: #e2e2d9;            /* hairlines */
  --link: #0f6f68;            /* turquoise — AA on the off-white bg */
  --link-hover: #0a4f4a;

  /* Per-section pastel fills for the text blocks. Kept very pale so
     body text (--text) and links (--link) stay well above WCAG AA. */
  --tint-education: #e7f5f4;  --edge-education: #cde7e4;   /* turquoise */
  --tint-languages: #fbf3d9;  --edge-languages: #ecddab;   /* yellow    */
  --tint-projects:  #e9f4ec;  --edge-projects:  #cde6d3;   /* green     */
  --tint-skills:    #efeafa;  --edge-skills:    #dbd2ef;   /* lilac     */
  --tint-contact:   #fbeee3;  --edge-contact:   #efd9c5;   /* peach     */

  --maxw: 1140px;
  --sidebar-w: 232px;
  --measure: 44rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a17;
    --text: #eae9e1;
    --muted: #a6a69a;
    --rule: #34342c;
    --link: #74ddd6;
    --link-hover: #9fe9e4;

    --tint-education: #15201e;  --edge-education: #2b423f;
    --tint-languages: #232110;  --edge-languages: #443d22;
    --tint-projects:  #15211a;  --edge-projects:  #2b4233;
    --tint-skills:    #1e1a29;  --edge-skills:    #362e46;
    --tint-contact:   #261e17;  --edge-contact:   #45362a;
  }
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1.05rem;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

img { max-width: 100%; height: auto; }

p { max-width: var(--measure); margin: 0 0 1rem; }

a { color: var(--link); text-underline-offset: 0.15em; }
a:hover { color: var(--link-hover); }

h1, h2, h3 { line-height: 1.3; }

:where(a, button, input, textarea, .nav-toggle):focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 1000;
  background: var(--bg);
  color: var(--link);
  border: 1px solid var(--link);
  padding: 0.5rem 0.9rem;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 0.5rem; }

.hidden-visually {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.layout { max-width: var(--maxw); margin: 0 auto; }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.sidebar__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
}

.sidebar__identity {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.sidebar__photo {
  display: block;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2, var(--rule));
}

.sidebar__name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.sidebar__name a { text-decoration: none; color: var(--text); }
.sidebar__name a:hover { color: var(--link-hover); }

.sidebar__panel { display: none; padding: 0 1.25rem 1.25rem; }
body[data-nav-open="true"] .sidebar__panel { display: block; }

.sidebar__tagline { margin: 0 0 1.1rem; color: var(--muted); max-width: none; }

.sidebar nav ul,
.sidebar__contact { list-style: none; margin: 0; padding: 0; }

.sidebar nav a {
  display: block;
  padding: 0.35rem 0;
  text-decoration: none;
  color: var(--text);
}
.sidebar nav a:hover,
.sidebar nav a:focus-visible { color: var(--link); text-decoration: underline; }

.sidebar__contact {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.95rem;
  color: var(--muted);
}
.sidebar__contact li { margin: 0.3rem 0; }

/* Hamburger */
.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--rule);
  padding: 0.4rem 0.7rem;
  font: inherit;
  cursor: pointer;
}
.nav-toggle__box {
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  width: 18px; height: 12px;
}
.nav-toggle__line { display: block; height: 2px; background: currentColor; }

main { padding: 1.5rem 1.25rem 3rem; }

section[id] {
  scroll-margin-top: 4.5rem;
  padding: 1.75rem 0.75rem;
  margin: 0 -0.75rem;
  border-top: 1px solid var(--rule);
}
section[id]:first-child { border-top: 0; }

/* Each section passes its own pastel down to the blocks inside it. */
#education { --tint: var(--tint-education); --edge: var(--edge-education); }
#languages { --tint: var(--tint-languages); --edge: var(--edge-languages); }
#projects  { --tint: var(--tint-projects);  --edge: var(--edge-projects);  }
#skills    { --tint: var(--tint-skills);    --edge: var(--edge-skills);    }
#contact   { --tint: var(--tint-contact);   --edge: var(--edge-contact);   }

section > h2 {
  margin: 0 0 1.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

footer {
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.9rem;
}
footer p { margin: 0; }
.footer__updated { margin-top: 0.35rem; font-size: 0.85rem; }
footer .footer__note {
  max-width: 60ch;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
}
.footer__note-label { font-weight: 700; }

/* --------------------------------------------------------------------------
   Content
   -------------------------------------------------------------------------- */

.stack { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }

.entry {
  max-width: var(--measure);
  background: var(--tint);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 1rem 1.15rem;
}
.entry__title { margin: 0 0 0.15rem; font-size: 1.1rem; font-weight: 700; }
.entry__meta { margin: 0 0 0.4rem; color: var(--muted); font-style: italic; }
.entry__note { margin: 0; }
.entry__links { margin: 0.6rem 0 0; }
.entry__filemeta { color: var(--muted); font-size: 0.9em; white-space: nowrap; }
.new-tab-icon { font-size: 0.85em; }

.tags {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: var(--measure);
}
.tags li {
  background: var(--tint);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
}

.projects {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}
.project {
  max-width: var(--measure);
  background: var(--tint);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 1rem 1.15rem;
}
.project__name { margin: 0 0 0.25rem; font-size: 1.1rem; font-weight: 700; }

/* Small site favicons next to project names / project links. */
.site-icon {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  object-fit: contain;
  vertical-align: -0.2em;
}
.project__name .site-icon { margin-right: 0.5rem; }
.site-icon--inline {
  width: 16px;
  height: 16px;
  margin-right: 0.35rem;
  vertical-align: -0.15em;
}
.project__desc { margin: 0 0 0.4rem; color: var(--text); }

/* Tech stack — its own strip below the description. */
.project__stack {
  list-style: none;
  margin: 0.85rem 0 0.6rem;
  padding: 0.6rem 0 0;
  border-top: 1px solid var(--edge);
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.project__stack li:not(:last-child)::after {
  content: "·";
  margin-left: 0.5rem;
}
.entry__stack { margin: 0.5rem 0 0; padding: 0; border-top: 0; }

.project__link { text-decoration: none; position: relative; }
.project__link:hover { text-decoration: underline; }

/* Reveal the destination URL on hover / keyboard focus. */
.project__link[data-url]::after {
  content: attr(data-url);
  position: absolute;
  left: 0;
  top: calc(100% + 0.4rem);
  z-index: 1;
  white-space: nowrap;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.1rem 0.45rem;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.project__link[data-url]:hover::after,
.project__link[data-url]:focus-visible::after { opacity: 1; }

/* --------------------------------------------------------------------------
   Contact form
   -------------------------------------------------------------------------- */

.contact-form {
  display: grid;
  gap: 1rem;
  max-width: 32rem;
  margin-top: 1rem;
  background: var(--tint);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 1.25rem;
}
.field { display: grid; gap: 0.3rem; }
.field label { font-weight: 700; }

.contact-form input,
.contact-form textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  padding: 0.55rem 0.65rem;
  width: 100%;
}
.contact-form input:focus,
.contact-form textarea:focus { border-color: var(--link); }
.contact-form textarea { resize: vertical; }

.contact-form button {
  justify-self: start;
  font: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--text);
  padding: 0.5rem 1.4rem;
}
.contact-form button:hover { background: var(--text); color: var(--bg); }

/* --------------------------------------------------------------------------
   Standalone pages (thanks / 404 / privacy) — a plain centred column,
   not the homepage sidebar grid.
   -------------------------------------------------------------------------- */

.page {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}
.page__brand {
  display: inline-block;
  margin-bottom: 2rem;
  font-size: 1.15rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}
.page__brand:hover { color: var(--link-hover); }
.page h1 { margin: 0 0 0.75rem; font-size: 1.9rem; }
.page h2 {
  margin: 2rem 0 0.4rem;
  font-size: 1.15rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}
.page p { margin: 0 0 1rem; }

.button {
  display: inline-block;
  margin-top: 0.5rem;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  background: var(--link);
  color: var(--bg);
  border: 1px solid var(--link);
  border-radius: 4px;
  padding: 0.6rem 1.3rem;
}
.button:hover { background: var(--link-hover); border-color: var(--link-hover); color: var(--bg); }

/* --------------------------------------------------------------------------
   Desktop — narrow reading column beside a quiet sidebar
   -------------------------------------------------------------------------- */

@media (min-width: 820px) {
  .layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-areas:
      "sidebar main"
      "sidebar footer";
    align-items: start;
    gap: 0 3rem;
    padding: 0 1.5rem;
  }

  .sidebar {
    grid-area: sidebar;
    align-self: stretch;
    height: 100vh;
    overflow-y: auto;
    border-bottom: 0;
    border-right: 1px solid var(--rule);
    padding: 2.5rem 1.5rem 2rem 0;
  }
  .sidebar__bar { display: block; padding: 0; }
  .sidebar__identity { display: block; text-align: center; }
  .sidebar__photo { width: 104px; height: 104px; margin: 0 auto 0.9rem; }
  .sidebar__name { font-size: 1.3rem; }
  .sidebar__panel { display: block !important; padding: 1.5rem 0 0; }

  .nav-toggle { display: none; }

  main { grid-area: main; padding: 2.5rem 0; max-width: 52rem; }
  footer { grid-area: footer; padding: 1.5rem 0 3rem; }

  section[id] { scroll-margin-top: 1.5rem; padding: 2rem 1rem; margin: 0 -1rem; }

  .projects { grid-template-columns: 1fr 1fr; gap: 2rem 3rem; }
  .project { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* --------------------------------------------------------------------------
   Print — "Save as PDF" produces a clean CV. Sidebar nav, hamburger and the
   contact form are dropped; pastels flatten; link destinations are spelled out.
   -------------------------------------------------------------------------- */

@media print {
  :root {
    --bg: #fff; --text: #000; --muted: #333; --rule: #bbb;
    --link: #000; --link-hover: #000;
  }

  @page { margin: 1.6cm; }

  .skip-link,
  .nav-toggle,
  .sidebar nav,
  .sidebar__photo,
  .new-tab-icon,
  .site-icon,
  .contact-form { display: none !important; }

  body { font-size: 10.5pt; line-height: 1.45; }

  .layout { display: block; max-width: none; padding: 0; gap: 0; }

  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
    border: 0;
    padding: 0 0 0.4cm;
  }
  .sidebar__bar { padding: 0; }
  /* Print width is < 820px, so the desktop rule that reveals the panel
     doesn't fire — force it open here so the tagline + contacts print. */
  .sidebar__panel { display: block !important; padding: 0; }
  .sidebar__name { font-size: 19pt; }
  .sidebar__tagline { margin: 0.2cm 0 0; }
  .sidebar__contact { border-top: 0; margin-top: 0.25cm; padding-top: 0; }

  main { padding: 0; max-width: none; }
  footer { padding: 0.4cm 0 0; }

  section[id] {
    padding: 0.35cm 0;
    margin: 0;
    border-top: 1px solid var(--rule);
  }
  section > h2 { color: #000; break-after: avoid; }

  /* Flatten the pastel cards */
  .entry,
  .project,
  .contact-form { background: none !important; border: 1px solid #ccc !important; }
  .entry,
  .project { break-inside: avoid; }
  .tags li { background: none !important; border: 1px solid #ccc !important; }
  .project__stack { border-top-color: #ccc; }

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

  /* Spell out where links go, on paper */
  .project__link[data-url]::after {
    content: " — " attr(data-url);
    position: static;
    opacity: 1;
    background: none;
    border: 0;
    padding: 0;
    font-size: inherit;
    color: #000;
    white-space: normal;
  }
  .entry__links a[href^="http"]::after,
  .sidebar__contact a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    word-break: break-all;
  }
}
