/* Xuheng Ma — one screen. The black hole is the way in: data-view on .os and
   .on on the open pane drive every transition; app.js supplies the geometry
   as custom properties so the type lands where the horizon does. The horizon
   opens from the top for the short panes and from the side for the long ones
   (the CV and each piece of research). */

:root {
  color-scheme: dark;
  --muted: #9aa1ad;
  --hair: rgba(255, 255, 255, 0.14);
  --edge: rgba(255, 255, 255, 0.3);
  --blue: #5b9bff;
  --blue-hi: #8db9ff;
  --glass: rgba(8, 9, 12, 0.66);
  --ui: 'Inter', system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.65, 0, 0.35, 1);
  --out: cubic-bezier(0.2, 0.7, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: #000; overscroll-behavior: none; }
body {
  overflow: hidden;
  color: #fff;
  font: 400 14px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; font-size: inherit; font-weight: inherit; }
ul, ol { list-style: none; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
::selection { background: rgba(91, 155, 255, 0.35); }

.os {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  --name-top: 70vh;
  --sub-top: calc(70vh + 36px);
  --name-lift: -200px;
  --name-grow: 2;
  --sub-lift: -168px;
  --sub-grow: 1.2308;
  --pane-left: calc(50% - 280px);
  --pane-top: 40vh;
  --pane-w: 560px;
  --pane-max: 50vh;
  --about-gap: 152px;
  --rest: 1;
  --dur: 1.2s;
  --side-left: 45vw;
  --side-top: 64px;
  --side-max: 80vh;
  --cv-w: 640px;
  --work-w: 720px;
  --cv-gap: 110px;
  --cv-name-x: 0px;
  --cv-name-y: -300px;
  --cv-name-grow: 1.6;
  --cv-sub-x: 0px;
  --cv-sub-y: -280px;
  --cv-sub-grow: 1.1538;
}

#sky {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  transition: opacity 1.2s ease;
}

/* ---- top bar ---- */
.bar {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(20px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  transition: opacity 0.8s ease;
}
.bar .home {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: auto;
}
.clock { display: flex; gap: 12px; font: 400 12px/1 var(--mono); }
.clock #date { color: var(--muted); }

/* ---- the name: under the hole at rest, the title of About and of the CV once inside ---- */
.idn, .ids {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: transform var(--dur) var(--ease), opacity 0.35s ease, visibility 0s;
}
.idn {
  top: calc(var(--name-top) - 9px);
  display: flex;
  justify-content: center;
  transform-origin: 50% 9px;
  font-size: 22px;
  font-weight: 600;
  line-height: 26px;
  letter-spacing: -0.01em;
  transform: translate(0, 0) scale(var(--rest));
}
.idn a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 12px;
  pointer-events: auto;
}
.idn span { font-size: 14px; font-weight: 400; letter-spacing: 0; color: var(--muted); }
.ids {
  top: var(--sub-top);
  text-align: center;
  transform-origin: 50% 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted);
  transform: translate(0, 0) scale(var(--rest));
}

.os:not([data-view="home"]) .idn { transform: translate(0, var(--name-lift)) scale(var(--name-grow)); }
.os:not([data-view="home"]) .ids { transform: translate(0, var(--sub-lift)) scale(var(--sub-grow)); }
.os[data-view="cv"] .idn { transform: translate(var(--cv-name-x), var(--cv-name-y)) scale(var(--cv-name-grow)); }
.os[data-view="cv"] .ids { transform: translate(var(--cv-sub-x), var(--cv-sub-y)) scale(var(--cv-sub-grow)); }
.os:not([data-view="home"]) .idn a { pointer-events: none; }
.os:not([data-view="home"]):not([data-view="about"]):not([data-view="cv"]) .idn,
.os:not([data-view="home"]):not([data-view="about"]):not([data-view="cv"]) .ids,
.os.short[data-view="about"] .ids,
.os.short[data-view="cv"] .idn,
.os.short[data-view="cv"] .ids {
  opacity: 0;
  visibility: hidden;
  transition: transform var(--dur) var(--ease), opacity 0.35s ease, visibility 0s linear 0.35s;
}
.os[data-view="about"]:not([data-prev="home"]) .idn,
.os[data-view="about"]:not([data-prev="home"]) .ids,
.os[data-view="cv"]:not([data-prev="home"]) .idn,
.os[data-view="cv"]:not([data-prev="home"]) .ids { transition-delay: 0s, 0.2s, 0s; }

/* ---- panes: white type on the black inside the horizon ---- */
.pane {
  position: absolute;
  left: calc(var(--pane-left) - 16px);
  top: var(--pane-top);
  width: calc(var(--pane-w) + 32px);
  max-height: var(--pane-max);
  padding: 0 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}

/* the long panes: a column beside the horizon, header fixed, body scrolling */
.pane.side {
  left: calc(var(--side-left) - 16px);
  top: var(--side-top);
  width: calc(var(--cv-w) + 32px);
  max-height: var(--side-max);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(18px);
}
.pane.work { width: calc(var(--work-w) + 32px); }
.pane.side > header { flex: none; }
.lead { flex: none; height: var(--cv-gap); }
.os.short .lead { display: none; }
.body {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 -16px;
  padding: 0 16px 28px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.body:focus-visible { outline: 1px solid rgba(91, 155, 255, 0.6); outline-offset: -1px; }

.pane.on {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.5s ease 0.2s, transform 0.6s var(--out) 0.2s, visibility 0s;
}
.os[data-move] .pane.on { transition-delay: 0.6s, 0.6s, 0s; }

/* more below or above: fade the lines instead of cutting them */
.pane.more, .body.more {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent);
}
.body.less {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28px);
  mask-image: linear-gradient(to bottom, transparent, #000 28px);
}
.body.less.more {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28px, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 28px, #000 calc(100% - 40px), transparent);
}

.pane > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  border-bottom: 1px solid var(--hair);
}
.pane h2 {
  font: 400 11px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-right: -16px;
  border-radius: 50%;
  color: var(--muted);
  transition: color 0.2s ease;
}
.x:hover { color: #fff; }
.x svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.tools { display: flex; align-items: center; gap: 4px; }
.dl, .back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  font: 400 11px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.2s ease;
}
.dl { padding: 0 10px; }
.back { padding-right: 14px; }
.dl:hover, .back:hover { color: #fff; }
.dl svg, .back svg, .go {
  flex: none;
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.actions { display: flex; justify-content: center; gap: 12px; padding-top: var(--about-gap); }
.btn {
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 30px;
  border-radius: 22px;
  font-weight: 600;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.btn.solid { background: #fff; color: #000; }
.btn.solid:hover { background: #dbe8ff; }
.btn.line { border: 1px solid var(--edge); }
.btn.line:hover { border-color: #fff; }

.rows { padding-top: 4px; }
.rows a { display: flex; align-items: center; gap: 24px; min-height: 60px; }
.rows li + li { border-top: 1px solid var(--hair); }
.os.short .rows a { min-height: 48px; }
.rows .t { flex: 1 1 auto; font-size: 16px; font-weight: 500; }
.rows .y { flex: none; font: 400 12px/1.4 var(--mono); color: var(--muted); }
.go { color: var(--muted); transition: color 0.2s ease, transform 0.25s var(--out); }
.rows a:hover .go { color: #fff; transform: translateX(3px); }

/* email: two addresses, a click copies */
.mails .k {
  flex: none;
  width: 92px;
  font: 400 11px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.mails .v { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 16px; font-weight: 500; }
.c { position: relative; flex: none; width: 16px; height: 16px; color: var(--muted); transition: color 0.2s ease; }
.mails a:hover .c { color: #fff; }
.c svg {
  position: absolute;
  inset: 0;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.2s ease, transform 0.25s var(--out);
}
.c .i-done { color: var(--blue); opacity: 0; transform: scale(0.6); }
.c::before {
  content: 'Copied';
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  font: 400 11px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.done .c .i-copy { opacity: 0; transform: scale(0.6); }
.done .c .i-done, .done .c::before { opacity: 1; }
.done .c .i-done { transform: none; }
.say { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.paper { display: flex; flex-direction: column; gap: 14px; padding-top: 24px; }
.paper .t { font-size: 20px; font-weight: 500; line-height: 1.4; text-wrap: balance; }
.paper .m {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  font: 400 12px/1.4 var(--mono);
  color: var(--muted);
}
.paper .m a { display: flex; align-items: center; min-height: 44px; color: var(--blue); transition: color 0.2s ease; }
.paper .m a:hover { color: var(--blue-hi); }

/* ---- the CV ---- */
.cv .body { border-top: 1px solid var(--hair); }
.os.short .cv .body { border-top: 0; }
.cv .body section { padding: 22px 0 4px; }
.cv .body section + section { border-top: 1px solid var(--hair); }
.cv h3 {
  margin-bottom: 14px;
  font: 400 11px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.tags { padding-bottom: 18px; font-size: 15px; line-height: 1.6; color: #d0d5dd; }
.item { padding-bottom: 18px; }
.item .h { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; }
.item .t { font-size: 16px; font-weight: 500; line-height: 1.4; }
.item p.t { font-size: 15px; line-height: 1.5; }
.item .t a { transition: color 0.2s ease; }
.item .t a:hover { color: var(--blue-hi); }
.item .y { flex: none; font: 400 12px/1.4 var(--mono); color: var(--muted); }
.item .s { margin-top: 3px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.pts { display: grid; gap: 6px; margin-top: 8px; }
.pts li { position: relative; padding-left: 16px; font-size: 14px; line-height: 1.55; color: #d0d5dd; }
.pts li::before { content: ''; position: absolute; left: 2px; top: 0.76em; width: 5px; height: 1px; background: var(--muted); }
.ref, .meta a { color: var(--blue); transition: color 0.2s ease; }
.ref:hover, .meta a:hover { color: var(--blue-hi); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 20px; padding-bottom: 18px; font-size: 14px; line-height: 1.5; }
.kv dt { color: var(--muted); }
.kv dd { color: #d0d5dd; }

/* ---- a piece of research: title, a few lines, then the pictures ---- */
.work h3 { padding-top: 26px; font-size: 26px; font-weight: 600; line-height: 1.2; letter-spacing: -0.015em; text-wrap: balance; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 12px; font: 400 12px/1.5 var(--mono); color: var(--muted); }
.lede { max-width: 64ch; margin-top: 18px; font-size: 15px; line-height: 1.65; color: #d0d5dd; }
.media { margin-top: 30px; }
.media figcaption { max-width: 72ch; margin-top: 12px; font: 400 11px/1.6 var(--mono); color: var(--muted); }
.frame { position: relative; width: 100%; overflow: hidden; background: #000; }
.film.narrow .frame, .film.narrow .seek { width: min(100%, 440px, 52vh); }
.frame video { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.pp { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer; }
.pp svg {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  padding: 16px;
  border: 1px solid var(--edge);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  fill: #fff;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.film.paused .pp svg { opacity: 1; }
.seek { position: relative; height: 20px; cursor: pointer; touch-action: none; }
.seek::before { content: ''; position: absolute; left: 0; right: 0; top: 9px; height: 2px; background: #23262d; }
.seek i { position: absolute; left: 0; top: 9px; width: 0; height: 2px; background: var(--blue); }
.cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 4px;
  font: 400 11px/1.4 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  color: #c9ced6;
}
.zoom { display: block; max-width: 100%; margin: 0; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.zoom img { display: block; width: auto; max-width: 100%; height: auto; max-height: min(54vh, 560px); }

.lightbox {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top, 0px)) 20px max(20px, env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.96);
  opacity: 0;
  visibility: hidden;
  cursor: zoom-out;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.lightbox.on { opacity: 1; visibility: visible; transition: opacity 0.25s ease, visibility 0s; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox:focus { outline: none; }

/* ---- dock ---- */
.dock {
  position: absolute;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--hair);
  border-radius: 22px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  -webkit-user-select: none;
  user-select: none;
  transition: opacity 0.8s ease 0.15s, transform 0.9s var(--out) 0.15s;
}
.dock a {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  transition: background 0.2s ease;
}
.dock a:hover { background: rgba(255, 255, 255, 0.1); }
.dock svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.dock i {
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--blue);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.dock a[aria-current] i { opacity: 1; }
@media (hover: hover) {
  .dock a::after {
    content: attr(aria-label);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 16px);
    transform: translate(-50%, 4px);
    padding: 6px 9px;
    border: 1px solid var(--hair);
    border-radius: 8px;
    background: rgba(8, 9, 12, 0.86);
    font: 400 11px/1 var(--mono);
    letter-spacing: 0.04em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
  }
  .dock a:hover::after,
  .dock a:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- boot: once per session ---- */
.boot {
  position: absolute;
  left: 50%;
  top: calc(var(--sub-top) + 9px);
  width: 160px;
  height: 2px;
  margin-left: -80px;
  overflow: hidden;
  background: #2a2d34;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.boot i { display: block; width: 0; height: 100%; background: var(--blue); }
.os[data-boot="run"] .boot { opacity: 1; }
.os[data-boot="run"] .boot i { width: 100%; transition: width 1.5s cubic-bezier(0.3, 0, 0.2, 1) 0.1s; }
.os[data-boot] .bar,
.os[data-boot] .ids { opacity: 0; }
.os[data-boot] .dock { opacity: 0; transform: translateX(-50%) translateY(14px); pointer-events: none; }
.os[data-boot] .bar .home,
.os[data-boot] .idn a { pointer-events: none; }
.os[data-boot="pre"] .idn,
.os[data-boot="pre"] #sky { opacity: 0; }
.os[data-boot="run"] .idn { transition-duration: 1.2s, 0.9s, 0s; }

/* ---- no WebGL: a still of the hole, a drawn horizon ---- */
.poster {
  position: absolute;
  left: var(--poster-left);
  top: var(--poster-top);
  width: var(--poster-w);
  max-width: none;
  height: auto;
  -webkit-mask-image: radial-gradient(closest-side, #000 55%, transparent);
  mask-image: radial-gradient(closest-side, #000 55%, transparent);
  cursor: pointer;
  transition: opacity 0.5s ease;
}
.arc {
  position: absolute;
  left: 50%;
  top: var(--arc-top);
  width: var(--arc-d);
  height: var(--arc-d);
  margin-left: calc(var(--arc-d) / -2);
  border-radius: 50%;
  background: #000;
  box-shadow: 0 0 0 1.5px rgba(210, 228, 255, 0.85), 0 0 60px 6px rgba(91, 155, 255, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, left 1.1s var(--ease), top 1.1s var(--ease), width 1.1s var(--ease), height 1.1s var(--ease), margin-left 1.1s var(--ease);
}
.os[data-scene="side"] .arc {
  left: var(--arc2-x);
  top: var(--arc2-top);
  width: var(--arc2-d);
  height: var(--arc2-d);
  margin-left: calc(var(--arc2-d) / -2);
}
.os:not([data-view="home"]) .poster { opacity: 0; pointer-events: none; }
.os:not([data-view="home"]) .arc { opacity: 1; }

/* ---- small screens ---- */
@media (max-width: 599px) {
  .bar { display: none; }
  .dock { bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
  .rows a { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-content: center; gap: 3px 16px; min-height: 64px; padding: 8px 0; }
  .rows .y, .mails .v { grid-column: 1; grid-row: 2; }
  .go, .c { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .mails .k { width: auto; }
  .paper .t { font-size: 18px; }
  .work h3 { padding-top: 20px; font-size: 22px; }
  .item .h { flex-direction: column; gap: 2px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { padding-bottom: 10px; }
  .cols { letter-spacing: 0.04em; }
}

/* layout changes (resize, first paint, still frames) land without animating */
.os.snap, .os.snap *, .os.snap *::after { transition: none !important; }

@media (prefers-reduced-motion: reduce) {
  .os, .os *, .os *::after { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}
