/* ─────────────────────────────────────────────────────────────────────────────
   Hexa Vision
   A real-time WebGL visualization simulating compound eye vision
   through animated Voronoi patterns and hexagonal post-processing
   By Jonas Kjeldmand Jensen
   March 2026
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  --accent-rgb: 0, 255, 0;  /* follows the palette highlight, set from JS */
  --accent: rgb(var(--accent-rgb));

  --ink:       #f2f2f5;
  --ink-dim:   rgba(242, 242, 245, 0.62);
  --ink-faint: rgba(242, 242, 245, 0.36);
  --glass:     rgba(10, 10, 16, 0.74);
  --glass-hi:  rgba(255, 255, 255, 0.055);
  --line:      rgba(255, 255, 255, 0.09);

  --font-ui:   ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}

body {
  position: fixed;
  inset: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

/* ── Canvas ───────────────────────────────────────────────── */

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#scene.is-grabbing {
  cursor: grabbing;
}

/* ── Intro ────────────────────────────────────────────────── */

.intro {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  background: #000;
  transition: background-color 1.4s ease, opacity 0.8s ease;
}

.intro__hex {
  width: clamp(72px, 14vmin, 120px);
  overflow: visible;
  transition: transform 1.6s var(--ease-out), opacity 1.2s ease;
}

.intro__hex polygon {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  filter: drop-shadow(0 0 6px rgba(var(--accent-rgb), 0.7));
  vector-effect: non-scaling-stroke;
  animation: hex-trace 1.6s ease-in-out infinite alternate;
}

.is-ready .intro__hex polygon {
  animation: hex-draw 0.9s var(--ease-out) forwards;
}

.intro__title,
.intro__sub {
  margin: 0;
  text-align: center;
  opacity: 0;
  transition: opacity 0.7s ease, letter-spacing 1.4s var(--ease-out), filter 0.9s ease;
}

.intro__title {
  font-family: var(--font-mono);
  font-size: clamp(18px, 3.4vmin, 28px);
  font-weight: 500;
  letter-spacing: 0.42em;
  margin-right: -0.42em; /* balance the trailing letter-spacing */
  white-space: nowrap;
}

.intro__sub {
  font-size: clamp(12px, 1.8vmin, 14px);
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  transition-delay: 0.35s;
}

.is-ready .intro__title,
.is-ready .intro__sub {
  opacity: 1;
}

/* the scene focuses behind the title while the hexagon flies past the camera */
.intro.is-revealing {
  background-color: transparent;
  pointer-events: none;
}

.intro.is-revealing .intro__hex {
  transform: scale(14);
  opacity: 0;
}

.intro.is-done .intro__title,
.intro.is-done .intro__sub {
  opacity: 0;
  letter-spacing: 0.9em;
  filter: blur(6px);
  transition-delay: 0s;
}

.intro.is-done {
  opacity: 0;
  transition-delay: 0.3s;
}

@keyframes hex-trace {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0.15; }
}

@keyframes hex-draw {
  to { stroke-dashoffset: 0; }
}

/* ── Chrome (wordmark + corner button) ────────────────────── */

.chrome {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.9s ease, transform 0.45s var(--ease-out);
}

.is-live .chrome {
  opacity: 0.75;
  pointer-events: auto;
}

.is-live.is-idle .chrome {
  opacity: 0;
}

.is-live.is-idle .fab {
  pointer-events: auto; /* still there under your finger, just invisible */
}

.ui-hidden .chrome,
.ui-hidden .panel,
.ui-hidden .notification,
.ui-hidden .hint {
  display: none !important;
}

.wordmark {
  position: fixed;
  top: calc(var(--safe-t) + 20px);
  left: calc(var(--safe-l) + 22px);
  z-index: 10;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-dim);
  pointer-events: none !important;
}

.fab {
  position: fixed;
  right: calc(var(--safe-r) + 18px);
  bottom: calc(var(--safe-b) + 18px);
  z-index: 20;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  backdrop-filter: blur(16px) saturate(150%);
  cursor: pointer;
}

.fab svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: stroke 0.6s ease, transform 0.6s var(--ease-out);
}

.fab:hover svg {
  transform: rotate(30deg);
}

.is-live .fab:hover {
  opacity: 1;
}

.panel-open .fab {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

/* ── Panel ────────────────────────────────────────────────── */

.panel {
  position: fixed;
  right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + 16px);
  z-index: 30;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 32px - var(--safe-t) - var(--safe-b));
  max-height: calc(100dvh - 32px - var(--safe-t) - var(--safe-b));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 14px 18px 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  scrollbar-width: none;

  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.96);
  transform-origin: bottom right;
  transition:
    opacity 0.3s ease,
    transform 0.45s var(--ease-out),
    visibility 0s linear 0.45s;
}

.panel::-webkit-scrollbar {
  display: none;
}

.panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 0.3s ease,
    transform 0.45s var(--ease-out),
    visibility 0s;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel__title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-right: -10px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--glass-hi);
}

.icon-btn svg,
.action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Actions ──────────────────────────────────────────────── */

.actions {
  display: flex;
  gap: 8px;
}

.action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 66px;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass-hi);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
}

.action:hover {
  background: rgba(255, 255, 255, 0.09);
}

.action:active {
  transform: scale(0.96);
}

.action[aria-pressed="true"] {
  border-color: rgba(var(--accent-rgb), 0.6);
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--accent);
}

.action[hidden] {
  display: none;
}

/* ── Groups ───────────────────────────────────────────────── */

.group {
  margin-top: 18px;
}

.group h2 {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ── Swatches ─────────────────────────────────────────────── */

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.swatch {
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  transition: transform 0.2s var(--ease-out);
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch[aria-pressed="true"] {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ── Sliders ──────────────────────────────────────────────── */

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 12px;
  font-size: 13px;
  color: var(--ink-dim);
}

.slider output {
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
}

.slider input {
  grid-column: 1 / -1;
}

input[type="range"] {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;
  margin: 0 0 4px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--accent) var(--fill), rgba(255, 255, 255, 0.13) var(--fill));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.13);
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 4px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.35);
}

/* ── Switches ─────────────────────────────────────────────── */

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  font-size: 14px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.switch:first-child {
  border-top: 0;
}

.switch[hidden] {
  display: none;
}

.switch input {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: background-color 0.25s ease;
}

.switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s var(--ease-out);
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::before {
  transform: translateX(18px);
}

.switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.panel__foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-faint);
}

.panel__foot p {
  margin: 0 0 8px;
}

.panel__foot p:last-child {
  margin-bottom: 0;
}

.panel__foot a {
  color: var(--accent);
  text-decoration: none;
}

kbd {
  display: inline-block;
  min-width: 20px;
  margin: 0 2px 4px 0;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: center;
  color: var(--ink-dim);
}

.keys kbd:not(:first-child) {
  margin-left: 8px;
}

/* Keyboard shortcuts are noise on a tablet. */
@media (pointer: coarse) {
  .keys {
    display: none;
  }
}

/* ── Hint & toast ─────────────────────────────────────────── */

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 34px);
  z-index: 15;
  width: max-content;
  max-width: calc(100vw - 150px);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.7;
  letter-spacing: 0.16em;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink-dim);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 1s ease, transform 1s var(--ease-out);
}

.hint.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 18px);
  z-index: 40;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -10px);
  transition: opacity 0.3s ease, transform 0.4s var(--ease-out);
}

.toast:empty {
  display: none;
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ── Notification ─────────────────────────────────────────── */

.notification {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 18px);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 16px 12px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 24px);
  transition: opacity 0.5s ease, transform 0.7s var(--ease-out), visibility 0s linear 0.7s;
}

.notification.is-shown {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity 0.5s ease, transform 0.7s var(--ease-out), visibility 0s;
}

.notification a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.notification button {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -6px -8px -6px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 14px;
  color: var(--ink-faint);
  cursor: pointer;
}

.notification button:hover {
  color: var(--ink);
}

.panel-open .notification {
  opacity: 0;
  visibility: hidden;
}

/* ── Fallback ─────────────────────────────────────────────── */

.fallback {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  place-content: center;
  padding: 24px;
  background: #000;
  text-align: center;
  color: var(--ink-dim);
  font-size: 15px;
  line-height: 1.6;
}

.fallback p {
  max-width: 420px;
  margin: 0 auto;
}

.fallback__title {
  margin-bottom: 8px !important;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink);
}

.has-failed .fallback {
  display: grid;
}

/* ── Small screens ────────────────────────────────────────── */

@media (max-width: 560px) {
  .panel {
    left: calc(var(--safe-l) + 10px);
    right: calc(var(--safe-r) + 10px);
    bottom: calc(var(--safe-b) + 10px);
    width: auto;
    max-height: 66vh;
    max-height: 66dvh;
    transform-origin: bottom center;
  }

  .hint {
    bottom: calc(var(--safe-b) + 92px);
    max-width: calc(100vw - 48px);
    letter-spacing: 0.1em;
  }

  .notification {
    bottom: calc(var(--safe-b) + 84px);
  }
}

/* ── Reduced motion ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .intro,
  .intro__hex,
  .intro__title,
  .intro__sub {
    transition-duration: 0.3s !important;
  }

  .intro__hex polygon {
    animation: none !important;
    stroke-dashoffset: 0;
  }
}
