/* Ray Hawkins Kaban — portfolio styles. Tokens and rules explained in DESIGN.md. */

@font-face {
  font-family: "Inter";
  src: url("/assets/fonts/Inter-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/assets/fonts/JetBrainsMono-Variable.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

/* ---------- Tokens ---------- */

:root {
  --bg: #f3f0ea;
  --surface: #eae5dc;
  --ink: #1c1917;
  --ink-2: #5e574f;
  --ink-3: #6f665c;
  --line: rgb(28 25 23 / 0.13);
  --accent: #8c2b2b;

  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1160px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141211;
    --surface: #1e1b19;
    --ink: #ece6dd;
    --ink-2: #a39b90;
    --ink-3: #8a8277;
    --line: rgb(236 230 221 / 0.12);
    --accent: #e2806c;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141211;
  --surface: #1e1b19;
  --ink: #ece6dd;
  --ink-2: #a39b90;
  --ink-3: #8a8277;
  --line: rgb(236 230 221 / 0.12);
  --accent: #e2806c;
  color-scheme: dark;
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 24px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}

h1, h2, h3, p, ol, ul, dl, dd, figure { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; height: auto; }

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

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

.wrap {
  width: min(var(--max), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

.skip {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  padding: 8px 14px;
  background: var(--ink);
  color: var(--bg);
  z-index: 10;
}
.skip:focus { top: 12px; }

.link {
  background: linear-gradient(currentColor, currentColor) 0 100% / 100% 1px no-repeat;
  transition: background-size 0.4s var(--ease), color 0.2s;
}
.link:hover {
  color: var(--accent);
  background-size: 0 1px;
  background-position: 100% 100%;
}

.eyebrow {
  font-size: 0.875rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--ink-3); }

.arrow {
  flex: none;
  transition: transform 0.45s var(--ease), color 0.2s;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  gap: 32px;
  height: 76px;
}

.wordmark {
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-right: auto;
}

.nav {
  display: flex;
  gap: 28px;
  font-size: 0.9375rem;
  color: var(--ink-2);
}
.nav a { transition: color 0.2s; }
.nav a:hover { color: var(--ink); }

.tools { display: flex; align-items: center; gap: 10px; }

.lang-switch,
.theme-toggle {
  display: grid;
  place-items: center;
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: 500 0.8125rem/1 var(--sans);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}
.theme-toggle { padding: 0; }
.lang-switch:hover,
.theme-toggle:hover { background: var(--surface); border-color: transparent; }
.theme-toggle svg { transition: transform 0.6s var(--ease); }
[data-theme="dark"] .theme-toggle svg { transform: rotate(180deg); }

@media (max-width: 720px) {
  .nav { display: none; }
}

/* ---------- Hero ---------- */

.hero {
  padding-block: clamp(56px, 14vh, 150px) clamp(72px, 12vw, 140px);
}

.hero-title {
  max-width: 13ch;
  font-size: clamp(2.75rem, 8vw, 6.75rem);
  font-weight: 620;
  line-height: 0.98;
  letter-spacing: -0.048em;
}

.hero-title .w {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  padding-bottom: 0.08em;
  margin-bottom: -0.08em;
}
.hero-title .w > span {
  display: inline-block;
  animation: rise 1s var(--ease) both;
  animation-delay: calc(var(--i) * 60ms + 80ms);
}

@keyframes rise {
  from { transform: translateY(105%); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
}

.hero-foot {
  display: grid;
  grid-template-columns: minmax(0, 36rem) auto;
  justify-content: space-between;
  align-items: end;
  gap: 40px;
  margin-top: clamp(40px, 7vw, 88px);
  animation: fade-up 1s var(--ease) 0.65s both;
}

.lede {
  font-size: clamp(1.125rem, 1.6vw, 1.3125rem);
  line-height: 1.55;
  color: var(--ink-2);
}
.lede .link { color: var(--ink); }
.lede .link:hover { color: var(--accent); }

.hero-meta {
  display: flex;
  gap: 40px;
  font-size: 0.9375rem;
}
.hero-meta dt { color: var(--ink-3); font-size: 0.8125rem; }
.hero-meta dd { font-variant-numeric: tabular-nums; }

@media (max-width: 820px) {
  .hero-foot { grid-template-columns: 1fr; }
}

/* ---------- Sections ---------- */

.section { padding-block: clamp(64px, 10vw, 128px); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  font-size: clamp(1.625rem, 2.6vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.count {
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}

/* ---------- Work list ---------- */

.work-row {
  position: relative;
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1.05fr) minmax(0, 1fr) 11rem 24px;
  align-items: baseline;
  gap: 24px;
  padding: 30px 12px;
  border-bottom: 1px solid var(--line);
  isolation: isolate;
}

.work-row::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--surface);
  transform: scaleY(0);
  transform-origin: 50% 100%;
  transition: transform 0.5s var(--ease);
}

.work-index {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--ink-3);
  transition: color 0.2s;
}

.work-title {
  font-size: clamp(1.5rem, 2.7vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.1;
  transition: transform 0.5s var(--ease);
}

.work-summary { color: var(--ink-2); font-size: 0.9875rem; }
.work-meta { color: var(--ink-3); font-size: 0.875rem; }
.work-row .arrow { align-self: center; color: var(--ink-3); }

@media (hover: hover) {
  .work-row:hover::before { transform: scaleY(1); }
  .work-row:hover .work-title { transform: translateX(10px); }
  .work-row:hover .work-index,
  .work-row:hover .arrow { color: var(--accent); }
  .work-row:hover .arrow { transform: translate(3px, -3px); }
}

@media (max-width: 900px) {
  .work-row {
    grid-template-columns: 2.5rem minmax(0, 1fr) 24px;
    row-gap: 8px;
    padding-inline: 0;
  }
  .work-summary, .work-meta { grid-column: 2 / 3; }
  .work-row .arrow { grid-column: 3; grid-row: 1; }
}

/* ---------- Experience ---------- */

.job {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: 24px;
  padding-block: 28px;
  border-bottom: 1px solid var(--line);
}

.job-period {
  font-size: 0.875rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.job-role {
  font-size: 1.1875rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.35;
}
.job-org {
  display: block;
  font-weight: 450;
  color: var(--ink-2);
  letter-spacing: -0.01em;
}
.job-note {
  margin-top: 10px;
  max-width: 60ch;
  color: var(--ink-2);
  font-size: 0.9875rem;
}

@media (max-width: 720px) {
  .job { grid-template-columns: 1fr; gap: 6px; }
}

/* ---------- About ---------- */

.about {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: clamp(32px, 6vw, 96px);
  padding-top: 48px;
}

.portrait {
  position: sticky;
  top: 32px;
  align-self: start;
}
.portrait img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: 50% 30%;
  border-radius: 4px;
  background: var(--surface);
}
.portrait figcaption {
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--ink-3);
}

.about-body > p {
  font-size: clamp(1.125rem, 1.5vw, 1.25rem);
  line-height: 1.6;
  max-width: 34em;
}
.about-body > p + p { margin-top: 1em; color: var(--ink-2); }

.facts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px 32px;
  margin-top: 56px;
}
.facts-grid h3 {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.facts-grid li {
  display: grid;
  gap: 2px;
  padding-block: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.9375rem;
}
.facts-grid strong { font-weight: 600; }
.facts-grid span { color: var(--ink-2); }
.facts-grid .muted { color: var(--ink-3); font-size: 0.875rem; }
.span-2 { grid-column: 1 / -1; }
.certs { display: grid; grid-template-columns: 1fr 1fr; column-gap: 32px; }

@media (max-width: 820px) {
  .about { grid-template-columns: 1fr; }
  .portrait { position: static; max-width: 360px; }
}
@media (max-width: 560px) {
  .facts-grid, .certs { grid-template-columns: 1fr; }
}

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

.contact { border-top: 1px solid var(--line); }

.contact-title {
  max-width: 14ch;
  font-size: clamp(2.25rem, 6vw, 4.75rem);
  font-weight: 620;
  letter-spacing: -0.045em;
  line-height: 1;
}

.contact-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 20px;
  margin-top: 40px;
}

/* Copy needs JS, so it only appears when JS runs. */
.copy { display: none; }
.js .copy {
  display: inline-grid;
  place-items: center;
  height: 36px;
  min-width: 72px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--ink-2);
  font: 500 0.8125rem/1 var(--sans);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.js .copy:hover { background: var(--surface); border-color: transparent; color: var(--ink); }

.contact-mail {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(1.25rem, 3.4vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  transition: color 0.2s, border-color 0.2s;
  overflow-wrap: anywhere;
}
.contact-mail .arrow { width: 0.9em; height: 0.9em; }
.contact-mail:hover { color: var(--accent); border-color: currentColor; }
.contact-mail:hover .arrow { transform: translate(4px, -4px); }

.contact-links {
  display: flex;
  gap: 28px;
  margin-top: 32px;
  color: var(--ink-2);
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px 32px;
  padding-block: 28px 40px;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
  color: var(--ink-3);
}

/* ---------- Case study page ---------- */

.work-page { padding-bottom: 32px; }
.back { display: inline-block; margin-top: 32px; font-size: 0.9375rem; color: var(--ink-2); }

.work-hero { padding-block: clamp(48px, 9vw, 112px) 56px; }
.work-hero h1 {
  margin-top: 16px;
  max-width: 16ch;
  font-size: clamp(2.5rem, 7vw, 5.5rem);
  font-weight: 620;
  letter-spacing: -0.048em;
  line-height: 1;
}
.work-hero .lede { margin-top: 28px; max-width: 40rem; }

.facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 0.9375rem;
}
.facts dt { color: var(--ink-3); font-size: 0.8125rem; margin-bottom: 4px; }

@media (max-width: 820px) {
  .facts { grid-template-columns: 1fr 1fr; }
}

.prose {
  max-width: 44rem;
  margin-left: auto;
  margin-right: clamp(0px, 8vw, 120px);
  font-size: 1.0625rem;
  line-height: 1.75;
}
.prose > * + * { margin-top: 1.1em; }
.prose h2 {
  margin-top: 2.6em;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.25;
}
.prose h2:first-child { margin-top: 0; }
.prose ul { padding-left: 1.2em; list-style: disc; }
.prose li + li { margin-top: 0.4em; }
.prose li::marker { color: var(--ink-3); }
.prose strong { font-weight: 600; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface);
}
.prose .code pre {
  margin: 0;
  padding: 20px 22px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.84rem;
  line-height: 1.65;
}
.prose .code code { padding: 0; background: none; font-size: inherit; }

/* Architecture diagrams: inline SVG in case-study Markdown, coloured by tokens so both themes work. */
.prose .diagram { margin-block: 2.2em; overflow-x: auto; }
.diagram svg { display: block; width: 100%; min-width: 440px; height: auto; font-family: var(--sans); }
.diagram rect { fill: var(--surface); stroke: var(--line); }
.diagram .core rect { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.diagram text { fill: var(--ink); font-size: 14px; font-weight: 600; text-anchor: middle; }
.diagram text.sub { fill: var(--ink-2); font-size: 12px; font-weight: 400; }
.diagram .edge { fill: none; stroke: var(--ink-3); stroke-width: 1.25; marker-end: url(#arrowhead); }
.diagram .edge.dashed { stroke-dasharray: 4 4; }
.diagram marker path { fill: var(--ink-3); }
.diagram figcaption { margin-top: 12px; font-size: 0.8125rem; color: var(--ink-3); }

@media (max-width: 820px) {
  .prose { margin-right: auto; }
}

.next-work {
  display: grid;
  gap: 8px;
  margin-top: clamp(80px, 12vw, 160px);
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.next-work a {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  width: fit-content;
  font-size: clamp(1.75rem, 4.5vw, 3.5rem);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.1;
  transition: color 0.2s;
}
.next-work a:hover { color: var(--accent); }
.next-work a:hover .arrow { transform: translate(4px, -4px); }
.next-work .arrow { width: 0.8em; height: 0.8em; }

.notfound { padding-block: 18vh; }
.notfound h1 {
  margin: 12px 0 32px;
  font-size: clamp(2.25rem, 6vw, 4.5rem);
  letter-spacing: -0.045em;
  line-height: 1;
}

/* ---------- Motion ---------- */

.js [data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease);
  transition-delay: calc(var(--d, 0) * 70ms);
}
.js [data-reveal].in { opacity: 1; transform: none; }

.work-list li:nth-child(2), .timeline li:nth-child(2) { --d: 1; }
.work-list li:nth-child(3), .timeline li:nth-child(3) { --d: 2; }
.work-list li:nth-child(4), .timeline li:nth-child(4) { --d: 3; }
.work-list li:nth-child(5), .timeline li:nth-child(5) { --d: 4; }
.about-body { --d: 1; }

@view-transition { navigation: auto; }
::view-transition-group(*) { animation-duration: 0.5s; animation-timing-function: var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .js [data-reveal] { opacity: 1; transform: none; }
  @view-transition { navigation: none; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
