/* ==========================================================================
   Luca Martucci — site stylesheet
   Serif text (Source Serif 4) for reading, Inter for interface details.
   ========================================================================== */

:root {
  --bg:           #fbfaf7;
  --text:         #1c2330;
  --muted:        #5a6474;
  --rule:         #e6e2d9;
  --rule-strong:  #d4cebf;
  --accent:       #1f4a8a;
  --accent-ink:   #ffffff;

  --sidebar-bg:    #0f2341;
  --sidebar-text:  #ffffff;
  --sidebar-muted: rgba(255, 255, 255, 0.72);
  --gold:          #e2a93b;

  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  --sidebar-w: 17rem;
  --measure:   42rem;
}

/* Dark theme: chosen with the switch, or the system setting when no choice is stored
   (the no-JavaScript fallback is the media query). */
:root[data-theme="dark"] {
  --bg:          #12161d;
  --text:        #e4e7ec;
  --muted:       #9ca5b4;
  --rule:        #252b35;
  --rule-strong: #343c49;
  --accent:      #8fb5ee;
  --accent-ink:  #0d1420;
  --sidebar-bg:  #0b1830;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:          #12161d;
    --text:        #e4e7ec;
    --muted:       #9ca5b4;
    --rule:        #252b35;
    --rule-strong: #343c49;
    --accent:      #8fb5ee;
    --accent-ink:  #0d1420;
    --sidebar-bg:  #0b1830;
    color-scheme: dark;
  }
}
:root[data-theme="light"] { color-scheme: light; }

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

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

html {
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

p, ul, ol { margin: 0 0 1rem; }
img { max-width: 100%; height: auto; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  transition: color .15s ease, text-decoration-color .15s ease, background-color .15s ease, border-color .15s ease;
}
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0 0 .75rem;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 10;
  padding: .5rem .9rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--sans);
  font-size: .875rem;
  text-decoration: none;
  border-radius: 4px;
}
.skip-link:focus { top: 1rem; }

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  font-family: var(--sans);
}

.sidebar-inner { padding: 3.5rem 2.25rem; }

.sidebar-brand {
  display: block;
  color: var(--sidebar-text);
  text-decoration: none;
}
.sidebar-brand:hover .sidebar-name { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }

.crest {
  display: block;
  width: 64px;
  height: auto;
  margin-bottom: 1.5rem;
}

.sidebar-name {
  display: block;
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.sidebar-nav {
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.nav-item {
  display: block;
  padding: .35rem 0 .35rem .85rem;
  margin-left: -.85rem;
  border-left: 2px solid transparent;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .95rem;
  line-height: 1.4;
}
.nav-item:hover { text-decoration: underline; text-underline-offset: .25em; text-decoration-color: rgba(255,255,255,.5); }

.nav-section { font-weight: 600; }
.nav-section.is-current { border-left-color: var(--gold); }

.nav-external {
  font-weight: 400;
  color: var(--sidebar-muted);
}
.nav-external i { font-size: .65em; margin-left: .3em; vertical-align: .1em; }

.sidebar :focus-visible { outline-color: var(--gold); }

/* Theme switch */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin-top: 2rem;
  padding: .4rem .75rem;
  font: 500 .8125rem/1.2 var(--sans);
  color: var(--sidebar-muted);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.theme-toggle:hover {
  color: var(--sidebar-text);
  border-color: rgba(255, 255, 255, .5);
  background: rgba(255, 255, 255, .06);
}
.theme-toggle .icon-light { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: none; }

@media (min-width: 52em) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    overflow-y: auto;
  }
}

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

.content { padding: 2.75rem 1.25rem 2rem; }

.content > * { max-width: var(--measure); }

@media (min-width: 52em) {
  .content {
    margin-left: var(--sidebar-w);
    padding: 5.5rem 4.5rem 3rem;
  }
}
@media (min-width: 80em) {
  .content { padding-left: 6.5rem; }
}

/* Sections */

.page-section {
  padding: 3.5rem 0;
  scroll-margin-top: 1.5rem;
}
.page-section:first-child { padding-top: 0; }
.page-section + .page-section { border-top: 1px solid var(--rule); }

.page-section > h2 {
  font-size: 1.65rem;
  margin-bottom: 2rem;
}
.page-section > h2::after {
  content: "";
  display: block;
  width: 2.25rem;
  height: 2px;
  margin-top: .7rem;
  background: var(--gold);
}

.intro p {
  font-size: 1.2rem;
  line-height: 1.65;
  margin: 0;
}

/* Curriculum Vitæ */

.cv { list-style: none; padding: 0; margin: 0; }

.cv-entry {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  column-gap: 1.75rem;
  padding: 1.25rem 0;
}
.cv-entry:first-child { padding-top: 0; }
.cv-entry + .cv-entry { border-top: 1px solid var(--rule); }

.cv-dates {
  font-family: var(--sans);
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: .25rem;
  white-space: nowrap;
}

.cv-institution { font-size: 1.125rem; margin: 0; }
.cv-role { margin: .1rem 0 0; }
.cv-note { color: var(--muted); font-size: 1rem; }
.cv-note p { margin: .35rem 0 0; }
.cv-body .links { margin-top: .65rem; }

/* Portfolio */

.work-group + .work-group { margin-top: 2.5rem; }

.work-group-title {
  font-family: var(--sans);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 .5rem;
}

.work-list { list-style: none; padding: 0; margin: 0; }

.work-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.25rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--rule);
}
.work-item .links { flex: none; }

/* Link tags (PDF, Code, GitHub) */

.links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: .35em;
  padding: .2rem .5rem;
  font-family: var(--sans);
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  line-height: 1.4;
  color: var(--accent);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  text-decoration: none;
}
.tag:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.tag i { font-size: 1.15em; }

/* Footer */

.site-footer {
  margin-top: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: .8125rem;
  color: var(--muted);
}
.site-footer p { margin: 0; }

/* Other pages (404, posts) */

.page-title, .post-title { font-size: 1.9rem; }
.post-title a { color: inherit; text-decoration: none; }
.post-date { display: block; font-family: var(--sans); font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.lead { font-size: 1.2rem; }
.post + .post { margin-top: 3rem; padding-top: 3rem; border-top: 1px solid var(--rule); }

/* ---------- Small screens ---------- */

@media (max-width: 51.99em) {
  .sidebar-inner { padding: 1.75rem 1.25rem 1.25rem; }
  .sidebar-brand { display: flex; align-items: center; gap: .9rem; }
  .crest { width: 40px; margin: 0; }
  .sidebar-name { font-size: 1.5rem; }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: .25rem 1.25rem;
    margin-top: 1.25rem;
  }
  .nav-item {
    margin-left: 0;
    padding: .3rem 0;
    border-left: 0;
    border-bottom: 2px solid transparent;
  }
  .nav-section.is-current { border-bottom-color: var(--gold); }

  .sidebar-inner { position: relative; }
  .theme-toggle {
    position: absolute;
    top: 1.75rem;
    right: 1.25rem;
    margin: 0;
    padding: .45rem .6rem;
  }
  .theme-toggle-label { display: none; }

  .page-section { padding: 2.75rem 0; }
  .page-section > h2 { font-size: 1.5rem; margin-bottom: 1.5rem; }
  .intro p { font-size: 1.125rem; }

  .cv-entry { grid-template-columns: 1fr; row-gap: .25rem; }
  .cv-dates { padding-top: 0; }

  .work-item { flex-direction: column; gap: .4rem; }
}

/* ---------- Preferences & print ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

@media print {
  .sidebar, .skip-link, .theme-toggle { display: none; }
  .content { margin: 0; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  a { color: inherit; }
  .tag { border-color: #999; color: #000; }
  .page-section { break-inside: avoid-page; }
}
