:root {
  --bg: #000000;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.5);
  --line: rgba(255, 255, 255, 0.9);
  --nav-dim: rgba(255, 255, 255, 0.33);
  --nav-active-dim: rgba(255, 255, 255, 0.6);
  --underline: rgba(255, 255, 255, 0.3);
  --button-bg: #ffffff;
  --button-fg: #000000;
  --button-glow: rgba(255, 255, 255, 0.22);
  --tooltip-bg: rgba(12, 12, 12, 0.95);
  --tooltip-fg: rgba(255, 255, 255, 0.9);
  --tooltip-border: rgba(255, 255, 255, 0.16);
  --toast-bg: rgba(8, 8, 8, 0.82);
  --toast-fg: rgba(255, 255, 255, 0.9);
  --toast-border: rgba(255, 255, 255, 0.16);
  --focus: rgba(255, 255, 255, 0.9);
  --scrim: rgba(0, 0, 0, 0.55);
  --mobile-fade: rgba(0, 0, 0, 0.9);
  --menu-bg: rgba(8, 8, 8, 0.42);
  --menu-border: rgba(255, 255, 255, 0.22);
  --drawer-bg: #000000;
  --icon-bg: #ffffff;
  --icon-shadow: rgba(255, 255, 255, 0.2);
  --rail-width: clamp(336px, 30vw, 510px);
  --gutter: clamp(26px, 2.9vw, 52px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font-sans: "Segoe UI Variable Display", "Segoe UI", "Helvetica Neue", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", "Roboto Mono", "Consolas", monospace;
}

[data-theme="light"] {
  --bg: #ffffff;
  --fg: #000000;
  --muted: rgba(0, 0, 0, 0.48);
  --line: rgba(0, 0, 0, 0.88);
  --nav-dim: rgba(0, 0, 0, 0.33);
  --nav-active-dim: rgba(0, 0, 0, 0.6);
  --underline: rgba(0, 0, 0, 0.28);
  --button-bg: #000000;
  --button-fg: #ffffff;
  --button-glow: rgba(0, 0, 0, 0.22);
  --tooltip-bg: #000000;
  --tooltip-fg: #ffffff;
  --tooltip-border: rgba(0, 0, 0, 0.18);
  --toast-bg: rgba(255, 255, 255, 0.9);
  --toast-fg: #000000;
  --toast-border: rgba(0, 0, 0, 0.16);
  --focus: rgba(0, 0, 0, 0.9);
  --scrim: rgba(255, 255, 255, 0.5);
  --mobile-fade: rgba(255, 255, 255, 0.92);
  --menu-bg: rgba(255, 255, 255, 0.5);
  --menu-border: rgba(0, 0, 0, 0.22);
  --drawer-bg: #ffffff;
  --icon-bg: #ffffff;
  --icon-shadow: rgba(0, 0, 0, 0.18);
}

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

html {
  height: 100%;
  background: var(--bg);
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
}

body {
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition:
    background-color 0.35s ease,
    color 0.35s ease;
}

body.menu-open {
  overflow: hidden;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

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

button:focus-visible,
a:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: 5px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  padding: 10px 14px;
  border-radius: 2px;
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  transform: translateY(-180%);
  transition: transform 0.3s var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ */
/* Shell                                                              */
/* ------------------------------------------------------------------ */

.site-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100svh;
  min-height: 620px;
  background: transparent;
}

.rail {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: clamp(28px, 4.2vh, 48px) var(--gutter) clamp(24px, 3.4vh, 38px);
  background: transparent;
}

/* ------------------------------------------------------------------ */
/* Brand                                                              */
/* ------------------------------------------------------------------ */

.brand {
  display: flex;
  align-items: center;
  gap: 15px;
  width: fit-content;
  max-width: 100%;
  animation: rise-in 1s var(--ease-out) both;
}

.brand-mark {
  display: grid;
  flex: none;
  width: 58px;
  height: 58px;
  overflow: hidden;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--icon-bg);
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  transition:
    transform 0.7s var(--ease-out),
    box-shadow 0.5s ease;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand:hover .brand-mark {
  transform: scale(1.04);
  box-shadow: 0 0 34px var(--icon-shadow);
}

.brand-name {
  color: var(--fg);
  font-size: clamp(20px, 1.85vw, 29px);
  font-weight: 450;
  letter-spacing: -0.04em;
  line-height: 1.18;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Rules                                                              */
/* ------------------------------------------------------------------ */

.rail-line {
  width: 100%;
  height: 1px;
  background: var(--line);
  transform-origin: left center;
}

.rail-line--top {
  margin-top: clamp(20px, 3vh, 29px);
  animation: draw-line 1.25s 0.12s var(--ease-out) both;
}

.rail-line--bottom {
  background: var(--line);
  animation: draw-line 1.25s 0.46s var(--ease-out) both;
}

/* ------------------------------------------------------------------ */
/* Navigation                                                         */
/* ------------------------------------------------------------------ */

.primary-nav {
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.75vh, 9px);
  margin-top: clamp(38px, 7.5vh, 88px);
  animation: rise-in 1.05s 0.16s var(--ease-out) both;
}

.nav-link {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16px;
  gap: 13px;
  align-items: center;
  width: 100%;
  padding: clamp(7px, 1.15vh, 12px) 0;
  color: var(--muted);
  font-size: clamp(31px, 3.15vw, 54px);
  font-weight: 380;
  letter-spacing: -0.045em;
  line-height: 1.08;
  transition:
    color 0.35s ease,
    transform 0.55s var(--ease-out);
}

.nav-link::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: 0;
  left: 0;
  height: 1px;
  background: var(--underline);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.55s var(--ease-out);
}

.nav-link:hover,
.nav-link:focus-visible {
  color: var(--fg);
  transform: translateX(8px);
}

.nav-link:hover::after,
.nav-link:focus-visible::after {
  transform: scaleX(1);
}

.primary-nav:hover .nav-link:not(:hover) {
  color: var(--nav-dim);
}

.primary-nav:hover .nav-link.is-active:not(:hover) {
  color: var(--nav-active-dim);
}

.nav-link.is-active {
  color: var(--fg);
}

.nav-text {
  min-width: 0;
}

.nav-symbol {
  color: var(--fg);
  font-size: 10px;
  line-height: 1;
  opacity: 0;
  transform: translateX(-5px) scale(0.8);
  transition:
    opacity 0.35s ease,
    transform 0.45s var(--ease-out);
}

.nav-link.is-active .nav-symbol {
  opacity: 0.85;
  transform: none;
}

.nav-link:hover .nav-symbol {
  opacity: 0.55;
  transform: none;
}

/* ------------------------------------------------------------------ */
/* Rail footer / controls                                             */
/* ------------------------------------------------------------------ */

.rail-footer {
  margin-top: auto;
  padding-top: 32px;
  animation: rise-in 1.1s 0.4s var(--ease-out) both;
}

.orb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: clamp(17px, 2.8vh, 26px);
}

.orb {
  position: relative;
  display: grid;
  width: clamp(40px, 2.9vw, 44px);
  height: clamp(40px, 2.9vw, 44px);
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--button-fg);
  cursor: pointer;
  transition:
    transform 0.4s var(--ease-out),
    background 0.35s ease,
    color 0.35s ease,
    box-shadow 0.4s ease;
}

.orb svg {
  width: 17px;
  height: 17px;
  transition: transform 0.55s var(--ease-out);
}

.theme-icon--moon {
  display: none;
}

[data-theme="light"] .theme-icon--sun {
  display: none;
}

[data-theme="light"] .theme-icon--moon {
  display: block;
}

.effects-icon--off {
  display: none;
}

.auth-icon--unlocked {
  display: none;
}

.auth-toggle {
  overflow: visible;
}

.auth-toggle img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.auth-toggle.is-authed::before {
  position: absolute;
  top: -1px;
  right: -1px;
  z-index: 2;
  width: 8px;
  height: 8px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--fg);
  content: "";
}

.auth-toggle.is-authed .auth-icon--locked {
  display: none;
}

.auth-toggle.is-authed .auth-icon--unlocked {
  display: block;
}

[data-effects="off"] .effects-icon--on {
  display: none;
}

[data-effects="off"] .effects-icon--off {
  display: block;
}

.orb::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  z-index: 20;
  padding: 6px 9px;
  border: 1px solid var(--tooltip-border);
  border-radius: 2px;
  background: var(--tooltip-bg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
  color: var(--tooltip-fg);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.04em;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.25s ease,
    transform 0.35s var(--ease-out);
}

.orb:hover,
.orb:focus-visible {
  transform: translateY(-4px);
  background: var(--button-bg);
  box-shadow: 0 0 30px var(--button-glow);
}

.orb:hover::after,
.orb:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.orb:hover svg {
  transform: rotate(8deg) scale(1.05);
}

.orb:active {
  transform: translateY(-1px) scale(0.96);
}

/* ------------------------------------------------------------------ */
/* Stage                                                              */
/* ------------------------------------------------------------------ */

.stage {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  background: transparent;
  touch-action: manipulation;
}

.stage:focus {
  outline: none;
}

#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  animation: canvas-in 1.8s 0.15s ease forwards;
}

/* ------------------------------------------------------------------ */
/* Toast                                                              */
/* ------------------------------------------------------------------ */

.toast {
  position: absolute;
  bottom: clamp(32px, 5vh, 52px);
  left: 50%;
  z-index: 6;
  max-width: calc(100% - 40px);
  padding: 10px 16px;
  border: 1px solid var(--toast-border);
  border-radius: 999px;
  background: var(--toast-bg);
  box-shadow: 0 16px 55px rgba(0, 0, 0, 0.2);
  color: var(--toast-fg);
  font-size: 11px;
  letter-spacing: 0.035em;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition:
    opacity 0.35s ease,
    transform 0.5s var(--ease-out);
  backdrop-filter: blur(16px);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------------ */
/* Mobile chrome                                                      */
/* ------------------------------------------------------------------ */

.mobile-bar,
.scrim {
  display: none;
}

.noscript-note {
  position: fixed;
  bottom: 22px;
  left: 50%;
  z-index: 150;
  padding: 10px 14px;
  border: 1px solid var(--toast-border);
  background: var(--bg);
  color: var(--fg);
  font-size: 12px;
  transform: translateX(-50%);
}

/* ------------------------------------------------------------------ */
/* Animations                                                         */
/* ------------------------------------------------------------------ */

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes draw-line {
  from {
    opacity: 0;
    transform: scaleX(0);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

@keyframes canvas-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ------------------------------------------------------------------ */
/* Short desktop screens                                              */
/* ------------------------------------------------------------------ */

@media (max-height: 760px) and (min-width: 901px) {
  .rail {
    padding-top: 24px;
    padding-bottom: 22px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .rail-line--top {
    margin-top: 17px;
  }

  .primary-nav {
    gap: 0;
    margin-top: 24px;
  }

  .nav-link {
    padding: 5px 0;
    font-size: clamp(27px, 2.5vw, 36px);
  }

  .orb-row {
    gap: 8px;
    margin-top: 16px;
  }

  .orb {
    width: 36px;
    height: 36px;
  }

  .orb svg {
    width: 15px;
    height: 15px;
  }
}

/* ------------------------------------------------------------------ */
/* Mobile / tablet                                                    */
/* ------------------------------------------------------------------ */

@media (max-width: 900px) {
  .site-shell {
    display: block;
    height: 100vh;
    height: 100svh;
    min-height: 0;
  }

  .rail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(84vw, 364px);
    height: 100vh;
    height: 100svh;
    padding: 92px 28px max(26px, env(safe-area-inset-bottom));
    overflow-y: auto;
    background: var(--drawer-bg);
    box-shadow: 40px 0 100px rgba(0, 0, 0, 0.55);
    visibility: hidden;
    transform: translateX(-102%);
    transition:
      transform 0.55s var(--ease-out),
      visibility 0s linear 0.55s;
    overscroll-behavior: contain;
    backdrop-filter: blur(10px);
  }

  body.menu-open .rail {
    visibility: visible;
    transform: translateX(0);
    transition:
      transform 0.55s var(--ease-out),
      visibility 0s linear 0s;
  }

  .rail .brand {
    display: none;
  }

  .rail-line--top {
    margin-top: 0;
  }

  .primary-nav {
    gap: 1px;
    margin-top: 28px;
  }

  .nav-link {
    padding: 12px 0;
    font-size: clamp(32px, 9.4vw, 40px);
  }

  .nav-link:hover {
    transform: translateX(5px);
  }

  .rail-footer {
    margin-top: auto;
    padding-top: 32px;
  }

  .orb-row {
    gap: 10px;
    margin-top: 20px;
  }

  .orb {
    width: 40px;
    height: 40px;
  }

  .orb::after {
    display: none;
  }

  .stage {
    width: 100%;
    height: 100vh;
    height: 100svh;
  }

  .toast {
    bottom: max(28px, calc(env(safe-area-inset-bottom) + 16px));
    font-size: 10.5px;
  }

  .mobile-bar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(16px, calc(env(safe-area-inset-top) + 10px)) 20px 16px;
    background: linear-gradient(180deg, var(--mobile-fade), transparent);
    pointer-events: none;
  }

  .mobile-brand {
    display: flex;
    gap: 10px;
    align-items: center;
    color: var(--fg);
    font-size: 16px;
    font-weight: 450;
    letter-spacing: -0.035em;
    line-height: 1;
    white-space: nowrap;
    pointer-events: auto;
  }

  .brand-mark--small {
    width: 38px;
    height: 38px;
  }

  .brand-mark--small:hover {
    transform: none;
  }

  .menu-toggle {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 45px;
    height: 45px;
    padding: 0;
    border: 1px solid var(--menu-border);
    border-radius: 999px;
    background: var(--menu-bg);
    color: var(--fg);
    cursor: pointer;
    pointer-events: auto;
    backdrop-filter: blur(12px);
    transition:
      background 0.35s ease,
      border-color 0.35s ease,
      color 0.35s ease;
  }

  .menu-toggle__icon {
    position: relative;
    display: block;
    width: 15px;
    height: 9px;
  }

  .menu-toggle__icon i {
    position: absolute;
    left: 0;
    display: block;
    width: 15px;
    height: 1px;
    background: currentColor;
    transition:
      top 0.4s var(--ease-out),
      transform 0.4s var(--ease-out);
  }

  .menu-toggle__icon i:first-child {
    top: 0;
  }

  .menu-toggle__icon i:last-child {
    top: 8px;
  }

  body.menu-open .menu-toggle {
    border-color: var(--button-bg);
    background: var(--button-bg);
    color: var(--button-fg);
  }

  body.menu-open .mobile-brand {
    pointer-events: none;
  }

  body.menu-open .menu-toggle__icon i:first-child {
    top: 4px;
    transform: rotate(45deg);
  }

  body.menu-open .menu-toggle__icon i:last-child {
    top: 4px;
    transform: rotate(-45deg);
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: block;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease;
    backdrop-filter: blur(3px);
  }

  body.menu-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 390px) {
  .rail {
    padding-right: 23px;
    padding-left: 23px;
  }

  .mobile-bar {
    padding-right: 16px;
    padding-left: 16px;
  }

  .mobile-brand {
    font-size: 15px;
  }
}

/* ------------------------------------------------------------------ */
/* Effects off                                                        */
/* ------------------------------------------------------------------ */

html[data-effects="off"] #starfield {
  opacity: 0 !important;
  animation: none !important;
}

html[data-effects="off"] *,
html[data-effects="off"] *::before,
html[data-effects="off"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* ------------------------------------------------------------------ */
/* Reduced motion                                                     */
/* ------------------------------------------------------------------ */

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

  #starfield {
    opacity: 1;
  }
}

/* ------------------------------------------------------------------ */
/* Login dialog                                                       */
/* ------------------------------------------------------------------ */

.site-auth-dialog {
  width: min(92vw, 390px);
  padding: 0;
  border: 1px solid var(--tooltip-border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.55);
}

.site-auth-dialog[open] {
  animation: site-auth-in 180ms ease-out both;
}

.site-auth-dialog::backdrop {
  background: var(--scrim);
}

@keyframes site-auth-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.site-auth-form {
  padding: 26px;
}

.site-auth-kicker {
  margin: 0 0 16px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  line-height: 1;
  text-transform: uppercase;
}

.site-auth-form h2 {
  margin: 0 0 8px;
  color: var(--fg);
  font-size: 31px;
  font-weight: 400;
  letter-spacing: -0.05em;
  line-height: 1.1;
}

.site-auth-copy {
  max-width: 300px;
  margin: 0 0 21px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.site-auth-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.site-auth-field span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  line-height: 1;
  text-transform: uppercase;
}

.site-auth-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--tooltip-border);
  border-radius: 6px;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-size: 12px;
}

.site-auth-field input:focus {
  border-color: var(--fg);
}

.site-auth-field input::placeholder {
  color: var(--muted);
}

.site-auth-error {
  min-height: 16px;
  margin: 8px 0 0;
  color: #ff8c8c;
  font-size: 10px;
  line-height: 1.4;
}

.site-auth-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 15px;
}

.site-auth-button {
  height: 38px;
  padding: 0 16px;
  border-radius: 5px;
  font-size: 11px;
}

.site-auth-button--ghost {
  border: 1px solid var(--tooltip-border);
  background: transparent;
  color: var(--fg);
}

.site-auth-button--ghost:hover {
  background: var(--button-bg);
  color: var(--button-fg);
}

.site-auth-button--solid {
  border: 1px solid var(--fg);
  background: var(--button-bg);
  color: var(--button-fg);
}

.site-auth-button--solid:hover {
  opacity: 0.82;
}

.site-auth-button:disabled {
  cursor: wait;
  opacity: 0.45;
}

@media (max-width: 560px) {
  .site-auth-form {
    padding: 22px 18px;
  }

  .site-auth-form h2 {
    font-size: 28px;
  }
}
