/* The page: design tokens, layout and components (docs/design.md, section 4). */

:root {
  color-scheme: dark;

  /* Material 3 dark surfaces, over a deep vertical gradient: black at the top, a deep
     indigo (the lime accent's complement) through the middle, a deep moss (the lime's own
     hue, darkened) at the bottom */
  --bg: #000;
  --bg-mid: #120e33;
  --bg-end: #142409;
  --surface-1: #0e0f11;
  --surface-2: #15171a;
  --surface-3: #1c1f24;
  --outline: #2b2f36;
  --outline-strong: #464c56;
  --on: #f3f3ef;
  --on-var: #a0a6b0;

  /* the site's own accent */
  --lime: #d4ff3a;
  --on-lime: #0b0d00;

  --font: 'Bricolage Grotesque Variable', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans SC', 'Microsoft YaHei', system-ui, sans-serif;
  --mono: 'JetBrains Mono Variable', ui-monospace, 'SF Mono', Menlo, 'PingFang SC', 'Microsoft YaHei', monospace;

  /* keep in step with js/grid-width.js */
  --page-pad: clamp(16px, 4vw, 48px);
  --grid-max: 1600px;
  --gap: 10px;
  --radius: 14px;

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0.05, 0.7, 0.1, 1);
}

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-mid) 52%, var(--bg-end) 100%);
  background: linear-gradient(in oklab 180deg, var(--bg) 0%, var(--bg-mid) 52%, var(--bg-end) 100%);
  color: var(--on);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

:lang(zh) body {
  line-height: 1.65;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

/* The page is starting in Chinese (index.html): the English texts in the HTML stay hidden
   until main.js writes the Chinese ones, and show after 3 s whatever happens. */
.i18n-pending [data-i18n] {
  visibility: hidden;
  animation: i18n-show 0s 3s forwards;
}

@keyframes i18n-show {
  to {
    visibility: visible;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  display: block;
  flex: none;
}

/* ---------- top app bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 var(--page-pad);
  background: rgb(0 0 0 / 0.45);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid transparent;
  transition: border-color 200ms var(--ease), background-color 200ms var(--ease);
  -webkit-user-select: none;
  user-select: none;
}

.topbar.scrolled {
  background: rgb(6 6 14 / 0.55);
  border-bottom-color: rgb(255 255 255 / 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
  font-stretch: 85%;
  font-size: 22px;
  letter-spacing: -0.02em;
  border-radius: 8px;
}

.brand img {
  display: block;
  width: 32px;
  height: 32px;
  -webkit-user-drag: none;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* the language switch: a two-segment pill */
.lang {
  display: flex;
  padding: 3px;
  border: 1px solid var(--outline-strong);
  border-radius: 999px;
}

.lang button {
  min-width: 48px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--on-var);
  font: 600 13px/1 var(--mono);
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

.lang button[lang='zh-CN'] {
  font-family: var(--font);
  font-size: 14px;
}

.lang button:hover {
  color: var(--on);
  background: rgb(255 255 255 / 0.08);
}

.lang button[aria-pressed='true'] {
  background: var(--lime);
  color: var(--on-lime);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--on);
  cursor: pointer;
  transition: background-color 200ms var(--ease);
  -webkit-user-select: none;
  user-select: none;
}

.icon-btn:hover {
  background: rgb(255 255 255 / 0.08);
}

.icon-btn:active {
  background: rgb(255 255 255 / 0.14);
}

/* ---------- intro ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--grid-max) + 2 * var(--page-pad));
  margin: 0 auto;
  padding: 0 var(--page-pad);
}

.intro {
  padding: clamp(24px, 4.5vw, 60px) 0 clamp(18px, 2.8vw, 36px);
}

.prompt {
  margin: 0 0 14px;
  font: 500 clamp(12px, 1.3vw, 14px) / 1.4 var(--mono);
  color: var(--on-var);
  overflow-wrap: anywhere;
}

.prompt .user {
  color: var(--lime);
}

.prompt .cmd {
  color: var(--on);
}

.caret {
  display: inline-block;
  width: 0.6em;
  height: 1.15em;
  margin-left: 2px;
  vertical-align: -0.2em;
  background: var(--lime);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.headline {
  /* Two lines of the same height in both languages, so switching language moves nothing
     below the headline. */
  --line: clamp(38px, 6vw, 96px);
  margin: 0;
  font-weight: 800;
  font-stretch: 78%;
  font-size: clamp(40px, 6.4vw, 104px);
  line-height: var(--line);
  letter-spacing: -0.035em;
}

:lang(zh) .headline {
  font-size: clamp(32px, 5vw, 80px);
  letter-spacing: 0;
}

.headline > span {
  display: block;
  height: var(--line);
  white-space: nowrap;
}

.headline .hl {
  color: var(--lime);
  font-style: italic;
  font-variation-settings: 'opsz' 96;
}

:lang(zh) .headline .hl {
  font-style: normal;
}

/* ---------- the live-tile grid ---------- */

.grid-wrap {
  container-type: inline-size;
  padding-bottom: clamp(40px, 6vw, 80px);
}

.grid {
  --cols: 4;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols));
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ---------- tiles ---------- */

.tile {
  --accent: var(--lime);
  --rx: 0deg;
  --ry: 0deg;
  position: relative;
  container-type: size;
  overflow: hidden;
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--accent) 22%, #050505);
  isolation: isolate;
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry)) scale(var(--press, 1));
  transition: transform 450ms var(--ease-out), box-shadow 300ms var(--ease);
  -webkit-tap-highlight-color: transparent;
  /* a tile is pressed, not read: no text selection, no dragging, no long-press menu */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.tile::after {
  /* the frame: a hairline at rest, the accent while playing */
  content: '';
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: inherit;
  border: 1px solid rgb(255 255 255 / 0.09);
  pointer-events: none;
  transition: border-color 300ms var(--ease), border-width 300ms var(--ease);
}

.tile.is-playing::after {
  border: 2px solid var(--accent);
}

.tile.pressed {
  --press: 0.975;
  transition: transform 120ms var(--ease);
}

.tile:has(.tile-link:focus-visible) {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

.tile-link:focus-visible {
  outline: none;
}

.tile-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  filter: grayscale(1) contrast(1.08) brightness(0.62);
  opacity: 0;
  transition: filter 450ms var(--ease), opacity 600ms var(--ease);
}

.tile-stage.ready {
  opacity: 1;
}

.tile-tint {
  position: absolute;
  inset: 0;
  background: var(--accent);
  mix-blend-mode: color;
  opacity: 0.95;
  pointer-events: none;
  transition: opacity 450ms var(--ease);
}

.tile-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, rgb(0 0 0 / 0.82) 0%, rgb(0 0 0 / 0.35) 38%, rgb(0 0 0 / 0) 62%),
    linear-gradient(to bottom, rgb(0 0 0 / 0.45) 0%, rgb(0 0 0 / 0) 26%);
  pointer-events: none;
  transition: opacity 450ms var(--ease);
}

.tile.is-playing .tile-stage {
  filter: none;
}

.tile.is-playing .tile-tint {
  opacity: 0;
}

.tile.is-playing .tile-scrim {
  opacity: 0.55;
}

.tile-meta {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: clamp(10px, 4.5cqmin, 18px) clamp(12px, 5cqmin, 22px);
  font: 600 clamp(10px, 3.6cqmin, 13px) / 1 var(--mono);
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 300ms var(--ease);
}

.tile-index {
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: #000;
}

.tile-tags {
  color: rgb(255 255 255 / 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile.is-playing .tile-tags {
  opacity: 0;
}

.tile-info {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: clamp(12px, 5cqmin, 24px) clamp(12px, 5cqmin, 24px) clamp(14px, 5.5cqmin, 26px);
  pointer-events: none;
  transform-origin: 0 100%;
  transition: transform 450ms var(--ease), opacity 300ms var(--ease);
}

.tile-title {
  margin: 0;
  font-weight: 800;
  font-stretch: 80%;
  font-size: clamp(20px, 9cqmin, 60px);
  line-height: 0.95;
  letter-spacing: -0.025em;
  text-wrap: balance;
  text-shadow: 0 2px 18px rgb(0 0 0 / 0.5);
}

:lang(zh) .tile-title {
  font-size: clamp(19px, 8cqmin, 52px);
  line-height: 1.15;
  letter-spacing: 0;
}

.tile-tagline {
  margin: 0.5em 0 0;
  max-width: 34em;
  font-size: clamp(12px, 4cqmin, 17px);
  font-weight: 500;
  line-height: 1.3;
  color: rgb(255 255 255 / 0.82);
  text-wrap: pretty;
  transition: opacity 300ms var(--ease);
}

/* active (hovered, focused or chosen by the focus line; playing unless motion is reduced): the
   title shrinks to a label at the bottom left, as on a Metro live tile, and the buttons show */
.tile.is-active .tile-info {
  transform: scale(0.52);
}

.tile.is-active .tile-tagline,
.tile:focus-within .tile-tagline {
  opacity: 0;
}

.tile-link {
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  -webkit-user-drag: none;
}

.tile-chips {
  position: absolute;
  right: clamp(10px, 4.5cqmin, 20px);
  bottom: clamp(12px, 5cqmin, 22px);
  z-index: 6;
  display: flex;
  gap: 8px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 300ms var(--ease), transform 450ms var(--ease-out);
  pointer-events: none;
}

.tile.is-active .tile-chips,
.tile:focus-within .tile-chips {
  opacity: 1;
  transform: none;
}

.tile.is-active .tile-chips .chip-try,
.tile:focus-within .tile-chips .chip-try {
  pointer-events: auto;
}

/* stickers: white paper, black border, a hard shadow in the accent */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 12px 0 10px;
  border: 2px solid #000;
  border-radius: 999px;
  background: #fbf7ee;
  color: #000;
  font: 700 13px/1 var(--mono);
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 3px 3px 0 var(--accent);
  -webkit-user-drag: none;
  transition: transform 150ms var(--ease), box-shadow 150ms var(--ease);
}

:lang(zh) .chip {
  font-family: var(--font);
  font-size: 13px;
}

.chip .icon {
  width: 18px;
  height: 18px;
}

.chip-try {
  background: var(--accent);
  box-shadow: 3px 3px 0 #fbf7ee;
}

.chip-try:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 #fbf7ee;
}

.chip-try:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #fbf7ee;
}

/* Narrow tiles keep both buttons, GitHub always with its word: Try it shrinks to its icon. */
@container (max-width: 300px) {
  .chip-try {
    padding: 0 7px;
  }

  .chip-try .chip-label {
    display: none;
  }
}

/* ---------- touch screens ----------
   A tap on a tile plays it (tiles.js), so the tile is not a link: its buttons are, always
   shown in a row under the tagline. The title keeps its size while the tile plays. */

.touch .tile {
  cursor: pointer;
}

.touch .tile-link {
  display: none;
}

.touch .tile-info {
  padding-bottom: calc(clamp(14px, 5.5cqmin, 26px) + 42px);
}

.touch .tile.is-active .tile-info {
  transform: none;
}

.touch .tile.is-active .tile-tagline,
.touch .tile:focus-within .tile-tagline {
  opacity: 1;
}

.touch .tile-chips {
  left: clamp(12px, 5cqmin, 24px);
  right: auto;
  opacity: 1;
  transform: none;
}

.touch .tile-chips .chip {
  pointer-events: auto;
}

.tile-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  height: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms var(--ease);
}

.tile-progress span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: 0 0;
  transform: scaleX(var(--progress, 0));
}

.tile.is-playing .tile-progress {
  opacity: 1;
}

/* ---------- footer ---------- */

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 20px var(--page-pad) 28px;
  background: rgb(0 0 0 / 0.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-top: 1px solid rgb(255 255 255 / 0.08);
  font: 500 12px/1.6 var(--mono);
  color: var(--on-var);
}

.footer p {
  margin: 0;
}

.footer .sep {
  margin: 0 0.6em;
  color: var(--outline-strong);
}

.footer a {
  text-decoration: none;
  border-bottom: 1px dotted var(--outline-strong);
}

.footer a:hover {
  color: var(--on);
  border-bottom-color: var(--lime);
}

/* ---------- the About dialog (Material 3) ---------- */

.about {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--outline);
  border-radius: 28px;
  background: var(--surface-3);
  color: var(--on);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.6);
}

.about::backdrop {
  background: rgb(0 0 0 / 0.66);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.about[open] {
  animation: dialog-in 350ms var(--ease-out);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
}

.about-body {
  position: relative;
  padding: 28px 24px 24px;
}

.about-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.about-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-right: 40px;
}

.avatar {
  /* the logo stands in for an avatar: as tall as the name and the handle together */
  flex: none;
  width: 92px;
  height: 92px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* The name takes one height in both languages: two lines of English, one of Chinese. */
.about .name {
  --name-h: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: var(--name-h);
  margin: 0;
  font-weight: 800;
  font-stretch: 85%;
  letter-spacing: -0.02em;
}

.about .name span {
  display: block;
  white-space: nowrap;
}

.about .name.lines-2 {
  font-size: 31px;
  line-height: calc(var(--name-h) / 2);
}

.about .name.lines-1 {
  font-size: 50px;
  line-height: var(--name-h);
  letter-spacing: 0.02em;
}

.about .handle {
  margin: 4px 0 0;
  font: 500 14px/20px var(--mono);
  color: var(--lime);
}

.about-bio {
  margin: 22px 0 0;
  color: var(--on-var);
  font-size: 15px;
  line-height: 1.6;
}

:lang(zh) .about-bio {
  line-height: 1.8;
}

.about-links-title {
  margin: 20px 0 10px;
  font: 600 12px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--on-var);
  -webkit-user-select: none;
  user-select: none;
}

.about-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.link-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px 0 10px;
  border: 1px solid var(--outline-strong);
  border-radius: 10px;
  color: var(--on);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 200ms var(--ease), border-color 200ms var(--ease);
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.link-chip .icon {
  width: 20px;
  height: 20px;
  color: var(--lime);
}

a.link-chip:hover {
  background: rgb(255 255 255 / 0.06);
  border-color: var(--lime);
}

/* ---------- motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}
