/* 蒋宇轩 · personal site — UI layer over the particle canvas */

:root {
  --accent: #aa88ff;
  --text: #dddddd;
  --muted: #8a8a8a;
  --chip: #1c1c1c;
  --line: #2a2a2a;
  --font: "SF Mono", "Menlo", "Consolas", "Liberation Mono", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", monospace;
  /* 24px from the edges; env() is 0 except behind a notch / home indicator (viewport-fit=cover) */
  --top: max(24px, env(safe-area-inset-top));
  --right: max(24px, env(safe-area-inset-right));
  --bottom: max(24px, env(safe-area-inset-bottom));
  --left: max(24px, env(safe-area-inset-left));
  /* the home indicator's own band at the frame's bottom (0 elsewhere): what sits lower than --bottom stays above it */
  --inset-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

/* Phones and tablets held upright: the page is laid out at landscape size and turned 90° clockwise, to be read
   with the device turned to landscape (js/frame.js sets .is-rotated and the frame size). Desktop never turns. */
html.is-rotated {
  /* the frame's left edge is the screen's top (notch side), its right edge the screen's bottom (home indicator) */
  --top: max(24px, env(safe-area-inset-right));
  --right: max(24px, env(safe-area-inset-bottom));
  --bottom: max(24px, env(safe-area-inset-left));
  --left: max(24px, env(safe-area-inset-top));
  --inset-bottom: env(safe-area-inset-left, 0px);
}

/* scroll boxes follow the finger along their own axis there (js/frame.js, Frame.scrollable) */
html.is-rotated .about,
html.is-rotated .tags {
  touch-action: none;
}

html.is-rotated body {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--frame-w);
  height: var(--frame-h);
  transform-origin: 0 0;
  transform: translateX(var(--real-w)) rotate(90deg);
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  /* a drag stirs the particle cloud instead of panning, zooming or pull-to-refresh */
  touch-action: none;
  overscroll-behavior: none;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.35;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2 {
  margin: 0;
  font: inherit;
}

p,
ul {
  margin: 0;
  padding: 0;
}

a,
button {
  -webkit-tap-highlight-color: transparent;
}

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

#bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Blend fix: .ui must not be a stacking context. position:fixed or a z-index (or opacity,
   transform, filter) would make it one, i.e. an isolated group, and the plus-lighter children
   would then only blend with the empty .ui layer, never with the canvas. Absolute with
   z-index auto still paints above the fixed canvas: same paint layer, later in the DOM. */
.ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* text blocks add their light to the particles (the works page cards do not blend) */
.brand,
.counter,
.tags,
.about {
  mix-blend-mode: plus-lighter;
}

/* brand */

.brand {
  position: absolute;
  top: var(--top);
  left: var(--left);
  display: flex;
  align-items: center;
  gap: 14px;
}

.mark {
  display: block;
  flex: none;
  width: 40px;
  height: 40px;
}

.name {
  font-size: 20px;
  letter-spacing: 0.02em;
  color: #fff;
}

.role {
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* counter */

.counter {
  position: absolute;
  top: var(--top);
  right: var(--right);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #0a0a0a;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: #fff;
}

/* tag chips */

.tags {
  position: absolute;
  top: 120px;
  left: var(--left);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 320px;
}

.chip {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  padding: 5px 9px;
  border: 0;
  border-radius: 0;
  background: var(--chip);
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap; /* a two-word label such as VIBE CODING stays on one line */
  color: #cfcfcf;
  cursor: pointer;
  pointer-events: auto;
  transition: color 300ms, background-color 300ms;
}

@media (hover: hover) {
  .chip:hover {
    color: var(--accent);
  }
}

.chip:focus-visible {
  color: var(--accent);
  outline-offset: 1px;
}

.chip.is-active {
  background: #e6e6e6;
  color: #000;
}

/* link to the other page (homepage: works; works page: back), where the chips sit on the works page */

.page-link {
  position: absolute;
  top: 120px;
  left: var(--left);
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 3px;
  pointer-events: auto;
  mix-blend-mode: plus-lighter;
  transition: opacity 300ms;
}

@media (hover: hover) {
  .page-link:hover {
    opacity: 0.7;
  }
}

/* the counter links to the works page on the homepage */
a.counter {
  text-decoration: none;
  pointer-events: auto;
  transition: border-color 300ms;
}

@media (hover: hover) {
  a.counter:hover {
    border-color: var(--accent);
  }
}

/* text column */

/* Taller than its space (short windows, phones), the column scrolls inside itself instead of
   being cut off; ui.js then adds .is-scrollable (pointer events for wheel/touch, edge fades). */
.about {
  --fade-top: 0px;
  --fade-bottom: 48px; /* > the largest empty gap (2.2em), so the fade always dims some text */
  position: absolute;
  top: 50%;
  right: 90px;
  width: 380px;
  max-height: calc(100% - var(--top) - var(--bottom));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  transform: translateY(-50%);
  touch-action: pan-y;
}

.about::-webkit-scrollbar {
  display: none;
}

.about.is-scrollable {
  pointer-events: auto;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent);
}

.about.is-scrolled {
  --fade-top: 24px;
}

.about.is-end {
  --fade-bottom: 0px;
}

.about section + section {
  margin-top: 2.2em;
}

.about h2 {
  margin-bottom: 1em;
  font-size: 13px;
  color: var(--accent);
}

.about p {
  margin-bottom: 1em;
  text-align: justify;
}

.about ul {
  list-style: inside;
}

.about p:last-child,
.about ul:last-child {
  margin-bottom: 0;
}

.about a {
  display: block;
  margin: 4px 0;
  color: inherit;
  text-decoration: underline;
  pointer-events: auto;
  transition: opacity 300ms;
}

/* inside the scroll box an outer outline would be clipped */
.about a:focus-visible {
  outline-offset: -1px;
}

@media (hover: hover) {
  .about a:hover {
    opacity: 0.7;
  }
}

/* the site's title, bottom left (the font is in title-font.css, linked by index.html only) */
.site-title {
  position: absolute;
  bottom: calc(var(--bottom) - 0.165em); /* the letters' bottom edge on the bottom margin */
  left: var(--left);
  margin: 0;
  color: #fff;
  font-family: "Portfolio Title", var(--font);
  font-size: min(110px, var(--frame-h, 100dvh) * 0.085, var(--frame-w, 100vw) * 0.065);
  font-style: normal;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  mix-blend-mode: plus-lighter;
}

/* responsive: the breakpoints are classes from js/frame.js, measured on the frame, which on a phone held
   upright is the landscape page (a media query would measure the upright screen) */

/* frame width <= 1100px: same right edge as the counter: centred, but never closer than 24px under it */
.w-1100 .about {
  right: var(--right);
  width: 320px;
  max-height: calc(100% - var(--top) - 68px - var(--bottom));
  transform: translateY(max(-50%, var(--top) + 68px - var(--frame-h, 100dvh) / 2));
}

/* frame width <= 760px */
/* under the brand; the text column below leaves room for it */
.w-760 .page-link {
  top: calc(var(--top) + 56px);
}

/* bottom column; if taller than the space under the brand and the link it scrolls inside itself */
.w-760 .about {
  top: auto;
  right: var(--right);
  bottom: var(--bottom);
  left: var(--left);
  width: auto;
  max-height: calc(100% - 106px - var(--top) - var(--bottom));
  transform: none;
  pointer-events: auto;
}

.w-760 .about p {
  text-align: left;
}

/* the text column takes the bottom: the title moves to the top, centred between the brand and the counter and
   level with their middle (22px under the top margin) */
.w-760 .site-title {
  top: calc(var(--top) + 22px - 0.49em);
  bottom: auto;
  left: 50%;
  font-size: min(var(--frame-h, 100dvh) * 0.09, var(--frame-w, 100vw) * 0.06);
  transform: translateX(-50%);
}

/* resume viewer (js/resume.js): the resume as a sheet of paper over the dimmed page, with a download link.
   Opening: the backdrop fades in, the sheet rises into place while a light line scans down it and reveals it,
   then the bar's items fade in one after another. Inside the turned page on phones it turns with it. */
.resume {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.74);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 280ms ease;
}

.resume[hidden] {
  display: none;
}

.resume.is-open {
  opacity: 1;
}

.resume.is-closing {
  opacity: 0;
  transition-duration: 220ms;
}

.resume-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 28px;
  padding: calc(var(--top) - 8px) var(--right) 4px var(--left);
  color: var(--text);
}

.resume-label {
  margin: 0 auto 0 0;
  color: var(--accent);
}

.resume-download,
.resume-close {
  padding: 8px 0;
  border: 0;
  background: none;
  color: #fff;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: opacity 300ms;
}

@media (hover: hover) {
  .resume-download:hover,
  .resume-close:hover {
    opacity: 0.7;
  }
}

/* positioned, so that js/resume.js measures the sheet from here (zoom) */
.resume-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto; /* both ways: zoomed in, the resume is wider than the view */
  overscroll-behavior: contain;
  /* at the bottom, room for the zoom buttons: the end of the resume scrolls up clear of them */
  padding: 12px var(--right) calc(var(--bottom) + 48px) var(--left);
  outline: none;
  scrollbar-color: #555 transparent;
  scrollbar-width: thin;
}

/* phones and tablets: js/resume.js moves and zooms the resume by hand (one finger moves it, two fingers zoom it), so
   the browser neither scrolls a turned page along the screen's axes nor zooms the whole page */
.resume.is-touch,
.resume.is-touch .resume-scroll {
  touch-action: none;
}

/* --zoom (js/resume.js): 1 is the usual size, 100 % */
.resume-sheet {
  position: relative;
  width: calc(min(880px, 100%) * var(--zoom, 1));
  margin: 0 auto;
}

/* A4; the paper colour shows until the image has loaded */
.resume-paper {
  position: relative;
  overflow: hidden;
  aspect-ratio: 210 / 297;
  background: #fcfbf9;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.resume-img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transition: opacity 400ms ease;
}

.resume.is-loaded .resume-img {
  opacity: 1;
}

.resume-loading {
  position: absolute;
  top: 30%;
  right: 0;
  left: 0;
  margin: 0;
  color: #999999;
  letter-spacing: 0.2em;
  text-align: center;
  animation: resume-blink 1.2s steps(2, jump-none) infinite;
}

.resume.is-loaded .resume-loading {
  display: none;
}

/* the scan line: a bright line at the bottom edge of a box as tall as the sheet, with a soft trail above it */
.resume-scan {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: linear-gradient(to bottom, rgba(170, 136, 255, 0) calc(100% - 90px), rgba(170, 136, 255, 0.24) calc(100% - 2px), #e8deff calc(100% - 2px));
  pointer-events: none;
}

.resume.is-open .resume-sheet {
  animation: resume-rise 700ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.resume.is-open .resume-paper {
  animation: resume-reveal 820ms cubic-bezier(0.65, 0, 0.35, 1) both;
}

.resume.is-open .resume-scan {
  animation: resume-scan 820ms cubic-bezier(0.65, 0, 0.35, 1) both;
}

.resume.is-open .resume-bar > * {
  animation: resume-fade 420ms ease 160ms both;
}

.resume.is-open .resume-bar > :nth-child(2) {
  animation-delay: 240ms;
}

.resume.is-open .resume-bar > :nth-child(3) {
  animation-delay: 320ms;
}

.resume.is-closing .resume-sheet {
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition: opacity 220ms ease, transform 220ms ease;
}

/* zoom buttons over the bottom right of the resume: − 100% + (js/resume.js; the percentage goes back to 100 %).
   The same as the works page's (css/works.css, .viewer-zoom) */
.resume-zoom {
  position: absolute;
  right: var(--right);
  bottom: max(12px, var(--bottom) - 8px, var(--inset-bottom, 0px));
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* until js/resume.js shows them (an older resume.js would not know them) */
.resume-zoom[hidden] {
  display: none;
}

.resume-zoom button {
  min-width: 38px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: #fff;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  transition: color 200ms, opacity 200ms;
}

.resume-zoom .resume-zoom-reset {
  min-width: 58px;
  font-variant-numeric: tabular-nums;
}

/* at 30 % / 300 %: dimmed but still focusable (aria-disabled), so keyboard focus is never dropped. Only the sign is
   dimmed: with opacity, the focus ring would fade with it */
.resume-zoom button[aria-disabled="true"] {
  color: rgba(255, 255, 255, 0.35);
  cursor: default;
}

/* a finger needs a bigger target */
@media (pointer: coarse) {
  .resume-zoom button {
    position: relative;
    min-width: 44px;
    height: 44px;
  }

  .resume-zoom .resume-zoom-reset {
    min-width: 62px;
  }

  /* a button takes a finger anywhere in its box: drawn round, it would leave its corners, between two buttons, dead */
  .resume-zoom button::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  /* and a finger that lands just beside the buttons neither closes the resume nor moves it. The buttons above are
     positioned (relative) so that they lie over this ring: otherwise it would take their taps as well */
  .resume-zoom::before {
    content: "";
    position: absolute;
    inset: -12px;
    border-radius: inherit;
  }
}

@media (hover: hover) {
  .resume-zoom button:not([aria-disabled="true"]):hover {
    color: var(--accent);
  }
}

.resume.is-open .resume-zoom {
  animation: resume-fade 420ms ease 400ms both;
}

/* read out by screen readers only (the zoom size); css/works.css has the same rule for the works page */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@keyframes resume-rise {
  from {
    opacity: 0;
    transform: translateY(36px) scale(0.94);
  }
}

@keyframes resume-reveal {
  from {
    clip-path: inset(0 0 100% 0);
  }

  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes resume-scan {
  0% {
    opacity: 1;
    transform: translateY(-100%);
  }

  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateY(0);
  }
}

@keyframes resume-fade {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes resume-blink {
  50% {
    opacity: 0.3;
  }
}

/* WeChat: how to download (js/resume.js); above the zoom buttons (46px high on a phone, and a gap) */
.resume-hint {
  position: absolute;
  bottom: calc(max(12px, var(--bottom) - 8px, var(--inset-bottom, 0px)) + 58px);
  left: 50%;
  max-width: calc(100% - var(--left) - var(--right));
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  line-height: 1.6;
  text-transform: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 200ms, transform 200ms;
  pointer-events: none;
}

.resume-hint.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .resume.is-open .resume-sheet,
  .resume.is-open .resume-paper,
  .resume.is-open .resume-bar > *,
  .resume.is-open .resume-zoom,
  .resume-loading {
    animation: none;
  }

  .resume-scan {
    display: none;
  }

  .resume.is-closing .resume-sheet {
    transform: none;
  }
}

@media (forced-colors: active) {
  .resume-scan {
    display: none;
  }

  /* the theme's own colour for what cannot be used (the dimming above is replaced by the theme's text colour) */
  .resume-zoom button[aria-disabled="true"] {
    color: GrayText;
  }
}

/* forced colours (Windows contrast themes) paint the page background in the theme's colour, often white:
   adding light onto it would turn the text white on white. Last in the file, so it wins over the blend modes above */
@media (forced-colors: active) {
  .brand,
  .counter,
  .tags,
  .about,
  .page-link,
  .site-title {
    mix-blend-mode: normal;
  }
}
