:root {
  --ink: #0b0c0e;
  --surface: #111317;
  --text: #e7e9ec;
  --muted: #a9b0b9;
  --line: #262b32;
  --line-strong: #5a6470;
  --accent: #f5a83c;
  --accent-ink: #0b0c0e;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --wrap: 1120px;
  --gutter: 88px;
  --pad: clamp(20px, 5vw, 48px);
}

[data-theme="light"] {
  --ink: #f2efe8;
  --surface: #eae6dd;
  --text: #14161a;
  --muted: #565d66;
  --line: #d5cfc2;
  --line-strong: #837c6d;
  --accent: #8f4e05;
  --accent-ink: #f2efe8;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

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

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.mono {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding-left: var(--pad);
  padding-right: var(--pad);
}

/* Focus: visible, accent, never removed without replacement */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 1px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 20;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--mono);
  font-size: 0.8125rem;
}

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

/* Header */
.site-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--ink);
  border-bottom: 1px solid var(--line);
}

.head-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
}

.wordmark {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 1.0625rem;
  letter-spacing: -0.01em;
  margin-right: auto;
}

.nav {
  display: flex;
  gap: clamp(14px, 3vw, 32px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav a {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 2px;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  transition: color 160ms ease, background-size 200ms ease;
}

.nav a:hover {
  color: var(--text);
  background-size: 100% 1px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}

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

.theme-toggle:active {
  transform: translateY(1px);
}

.theme-toggle-value {
  color: var(--accent);
}

/* Hero */
.hero {
  padding-top: clamp(56px, 9vw, 104px);
  padding-bottom: clamp(64px, 10vw, 120px);
  border-bottom: 1px solid var(--line);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 0.85fr);
  gap: clamp(32px, 6vw, 80px);
  align-items: end;
}

.kicker {
  color: var(--accent);
  margin-bottom: 18px;
}

h1 {
  font-size: clamp(3.5rem, 12vw, 8.5rem);
  letter-spacing: -0.045em;
  line-height: 0.9;
  margin-bottom: 24px;
}

.lead {
  max-width: 34ch;
  color: var(--text);
  font-size: clamp(1.0625rem, 1.4vw, 1.1875rem);
  line-height: 1.55;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

.btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: 2px;
  font-weight: 500;
  font-size: 0.9375rem;
  transition: transform 140ms ease, background-color 140ms ease, color 140ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-quiet {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.btn-quiet:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Spec sheet */
.spec {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  column-gap: 12px;
  margin: 0;
  border-top: 1px solid var(--line);
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: 0.02em;
}

.spec dt,
.spec dd {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.spec dt {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
}

.spec dd {
  margin: 0;
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1.45;
}

.spec-big {
  display: block;
  font-family: var(--sans);
  font-size: 2.5rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
  margin-bottom: 6px;
}

.spec-link {
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 2px;
  transition: color 140ms ease, border-color 140ms ease;
}

.spec-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Sections */
.section {
  padding-top: clamp(64px, 9vw, 112px);
  padding-bottom: clamp(64px, 9vw, 112px);
  border-bottom: 1px solid var(--line);
}

.section-grid {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  gap: clamp(16px, 3vw, 32px);
}

.gutter {
  color: var(--muted);
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.section-body {
  min-width: 0;
}

h2 {
  font-size: clamp(2rem, 5vw, 3rem);
  margin-bottom: 14px;
}

.section-note {
  max-width: 56ch;
  color: var(--muted);
  margin-bottom: clamp(28px, 5vw, 48px);
}

/* Work index */
.index {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.project {
  border-bottom: 1px solid var(--line);
}

.project-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 110px 62px;
  gap: 16px;
  align-items: center;
  width: 100%;
  min-height: 64px;
  padding: 16px 8px 16px 0;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.project-row:hover,
.project[data-open="true"] .project-row {
  background: var(--surface);
}

.index-no {
  color: var(--muted);
  transition: color 160ms ease;
}

.project-row:hover .index-no,
.project[data-open="true"] .index-no {
  color: var(--accent);
}

.project-title {
  font-size: 1.0625rem;
  font-weight: 500;
  min-width: 0;
}

.project-sub {
  color: var(--muted);
  font-weight: 400;
  margin-left: 10px;
}

.project-lang {
  color: var(--muted);
  justify-self: start;
}

.project-cue {
  justify-self: end;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  padding: 4px 8px;
  font-size: 0.625rem;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.project[data-open="true"] .project-cue {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.project-panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: grid-template-rows 300ms ease, opacity 220ms ease,
    transform 300ms cubic-bezier(0.2, 0.7, 0.3, 1), visibility 0s linear 300ms;
}

.project[data-open="true"] .project-panel {
  grid-template-rows: 1fr;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: grid-template-rows 300ms ease, opacity 220ms ease,
    transform 300ms cubic-bezier(0.2, 0.7, 0.3, 1), visibility 0s;
}

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

.project-card {
  margin: 0 0 20px 60px;
  padding: 18px 20px;
  max-width: 72ch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 2px;
}

.project-desc {
  font-size: 0.9375rem;
  line-height: 1.6;
}

.project-source {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.project-repo {
  color: var(--text);
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 2px;
  overflow-wrap: anywhere;
  transition: color 140ms ease, border-color 140ms ease;
}

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

/* Stack */
.stack {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.stack-row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr);
  gap: clamp(16px, 4vw, 48px);
  align-items: baseline;
  padding: clamp(22px, 3vw, 34px) 0;
  border-bottom: 1px solid var(--line);
}

.stack-name {
  font-size: clamp(1.75rem, 4.2vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1;
}

.stack-desc {
  color: var(--muted);
  max-width: 44ch;
}

/* Contact */
.section-contact {
  border-bottom: 0;
}

.contact-link {
  display: inline-block;
  font-size: clamp(1.75rem, 6vw, 4rem);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.1;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 6px;
  margin-bottom: 24px;
  overflow-wrap: anywhere;
  transition: color 140ms ease;
}

.contact-link:hover {
  color: var(--accent);
}

.contact-meta {
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: none;
  font-size: 0.8125rem;
}

.contact-alt {
  color: var(--text);
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 2px;
  transition: color 140ms ease, border-color 140ms ease;
}

.contact-alt:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Footer */
.site-foot {
  border-top: 1px solid var(--line);
  padding: 28px 0 40px;
}

.foot-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  justify-content: space-between;
  color: var(--muted);
}

.foot-inner a {
  border-bottom: 1px solid var(--line);
  padding-bottom: 2px;
  transition: color 140ms ease, border-color 140ms ease;
}

.foot-inner a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Motion: entry order follows reading order, nothing loops except the caret */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes caret-blink {
  0%,
  54% {
    opacity: 1;
  }
  55%,
  100% {
    opacity: 0.12;
  }
}

.caret {
  display: inline-block;
  animation: caret-blink 1.7s steps(1, end) 1.1s infinite;
}

.hero-copy > *,
.spec {
  animation: rise 560ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.kicker {
  animation-delay: 60ms;
}

h1 {
  animation-delay: 120ms;
}

.lead {
  animation-delay: 200ms;
}

.hero-actions {
  animation-delay: 280ms;
}

.spec {
  animation-delay: 240ms;
}

.js .reveal-item {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 460ms ease var(--reveal-delay, 0ms),
    transform 460ms cubic-bezier(0.2, 0.7, 0.3, 1) var(--reveal-delay, 0ms);
}

.js .is-in .reveal-item,
.js .reveal-item.is-in {
  opacity: 1;
  transform: translateY(0);
}

html.theming,
html.theming * {
  transition: background-color 240ms ease, border-color 240ms ease,
    color 240ms ease;
}

/* Responsive */
@media (max-width: 860px) {
  .hero-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 40px;
  }

  .spec {
    max-width: 420px;
  }

  .stack-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
}

@media (max-width: 720px) {
  .section-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .gutter {
    padding-top: 0;
    border-top: 0;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .gutter::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
  }

  .project-row {
    grid-template-columns: 32px minmax(0, 1fr) auto;
    grid-template-areas:
      "no title cue"
      "no lang lang";
    row-gap: 6px;
    column-gap: 12px;
    padding: 16px 0;
  }

  .index-no {
    grid-area: no;
  }

  .project-title {
    grid-area: title;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .project-sub {
    margin-left: 0;
    font-size: 0.9375rem;
  }

  .project-lang {
    grid-area: lang;
  }

  .project-cue {
    grid-area: cue;
  }

  .project-card {
    margin-left: 0;
  }
}

@media (max-width: 560px) {
  .head-inner {
    gap: 14px;
    min-height: 60px;
  }

  .nav {
    gap: 12px;
  }

  .nav a {
    font-size: 0.6875rem;
  }

  .theme-toggle {
    padding: 0 10px;
  }

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

  .hero-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

@media print {
  .site-head {
    position: static;
  }

  .js .reveal-item {
    opacity: 1;
    transform: none;
  }

  .caret {
    animation: none;
    opacity: 1;
  }
}

@media (max-width: 400px) {
  .head-inner {
    flex-wrap: wrap;
    gap: 4px 12px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .wordmark {
    order: 1;
  }

  .theme-toggle {
    order: 2;
    margin-left: auto;
  }

  .nav {
    order: 3;
    width: 100%;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 4px;
  }

  html {
    scroll-padding-top: 108px;
  }
}

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }

  .caret {
    animation: none;
    opacity: 1;
  }

  .hero-copy > *,
  .spec {
    animation: none;
  }

  .js .reveal-item {
    opacity: 1;
    transform: none;
    transition: none;
  }

  html.theming,
  html.theming * {
    transition: none;
  }
}
