/*
  Shared stylesheet for every page on elijahvfg.com.
  Layout follows paco.me: a narrow column with labelled grids; colors come from Frank Chimero's
  palette (dark: his #3d4340 green-grey, light: #eee paper with sage accent).
  Dark is the default. theme.js sets data-theme="light" when a visitor
  picks it, and the inline script in each <head> restores it before paint.
*/

:root {
  color-scheme: dark;

  --bg: #3d4340;
  --fg: #eeeeee;
  --text: #dcdfdd;
  --dim: #b0bab5; /* Frank's #717d78, lightened to pass AA on --bg */
  --faint: #717d78;
  --border: #4f5753;
  --border-strong: #69736e;
  --surface: #434a46;
  --accent: #b4cbc0;
  --selection: #232927;

  --font-sans: "Inter", "Inter var", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-base: 0.9375rem; /* 15px */
  --text-sm: 0.875rem; /* 14px */
  --leading: 1.75;
  --leading-sm: 1.6;

  --content-width: 42rem;
  --prose-width: 36rem;
  --gutter: 1.25rem;
  --radius: 10px;
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space: 1rem;
  --space-lg: 1.75rem;
  --space-xl: 2.75rem;
  --space-xxl: 4.5rem;

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --fast: 150ms var(--ease);
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #eeeeee;
  --fg: #2f3432;
  --text: #2f3432;
  --dim: #626b67; /* Frank's #828b87, darkened to pass AA on --bg */
  --faint: #828b87;
  --border: #d0d6d4;
  --border-strong: #aab3af;
  --surface: #f6f6f6;
  --accent: #536e62; /* Frank's #5e786d, darkened to pass AA */
  --selection: #d0d6d4;
}

/* - Foundations ------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--selection);
  color: var(--fg);
}

h1,
h2,
h3,
h4,
p,
ul,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-size: inherit;
  line-height: inherit;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color var(--fast), text-decoration-color var(--fast);
}

a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

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

time {
  font-variant-numeric: tabular-nums;
}

p,
li,
dd {
  text-wrap: pretty;
}

h1,
h2,
h3,
h4 {
  text-wrap: balance;
}

/* Keeps a link's ↗ arrow on the same line as its last word */
.nobr {
  white-space: nowrap;
}

.dim {
  color: var(--dim);
}

/* Small arrow after links that leave the site */
.out {
  width: 0.625rem;
  height: 0.625rem;
  margin-left: 0.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  color: var(--faint);
  vertical-align: 0.05em;
}

/* - Page shell ---------------------------------------------------- */

.page {
  max-width: calc(var(--content-width) + var(--gutter) * 2);
  margin: 0 auto;
  padding: clamp(3rem, 12vh, 7rem) var(--gutter) var(--space-xxl);
}

/* Name or back link on the left, theme toggle on the right */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space);
  margin-bottom: var(--space-lg);
}

.topbar h1 {
  color: var(--fg);
  font-weight: 500;
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--dim);
  font-size: var(--text-sm);
  text-decoration: none;
}

/* - Theme toggle -------------------------------------------------- */

.theme-toggle {
  position: relative;
  flex: none;
  width: 3rem;
  height: 1.625rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--dim);
  cursor: pointer;
  transition: border-color var(--fast);
}

.theme-toggle:hover {
  border-color: var(--border-strong);
}

.theme-toggle:focus-visible {
  border-radius: 999px;
}

.theme-toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 0 0 1px var(--border);
  transform: translateX(1.375rem);
  transition: transform 200ms var(--ease);
}

.theme-toggle svg {
  width: 0.75rem;
  height: 0.75rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
}

.theme-toggle .sun {
  display: none;
}

[data-theme="light"] .theme-toggle .knob {
  transform: none;
}

[data-theme="light"] .theme-toggle .sun {
  display: block;
}

[data-theme="light"] .theme-toggle .moon {
  display: none;
}

/* Without JavaScript the toggle can't work, so hide it */
:root:not([data-theme]) .theme-toggle {
  display: none;
}

/* - Intro --------------------------------------------------------- */

.intro p {
  max-width: var(--prose-width);
}

.intro h1 {
  margin-bottom: var(--space);
  color: var(--fg);
  font-weight: 500;
}

.intro p + p {
  margin-top: var(--space);
}

.intro .dim {
  margin-top: var(--space-xs);
}

.social {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs) var(--space-sm);
  margin: var(--space-lg) 0 0 calc(var(--space-sm) * -1);
  padding: 0;
  list-style: none;
}

.social a {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  color: var(--dim);
  border-radius: 6px;
}

.social a:hover {
  color: var(--fg);
}

.social svg {
  width: 1.0625rem;
  height: 1.0625rem;
  fill: currentColor;
}

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

main {
  margin-top: var(--space-xl);
}

section + section {
  margin-top: var(--space-xxl);
}

section > h2 {
  margin-bottom: var(--space);
  color: var(--dim);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: var(--leading-sm);
}

/* - Columns (Paco-style grid) ------------------------------------
   <div class="columns">
     <section class="column"><h2 class="label">…</h2><ul class="items">…</ul></section>
   Each item: a title (usually the link), then muted lines below. */

.columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-xl) var(--space-lg);
  align-items: start;
}

.columns > .column {
  margin-top: 0;
}

.columns.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* .rows-2: every column's items share the same rows, so the second item
   in each column starts on the same line even when descriptions differ
   in length. Each column spans one label row plus two item rows. */
@media (min-width: 40.0625rem) {
  @supports (grid-template-rows: subgrid) {
    .columns.rows-2 {
      row-gap: var(--space-lg);
    }

    .columns.rows-2 > .column {
      display: grid;
      grid-row: span 3;
      grid-template-rows: subgrid;
    }

    .columns.rows-2 .label {
      margin-bottom: 0;
    }

    .columns.rows-2 .items {
      display: grid;
      grid-row: span 2;
      grid-template-rows: subgrid;
    }

    .columns.rows-2 .items > li + li {
      margin-top: 0;
    }
  }
}

.label {
  margin-bottom: var(--space-lg);
  color: var(--dim);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: var(--leading-sm);
}

.items {
  padding: 0;
  list-style: none;
}

.items > li + li {
  margin-top: var(--space-lg);
}

.item-title {
  color: var(--fg);
  font-size: inherit;
  font-weight: 400;
}

.item-title a {
  color: var(--fg);
  text-decoration-color: var(--faint);
}

.item-title a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.item p {
  color: var(--dim);
}

.item .meta {
  margin-top: var(--space-xs);
  color: var(--dim);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}

.meta a {
  color: var(--dim);
}

.meta a:hover {
  color: var(--accent);
}

/* - Entries (experience, education) ------------------------------- */

.entry-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0 var(--space);
}

.entry > * + * {
  margin-top: var(--space-sm);
}

.entry h3 {
  color: var(--fg);
  font-weight: 400;
}

.entry-meta,
.entry .role {
  color: var(--dim);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}

.entry-head + .role {
  margin-top: 0;
}

.entries > .entry + .entry {
  margin-top: var(--space-xl);
}

.entry ul {
  padding-left: 1rem;
  list-style: disc;
}

.entry li {
  padding-left: var(--space-xs);
}

.entry li::marker {
  color: var(--faint);
}

.entry li + li {
  margin-top: var(--space-sm);
}

/* - Label / value rows (skills) ---------------------------------- */

.rows > div {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  align-items: baseline;
  gap: 0 var(--space);
}

.rows > div + div {
  margin-top: var(--space-sm);
}

.rows dt {
  color: var(--dim);
  font-size: var(--text-sm);
}

/* - Chat panel ("Ask about Elijah", public/chat.js) ----------------- */

:root {
  --chat-width: 24rem;
}

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

/* On wide screens the open panel sits beside the page, which stays usable. */
@media (min-width: 64rem) {
  html.chat-open body {
    padding-right: var(--chat-width);
  }
}

.chat-launcher {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 8px 28px -14px rgb(0 0 0 / 0.45);
  color: var(--fg);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color var(--fast);
}

.chat-launcher:hover {
  border-color: var(--border-strong);
}

.chat-launcher:focus-visible {
  border-radius: 999px;
}

.chat-launcher svg {
  width: 0.875rem;
  height: 0.875rem;
  fill: var(--accent);
}

html.chat-open .chat-launcher:not(.is-inline) {
  display: none;
}

.chat-slot {
  display: flex;
  justify-content: center;
  margin-top: var(--space-xl);
}

.chat-slot:empty {
  display: none;
}

.chat-launcher.is-inline {
  position: static;
  padding: 0.65rem 1.15rem 0.65rem 0.95rem;
  font-size: var(--text-base);
}

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(var(--chat-width), 100vw);
  border-left: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 220ms var(--ease), visibility 0s linear 220ms;
}

html.chat-open .chat-panel {
  transform: none;
  visibility: visible;
  transition: transform 220ms var(--ease);
}

html.chat-no-anim .chat-panel {
  transition: none;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space);
  padding: 1rem 1rem 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.chat-title {
  color: var(--fg);
  font-weight: 500;
}

.chat-sub {
  color: var(--dim);
  font-size: 0.8125rem;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.chat-text-button,
.chat-icon-button,
.chat-suggestion {
  border: 0;
  background: none;
  color: var(--dim);
  font: inherit;
  cursor: pointer;
  transition: color var(--fast), border-color var(--fast);
}

.chat-text-button {
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8125rem;
}

.chat-icon-button {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
}

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

.chat-icon-button svg,
.chat-send svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space);
  padding: 1.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-empty {
  color: var(--dim);
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-sm);
  margin-top: var(--space);
}

.chat-suggestion {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  text-align: left;
}

.chat-suggestion:hover {
  border-color: var(--border-strong);
  color: var(--fg);
}

.chat-msg {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg.user {
  align-self: flex-end;
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px 14px 4px 14px;
  background: var(--surface);
  color: var(--fg);
}

.chat-msg.assistant {
  color: var(--text);
}

.chat-msg.is-error,
.chat-notice,
.chat-flag {
  color: var(--dim);
}

.chat-typing {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.5rem 0;
}

.chat-typing i {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--faint);
  animation: chat-dot 1.2s ease-in-out infinite;
}

.chat-typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

.chat-form {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: 0.375rem 0.375rem 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  transition: border-color var(--fast), box-shadow var(--fast);
}

.chat-input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.chat-input-row textarea {
  flex: 1;
  min-height: 2rem;
  max-height: 9rem;
  padding: 0.3rem 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  line-height: 1.5;
  resize: none;
}

.chat-input-row textarea:focus-visible {
  outline: none;
}

.chat-input-row textarea::placeholder {
  color: var(--dim);
}

.chat-send {
  display: grid;
  flex: none;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  cursor: pointer;
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-send.is-stop svg {
  fill: currentColor;
  stroke: none;
}

.chat-note {
  margin-top: var(--space-sm);
  color: var(--dim);
  font-size: 0.75rem;
  line-height: 1.45;
}

.chat-msg a {
  color: var(--fg);
}

@media (prefers-reduced-transparency: reduce) {
  .chat-launcher {
    background: var(--surface);
  }

  .chat-panel {
    background: var(--bg);
  }

  .chat-launcher,
  .chat-panel {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel,
  html.chat-open .chat-panel {
    transition: none;
  }

  .chat-typing i {
    animation: none;
    opacity: 0.6;
  }
}

/* On phones the panel covers the page, so it's opaque and full width. */
@media (max-width: 34rem) {
  .chat-launcher {
    right: var(--gutter);
    bottom: var(--gutter);
  }

  .chat-panel {
    width: 100%;
    border-left: 0;
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  /* 16px keeps iOS from zooming in when the input gets focus. */
  .chat-input-row textarea {
    font-size: 1rem;
  }
}

/* - Entrance ------------------------------------------------------ */

@media (prefers-reduced-motion: no-preference) {
  .page > * {
    animation: enter 600ms var(--ease) both;
  }

  .page > :nth-child(2) {
    animation-delay: 60ms;
  }

  .page > :nth-child(3) {
    animation-delay: 120ms;
  }

  @keyframes enter {
    from {
      opacity: 0;
      transform: translateY(6px);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  a,
  .theme-toggle,
  .theme-toggle .knob {
    transition: none;
  }
}

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

@media (max-width: 40rem) {
  .columns,
  .columns.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 34rem) {
  .rows > div {
    grid-template-columns: 1fr;
  }

  .entry-head {
    flex-direction: column;
    gap: 0;
  }
}
