:root {
  --bg: #0b1016;
  --bg-2: #121922;
  --bg-3: #18212c;
  --surface: #151d27;
  --text: #f5f7fa;
  --muted: #c3ccd6;
  --faint: #9aa6b4;
  --line: #2a3644;
  --accent: #3ecfbe;
  --accent-2: #7dd3fc;
  --accent-ink: #04211d;
  --warn: #fbbf24;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --max: 1100px;
  --nav-h: 68px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

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

a:hover {
  color: #6ee7d8;
}

.skip {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  background: transparent;
  color: var(--accent-ink);
  font-weight: 700;
  z-index: 200;
}

.skip:focus,
.skip:focus-visible {
  left: 0.75rem;
  top: 0.6rem;
  width: auto;
  height: auto;
  overflow: visible;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  background: var(--accent);
}

.wrap {
  width: min(var(--max), calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #0b1016;
  border-bottom: 1px solid var(--line);
}

.nav {
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  color: var(--text);
}

.caterpillar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: 0.35rem;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.32rem 0.72rem 0.32rem 0.4rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.caterpillar-toggle:hover,
.caterpillar-toggle:focus-visible {
  color: var(--text);
  border-color: var(--accent);
}

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

.caterpillar-toggle[aria-pressed="true"] {
  color: var(--text);
  border-color: #22d3ee;
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.22);
}

.caterpillar-toggle-dot {
  width: 1.4rem;
  height: 0.84rem;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  position: relative;
  flex-shrink: 0;
}

.caterpillar-toggle-dot::after {
  content: "";
  position: absolute;
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: var(--faint);
  top: 0.06rem;
  left: 0.08rem;
  transition: transform 0.2s ease, background 0.2s ease;
}

.caterpillar-toggle[aria-pressed="true"] .caterpillar-toggle-dot::after {
  transform: translateX(0.52rem);
  background: #7cff4a;
}

@media (pointer: coarse) {
  .caterpillar-toggle {
    display: none;
  }
}

.menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}

.hero {
  padding: 3.4rem 0 1.4rem;
  overflow: clip;
}

.hero-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(260px, 1fr);
  gap: 1.5rem 2rem;
  align-items: center;
}

.hero-scene {
  position: relative;
  height: 340px;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(34, 211, 238, 0.08), transparent 46%),
    radial-gradient(ellipse at 50% 80%, rgba(15, 23, 32, 0.2), #0b1016 70%);
  border: 1px solid var(--line);
}

.hero-canvas,
.hero-static {
  display: block;
  width: 100%;
  height: 100%;
}

.hero-canvas {
  position: relative;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.7s ease;
  image-rendering: pixelated;
}

.hero-static {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.7s ease;
}

.scene-live .hero-canvas {
  opacity: 1;
}

.scene-live .hero-static {
  opacity: 0;
}

.scene-static .hero-canvas {
  display: none;
}

.scene-static .hero-static {
  position: relative;
  opacity: 1;
}

.scene-nodes {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.scene-node-btn {
  position: absolute;
  left: 0;
  top: 0;
  width: 3rem;
  height: 3rem;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  pointer-events: auto;
  cursor: pointer;
}

.scene-node-btn:focus-visible {
  outline: 2px solid #22d3ee;
  outline-offset: 3px;
  border-radius: 8px;
}

.scene-node-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, 2.7rem);
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #e8eef8;
  white-space: nowrap;
  pointer-events: none;
  padding: 0.12rem 0.32rem 0.1rem;
  border-radius: 0.28rem;
  background: rgba(11, 16, 22, 0.84);
  text-shadow: 0 1px 2px #0b1016;
}

.scene-static .scene-nodes {
  position: absolute;
  inset: auto 0.6rem 0.6rem;
  top: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  height: auto;
  pointer-events: auto;
}

.scene-static .scene-node-btn {
  position: static;
  width: auto;
  height: auto;
  min-height: 2.3rem;
  padding: 0.35rem 0.65rem;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
}

.scene-static .scene-node-label {
  position: static;
  transform: none;
  background: transparent;
  padding: 0;
  text-shadow: none;
}

.hero-scene-hud {
  position: absolute;
  inset: 0.7rem 0.85rem auto;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  pointer-events: none;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.node-card {
  position: absolute;
  left: 0.7rem;
  right: 0.7rem;
  bottom: 0.7rem;
  z-index: 6;
  padding: 0.8rem 0.9rem 0.85rem;
  border-radius: 12px;
  background: rgba(15, 22, 30, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.node-card-kicker {
  margin: 0 0 0.3rem;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #22d3ee;
}

.node-card-copy {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.node-card-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem 1rem;
}

.node-card-link {
  font-size: 0.85rem;
  font-weight: 650;
  text-decoration: none;
}

.node-card-close {
  border: 0;
  background: transparent;
  color: var(--faint);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.15rem 0.2rem;
}

.node-card-close:hover,
.node-card-close:focus-visible {
  color: var(--text);
}

.play-arrow-wrap {
  display: flex;
  justify-content: center;
  padding: 1.15rem 0 0.35rem;
}

.play-arrow {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  padding: 0.35rem;
  border-radius: 16px;
}

.play-arrow:hover,
.play-arrow:focus-visible {
  color: var(--text);
}

.play-arrow:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.play-arrow-glyph {
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.08);
  box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.45), 0 0 18px rgba(34, 211, 238, 0.28);
  animation: play-arrow-pulse 2.2s ease-in-out infinite;
  transition: transform 0.35s ease;
}

.play-arrow-glyph::after {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-right: 2px solid #a5f3fc;
  border-bottom: 2px solid #a5f3fc;
  transform: translateY(-2px) rotate(45deg);
}

.play-arrow:hover .play-arrow-glyph,
.play-arrow:focus-visible .play-arrow-glyph {
  border-color: #22d3ee;
  background: rgba(34, 211, 238, 0.16);
}

.play-arrow[aria-expanded="true"] .play-arrow-glyph {
  transform: rotate(180deg);
  animation: none;
}

@keyframes play-arrow-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.42), 0 0 16px rgba(34, 211, 238, 0.24);
    transform: translateY(0);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(34, 211, 238, 0), 0 0 22px rgba(34, 211, 238, 0.38);
    transform: translateY(4px);
  }
}

section.space-game {
  padding: 0;
  border-top: 0;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 1.25s cubic-bezier(0.22, 1, 0.36, 1);
  scroll-margin-top: calc(var(--nav-h) + 0.6rem);
}

section.space-game.is-open {
  grid-template-rows: 1fr;
  padding-bottom: 2.2rem;
}

.space-game-clip {
  overflow: hidden;
  min-height: 0;
}

.space-game-frame {
  display: flex;
  flex-direction: column;
  height: min(72vh, 640px);
  margin-top: 0.4rem;
  background: #070b10;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.space-game-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.9rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #0b1016;
}

.space-game-hud b {
  color: #a5f3fc;
  font-weight: 650;
}

.space-game-hud-actions {
  display: flex;
  gap: 0.45rem;
  margin-left: auto;
}

.space-game-hud .btn {
  padding: 0.38rem 0.8rem;
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
}

.space-game-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #070b10;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

#game-canvas:focus {
  outline: none;
}

.space-game-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(7, 11, 16, 0.42);
}

.space-game-overlay[hidden],
.space-game-intro[hidden],
.space-game-over[hidden],
#game-title-card[hidden],
#game-choose[hidden] {
  display: none;
}

.space-game-panel {
  text-align: center;
  max-width: 28rem;
}

.space-game-title {
  margin: 0 0 0.7rem;
  font-size: clamp(1.7rem, 4vw, 2.7rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #22d3ee;
  text-shadow: 0 0 22px rgba(34, 211, 238, 0.45);
}

.space-game-sub {
  margin: 0 0 1.1rem;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 650;
}

.space-game-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.space-game-diffs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.space-game-touch {
  display: none;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem 0.9rem;
  border-top: 1px solid var(--line);
  background: #0b1016;
}

.space-game-touch.is-visible {
  display: flex;
}

@media (pointer: fine) {
  .space-game-touch,
  .space-game-touch.is-visible {
    display: none;
  }
}

.space-game-touch button {
  flex: 1;
  min-height: 3.1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.space-game-touch button:active,
.space-game-touch button:focus-visible {
  border-color: #22d3ee;
  color: #a5f3fc;
}

.space-game-touch [data-touch="fire"] {
  background: rgba(34, 211, 238, 0.12);
  border-color: rgba(34, 211, 238, 0.4);
  color: #a5f3fc;
}

.caterpillar-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 180;
}

body.caterpillar-on,
body.caterpillar-on * {
  cursor: none !important;
}

html.is-playing-game,
html.is-playing-game body,
html.is-game-open,
html.is-game-open body {
  overflow: hidden;
  overscroll-behavior: none;
}

html.is-game-open .play-arrow-wrap {
  display: none;
}

html.is-game-open .site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.kicker {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 0.8rem;
}

h1,
h2,
h3 {
  letter-spacing: -0.03em;
  line-height: 1.15;
}

h1 {
  font-size: clamp(2.1rem, 5vw, 3.6rem);
  margin: 0 0 1rem;
  max-width: 16ch;
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  margin: 0 0 0.8rem;
}

h3 {
  font-size: 1.15rem;
  margin: 0 0 0.4rem;
}

.lede {
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 42rem;
  margin: 0 0 1.5rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font-weight: 650;
  font-size: 0.95rem;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: #6ee7d8;
  color: var(--accent-ink);
}

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

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

section {
  padding: 3.2rem 0;
  border-top: 1px solid var(--line);
}

section[id],
.page-hero,
#top {
  scroll-margin-top: var(--nav-h);
}

.about-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 2rem;
  align-items: start;
}

.portrait {
  width: 180px;
  height: 180px;
  border-radius: 28px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--bg-2);
}

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

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

.links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.3rem;
  margin-top: 1.1rem;
}

.skills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.skill,
.tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 550;
}

.tag-live {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.tag-note {
  color: #1f1303;
  background: var(--warn);
  border-color: var(--warn);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.card-body {
  padding: 1.1rem 1.15rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  flex: 1;
}

.card-media {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-3);
}

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

.placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--accent-2);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.meta {
  color: var(--faint);
  font-size: 0.82rem;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: auto;
  padding-top: 0.4rem;
}

.card-links a {
  font-weight: 650;
  text-decoration: none;
  font-size: 0.9rem;
}

.repo-list {
  display: grid;
  gap: 0.75rem;
}

.repo {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
}

.repo h3 {
  margin-bottom: 0.2rem;
}

.repo p {
  margin: 0;
  color: var(--muted);
}

.notice {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.28);
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1.2rem;
}

.prose {
  max-width: 44rem;
}

.prose p,
.prose li {
  color: var(--muted);
}

.prose h2 {
  margin-top: 2rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 1.2rem 0;
}

.feature {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
}

.feature h3 {
  margin-bottom: 0.35rem;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.6rem 0 2.2rem;
  color: var(--faint);
  font-size: 0.9rem;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-hero {
  padding-top: 2.4rem;
  padding-bottom: 0.4rem;
  border-top: none;
}

@media (max-width: 760px) {
  .menu-btn {
    display: inline-flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: #0b1016;
    border-bottom: 1px solid var(--line);
    flex-direction: column;
    align-items: stretch;
    padding: 0.8rem 1rem 1.1rem;
    gap: 0.2rem;
    box-shadow: 0 16px 28px rgba(0, 0, 0, 0.45);
  }

  .nav-links.is-open {
    display: flex;
  }

  .nav-links a {
    padding: 0.7rem 0.2rem;
  }

  .caterpillar-toggle {
    margin: 0.45rem 0 0.15rem;
    align-self: flex-start;
  }

  .about-grid,
  .grid,
  .feature-grid,
  .repo {
    grid-template-columns: 1fr;
  }

  .hero {
    padding-top: 2.1rem;
  }

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

  .hero-scene {
    height: 220px;
  }

  .scene-node-label {
    font-size: 0.5rem;
    letter-spacing: 0.06em;
    transform: translate(-50%, 1.55rem);
  }

  .space-game-frame {
    height: calc(100svh - var(--nav-h) - 0.75rem);
  }

  .space-game-hud {
    font-size: 0.68rem;
    gap: 0.4rem 0.65rem;
  }

  .space-game-hud-actions {
    width: 100%;
    margin-left: 0;
  }

  .space-game-hud .btn {
    flex: 1;
  }

  .portrait {
    width: 132px;
    height: 132px;
  }
}

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

  .play-arrow-glyph,
  .caterpillar-toggle-dot::after {
    animation: none;
    transition: none;
  }

  section.space-game {
    transition: none;
  }
}
