/* Slate palette on hue 212°: neutrals at 10% saturation, the accent and the
   chart colours at 30% saturation and 30% lightness. */
:root {
  color-scheme: light;
  overflow-y: scroll; /* always show the scrollbar, so opening a drawer doesn't shift the page */

  /* Surfaces */
  --surface-canvas: hsl(212, 10%, 96%);
  --surface-elevated: hsl(212, 10%, 99%);
  --surface-subtle: hsl(212, 10%, 92%);

  /* Text */
  --ink-primary: hsl(212, 18%, 13%);
  --ink-secondary: hsl(212, 12%, 34%);
  --ink-muted: hsl(212, 10%, 48%);
  --ink-on-accent: hsl(212, 15%, 97%);
  --ink-on-stone: hsl(212, 18%, 16%);

  /* Lines */
  --border-subtle: hsl(212, 10%, 90%);
  --border-default: hsl(212, 10%, 83%);

  /* Accent */
  --accent-primary: hsl(212, 30%, 30%);
  --accent-primary-hover: hsl(212, 30%, 22%);
  --accent-subtle-bg: hsl(212, 24%, 91%);
  --accent-subtle-border: hsl(212, 25%, 76%);
  --accent-subtle-ink: hsl(212, 32%, 24%);

  /* Chart colours: six categories, then stone neutrals from darker to lighter */
  --viz-cat-1: hsl(212, 30%, 30%);
  --viz-cat-2: hsl(152, 30%, 30%);
  --viz-cat-3: hsl(18, 30%, 30%);
  --viz-cat-4: hsl(40, 30%, 30%);
  --viz-cat-5: hsl(325, 26%, 31%);
  --viz-cat-6: hsl(184, 30%, 29%);
  --viz-stone-1: hsl(212, 10%, 82%);
  --viz-stone-2: hsl(212, 10%, 85%);
  --viz-stone-3: hsl(212, 10%, 88%);
  --viz-stone-4: hsl(212, 10%, 90%);

  /* Shape, motion, type */
  --radius-xs: 2px;
  --radius-sm: 4px;
  --transition-tactile: 200ms cubic-bezier(0.22, 1, 0.36, 1);
  --transition-morph: 260ms cubic-bezier(0.22, 1, 0.36, 1);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink-primary);
  background-color: var(--surface-canvas);
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

[hidden] {
  display: none !important;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Small uppercase heading above each column and list */
.col-label {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-default);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* ==========================================================================
   Page shell and header
   ========================================================================== */
.portfolio-shell {
  width: min(100% - 48px, 1280px);
  margin-inline: auto;
  padding-block: 56px 72px;
  transition: width var(--transition-morph);
}

.portfolio-shell[data-mode="workbench"] {
  width: min(100% - 36px, 1440px);
  padding-block: 36px 64px;
}

.site-header {
  margin-bottom: 44px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-default);
}

.portfolio-shell[data-mode="workbench"] .site-header {
  margin-bottom: 24px;
  padding-bottom: 14px;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(24px, 3.6vw, 38px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.site-header h1 span {
  color: var(--accent-primary);
}

.site-header .name {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-secondary);
}

.site-header .name a {
  color: var(--accent-primary);
  text-underline-offset: 3px;
}

.site-header .name a:hover {
  color: var(--accent-primary-hover);
}

/* ==========================================================================
   Constellation: domains → projects → categories, joined by ribbons
   ========================================================================== */
.constellation-stage {
  position: relative;
  display: grid;
  grid-template-columns: 168px minmax(300px, 440px) minmax(280px, 1fr);
  column-gap: clamp(56px, 7.5vw, 112px);
  align-items: start;
  min-height: 460px;
  padding-block: 4px;
}

.constellation-svg {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

/* Ribbons stay hidden until both of their ends are highlighted. */
.ribbon {
  fill: none;
  stroke: var(--accent-primary);
  stroke-linecap: round;
  opacity: 0;
  transition: opacity var(--transition-tactile);
}

.ribbon.is-active {
  opacity: 1;
}

.col-domains,
.col-projects,
.col-categories {
  position: relative;
  z-index: 1;
}

.col-domains .col-label {
  padding-right: 12px;
  text-align: right;
}

.col-projects .col-label {
  padding-inline: 14px;
}

.col-categories .col-label {
  padding-left: 14px;
}

/* Rows fade when they dim. Keeping them on their own compositing layer stops the browser
   from moving them on and off a layer at each fade, which makes the text flicker. */
.domain-pill,
.project-item,
.category-pill {
  will-change: opacity;
}

/* Domains: filter buttons, centred against the project list */
.col-domains {
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

.domain-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
}

.domain-pill {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 56px;
  padding: 12px 14px 12px 10px;
  border: 0;
  background-color: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
  cursor: pointer;
  transition:
    background-color var(--transition-tactile),
    color var(--transition-tactile),
    opacity var(--transition-tactile);
}

.domain-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  transition: color var(--transition-tactile);
}

.domain-pill:hover {
  background-color: var(--surface-subtle);
  color: var(--ink-primary);
}

.domain-pill.is-active {
  background-color: var(--accent-subtle-bg);
  color: var(--ink-primary);
}

.domain-pill.is-active .domain-count {
  color: var(--accent-primary);
}

.domain-pill.is-locked {
  background-color: var(--accent-primary);
  color: var(--ink-on-accent);
}

.domain-pill.is-locked:hover {
  background-color: var(--accent-primary-hover);
}

.domain-pill.is-locked .domain-count {
  color: var(--ink-on-accent);
  opacity: 0.85;
}

.domain-pill.is-dimmed {
  opacity: 0.36;
}

/* Projects: rows in timeline order; brief projects open a drawer below their row */
.project-list {
  display: flex;
  flex-direction: column;
}

.project-item {
  transition: opacity var(--transition-tactile);
}

.project-item.is-dimmed {
  opacity: 0.34;
}

.project-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 84px;
  padding: 13px 16px;
  border: 0;
  background: transparent;
  color: var(--ink-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-tactile);
}

.project-trigger:hover {
  background-color: var(--surface-subtle);
}

.project-item.is-active > .project-trigger,
.project-item.is-expanded > .project-trigger {
  background-color: var(--accent-subtle-bg);
}

.project-main {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.project-index {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  transition: color var(--transition-tactile);
}

.project-item.is-active .project-index,
.project-item.is-expanded .project-index {
  color: var(--accent-primary);
}

.project-title {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.workbench-badge {
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: var(--radius-xs);
  background-color: var(--accent-primary);
  color: var(--ink-on-accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background-color var(--transition-tactile);
}

.project-item.is-active .workbench-badge,
.project-trigger:hover .workbench-badge {
  background-color: var(--accent-primary-hover);
}

.project-drawer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--transition-morph);
}

.project-item.is-expanded .project-drawer {
  grid-template-rows: 1fr;
}

.project-drawer-inner {
  overflow: hidden;
}

.project-item.is-expanded .project-drawer-inner {
  margin: 0 14px 12px 26px;
  padding: 10px 14px 12px;
  border-left: 2px solid var(--accent-primary);
  background-color: var(--surface-elevated);
}

.drawer-summary {
  margin: 0 0 10px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.drawer-keywords {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.drawer-keyword-group {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.4;
}

.drawer-keyword-group dt {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
}

.drawer-keyword-group dt::after {
  content: "—";
  margin-left: 6px;
  font-weight: 400;
  color: var(--ink-muted);
}

.drawer-keyword-group dd {
  margin: 0;
  color: var(--ink-secondary);
}

.drawer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.drawer-link {
  padding: 4px 10px;
  border: 1px solid var(--accent-subtle-border);
  border-radius: var(--radius-xs);
  background-color: var(--accent-subtle-bg);
  color: var(--accent-subtle-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition:
    background-color var(--transition-tactile),
    border-color var(--transition-tactile),
    color var(--transition-tactile);
}

.drawer-link:hover {
  border-color: var(--accent-primary);
  background-color: var(--accent-primary);
  color: var(--ink-on-accent);
}

/* Categories: fixed-height rows that reveal the highlighted projects' keywords */
.category-list {
  display: flex;
  flex-direction: column;
}

.category-pill {
  display: flex;
  flex: 0 0 96px;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  height: 96px;
  padding: 8px 10px 8px 16px;
  border: 0;
  background-color: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--transition-tactile),
    color var(--transition-tactile),
    opacity var(--transition-tactile);
}

.cat-name {
  font-weight: 500;
}

.category-pill:hover,
.category-pill.is-active {
  color: var(--ink-primary);
}

.category-pill:hover {
  background-color: var(--surface-subtle);
}

.category-pill.is-active {
  background-color: var(--accent-subtle-bg);
}

.category-pill.is-locked {
  background-color: var(--accent-primary);
  color: var(--ink-on-accent);
}

.category-pill.is-dimmed {
  opacity: 0.34;
}

.cat-keywords {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  color: var(--accent-primary);
  opacity: 0;
  transition: opacity var(--transition-tactile);
}

.category-pill.is-active .cat-keywords {
  opacity: 1;
}

.category-pill.is-locked .cat-keywords {
  color: var(--ink-on-accent);
}

/* ==========================================================================
   Workbench: a deep project, with the project list as a spine on the left
   ========================================================================== */
.workbench-layout {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.workbench-spine {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background-color: var(--surface-elevated);
}

.back-button {
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-xs);
  background-color: var(--accent-primary);
  color: var(--ink-on-accent);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-tactile);
}

.back-button:hover {
  background-color: var(--accent-primary-hover);
}

.spine-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 7px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--transition-tactile),
    color var(--transition-tactile);
}

.spine-item:hover {
  background-color: var(--surface-subtle);
  color: var(--ink-primary);
}

.spine-item[aria-current="true"] {
  border-color: var(--accent-primary);
  background-color: var(--accent-subtle-bg);
  color: var(--accent-subtle-ink);
  font-weight: 600;
}

.spine-index {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
}

.spine-depth {
  font-size: 10.5px;
  color: var(--ink-muted);
}

.workbench-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.workbench-title {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

/* Workbench tabs (src/robocar3/Workbench.tsx) */
.tab-list {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-default);
}

.tab {
  padding: 10px 14px;
  border: 0;
  background: none;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition-tactile);
}

.tab:hover {
  color: var(--ink-primary);
}

.tab[aria-selected="true"] {
  color: var(--ink-primary);
  box-shadow: inset 0 -2px 0 var(--accent-primary);
}

.overview-section {
  max-width: 900px;
  padding: 16px 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-secondary);
}

.overview-section h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-primary);
}

.overview-section p,
.overview-section ul {
  margin: 0 0 8px;
}

.overview-section ul {
  padding-left: 20px;
}

.overview-section b {
  font-weight: 600;
  color: var(--ink-primary);
}

.overview-note {
  font-size: 14px;
  color: var(--ink-muted);
}

.overview-figures {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
}

.overview-figures figure {
  width: 200px;
  margin: 0;
}

.overview-figures figcaption {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-muted);
}

.thumb {
  display: block;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  cursor: zoom-in;
}

.thumb img {
  display: block;
  width: 200px;
  height: 200px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  transition: opacity var(--transition-tactile);
}

.thumb:hover img {
  opacity: 0.88;
}

/* Full-size image overlay (Lightbox in Workbench.tsx) */
.lightbox {
  max-width: 95vw;
  max-height: 95vh;
  padding: 0;
  border: 0;
  background: none;
  outline: none; /* the dialog takes focus when it opens; the image needs no ring */
  cursor: zoom-out;
}

.lightbox::backdrop {
  background-color: hsla(212, 18%, 8%, 0.85);
}

.lightbox figure {
  margin: 0;
}

.lightbox img {
  display: block;
  width: auto;
  max-width: 95vw;
  height: auto;
  max-height: 85vh;
  border-radius: var(--radius-sm);
}

.lightbox figcaption {
  margin-top: 10px;
  font-size: 14px;
  text-align: center;
  color: var(--ink-on-accent);
}

/* Three-level diagram (src/robocar3/Architecture.tsx) */
.architecture {
  max-width: 720px;
  margin: 0;
}

.architecture svg {
  display: block;
  width: 100%;
}

.architecture figcaption {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.arch-box {
  fill: var(--surface-elevated);
  stroke: var(--border-default);
}

.arch-box.is-board {
  fill: var(--accent-subtle-bg);
  stroke: var(--accent-primary);
}

.arch-label {
  font-size: 11px;
  fill: var(--ink-secondary);
}

.arch-label.on-arrow {
  paint-order: stroke;
  stroke: var(--surface-canvas);
  stroke-width: 8px;
  stroke-linejoin: round;
}

.arch-arrow {
  stroke: var(--accent-primary);
  stroke-width: 1.6;
  stroke-opacity: 0.6;
}

.arch-arrow.is-up {
  stroke: var(--ink-muted);
}

.arch-arrowhead {
  fill: var(--accent-primary);
}

/* Zoomable parts treemap (src/robocar3/Treemap.tsx) */
.treemap {
  height: max(420px, calc(100vh - 220px));
}

.treemap svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.treemap-level.is-fading {
  pointer-events: none;
}

.treemap-tile.is-group {
  cursor: zoom-in;
}

.treemap-tile:hover rect {
  fill-opacity: 0.88;
}

.treemap-tile.cat-1 rect { fill: var(--viz-cat-1); }
.treemap-tile.cat-2 rect { fill: var(--viz-cat-2); }
.treemap-tile.cat-3 rect { fill: var(--viz-cat-3); }
.treemap-tile.cat-4 rect { fill: var(--viz-cat-4); }
.treemap-tile.cat-5 rect { fill: var(--viz-cat-5); }
.treemap-tile.cat-6 rect { fill: var(--viz-cat-6); }
.treemap-tile.stone-1 rect { fill: var(--viz-stone-1); }
.treemap-tile.stone-2 rect { fill: var(--viz-stone-2); }
.treemap-tile.stone-3 rect { fill: var(--viz-stone-3); }
.treemap-tile.stone-4 rect { fill: var(--viz-stone-4); }

.treemap-label {
  height: 100%;
  padding: 8px 10px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-on-accent);
}

.treemap-tile.is-part .treemap-label {
  color: var(--ink-on-stone);
}

.treemap-label > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.treemap-label-name {
  margin-bottom: 2px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.treemap-bar rect {
  fill: var(--ink-primary);
}

.treemap-bar text {
  font-size: 13px;
  font-weight: 600;
  fill: var(--surface-canvas);
  pointer-events: none;
}

.treemap-bar.is-zoomed {
  cursor: zoom-out;
}

/* ==========================================================================
   Narrow screens
   ========================================================================== */
@media (max-width: 1080px) {
  .constellation-stage {
    grid-template-columns: 140px minmax(240px, 1fr) minmax(220px, 1fr);
    column-gap: 32px;
  }
}

@media (max-width: 820px) {
  .portfolio-shell {
    width: calc(100% - 32px);
    padding-block: 36px 48px;
  }

  .constellation-stage {
    grid-template-columns: 1fr;
    row-gap: 28px;
  }

  .constellation-svg {
    display: none;
  }

  .col-domains .col-label {
    text-align: left;
  }

  .domain-list {
    flex: none;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .workbench-layout {
    grid-template-columns: 1fr;
  }

  .workbench-spine {
    position: static;
  }

  .treemap {
    height: 460px;
  }
}
