:root {
  --bg: #000;
  --text: #e6ddc9;
  --text-dim: #9a917f;
  --purple: #6b2d8c;
  --purple-glow: rgba(107, 45, 140, 0.35);
  --red: #7a1414;
  --border: #2a2420;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

/* iOS Safari's chrome grows/shrinks as you scroll, and 100vh doesn't
   account for that -- dvh does. Falls back to vh automatically on
   browsers that don't know dvh (the second declaration just never
   applies there, first one stands). */
html {
  min-height: 100vh;
  min-height: 100dvh;
}

::selection {
  background: var(--purple);
  color: #fff;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--purple) #000;
}

::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: #000;
}

::-webkit-scrollbar-thumb {
  background: var(--purple);
  border-radius: 6px;
}

/* Faint film grain over everything -- pure black reads flat and lifeless
   without it. Pointer-events: none so it never intercepts clicks/taps. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: "Special Elite", "Courier New", monospace;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.3;
  text-shadow: 0 0 18px var(--purple-glow);
}

h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  margin: 0.4em 0 0.2em;
}

h2 {
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  margin: 1.6em 0 0.6em;
}

h3 {
  font-size: 1.2rem;
  margin: 0 0 0.3em;
}

p {
  margin: 0 0 1em;
}

a {
  color: var(--text);
}

a:hover {
  color: #fff;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: #000;
  color: #fff;
  padding: 0.6em 1em;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

/* ── Header / nav ─────────────────────────────────────────────── */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-family: "Special Elite", monospace;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.site-nav a {
  text-decoration: none;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.site-nav a:hover {
  color: var(--text);
}

/* ── Layout ───────────────────────────────────────────────────── */

main {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.section {
  padding: 2.5rem 0;
  border-top: 1px solid var(--border);
}

.section:first-child {
  border-top: none;
}

/* Restrained purple smoky glow, used sparingly behind a section heading —
   not a busy background texture, just a soft radial bloom. */
.glow {
  position: relative;
}

.glow::before,
.glow::after {
  content: "";
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  width: 60vw;
  max-width: 700px;
  height: 300px;
  background: radial-gradient(ellipse at center, var(--purple-glow) 0%, transparent 70%);
  z-index: -1;
  pointer-events: none;
}

/* Slow base pulse, like a dying gas lamp. */
.glow::before {
  animation: glow-pulse 8s ease-in-out infinite;
}

/* Faster, subtler second layer riding on top of it -- an irregular
   flicker rather than a clean single pulse. */
.glow::after {
  animation: glow-flicker 2.6s steps(1, end) infinite;
  opacity: 0.4;
}

@keyframes glow-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes glow-flicker {
  0%, 19%, 21%, 100% { opacity: 0.4; }
  20% { opacity: 0.15; }
  55% { opacity: 0.4; }
  56% { opacity: 0.25; }
  57% { opacity: 0.4; }
}

/* Sparse dark-red splatter accent, echoing the mark under the logo's
   "STUDIOS" wordmark — used once, not decorative overkill. Very slowly
   settling downward, like it hasn't quite finished dripping. */
.splatter {
  position: relative;
}

.splatter h2::after {
  content: "";
  display: block;
  width: 5em;
  height: 0.6em;
  margin-top: 0.3em;
  background:
    radial-gradient(circle at 10% 50%, var(--red) 0 3px, transparent 4px),
    radial-gradient(circle at 35% 20%, var(--red) 0 2px, transparent 3px),
    radial-gradient(circle at 55% 70%, var(--red) 0 4px, transparent 5px),
    radial-gradient(circle at 80% 40%, var(--red) 0 2px, transparent 3px);
  background-repeat: no-repeat;
  opacity: 0.85;
  animation: drip 14s ease-in-out infinite;
}

@keyframes drip {
  0%, 85%, 100% { background-position: 0 0; }
  92% { background-position: 0 3px; }
}

/* ── Hero ─────────────────────────────────────────────────────── */

.hero {
  text-align: center;
  padding: 3rem 0 2rem;
}

.hero-logo {
  width: 100%;
  max-width: 560px;
  height: auto;
}

.hero h1 {
  margin-top: 0.6em;
}

.subheading {
  color: var(--text-dim);
  font-size: 1.2rem;
  font-style: italic;
  max-width: 42em;
  margin: 0 auto;
}

.intro-text {
  max-width: 42em;
  margin: 0 auto 1em;
}

.empty-note {
  color: var(--text-dim);
  font-style: italic;
}

/* ── Buttons / links ──────────────────────────────────────────── */

.button {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.6em 1.4em;
  border: 1px solid var(--purple);
  color: var(--text);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.9rem;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.button:hover {
  background: var(--purple-glow);
  box-shadow: 0 0 16px var(--purple-glow);
  color: #fff;
}

.link {
  color: var(--text-dim);
  text-decoration: underline;
}

.link:hover {
  color: var(--text);
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
}

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

.link-list li {
  margin-bottom: 0.5em;
}

/* ── Project cards ────────────────────────────────────────────── */

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.project-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 1rem;
  transition: border-color 0.2s ease;
}

.project-card:hover {
  border-color: var(--purple);
}

.project-card img {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 0.8rem;
}

.status {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.project-cover {
  width: 100%;
  max-width: 640px;
  height: auto;
  display: block;
  margin: 0 auto 1rem;
}

.screenshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.8rem;
  margin: 1.5rem 0;
}

.screenshot-grid img {
  width: 100%;
  height: auto;
  display: block;
}

.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1rem;
}

/* ── Contact form ─────────────────────────────────────────────── */

.contact-form {
  display: flex;
  flex-direction: column;
  max-width: 32em;
  margin-top: 1.5rem;
}

.contact-form label {
  margin-top: 1rem;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.contact-form input[type="text"],
.contact-form input[type="email"],
.contact-form select,
.contact-form textarea {
  background: #0a0a0a;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.6em 0.8em;
}

.contact-form input:focus,
.contact-form select:focus,
.contact-form textarea:focus {
  outline: 1px solid var(--purple);
}

.honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.cf-turnstile {
  margin-top: 1.2rem;
}

.contact-form button {
  align-self: flex-start;
  cursor: pointer;
  background: transparent;
  font-family: inherit;
}

#contact-status {
  margin-top: 0.8rem;
  font-size: 0.95rem;
}

#contact-status.error {
  color: #c46a6a;
}

#contact-status.success {
  color: #a9c46a;
}

/* ── Footer ───────────────────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.2rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.footer-links a {
  text-decoration: none;
  color: var(--text-dim);
}

.footer-links a:hover {
  color: var(--text);
}

/* ── Eyebrow labels ───────────────────────────────────────────── */

.eyebrow {
  display: block;
  font-family: "Special Elite", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--red);
  opacity: 0.85;
  margin-bottom: 0.3em;
}

/* ── Mirthlings ───────────────────────────────────────────────── */
/* Pixel art -- crisp scaling, no smoothing blur. */

.mirthling {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.mirthling-flavor {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.mirthling-flavor .mirthling {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.mirthling-flavor p {
  margin: 0;
}

/* Peeking out from beside the hero logo. */
.hero {
  position: relative;
}

/* Nav brand: a Mirthling peeks out on hover. */
.brand {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand .mirthling {
  width: 28px;
  height: 28px;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.brand:hover .mirthling {
  opacity: 1;
  transform: translateX(0);
}

/* Footer: a sleeping Mirthling in the corner, slow breathing loop. */
.footer-mirthling {
  width: 48px;
  height: 48px;
  margin: 0 auto 0.8rem;
  animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Contact form result states -- hidden until JS reveals the matching one. */
.mirthling-result {
  width: 72px;
  height: 72px;
  margin-top: 0.8rem;
  display: none;
}

.mirthling-result.shown {
  display: block;
}

/* 404 page */
.error-page {
  text-align: center;
  padding: 3rem 0;
}

.error-page .mirthling {
  width: 140px;
  height: 140px;
  margin: 0 auto 1rem;
}

/* ── Scroll reveal (progressive enhancement — see the "js" class added
   by base.html's inline script; without it, everything is just visible) */

.js .reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.js .reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ── Cursor glow (desktop only, added by site.js) ────────────────── */

.cursor-glow {
  position: fixed;
  top: 0;
  left: 0;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--purple-glow) 0%, transparent 70%);
  pointer-events: none;
  z-index: 5;
  mix-blend-mode: screen;
}

/* ── Easter-egg swarm ─────────────────────────────────────────────── */

.swarm-mirthling {
  position: fixed;
  bottom: -140px;
  width: 64px;
  height: 64px;
  z-index: 999;
  pointer-events: none;
  animation-name: swarm-rise;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes swarm-rise {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  85% { opacity: 1; }
  100% { transform: translateY(-105vh) rotate(12deg); opacity: 0; }
}

/* ── Native page-transition (progressive enhancement — no-op on
   browsers that don't support the View Transitions API for
   navigations) ────────────────────────────────────────────────── */

@view-transition {
  navigation: auto;
}

/* ── Responsive ───────────────────────────────────────────────── */

@media (max-width: 640px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .site-nav {
    gap: 1rem;
  }

  main {
    padding: 0 1.1rem;
  }

  .mirthling-flavor {
    flex-direction: column;
    text-align: center;
  }
}

/* iPhone notch / home-indicator safe areas. */
@supports (padding: max(0px)) {
  .site-header {
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
  }

  .site-footer {
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }
}

/* Touch devices: no hover-dependent content, no custom cursor glow,
   no tap-highlight flash. */
@media (hover: none), (pointer: coarse) {
  .cursor-glow {
    display: none;
  }

  .brand .mirthling {
    /* No hover on touch -- show it plainly instead of hiding it behind
       a hover state nothing will ever trigger. */
    opacity: 1;
    transform: none;
  }

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

/* Comfortable tap targets on touch devices (Apple HIG recommends >=44px). */
@media (max-width: 640px), (hover: none) {
  .site-nav a {
    padding: 0.4em 0;
    display: inline-block;
  }

  .button {
    padding: 0.75em 1.6em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .glow::before,
  .glow::after,
  .splatter h2::after,
  .footer-mirthling {
    animation: none;
  }

  .js .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}
