/* ---------- design tokens ---------- */
:root {
  --bg-0: #07070a;
  --bg-1: #0e0e14;
  --fg:   #e8e8ee;
  --fg-dim: #8a8a99;
  --accent: #ff7a3d;
  --accent-glow: #ff7a3d33;
  --line: #ffffff14;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --d-base: 0.85s;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-sans);
  color: var(--fg);
  background:
    radial-gradient(1200px 800px at 50% 110%, #1b0e08 0%, transparent 60%),
    radial-gradient(900px 700px at 20% -10%, #0a1a26 0%, transparent 55%),
    var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;

  /* The whole page is the camera frustum. perspective-origin slightly above
     center makes it feel like the camera is hovering looking down a touch. */
  perspective: 1500px;
  perspective-origin: 50% 38%;
}

/* ---------- floor / atmosphere ---------- */
.floor {
  position: fixed;
  left: 50%;
  bottom: -45vh;
  width: 240vw;
  height: 140vh;
  /* The translateZ(0) promotes .floor to its own composite layer, which
     contains all repaints from the grid drift below — they don't bubble
     up to the body. */
  transform: translateX(-50%) rotateX(72deg) translateZ(0);
  transform-origin: 50% 0%;
  pointer-events: none;
  /* fades the far end of the floor into the background */
  mask-image: linear-gradient(to top, #000 25%, transparent 90%);
  -webkit-mask-image: linear-gradient(to top, #000 25%, transparent 90%);
}
.grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 80px 80px;
  /* background-position is repainted each frame by the CPU rasterizer with
     subpixel precision. That's actually smoother than animating transform on
     a slow-moving GPU-rasterized layer (where the per-frame motion is below
     the integer-pixel quantization of the cached texture and you see steady
     1px-step jumps). The repaint is contained to the .floor layer above. */
  animation: drift 18s linear infinite;
  contain: paint;
}
@keyframes drift {
  from { background-position: 0 0; }
  to   { background-position: 0 80px; }
}

.fog {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 60vh;
  pointer-events: none;
  background: linear-gradient(to top, var(--bg-0) 5%, transparent 100%);
}
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, #000 130%);
}

/* ---------- stage ---------- */
.stage {
  position: relative;
  height: 100%;
  width: 100%;
  /* Flex centering, not grid + place-items: when a descendant uses
     overflow-wrap: anywhere (e.g. .name does, for the long heading), the
     implicit grid track collapses to character-width min-content and the
     stage-inner gets stuck at the left edge. Flex's justify/align-center
     don't depend on track sizing, so this is robust. */
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
  /* parallax tilt — JS smooths --mx/--my via RAF, no CSS transition needed
     (a CSS transition here would stack with the JS lerp and feel laggy). */
  transform: rotateX(var(--my, 0deg)) rotateY(var(--mx, 0deg));
  will-change: transform;
}
.stage-inner {
  width: min(640px, 88vw);
  transform-style: preserve-3d;
}

/* ---------- hero ---------- */
.hero { margin-bottom: clamp(36px, 6vh, 64px); }

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: block;
  margin: 0 0 22px;
  object-fit: cover;
  background: #15151c;
  /* layered glow + crisp 1px ring */
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 0 4px rgba(255, 122, 61, 0.10),
    0 16px 48px rgba(255, 122, 61, 0.18);

  /* enters first, slightly from above-front */
  --from-x: 0vw;
  --from-y: -14vh;
  --from-z: 420px;
  animation: sweepIn 0.95s var(--ease-out) both;
  animation-delay: 0s;
  will-change: transform, opacity;
}

.name {
  font-family: var(--font-sans);
  font-weight: 700;
  /* sized to fit "Indexguc:amrmatrix" on one line up to the 640px stage width;
     wraps gracefully at the <wbr> after the colon on narrower viewports */
  font-size: clamp(38px, 7vw, 72px);
  letter-spacing: -0.04em;
  line-height: 0.98;
  margin: 0;
  overflow-wrap: anywhere;
  background: linear-gradient(180deg, #ffffff 0%, #c9c9d6 75%, #6a6a78 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 30px 60px var(--accent-glow);

  /* sweeps in from bottom-left, big → normal */
  --from-x: -28vw;
  --from-y: 18vh;
  --from-z: 600px;
  animation: sweepIn 1.0s var(--ease-out) both;
  animation-delay: 0.05s;
  will-change: transform, opacity;
}

.tagline {
  margin: 20px 0 0;
  font-size: clamp(15px, 1.6vw, 18px);
  color: var(--fg-dim);
  letter-spacing: 0.01em;

  /* mirror the name: from bottom-right */
  --from-x: 28vw;
  --from-y: 14vh;
  --from-z: 480px;
  animation: sweepIn 1.0s var(--ease-out) both;
  animation-delay: 0.22s;
  will-change: transform, opacity;
}

/* ---------- link cards ----------
   2 cols × 3 rows, column-first fill order. HTML lists the left column first
   (github, email, placeholder), then the right column (amr_wtf, ScanThink,
   placeholder). The 3rd row in each column is a reserved slot. */
.links {
  display: grid;
  /* asymmetric: contact column narrower, project column wider. Ratio chosen
     so the contact column still fits "github.com/chenmoacr" (~138px mono)
     plus icon + arrow + padding without ellipsizing. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  grid-template-rows: repeat(3, auto);
  grid-auto-flow: column;
  gap: 12px;
}
@media (max-width: 540px) {
  .links {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-flow: row;
  }
  /* on mobile the reserved slots would just be dead vertical space */
  .card-placeholder { display: none; }
}

/* invisible spacer that reserves a row's height in either column.
   visibility:hidden (not display:none) so the grid row still exists. */
.card-placeholder {
  visibility: hidden;
  min-height: 58px;
  border-radius: 14px;
}

.card {
  --d: 0;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--fg);
  background: linear-gradient(180deg, #14141c 0%, #0d0d14 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  transform-style: preserve-3d;
  transition: transform 280ms var(--ease-out), border-color 200ms ease, background 200ms ease;

  /* default: sweep from bottom-right, big and forward */
  --from-x: 38vw;
  --from-y: 32vh;
  --from-z: 720px;
  animation: sweepIn 1.05s var(--ease-out) both;
  animation-delay: calc(0.4s + var(--d) * 0.08s);
  will-change: transform, opacity;
  backface-visibility: hidden;
}
/* Direction is column-based, not alternating: cards in the left column
   (HTML positions 1, 2 — position 3 is a placeholder, not a .card) sweep in
   from the bottom-left. Cards in the right column (positions 4, 5) keep the
   default and sweep from bottom-right. */
.card:nth-child(-n+3) {
  --from-x: -38vw;
}
.card::before {
  /* subtle accent sweep on hover */
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(140deg, transparent 35%, var(--accent) 50%, transparent 65%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity 240ms ease;
  pointer-events: none;
  z-index: -1;
}
.card:hover {
  transform: translateZ(20px) translateY(-2px);
  border-color: transparent;
  background: linear-gradient(180deg, #1a1a24 0%, #11111a 100%);
}
.card:hover::before { opacity: 1; }
.card:hover .card-arrow { transform: translateX(4px); color: var(--accent); }
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.card-icon {
  width: 22px;
  height: 22px;
  color: var(--fg-dim);
  transition: color 200ms ease;
}
.card:hover .card-icon { color: var(--fg); }

.card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-label { font-size: 14px; font-weight: 600; letter-spacing: 0.005em; }
.card-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-arrow {
  font-family: var(--font-mono);
  color: var(--fg-dim);
  font-size: 16px;
  transition: transform 200ms var(--ease-out), color 200ms ease;
}

/* ---------- footer ---------- */
.meta {
  margin-top: clamp(36px, 6vh, 64px);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.01em;

  /* gentle from-below-center, less dramatic so it doesn't compete with cards */
  --from-x: 0vw;
  --from-y: 10vh;
  --from-z: 250px;
  animation: sweepIn 0.9s var(--ease-out) both;
  animation-delay: 1.05s;
  will-change: transform, opacity;
}
.meta .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50%      { opacity: 1;   transform: scale(1.15); }
}

/* ---------- the entrance: a "camera sweep" from the bottom corners ----------
   Each animated element sets --from-x / --from-y / --from-z. Starting close
   to the camera (positive translateZ) makes it appear large; X/Y offsets
   place it off to one bottom corner. As all three converge to 0 the element
   shrinks and slides into its resting position.

   Pure compositor work: only opacity and a 3D translate animate. No filters,
   no layout, no paint. Holds up on weak GPUs. */
@keyframes sweepIn {
  from {
    opacity: 0;
    transform: translate3d(var(--from-x, 0vw), var(--from-y, 0vh), var(--from-z, 0));
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* ---------- accessibility: honor reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .grid { animation: none; }
  .meta .dot { animation: none; }
  .stage { transition: none; transform: none !important; }
  .name, .tagline, .card, .meta {
    animation: fadeIn 0.4s ease-out both;
    animation-delay: 0s !important;
  }
  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
  }
}

/* ---------- bilingual: only one language's content shows at a time ----------
   Content marked with lang="en" or lang="zh" is hidden when the document's
   active language doesn't match. The language is set on <html> by an inline
   script in <head> before this stylesheet evaluates, so there's no flash. */
html[lang="en"] [lang="zh"] { display: none; }
html[lang="zh"] [lang="en"] { display: none; }

/* ---------- language toggle ---------- */
.lang-toggle {
  position: fixed;
  top: 18px;
  right: 22px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  background: rgba(15, 15, 22, 0.55);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color 200ms ease, color 200ms ease, background 200ms ease;

  /* gentle entrance — slips in from above after the hero settles */
  --from-x: 0vw;
  --from-y: -3vh;
  --from-z: 100px;
  animation: sweepIn 0.7s var(--ease-out) 1.3s both;
}
.lang-toggle:hover {
  color: var(--fg);
  border-color: var(--accent);
}
.lang-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Both labels always render in the toggle; the active one is highlighted.
   Uses data-lang (not lang) so it bypasses the global content-hiding rules. */
.lang-toggle [data-lang] {
  opacity: 0.42;
  transition: opacity 200ms ease, color 200ms ease;
}
html[lang="en"] .lang-toggle [data-lang="en"],
html[lang="zh"] .lang-toggle [data-lang="zh"] {
  opacity: 1;
  color: var(--accent);
}
.lang-sep { opacity: 0.28; }

@media (prefers-reduced-motion: reduce) {
  .lang-toggle { animation: fadeIn 0.3s ease-out 0.2s both; }
}

/* ---------- selection ---------- */
::selection { background: var(--accent); color: #000; }
