@font-face {
  font-family: 'terminus';
  src: url('/assets/fonts/terminus.ttf') format('truetype');
  font-display: swap;
}

@counter-style binary {
  system: numeric;
  symbols: '0' '1';
  pad: 3 '0';
  suffix: '  ';
}

:root {
  --bg-void: #010403;
  --bg-panel: rgba(2, 12, 9, 0.76);
  --bg-inset: rgba(0, 0, 0, 0.55);
  --color-worm: #2dffab;
  --color-worm-dim: #1ca06b;
  --color-ring: #57cbde;
  --color-ring-dim: #2b7f8f;
  --color-law: #b48cff;
  --color-law-dim: #6d4fae;
  --color-ward: #ff6b9d;
  --text-body: #c4d4cc;
  --text-dim: #7c9087;
  --font-body: 'terminus', 'Courier New', monospace;
  --ease: 0.3s ease;
}

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

[hidden] {
  display: none !important;
}

html {
  font-size: 17px;
  scrollbar-color: var(--color-worm-dim) var(--bg-void);
}

body {
  --accent: var(--color-worm);
  --accent-dim: var(--color-worm-dim);
  --accent-glow: color-mix(in srgb, var(--accent) 55%, transparent);
  --accent-wash: color-mix(in srgb, var(--accent) 8%, transparent);
  margin: 0;
  min-height: 100vh;
  background: var(--bg-void) radial-gradient(ellipse at 72% 38%, rgba(28, 160, 107, 0.18), transparent 62%) fixed;
  color: var(--text-body);
  font-family: var(--font-body);
  line-height: 1.65;
}

body[data-accent="ring"] {
  --accent: var(--color-ring);
  --accent-dim: var(--color-ring-dim);
}

body[data-accent="law"] {
  --accent: var(--color-law);
  --accent-dim: var(--color-law-dim);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 5;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0 1px, transparent 1px 3px);
  opacity: 0.18;
  pointer-events: none;
}

::selection {
  background: var(--accent);
  color: #000;
}

:focus-visible {
  outline: 1px dashed var(--accent);
  outline-offset: 3px;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: text-shadow var(--ease);
}

a:hover {
  text-decoration: underline;
  text-shadow: 0 0 0.6rem var(--accent-glow);
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
}

.skip-link {
  position: absolute;
  left: -100rem;
  z-index: 10;
  padding: 0.4rem 0.8rem;
  background: #000;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 15rem minmax(0, 44rem);
  gap: 2rem;
  align-items: start;
  padding: 2.5rem 2.5rem 2rem;
}

.masthead {
  position: sticky;
  top: 2.5rem;
}

.masthead-name {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
  font-size: 2.6rem;
  line-height: 1;
  letter-spacing: 0.08em;
  animation: worm-pulse 4s ease-in-out infinite;
}

.masthead-name:hover {
  text-decoration: none;
}

.masthead-name img {
  width: 4rem;
  height: 4rem;
  animation: sigil-turn 120s linear infinite;
}

.masthead-tagline {
  margin: 0.7rem 0 0;
  color: var(--accent-dim);
  font-size: 0.75rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.masthead-rite {
  margin: 0.2rem 0 0;
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.masthead-rite span {
  color: var(--accent);
  animation: rite-blink 1s steps(2, jump-none) infinite;
}

.spine {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 1.6rem;
}

.spine a {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-worm-dim);
  background: var(--bg-inset);
  backdrop-filter: blur(10px);
  color: var(--color-worm);
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: transform var(--ease), background var(--ease), text-shadow var(--ease), border-color var(--ease);
}

.spine a:first-child {
  border-radius: 1rem 1rem 0 0;
}

.spine a:last-child {
  border-radius: 0 0 1rem 1rem;
}

.spine a span {
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.spine a:hover,
.spine a[aria-current] {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 16%, #000);
  text-decoration: none;
  text-shadow: 0 0 0.6rem currentColor;
}

.spine a:hover {
  transform: translateY(-2px);
}

.spine a[aria-current] {
  border-left-width: 0.5rem;
}

.spine .spine-ring {
  margin-top: 0.9rem;
  border-color: var(--color-ring-dim);
  color: var(--color-ring);
}

.spine .spine-law {
  margin-top: 0.9rem;
  border-color: var(--color-law-dim);
  color: var(--color-law);
}

.codex {
  min-width: 0;
  border: 1px solid var(--accent-dim);
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 0 3rem color-mix(in srgb, var(--accent) 12%, transparent);
}

.codex-bar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.15rem 0.6rem;
  background: linear-gradient(180deg, var(--accent-dim), color-mix(in srgb, var(--accent-dim) 55%, #000));
  color: #000;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.codex-body {
  padding: 1.6rem 2rem 2rem;
  animation: codex-in 0.3s ease;
}

.codex-body > :last-child,
.plate > :last-child,
.ward > :last-child {
  margin-bottom: 0;
}

.codex-path {
  display: flex;
  gap: 1rem;
  padding: 0.8rem 2rem;
  border-top: 1px solid color-mix(in srgb, var(--accent-dim) 50%, transparent);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.codex-path a[rel="next"] {
  margin-left: auto;
}

h1,
h2,
h3 {
  font-weight: normal;
}

h1 {
  margin: 0 0 0.3rem;
  color: var(--accent);
  font-size: 1.9rem;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-shadow: 0 0 1.2rem var(--accent-glow);
}

h2 {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 2.2rem 0 0.8rem;
  color: var(--accent-dim);
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h2::before {
  content: '';
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border: 1px solid var(--accent);
  transform: rotate(45deg);
}

h2::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--accent-dim), transparent);
}

h3 {
  margin: 1.5rem 0 0.4rem;
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: 0.06em;
}

p {
  margin: 0 0 0.8rem;
}

strong {
  color: var(--accent);
  font-weight: normal;
}

ul,
ol {
  margin: 0 0 1rem;
  padding-left: 1.6rem;
}

li {
  margin-bottom: 0.45rem;
}

li::marker {
  color: var(--accent);
}

code,
pre {
  font-family: inherit;
  color: var(--accent);
  word-break: break-all;
}

pre {
  flex: 1;
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: var(--bg-inset);
  white-space: pre-wrap;
}

.byline {
  margin-bottom: 1.4rem;
  color: var(--accent-dim);
  letter-spacing: 0.1em;
}

.muted {
  color: var(--text-dim);
  font-size: 0.88rem;
}

.ward-text {
  color: var(--color-ward);
}

.invocation {
  margin: 1.2rem 0;
  padding: 1rem 1.2rem;
  border-left: 0.25rem solid var(--accent-dim);
  background: var(--bg-inset);
  color: var(--accent);
  font-style: italic;
}

.plate,
.ward {
  margin: 1.2rem 0;
  padding: 1rem 1.2rem;
  border: 1px solid var(--accent-dim);
  background: var(--accent-wash);
}

.plate > :first-child,
.ward > :first-child {
  margin-top: 0;
}

.ward {
  border-color: var(--color-ward);
  background: color-mix(in srgb, var(--color-ward) 8%, transparent);
}

.ward h3 {
  color: var(--color-ward);
}

.principles {
  padding-left: 3rem;
  list-style: binary;
}

.law {
  padding-left: 2.6rem;
  list-style: upper-roman;
}

.law li {
  margin-bottom: 0.9rem;
}

.rite {
  padding: 0;
  list-style: none;
}

.rite li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 1rem;
  margin: 0;
  padding: 0.6rem 0;
  border-top: 1px dashed color-mix(in srgb, var(--accent-dim) 45%, transparent);
}

.rite b {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.timeline,
.record {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem 1rem;
  margin: 0 0 1rem;
}

.timeline dt {
  color: var(--accent);
}

.timeline dd,
.record dd {
  margin: 0;
}

.record {
  align-items: center;
}

.record dt {
  color: var(--text-dim);
}

.record dd,
.banner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.banner {
  flex-wrap: wrap;
}

.banner img {
  image-rendering: pixelated;
}

.web-list {
  padding: 0;
  list-style: none;
}

.web-list li {
  margin-bottom: 0.9rem;
}

.web-list p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.88rem;
}

form {
  display: grid;
  gap: 0.8rem;
  margin-top: 1rem;
}

label {
  display: grid;
  gap: 0.25rem;
  color: var(--accent);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}

input,
textarea {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--accent-dim);
  background: #000;
  color: var(--text-body);
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  transition: border-color var(--ease), box-shadow var(--ease);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0.8rem var(--accent-glow);
}

button {
  flex: none;
  justify-self: start;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--accent-dim);
  background: var(--bg-inset);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform var(--ease), background var(--ease), border-color var(--ease);
}

button:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, #000);
  transform: translateY(-2px);
}

button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.colophon {
  grid-column: 1 / -1;
  margin-top: 1rem;
  color: var(--color-worm-dim);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-align: center;
  opacity: 0.75;
}

.colophon p {
  margin: 0.2rem 0;
}

@keyframes worm-pulse {
  0%, 100% {
    text-shadow: 0 0 1.2rem var(--accent-glow), 0 0 2.6rem color-mix(in srgb, var(--accent-dim) 60%, transparent);
  }
  50% {
    text-shadow: 0 0 1.8rem var(--accent), 0 0 3.6rem var(--accent-glow);
  }
}

@keyframes sigil-turn {
  to {
    transform: rotate(360deg);
  }
}

@keyframes rite-blink {
  50% {
    opacity: 0.45;
  }
}

@keyframes codex-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}

@media (max-width: 1024px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.4rem;
    padding: 1.2rem 1rem;
  }

  .masthead {
    position: static;
  }

  .spine {
    flex-direction: row;
    flex-wrap: wrap;
    margin-top: 1.1rem;
  }

  .spine a:first-child,
  .spine a:last-child,
  .spine .spine-ring,
  .spine .spine-law {
    margin-top: 0;
    border-radius: 0;
  }

  .spine a {
    flex: 1 1 8rem;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  .masthead-name {
    font-size: 2rem;
  }

  .codex-body {
    padding: 1.1rem 1rem 1.4rem;
  }

  .codex-path {
    padding: 0.7rem 1rem;
  }

  .rite li {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }
}

@media (min-width: 1920px) {
  html {
    font-size: 19px;
  }
}

@media (min-width: 2560px) {
  html {
    font-size: 25px;
  }
}

@media (min-width: 3840px) {
  html {
    font-size: 38px;
  }
}

@media (min-width: 6000px) {
  html {
    font-size: 58px;
  }
}

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