:root {
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --edge: max(1rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --edge-top: max(1rem, env(safe-area-inset-top, 0px));
  --edge-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  --brand-size: clamp(2rem, 7vw + 0.5rem, 5.5rem);
  --dock-size: clamp(2.5rem, 8vw, 2.75rem);
  color-scheme: only light;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  background: #000000;
  color: #ffffff;
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Fullscreen solving orb until first plate paints */
#boot {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  background: #000000;
}

#boot-orb {
  width: 64px;
  height: 64px;
  display: block;
}

body:has(#boot) .brand,
body:has(#boot) .portal-dock {
  visibility: hidden;
}

#stage,
#blood {
  isolation: isolate;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  pointer-events: none;
}

#stage {
  z-index: 0;
  background: #ffffff;
}

.defs-svg {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Soft ink-in-water mask — matches test-mult look */
#blood {
  z-index: 1;
  visibility: hidden;
  mix-blend-mode: multiply;
  opacity: 1;
  -webkit-mask: url(#blood-mask);
  mask: url(#blood-mask);
}

body.is-bleeding #blood {
  visibility: visible;
}

#stage canvas,
#blood canvas {
  contain: strict;
  display: block;
  position: absolute !important;
  inset: 0;
  z-index: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

.brand {
  position: fixed;
  top: calc(var(--edge-top) + 0.35rem);
  left: calc(var(--edge) + 0.15rem);
  z-index: 2;
  margin: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 0.08ch;
  max-width: calc(100vw - (var(--edge) * 2) - 0.3rem);
  pointer-events: none;
  font-family: var(--font-display);
  font-size: var(--brand-size);
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.04em;
}

.brand h1 {
  margin: 0;
  font: inherit;
  color: #ffffff;
  animation: brand-in 1.1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.shell {
  appearance: none;
  position: relative;
  pointer-events: auto;
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 0.02em;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #e10600;
  /* Terminal glyphs — display serif turns `_` into a mid-dash joke */
  font-family: var(--font-ui);
  font-size: 0.72em;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  animation: brand-in 1.1s cubic-bezier(0.16, 1, 0.3, 1) 0.08s both;
}

.shell-hit {
  position: relative;
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: baseline;
  flex: none;
  pointer-events: auto;
}

/* Touch pad — do not bleed left into the h1 */
.shell::before {
  content: "";
  position: absolute;
  top: -0.45em;
  right: -0.4em;
  bottom: -0.4em;
  left: -0.08em;
}

.shell:focus-visible {
  outline: 2px solid #e10600;
  outline-offset: 4px;
}

.shell-gt,
.shell-cursor {
  display: inline-block;
  font: inherit;
  line-height: 1;
  vertical-align: baseline;
}

.shell-cursor {
  width: 0.55em;
  height: 0.1em;
  margin-left: 0.04em;
  background: currentColor;
  /* empty bar on the baseline — no serif `_` glyph */
  overflow: hidden;
  text-indent: -9999px;
  animation: shell-blink 1.05s steps(1, end) infinite;
}

@keyframes shell-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* Black chips — shell tip, soon, illegal */
.shell-tip {
  appearance: none;
  position: absolute;
  left: 0;
  top: calc(100% + 0.45rem);
  bottom: auto;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  width: max-content;
  max-width: min(92vw, 38rem);
  margin: 0;
  padding: 0.35rem 0.55rem;
  border: 1px solid #000000;
  background: #000000;
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-0.2rem);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.shell-tip-cmd {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.shell-tip-clip {
  flex: none;
  display: block;
}

/* Bridge the gap so the pointer can move onto the chip */
.shell-tip::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 0.55rem;
}

/* Tip only for desktop Linux / Windows (data-shell-tip set in JS) */
.shell-hit[data-shell-tip]:hover .shell-tip,
.shell-hit[data-shell-tip]:focus-within .shell-tip,
.shell-hit[data-shell-tip].is-open .shell-tip {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.shell-tip.is-copied {
  opacity: 1;
}

.portal-dock {
  position: fixed;
  right: calc(var(--edge) + 0.15rem);
  bottom: calc(var(--edge-bottom) + 0.15rem);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.portal-sign {
  appearance: none;
  position: relative;
  display: grid;
  place-items: center;
  width: var(--dock-size);
  height: var(--dock-size);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #000000;
  background: #000000;
  color: #ffffff;
  cursor: pointer;
}

.portal-orb {
  width: min(20px, 55%);
  height: min(20px, 55%);
  display: block;
  pointer-events: none;
}

.portal-sign::after {
  content: "soon";
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.45rem);
  padding: 0.35rem 0.55rem;
  border: 1px solid #000000;
  background: #000000;
  color: #ffffff;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(0.2rem);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.portal-sign:hover::after,
.portal-sign:focus-visible::after,
.portal-sign.is-soon::after {
  opacity: 1;
  transform: none;
}

.portal-sign:focus-visible {
  outline: 2px solid #000000;
  outline-offset: 3px;
}

#illegal {
  position: fixed;
  z-index: 99;
  pointer-events: none;
  border: 1px solid #000000;
  background: #000000;
  color: #ffffff;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.4rem 0.55rem;
  opacity: 0;
  transition: opacity 120ms ease;
}

#illegal.show {
  opacity: 1;
}

@keyframes brand-in {
  from {
    opacity: 0;
    transform: translateY(0.6rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 480px) {
  :root {
    --brand-size: clamp(1.85rem, 11vw, 2.75rem);
  }

  .brand {
    top: calc(var(--edge-top) + 0.5rem);
  }

  .shell-tip {
    left: 0;
    right: auto;
    max-width: min(92vw, 22rem);
    font-size: 0.62rem;
  }

  .portal-sign::after {
    font-size: 0.62rem;
    padding: 0.3rem 0.45rem;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  :root {
    --brand-size: clamp(1.5rem, 6vh + 0.5rem, 2.25rem);
  }

  .brand {
    top: max(0.5rem, env(safe-area-inset-top, 0px));
  }

  .portal-dock {
    bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .shell-cursor {
    opacity: 1 !important;
  }
}
