/* Shared tokens. Dark ("Night over the map") is the default; light follows the OS setting. */
:root {
  --bg: #0d1418;
  --bg-glow: #12303a;
  --surface: rgba(17, 27, 34, 0.82);
  --surface-strong: rgba(22, 35, 44, 0.95);
  --line: rgba(160, 200, 210, 0.16);
  --text: #e7eef1;
  --muted: #9aabb5;
  --accent: #35d0c0;
  --career: #f2a541;
  --algo: #5aa2ff;
  --games: #e9584c;
  --games-2: #c9a04a;
  --contour: rgba(53, 208, 192, 0.12);
  --contour-strong: rgba(53, 208, 192, 0.3);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --header-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef3f4;
    --bg-glow: #d3e8e8;
    --surface: rgba(255, 255, 255, 0.84);
    --surface-strong: rgba(255, 255, 255, 0.96);
    --line: rgba(20, 50, 60, 0.14);
    --text: #10222b;
    --muted: #4a606d;
    --accent: #0b7a70;
    --career: #9a5a06;
    --algo: #1f66c9;
    --games: #b3261e;
    --games-2: #7a5c12;
    --contour: rgba(11, 122, 112, 0.14);
    --contour-strong: rgba(11, 122, 112, 0.32);
    --shadow: 0 12px 32px rgba(16, 40, 50, 0.12);
    color-scheme: light;
  }
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg) radial-gradient(ellipse 90% 60% at 50% 0%, var(--bg-glow), transparent 70%) no-repeat fixed;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

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

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 20;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
}

.skip-link:focus {
  top: 12px;
}

/* Animated page background (js/site.js; the contour map is js/background.js). */
#bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

main,
.site-footer {
  position: relative;
  z-index: 1;
}

/* Header: no bar, just the home mark and the section links in the top-left corner.
   They scroll away with the page; the sound toggle stays fixed in the top-right corner (.sound-corner). */
.site-header {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 72px;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-nav a:not(.brand) {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.95rem;
  text-decoration: none;
}

/* Each section's icon from the landing page, in its section colour. */
.nav-icon {
  flex: none;
  color: var(--nav-accent);
}

.nav-career { --nav-accent: var(--career); }
.nav-algorithms { --nav-accent: var(--algo); }
.nav-games { --nav-accent: var(--games); }

.nav-icon .accent-2 {
  fill: var(--games-2);
  stroke: var(--games-2);
}

.site-nav a:not(.brand):hover,
.site-nav a[aria-current="page"] {
  background: var(--surface);
  color: var(--text);
}

/* Narrow screens: icons only. */
@media (max-width: 639px) {
  .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover {
  color: var(--text);
}

.icon-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-button .icon-on,
.icon-button[aria-pressed="true"] .icon-off {
  display: none;
}

.icon-button[aria-pressed="true"] .icon-on {
  display: block;
}

/* Main page: no header, just the sound toggle in the top-right corner. */
.sound-corner {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Hero: the title of the map sheet, set at full strength in the top-left corner. */
.hero {
  position: relative;
  isolation: isolate;
  max-width: 1120px;
  margin: 0 auto;
  padding: 88px 16px 8px;
}

/* A cartographic label halo: it clears the contour lines behind the text without boxing it in. */
.hero::before,
.portal::before {
  content: "";
  position: absolute;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--bg) 90%, transparent) 62%, transparent);
}

.hero::before {
  inset: 40px -8% -40px -12%;
  max-width: 900px;
}

.hero-title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 22px;
}

.portrait {
  width: 76px;
  height: 76px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--surface-strong), var(--surface));
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 10%, transparent), var(--shadow);
  color: var(--accent);
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero h1 {
  margin: 0;
  font-size: clamp(3rem, 10.5vw, 6rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.tagline {
  margin: 22px 0 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: clamp(0.8rem, 1.6vw, 0.95rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.intro {
  max-width: 54ch;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1.125rem;
  line-height: 1.65;
}

.page-home #explore {
  padding-top: 40px;
  padding-bottom: 96px;
}

/* Sections */
.section {
  max-width: 1120px;
  margin: 0 auto;
  padding: 64px 16px;
}

.page-home #explore + .contact {
  padding-top: 0;
}

.contact-title {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.contact p {
  max-width: 62ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.contact .tnummr {
  margin-left: 0.15em;
  vertical-align: middle;
  filter: invert(1);
}

@media (prefers-color-scheme: light) {
  .contact .tnummr { filter: none; }
}

.section-title {
  margin: 0 0 24px;
  font-size: clamp(1.6rem, 3.5vw, 2.1rem);
  letter-spacing: -0.015em;
}

/* The three destinations are summits on the contour map (js/background.js raises a hill under each),
   labelled like peaks on a map rather than boxed as cards. */
.portals {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.portal {
  --card-accent: var(--accent);
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 28px 4px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

/* Only the text gets a halo; the summit marker above it stays in the open among its contour rings. */
.portal::before {
  inset: 72px -32px -12px;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--bg) 88%, transparent) 70%, transparent);
}

.portal-career { --card-accent: var(--career); }
.portal-algo { --card-accent: var(--algo); }
.portal-games { --card-accent: var(--games); }

.portal:focus-visible {
  outline: 2px solid var(--card-accent);
  outline-offset: 4px;
  border-radius: var(--radius);
}

/* The summit symbol: a bare map symbol at the top of its hill, with a ground-coloured halo so the rings
   pass behind it cleanly. The box is also the anchor js/background.js centres the hill on. */
.portal-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  color: var(--card-accent);
  filter: drop-shadow(0 0 2px var(--bg)) drop-shadow(0 0 5px var(--bg));
  transition: scale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.portal:hover .portal-icon,
.portal:focus-visible .portal-icon {
  scale: 1.12;
}

.portal-icon svg {
  width: 36px;
  height: 36px;
  stroke-width: 1.6;
}

.portal-icon .accent-2 {
  fill: var(--games-2);
  stroke: var(--games-2);
}

.portal h2 {
  margin: 10px 0 0;
  font-size: clamp(1.55rem, 2.7vw, 2.05rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
  transition: color 0.25s ease;
}

.portal:hover h2,
.portal:focus-visible h2 {
  color: var(--card-accent);
}

.portal p {
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.portal-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
  color: var(--card-accent);
  font-weight: 600;
}

.portal-cta svg {
  transition: transform 0.25s ease;
}

.portal:hover .portal-cta svg,
.portal:focus-visible .portal-cta svg {
  transform: translateX(4px);
}

/* Project cards (rendered by js/project-cards.js from data/projects.js) */
/* At most three cards per row, so there is room for the text; fewer on narrow screens.
   js/project-cards.js reads --cols and widens the column of the open card, so the breakpoints live here
   (each is a 250px column minimum plus the page's side padding). */
.project-grid {
  --cols: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 20px;
  transition: grid-template-columns 0.35s ease;
}

@media (min-width: 552px) {
  .project-grid { --cols: 2; }
}

@media (min-width: 846px) {
  .project-grid { --cols: 3; }
}

.project-card {
  --card-accent: var(--algo);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.25s ease;
}

.project-card[data-section="games"] {
  --card-accent: var(--games);
}

.project-card:hover,
.project-card.is-open {
  border-color: color-mix(in srgb, var(--card-accent) 60%, var(--line));
}

.project-media {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}

.project-image {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--surface-strong);
}

.project-image-open {
  position: absolute;
  inset: 0;
  height: 100%;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.project-card.is-open .project-image-open {
  opacity: 1;
}

.project-complexity {
  align-self: flex-start;
  color: var(--card-accent);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.project-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px 20px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
}

/* Kept on every card so games.js can add a HI badge; hidden until something is in it. */
.badges:empty {
  display: none;
}

.badge {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge-example {
  border-style: dashed;
}

.project-card h3 {
  margin: 2px 0 0;
  font-size: 1.15rem;
}

.project-summary {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.project-details {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

.project-card.is-open .project-details {
  grid-template-rows: 1fr;
}

.project-details-inner {
  min-height: 0;
  overflow: hidden;
}

.project-details-inner p {
  margin: 0 0 10px;
  line-height: 1.6;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 12px;
  padding: 0;
  list-style: none;
}

.tags li {
  padding: 5px 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--card-accent) 13%, transparent);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1;
}

.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0 0 4px;
}

.project-link {
  color: var(--card-accent);
  font-weight: 600;
  text-decoration: none;
}

.project-link-secondary {
  color: var(--text);
}

.project-link:hover {
  text-decoration: underline;
}

/* min-height is the "Read more" button's height, so the date lines up on cards without one. */
.project-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-top: auto;
}

.project-toggle {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.project-toggle:hover {
  border-color: var(--card-accent);
}

.project-meta {
  margin-left: auto;
  white-space: nowrap;
}

.project-codesize,
.project-date {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
}

/* With both: "2k lines · May 2024". */
.project-codesize + .project-date::before {
  content: " · ";
}

.empty {
  color: var(--muted);
}

/* Footer */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 16px 44px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer p {
  margin: 0;
}

/* Scroll reveal. Uses `translate` so it doesn't clash with the hover `transform` on cards. */
.js .reveal {
  opacity: 0;
}

.js .reveal.is-visible {
  animation: rise 0.6s ease both;
  animation-delay: var(--delay, 0s);
}

@keyframes rise {
  from { opacity: 0; translate: 0 18px; }
  to { opacity: 1; translate: 0 0; }
}

@media (min-width: 720px) {
  .section { padding: 72px 28px; }
  .site-footer { padding: 28px 28px 44px; }
  .hero { padding: 120px 28px 8px; }

  .hero-title {
    flex-direction: row;
    align-items: center;
    gap: 28px;
  }

  .portrait {
    width: 92px;
    height: 92px;
    font-size: 1.7rem;
  }
}

/* On wide screens the summits scatter across the terrain instead of lining up in a row. */
@media (min-width: 880px) {
  .portals {
    grid-template-columns: repeat(3, 1fr);
    gap: 48px;
    align-items: start;
  }

  .portal-career { margin-top: 72px; }
  .portal-games { margin-top: 128px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
