/* ============================================================
   Alfidia Studios - interactive website demonstration
   Warm cream interface, charcoal text, selective orange.
   Spacing scale: 4 / 8 / 12 / 16 / 24 / 32 / 48
   Radii: 10 (small controls) / 12 (buttons) / 14 (panels)
   ============================================================ */

:root {
  /* Provisional Alfidia brand tokens (from the restyle brief).
     If the parent site defines approved equivalents, map these to them. */
  --alfidia-cream: #f6f1e8;
  --alfidia-surface: #fffcf6;
  --alfidia-orange: #ff650d;
  --alfidia-charcoal: #242320;
  --alfidia-muted: #625a50;
  --alfidia-border: #d9d0c3;

  /* Functional additions */
  --alfidia-orange-text: #ae3c08; /* small orange text: 5.4:1 on cream, 5.9:1 on surface */
  --alfidia-cream-deep: #ece4d4; /* tonal layering for one card */

  --font-ui: "Space Grotesk", system-ui, "Segoe UI", sans-serif;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-6: 24px;
  --s-8: 32px;
  --s-12: 48px;

  --r-sm: 10px;
  --r-md: 12px;
  --r-lg: 14px;

  --container: 1200px;
  --nav-h: 64px;
  --telemetry-h: 40px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--alfidia-cream);
  color: var(--alfidia-charcoal);
  font: 400 16px/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

.num {
  font-variant-numeric: tabular-nums;
}

::selection {
  background: var(--alfidia-orange);
  color: var(--alfidia-charcoal);
}

:focus-visible {
  outline: 2px solid var(--alfidia-charcoal);
  outline-offset: 2px;
}

.wrap {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--s-6);
}

@media (max-width: 768px) {
  .wrap {
    padding: 0 var(--s-4);
  }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--s-3) var(--s-6);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font: 600 15px/1.2 var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.2s var(--ease-out), color 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--alfidia-orange);
  color: var(--alfidia-charcoal); /* 5.3:1 on orange */
}

.btn-primary:hover {
  background: var(--alfidia-charcoal);
  color: var(--alfidia-cream);
}

.btn-secondary {
  background: var(--alfidia-surface);
  border-color: var(--alfidia-charcoal);
  color: var(--alfidia-charcoal);
}

.btn-secondary:hover {
  background: var(--alfidia-cream-deep);
}

/* ---------- Nav ---------- */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  z-index: 100;
  display: flex;
  align-items: center;
  background: var(--alfidia-cream);
  border-bottom: 1px solid var(--alfidia-border);
}

.nav .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border-radius: var(--r-sm);
}

.nav-brand img {
  height: 24px;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--s-6);
}

.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--s-1);
  font-size: 15px;
  font-weight: 500;
  color: var(--alfidia-muted);
}

.nav-link::after {
  content: "";
  position: absolute;
  left: var(--s-1);
  right: var(--s-1);
  bottom: 8px;
  height: 2px;
  background: var(--alfidia-orange);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s var(--ease-out);
}

.nav-link:hover {
  color: var(--alfidia-charcoal);
}

.nav-link:hover::after,
.nav-link:focus-visible::after {
  transform: scaleX(1);
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--alfidia-border);
  border-radius: var(--r-md);
  color: var(--alfidia-charcoal);
  cursor: pointer;
}

.nav-toggle:hover {
  background: var(--alfidia-cream-deep);
}

@media (max-width: 860px) {
  .nav-toggle {
    display: inline-flex;
  }
  .nav-links {
    display: none;
  }
  .nav-links.is-open {
    display: flex;
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--s-2) var(--s-4) var(--s-4);
    background: var(--alfidia-cream);
    border-bottom: 1px solid var(--alfidia-border);
  }
  .nav-links.is-open .nav-link {
    min-height: 48px;
    font-size: 16px;
  }
  .nav-links.is-open .nav-link::after {
    left: 0;
    right: auto;
    width: 32px;
  }
}

/* ---------- Hero ---------- */

.hero {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  overflow: hidden;
  padding-top: var(--nav-h);
}

.hero .wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  align-items: center;
  gap: var(--s-6);
  width: 100%;
  padding-top: var(--s-6);
  padding-bottom: var(--s-12);
}

@media (max-width: 980px) {
  .hero .wrap {
    grid-template-columns: minmax(0, 1fr);
    padding-top: var(--s-4);
    padding-bottom: var(--s-8);
  }
}

.hero-copy {
  position: relative;
  z-index: 2;
  min-width: 0;
}

.eyebrow {
  display: block;
  margin-bottom: var(--s-4);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--alfidia-orange-text);
}

.hero-title {
  margin-bottom: var(--s-4);
  max-width: 22ch;
  font-size: clamp(28px, 4vw, 36px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-weight: 700;
  text-wrap: balance;
}

.hero-title em {
  font-style: normal;
  text-decoration: underline;
  text-decoration-color: var(--alfidia-orange);
  text-decoration-thickness: 3px;
  text-underline-offset: 6px;
}

.hero-sub {
  margin-bottom: var(--s-6);
  max-width: 46ch;
  font-size: 16px;
  color: var(--alfidia-muted);
}

.hero-ctas {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  min-width: 0;
}

.hero-canvas-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 560px;
  justify-self: end;
  pointer-events: none;
}

@media (max-width: 980px) {
  .hero-canvas-wrap {
    justify-self: center;
    max-width: 400px;
  }
}

.hero-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: auto;
  touch-action: pan-y; /* vertical swipes still scroll the page; horizontal drag rotates */
}

/* ---------- Telemetry bar (live values) ---------- */

.telemetry {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  height: var(--telemetry-h);
  display: flex;
  align-items: center;
  background: var(--alfidia-cream);
  border-top: 1px solid var(--alfidia-border);
  font-size: 13px;
  color: var(--alfidia-muted);
}

.telemetry .wrap {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.telemetry-group {
  display: flex;
  gap: var(--s-6);
}

.telemetry b {
  font-weight: 600;
  color: var(--alfidia-charcoal);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  .telemetry-group.right {
    display: none;
  }
}

/* ---------- Section shell ---------- */

.section {
  position: relative;
  padding: var(--s-12) 0;
  scroll-margin-top: var(--nav-h); /* anchor links land below the fixed nav */
}

.section-head {
  max-width: 640px;
  margin-bottom: var(--s-8);
}

.section-title {
  margin-bottom: var(--s-3);
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-weight: 700;
}

.section-body {
  max-width: 56ch;
  font-size: 16px;
  color: var(--alfidia-muted);
}

/* ---------- Capabilities bento ---------- */

.bento {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-4);
}

.bento-card {
  grid-column: span 1;
  min-width: 0;
  padding: var(--s-6);
  background: var(--alfidia-surface);
  border: 1px solid var(--alfidia-border);
  border-radius: var(--r-lg);
  transition: border-color 0.2s var(--ease-out);
}

.bento-card:hover {
  border-color: var(--alfidia-muted);
}

.bento-span-2 {
  grid-column: span 2;
}

@media (max-width: 900px) {
  .bento {
    grid-template-columns: minmax(0, 1fr);
  }
  .bento-span-2 {
    grid-column: span 1;
  }
}

.bento-index {
  display: block;
  margin-bottom: var(--s-3);
  font-size: 13px;
  font-weight: 600;
  color: var(--alfidia-muted);
  font-variant-numeric: tabular-nums;
}

.bento-card h3 {
  margin-bottom: var(--s-3);
  font-size: 20px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.bento-card p {
  max-width: 46ch;
  margin-bottom: var(--s-4);
  font-size: 15px;
  color: var(--alfidia-muted);
}

.bento-media {
  position: relative;
  width: 100%;
  height: 160px;
  margin-bottom: var(--s-4);
  overflow: hidden;
  background: var(--alfidia-cream);
  border: 1px solid var(--alfidia-border);
  border-radius: var(--r-sm);
}

.bento-media canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.bento-tags,
.work-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.tag {
  padding: var(--s-1) var(--s-3);
  background: var(--alfidia-cream);
  border: 1px solid var(--alfidia-border);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--alfidia-charcoal);
}

/* Tonal card (card 3) */
.bento-card--tonal {
  background: var(--alfidia-cream-deep);
}

.bento-card--tonal .tag {
  background: var(--alfidia-surface);
}

/* Charcoal card (card 4) */
.bento-card--charcoal {
  background: var(--alfidia-charcoal);
  border-color: var(--alfidia-charcoal);
  color: var(--alfidia-cream);
}

.bento-card--charcoal:hover {
  border-color: var(--alfidia-orange);
}

.bento-card--charcoal .bento-index {
  color: var(--alfidia-border);
}

.bento-card--charcoal p {
  color: #cbc6bd; /* 8.4:1 on charcoal */
}

.bento-card--charcoal .tag {
  background: transparent;
  border-color: #6f685d;
  color: var(--alfidia-cream);
}

/* Waveform control */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--alfidia-muted);
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--alfidia-muted);
}

.slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--alfidia-muted);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border: 2px solid var(--alfidia-charcoal);
  border-radius: 50%;
  background: var(--alfidia-orange);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid var(--alfidia-charcoal);
  border-radius: 50%;
  background: var(--alfidia-orange);
}

.slider:focus-visible {
  outline: none;
}

.slider:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--alfidia-charcoal);
  outline-offset: 2px;
}

.slider:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--alfidia-charcoal);
  outline-offset: 2px;
}

/* ---------- Showcase (sticky text + live viewports) ---------- */

.work-row {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: var(--s-12);
  align-items: start;
}

@media (max-width: 900px) {
  .work-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
}

.work-sticky {
  position: sticky;
  top: calc(var(--nav-h) + var(--s-6));
}

@media (max-width: 900px) {
  .work-sticky {
    display: none; /* each viewport gets its own caption on small screens */
  }
}

.work-index {
  margin-bottom: var(--s-3);
  font-size: 13px;
  font-weight: 600;
  color: var(--alfidia-muted);
  font-variant-numeric: tabular-nums;
}

.work-index b {
  color: var(--alfidia-orange-text);
  font-weight: 700;
}

.work-title {
  margin-bottom: var(--s-2);
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.work-cat {
  margin-bottom: var(--s-4);
  font-size: 14px;
  color: var(--alfidia-muted);
}

.work-desc {
  max-width: 46ch;
  margin-bottom: var(--s-6);
  font-size: 16px;
  color: var(--alfidia-charcoal);
}

.work-item {
  padding-bottom: var(--s-12);
}

.work-item:last-child {
  padding-bottom: 0;
}

.work-caption {
  display: none;
  margin-top: var(--s-4);
}

@media (max-width: 900px) {
  .work-caption {
    display: block;
  }
  .work-caption .work-desc {
    margin-bottom: var(--s-4);
  }
}

.viewport {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
  background: var(--alfidia-surface);
  border: 1px solid var(--alfidia-border);
  border-radius: var(--r-lg);
}

@media (max-width: 600px) {
  .viewport {
    aspect-ratio: 4 / 3;
  }
}

.viewport canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.viewport-hint,
.viewport-readout,
.layer-tag {
  position: absolute;
  padding: var(--s-1) var(--s-3);
  background: var(--alfidia-surface);
  border: 1px solid var(--alfidia-border);
  border-radius: var(--r-sm);
  font-size: 13px;
  line-height: 1.5;
  color: var(--alfidia-charcoal);
  pointer-events: none;
}

.viewport-hint {
  left: var(--s-3);
  bottom: var(--s-3);
  color: var(--alfidia-muted);
}

.viewport-readout {
  right: var(--s-3);
  bottom: var(--s-3);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.layer-tag {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out);
}

.layer-tag.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Terra sun control (created by work-terra.js) */
.sun-hit {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  cursor: grab;
  touch-action: pan-y;
}

.sun-hit.is-dragging {
  cursor: grabbing;
}

.sun-hit:focus-visible {
  outline: none; /* the handle shows the focus ring instead of a full-width bar */
}

.sun-track {
  position: absolute;
  top: 21px;
  left: 8%;
  right: 8%;
  height: 2px;
  background: var(--alfidia-border);
  pointer-events: none;
}

.sun-handle {
  position: absolute;
  top: 10px;
  width: 24px;
  height: 24px;
  border: 2px solid var(--alfidia-charcoal);
  border-radius: 50%;
  background: var(--alfidia-orange);
  transform: translateX(-50%);
  pointer-events: none;
}

.sun-hit:focus-visible ~ .sun-handle {
  outline: 2px solid var(--alfidia-charcoal);
  outline-offset: 2px;
}

/* ---------- Footer ---------- */

.footer {
  padding: var(--s-8) var(--s-6) calc(var(--s-12) + var(--telemetry-h));
  border-top: 1px solid var(--alfidia-border);
}

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-3);
  font-size: 14px;
  color: var(--alfidia-muted);
}

@media (max-width: 768px) {
  .footer {
    padding-left: var(--s-4);
    padding-right: var(--s-4);
  }
}

/* ---------- Scroll reveal ---------- */

.reveal {
  opacity: 0;
  transform: translateY(16px);
}

.reveal.is-in {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
  }
  .btn,
  .nav-link::after,
  .bento-card,
  .layer-tag,
  .reveal.is-in {
    transition: none;
  }
}
