/* ==========================================================================
   ChenPi.ch — one screen: background render plus the wordmark.
   The only control is the light/dark toggle.

   The wordmark is an image, not live text and not a CSS mask: a mask asset is
   blocked by CORS over file://, which made the wordmark disappear when the page
   was opened straight from disk. Source is the author's own render
   (Untitled.png), cropped to its ink bounding box by
   work/build/make_wordmark.py — that crop is what lets the block centre
   exactly.
   ========================================================================== */

:root {
  /* Wordmark width. 28vw is the chosen weight; the 1100px cap only matters on
     very wide screens, and the 180px floor starts applying below ~643px wide so
     the mark does not become an unreadable sliver on phones. Tune this one
     value to resize it. */
  --wordmark-width: clamp(180px, 28vw, 1100px);

  --ink-light: #0d0d0f;
  --ink-dark: #f4f4f2;
  --fade: 420ms;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #dfe7f1;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

html[data-theme="dark"] body {
  background: #05070d;
}

/* --------------------------------------------------------------------------
   Background renders — both stay mounted so the toggle is instant.
   -------------------------------------------------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  transition: opacity var(--fade) ease;
}

html[data-theme="light"] .backdrop[data-for="dark"],
html[data-theme="dark"] .backdrop[data-for="light"] {
  opacity: 0;
}

/* --------------------------------------------------------------------------
   Wordmark

   Sized to stay inside 86vw and 56vh, then centred by the stage. Because the
   mask was trimmed to the ink box, geometric centring is also optical
   centring — there is no stray margin left to compensate for.
   -------------------------------------------------------------------------- */

.stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.name {
  margin: 0;
}

.name__mark {
  display: block;
  /* 190vh is a guard for short, wide windows: at the 5.0819 aspect it caps the
     mark's height at ~37% of the viewport. */
  width: min(var(--wordmark-width), 190vh);
  height: auto;
  filter: drop-shadow(0 0 clamp(6px, 1vw, 18px) rgba(255, 255, 255, 0.5));
}

/* The asset's ink is #0b0b0d, so inverting lands on #f4f4f2 — the dark-theme
   ink — without shipping a second file. Filters are universally available, and
   unlike a mask they also work offline over file://. */
html[data-theme="dark"] .name__mark {
  filter: invert(1) drop-shadow(0 0 clamp(6px, 1vw, 18px) rgba(0, 0, 0, 0.7));
}

/* --------------------------------------------------------------------------
   Theme toggle — the only interface on the page
   -------------------------------------------------------------------------- */

.theme-toggle {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  /* A faint disc keeps the control findable over the busy parts of the render
     without introducing visible button chrome. */
  background: rgba(255, 255, 255, 0.42);
  color: rgba(13, 13, 15, 0.72);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease;
}

html[data-theme="dark"] .theme-toggle {
  background: rgba(10, 12, 18, 0.38);
  color: rgba(244, 244, 242, 0.78);
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--ink-light);
  background: rgba(255, 255, 255, 0.72);
}

html[data-theme="dark"] .theme-toggle:hover,
html[data-theme="dark"] .theme-toggle:focus-visible {
  color: var(--ink-dark);
  background: rgba(10, 12, 18, 0.62);
}

.theme-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.theme-toggle__icon {
  display: block;
  width: 20px;
  height: 20px;
}

.theme-toggle__icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Show the destination: a sun means "switch to light". */
html[data-theme="dark"] .theme-toggle__sun,
html[data-theme="light"] .theme-toggle__moon {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .backdrop,
  .theme-toggle {
    transition: none;
  }
}
