/* ---- Tokens ---- */
:root {
  --bg: #0f1115;
  --surface: #15181e;
  --text: #e7e5e4;
  --muted: #9aa3b2;
  --accent: #6fe9ff;
  --accent-warm: #e6a267;
  --border: rgba(255, 255, 255, 0.08);

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "IBM Plex Mono", monospace;

  --maxw: 720px;
  --space: 1rem;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, h2, h3, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; }
img, svg { display: block; max-width: 100%; }

/* ---- Base ---- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2.5rem, 6vw, 5rem) 1.25rem 2rem;
}

/* ---- Sections rhythm ---- */
section { margin-block: clamp(2.5rem, 6vw, 4rem); }

h2 {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

/* ---- Links ---- */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover { color: var(--text); }

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

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

/* ---- Identity ---- */
.identity h1 {
  font-size: clamp(2rem, 6vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.identity .lede {
  margin-top: 0.85rem;
  font-size: clamp(1.125rem, 3vw, 1.375rem);
  color: var(--text);
  max-width: 32ch;
}
.identity .now {
  margin-top: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
}
.identity .now-label {
  color: var(--accent-warm);
  margin-right: 0.5rem;
}

/* ---- About ---- */
.about p + p { margin-top: 1rem; }
.about p { color: var(--text); }

/* ---- Work ---- */
.group + .group { margin-top: 2rem; }
.group-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.6rem;
}
.projects li {
  display: grid;
  grid-template-columns: minmax(0, 14rem) 1fr;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}
.projects li:first-child { border-top: none; }
.proj-name { font-weight: 600; color: var(--text); }
a.proj-name { color: var(--accent); }
a.proj-name:hover { color: var(--text); }
.proj-desc { color: var(--muted); font-size: 0.9375rem; align-self: center; }

.more {
  margin-top: 0.5rem;
  background: none;
  border: none;
  padding: 0.35rem 0;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--accent);
  cursor: pointer;
  transition: color 0.15s ease;
}
.more:hover { color: var(--text); }

/* Single-column rows on narrow screens */
@media (max-width: 32rem) {
  .projects li { grid-template-columns: 1fr; gap: 0.1rem; }
  .proj-desc { align-self: start; }
}

/* ---- Links ---- */
.links ul {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}
.links a { font-weight: 600; }

/* ---- Footer ---- */
.footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 1.5rem;
  padding-bottom: 2.5rem;
}
.footer p {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

/* Write-up pages */
.prose { padding-top: 4rem; max-width: 58rem; }
.prose .crumb { font-family: var(--font-mono); font-size: 0.85rem; color: var(--muted); margin-bottom: 2rem; }
.prose h1 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.prose .meta { font-family: var(--font-mono); font-size: 0.85rem; color: var(--muted); margin-bottom: 2rem; }
.prose p { margin-bottom: 1.1rem; }
.prose table { width: 100%; border-collapse: collapse; margin: 1.75rem 0; }
.prose table caption { text-align: left; color: var(--muted); font-size: 0.85rem;
                       margin-bottom: 0.6rem; }
.prose th, .prose td { text-align: left; padding: 0.6rem 0.9rem; border: 1px solid var(--border); vertical-align: top; line-height: 1.5; }
.prose thead th, .prose tbody th { font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
@media (max-width: 36rem) {
  .prose { overflow-wrap: anywhere; }
  .prose table { table-layout: fixed; }
  .prose th, .prose td { padding: 0.45rem 0.5rem; font-size: 0.85rem; }
  .prose thead th, .prose tbody th { white-space: normal; }
}

/* Fleet write-up diagram */
.fleet-map__figure { margin: 2rem 0; }
.fleet-map__mount { width: 100%; overflow-x: auto; }
.fleet-map { width: 100%; height: auto; }
.fleet-map text { font-family: var(--font-mono); font-size: 0.8rem; fill: var(--muted); }
.fleet-map__heading { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; }
.fleet-map circle { fill: var(--muted); transition: fill 200ms linear; }
.fleet-map .is-lit circle { fill: var(--accent); }
.fleet-map .is-notify circle { fill: var(--text); }
.fleet-map__edge { stroke: var(--accent); stroke-width: 1; opacity: 0.5; }
/* The destination column's rail: structure, drawn before any agent exists. It
   is dashed and muted so it cannot be mistaken for an edge, which is solid and
   accented and only ever appears once a real arrival has drawn it. */
.fleet-map__rail { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 6; opacity: 0.35; }
.fleet-map[data-reduced="true"] circle { transition: none; }
.fleet-map__figure figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 0.75rem; }

/* ---- Companion (cartoon Josh) ---- */
.companion {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 5;
  pointer-events: none;        /* container is click-through... */
  transform: translateX(-200px);
  will-change: transform;
}
.companion__rig {
  height: 84px;
  width: auto;
  display: block;
  transform: translateX(-50%); /* center the sprite on the container origin */
  transform-origin: center;
  pointer-events: auto;        /* ...but the sprite itself is clickable */
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  overflow: visible;
  filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.45));
}
/* What he says, in three places: the live region announces it, the mutter is
   the visible form of the same string while the chat is closed, and the
   bubble's log takes over once the chat is open. */
.companion__live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
/* Rides the walk with him: it is a mutter, and it belongs to him rather than
   to the viewport. Cleared by a timer in companion-chat.js, so the fade is
   decoration only and reduced motion killing it changes nothing. */
.companion__mutter {
  position: absolute;
  left: 0;
  bottom: 92px;
  margin: 0;
  width: max-content;
  max-width: 15rem;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.4rem 0.7rem;
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.companion__mutter[data-visible="true"] { opacity: 1; }

/* The bubble is a child of <body>. It follows the cartoon's published center
   and clamps before either edge; keeping it outside the transformed walker
   makes that viewport math reliable. */
.companion__open {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 1;
  width: 46px;
  height: 84px;
  transform: translateX(-50%);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0.5rem;
  cursor: pointer;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
}
.companion__open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.companion__bubble {
  position: fixed;
  left: clamp(9.5rem, var(--companion-x, 9.5rem), calc(100vw - 9.5rem));
  bottom: 6rem;
  z-index: 6;
  width: min(17rem, calc(100vw - 2rem));
  transform: translateX(-50%);
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.5;
}
.companion__say {
  color: var(--text);
  margin: 0 0 0.5rem;
  min-height: 1.5em;
}
.companion__bubble form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 0.5rem;
  align-items: start;
}
.companion__bubble input {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.4rem 0.55rem;
  font: inherit;
  font-family: var(--font-sans);
}
.companion__bubble input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.companion__voice {
  display: contents;
}
.companion__voice-button {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0.65rem;
  background: var(--surface);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  cursor: pointer;
}
.companion__voice-icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}
.companion__voice-button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
}
.companion__voice-button:disabled {
  border-color: var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}
.companion__voice-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.companion__voice-status {
  grid-column: 1 / -1;
  grid-row: 2;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

/* Mobile chat entry point. Josh is the touch target and the conversation stays
   with him: he clears the home indicator while the tracked bubble stays above
   his head. */
@media (max-width: 36rem) {
  .companion {
    display: block;
    bottom: env(safe-area-inset-bottom);
  }
  .companion__bubble {
    bottom: calc(6rem + env(safe-area-inset-bottom));
    font-size: 1rem;
  }
  .companion__bubble input {
    min-height: 44px;
    font-size: 1rem;
  }
}

/* Live fleet layer. Absent entirely when the feed is unreachable. */
.identity { position: relative; }
.fleet {
  /* The header is only as tall as the name, so the layer cannot inherit its
     box or the mesh squashes into a band behind the text. It gets its own
     height and sits behind the page content on a negative stacking level. */
  position: absolute;
  top: -1.5rem;
  left: 0;
  right: 0;
  height: 260px;
  pointer-events: none;
  z-index: -1;
}
.identity h1 { position: relative; z-index: 1; }
@media (max-width: 36rem) { .fleet { display: none; } }

.project-cards { display: grid; gap: 1.5rem; }
.project-card { padding: 1.5rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.project-card h3 { margin: 0.3rem 0 0.65rem; font-size: 1.3rem; line-height: 1.3; }
.project-category { color: var(--muted); font: 0.8rem var(--font-mono); }
.project-card figure { margin: 1.25rem 0; }
.project-card img { width: 100%; height: auto; border-radius: 6px; }
.project-card figcaption { margin-top: 0.5rem; color: var(--muted); font-size: 0.8rem; }
.project-links { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-top: 1rem; font-size: 0.9rem; }
@media (max-width: 36rem) { .project-card { padding: 1rem; } }
