/* MAL shared styles
   Load first on every page. Page-specific CSS: home, services, second-life, stoneface, type-lab, phase1. */

:root {
  /* surface */
  /* home-rock-shader.js defaultBg vec3(0.9, 0.86, 0.8) after sqrt + saturation */
  --rubin-ivory: #f5ecde;
  --background-color: var(--rubin-ivory);
  --text-color: rgba(0, 0, 0, 0.85);

  /* rubin palette */
  --rubin-gray: #87867f;
  --rubin-slate: #1f1e1d;
  --rubin-dark-gray: #5e5d59;
  --rubin-riso: #5e7edf;

  /* artwork (app.js) */
  --module-ink-rgb: 56, 31, 32;
  --module-ink-drift-rgb: 111, 37, 39;
  --module-accent-rgb: 200, 72, 71;
  --module-accent-drift-rgb: 143, 38, 68;
  --rum-500: #6d5f70;
  --rum-800: #532a40;

  /* mono utility */
  --mono-0: #ffffff;
  --mono-50: #f5f5f5;
  --mono-100: #ebebeb;
  --mono-200: #d9d9d9;
  --mono-300: #bfbfbf;
  --mono-400: #8c8c8c;
  --mono-500: #595959;
  --mono-600: #404040;
  --mono-700: #262626;
  --mono-800: #1a1a1a;
  --mono-900: #0f0f0f;

  /* type */
  --font-family-base: "IBM Plex Mono", "Courier Prime", Courier, monospace;
  --font-family-code: "IBM Plex Mono", "Courier Prime", Courier, monospace;
  --line-height-base: 1.5;
  --letter-spacing-base: 0.02em;

  /* motion */
  --motion-fast: 140ms;
  --motion-base: 240ms;
  --motion-slow: 420ms;
  --motion-ease-standard: cubic-bezier(0.2, 0, 0, 1);
}

html {
  min-height: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--rubin-ivory);
  color: var(--text-color);
  font-family: var(--font-family-base);
}

/* Shared page surface — link styles.css on every page for this token */
.chapter-page-shell,
.chapter-main,
.shader-deck-section,
.chapter-canvas,
.archive-main,
.sl-page,
.sl-main,
#services-app,
.services-stage,
.portfolio-page,
.portfolio-shell {
  background-color: var(--rubin-ivory);
}

a,
button,
[role="button"],
input,
select,
textarea,
label,
summary {
  cursor: pointer;
}

.header {
  background: transparent !important;
  box-shadow: none !important;
}

/* Enforce single-font system across all rendered chapter surfaces */
body,
.chapter-page-shell,
.header,
.chapter-link,
.mal-header-left,
.mal-header-right {
  font-family: var(--font-family-code) !important;
}

.chapter-page-shell,
.chapter-page {
  background-color: var(--rubin-ivory);
}

.chapter-page {
  max-width: 1400px;
  margin: 0 auto;
}

.chapter-header {
  border-bottom: none;
  box-shadow: none;
  background-color: transparent !important;
  font-family: var(--font-family-code);
  letter-spacing: 0.08em;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sl-page .chapter-header {
  padding: 0 22px;
  height: 60px;
  box-sizing: border-box;
}

.mal-header-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.mal-header-right {
  margin-left: auto;
  text-align: right;
}

.mal-header-sep {
  display: inline-block;
  margin: 0 10px;
  opacity: 0.65;
}

.mal-header-right a {
  text-decoration: none;
  color: var(--text-color);
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
}

.mal-header-right a:hover {
  border-bottom-color: var(--rubin-gray);
}

.mal-logo {
  position: relative;
  width: 24px;
  height: 24px;
  display: inline-block;
  color: var(--rubin-dark-gray);
  line-height: 0;
}


.mal-logo svg {
  width: 100%;
  height: 100%;
  display: block;
}

.mal-logo-cap {
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  opacity: 0.84;
}

.mal-logo-cap-base,
.mal-logo-cap-top-inner {
  stroke: var(--rubin-gray);
}

.mal-logo-dot {
  fill: var(--rubin-slate);
}

.chapter-main {
  background-color: var(--rubin-ivory);
  height: calc(100vh - 60px);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y proximity;
  scroll-behavior: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chapter-main::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.chapter-artwork {
  width: min(94vw, 620px);
  height: min(94vw, 620px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  overflow: hidden;
  padding: 10px;
  border-radius: 8px;
  box-shadow: none;
}

.chapter-secondary-artwork {
  width: min(94vw, 620px);
  height: min(94vw, 620px);
}

#chapter-1-artwork {
  width: min(75.2vw, 496px);
  height: min(75.2vw, 496px);
  position: relative;
}

.chapter-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
  background: transparent;
  touch-action: pan-y;
  pointer-events: none;
}

.chapter-hero-source {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(186px, 29vw, 258px);
  aspect-ratio: 1 / 1;
  margin: 0;
  border-radius: 0;
  overflow: hidden;
  clip-path: polygon(50% 0%, 83% 12%, 100% 43%, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0% 43%, 17% 12%);
  z-index: 3;
  box-shadow: none;
}

.chapter-hero-source img {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  object-fit: cover;
  object-position: 28% 38%;
  display: block;
}

.chapter-particles-mount {
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
}

.chapter-particles-mount canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- Shader interlude: three WebGL2 blocks (ShaderToy) --- */
.shader-deck-section {
  min-height: calc(100vh - 60px);
  scroll-snap-align: start;
  scroll-snap-stop: normal;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 72px 34px;
  border-top: none;
  box-sizing: border-box;
  font-family: var(--font-family-code) !important;
}

.shader-deck {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  width: 100%;
  max-width: 1280px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.shader-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: transparent;
  border: 1px solid color-mix(in oklab, var(--mono-200) 80%, transparent);
  outline: none;
}

.shader-card:focus-visible {
  box-shadow: 0 0 0 2px var(--mono-800);
}

.shader-canvas {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 2;
  display: block;
  border: none;
  background: transparent;
  touch-action: none;
  pointer-events: none;
  user-select: none;
}

.shader-card--video {
  padding: 24px;
  background: #000;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shader-card--video .shader-card-video {
  position: relative;
  width: 75%;
  height: 75%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  border: none;
  background: #000;
  pointer-events: none;
}

.shader-card--torus .torus-card-mount {
  position: absolute;
  inset: 0;
}

.shader-card--torus .torus-card-mount canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.orbit-text-mount {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.orbit-text-mount canvas {
  width: 100%;
  height: 100%;
  display: block;
  mix-blend-mode: screen;
  opacity: 0.86;
  filter: saturate(1.08) contrast(1.04);
}

@media (max-width: 1024px) {
  .mal-header-right {
    position: relative;
  }

  .mal-header-label {
    display: none;
  }

  .chapter-main {
    height: calc(100dvh - 60px);
    min-height: calc(100dvh - 60px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scroll-snap-type: y proximity;
  }

  .chapter-artwork {
    width: min(86vw, calc((100dvh - 60px) * 0.72));
    max-width: 86vw;
    height: min(86vw, calc((100dvh - 60px) * 0.72));
    aspect-ratio: 1;
    padding: 0;
    border-radius: 0;
  }

  #chapter-1-artwork {
    width: min(80vw, calc((100dvh - 60px) * 0.8));
    height: min(80vw, calc((100dvh - 60px) * 0.8));
  }

  .chapter-hero-source {
    width: clamp(156px, 41vw, 218px);
  }

  .shader-deck-section {
    min-height: auto;
    padding: 34px 14px 44px;
  }

  .shader-deck {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: min(92vw, 420px);
    aspect-ratio: auto;
    margin: 0 auto;
    perspective: none;
  }

  .shader-deck .shader-card {
    position: relative;
    inset: auto;
    transform-origin: 50% 50%;
    transition:
      transform var(--motion-slow) var(--motion-ease-standard),
      opacity var(--motion-base) var(--motion-ease-standard);
    cursor: pointer;
    aspect-ratio: 1 / 1;
  }

  .shader-deck .shader-card.is-active-render {
    will-change: transform, opacity;
  }

  .shader-deck .shader-card[data-pos="0"] {
    transform: none;
    opacity: 1;
    z-index: 1;
  }

  .shader-deck .shader-card[data-pos="1"] {
    transform: none;
    opacity: 1;
    z-index: 1;
  }

  .shader-deck .shader-card[data-pos="2"] {
    transform: none;
    opacity: 1;
    z-index: 1;
  }

  .shader-deck .shader-card.is-leaving {
    transform: none;
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  html,
  body,
  .chapter-main {
    scroll-behavior: auto !important;
  }

  .shader-deck .shader-card,
  .shader-deck .shader-card.is-leaving {
    transition: opacity 80ms linear !important;
    transform: none !important;
  }
}

/* --- Archive page: sectioned two-card decks --- */
.archive-page .chapter-main,
.archive-page .archive-main {
  height: auto;
  min-height: calc(100dvh - 60px);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: none;
}

.archive-main {
  display: flex;
  flex-direction: column;
  gap: 56px;
  padding: 28px 72px 64px;
  box-sizing: border-box;
}

.archive-intro {
  max-width: 42rem;
}

.archive-intro-text {
  margin: 0;
  line-height: 1.5;
  opacity: 0.88;
}

.archive-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.archive-section-head h2 {
  margin: 0 0 6px;
  font-family: var(--font-family-code) !important;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  font-weight: 400;
}

.archive-section-head p {
  margin: 0;
  max-width: 40rem;
  line-height: 1.45;
  opacity: 0.82;
  font-size: 0.94em;
}

.archive-artwork {
  display: flex;
  justify-content: center;
  width: 100%;
}

.archive-poem {
  margin-top: 10px;
  opacity: 0.92;
}

.archive-page .shader-deck-section {
  min-height: auto;
  padding: 0;
  background: transparent;
  border-top: none;
}

.archive-page .shader-deck {
  max-width: 1280px;
}

@media (max-width: 1024px) {
  .archive-main {
    padding: 20px 14px 48px;
    gap: 44px;
  }
}

/* Shared UI primitives (stoneface drawer, second-life) */
.gr-btn {
  border: 1px solid var(--mono-300);
  background: var(--mono-0);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.gr-panel {
  background: var(--mono-0);
  border: 1px solid var(--mono-200);
  border-radius: 8px;
  padding: 14px;
}

