/* Murk design system — mirrors the Figma file (🎨 Foundations). */

/* Fonts are self-hosted in fonts/ (variable files, SIL Open Font License). Instrument Sans
   carries its width axis too, for the die's condensed lettering. */
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("fonts/instrument-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("fonts/instrument-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url("fonts/geist-mono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url("fonts/geist-mono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Color */
  --bg: #06120d;                              /* color/bg/base */
  --ink: #dce6d2;                             /* color/text/primary */
  --muted: rgba(220, 230, 210, 0.6);          /* color/text/muted */
  --faint: rgba(220, 230, 210, 0.5);          /* color/text/faint */
  --glass: rgba(220, 230, 210, 0.08);         /* color/surface/subtle */
  --glass-pressed: rgba(220, 230, 210, 0.14); /* color/surface/subtle-pressed */
  --hairline: rgba(220, 230, 210, 0.26);      /* color/border/subtle */
  --mint: #7cf2c6;                            /* color/action/primary */
  --violet: #a98bff;
  --lime: #d9ff8a;
  --teal: #4fd1c5;
  --lilac: #c9b6ff;
  --focus: rgba(124, 242, 198, 0.8);          /* color/focus/ring */
  --iri: linear-gradient(90deg, var(--mint) 0%, var(--violet) 30%, var(--lime) 55%, var(--teal) 78%, var(--lilac) 100%);
  --iri-diag: linear-gradient(135deg, var(--mint) 0%, var(--violet) 30%, var(--lime) 55%, var(--teal) 78%, var(--lilac) 100%);

  /* Type */
  --sans: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Layout */
  --orb: min(86vw, 46vh, 400px);   /* the hole, rim included */
}
@supports (height: 1dvh) {
  :root { --orb: min(86vw, 46dvh, 400px); }
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body { overflow: hidden; }

.stage {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  --gap: clamp(18px, 4vh, 40px);
  --footer-h: 13px;  /* one line of footer; two with the voice credit */
  gap: var(--gap);
  padding:
    max(28px, calc(env(safe-area-inset-top) + 16px))
    max(24px, env(safe-area-inset-right))
    max(44px, calc(env(safe-area-inset-bottom) + 28px))
    max(24px, env(safe-area-inset-left));
}

/* ---------- The orb ---------- */
.orb-wrap {
  position: relative;
  width: var(--orb);
  aspect-ratio: 1;
  flex: none;
  will-change: transform;
}
.orb {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  font: inherit;
  cursor: grab;
  display: block;
  outline: none;
  touch-action: none;             /* holding and dragging the ball shakes it, so don't scroll or zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.orb.is-holding { cursor: grabbing; }
.orb > span { position: absolute; display: block; pointer-events: none; }

/* The whole screen is the ball; only the window shows. The window sits in a molded lip (the same
   in every version, ?gl=0/1/2). The lip is rounded, so it catches a little light at the top left
   and falls into shade at the bottom right, and it stands slightly off the ball, casting a soft
   shadow round itself. */
.window-ring {
  inset: 0;
  border-radius: 50%;
  background:
    linear-gradient(150deg, rgba(225, 240, 230, 0.12) 0%, rgba(225, 240, 230, 0.03) 30%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.5) 100%),
    radial-gradient(circle closest-side, #020604 92%, #0a1510 94.5%, #0f1d17 96.5%, #07100c 98.6%, #030805 100%);
  box-shadow:
    0 0 0 1px rgba(220, 235, 225, 0.035),
    0 calc(var(--orb) * 0.012) calc(var(--orb) * 0.035) rgba(0, 0, 0, 0.55);
}
.orb:focus-visible .window-ring {
  box-shadow: 0 0 0 3px var(--focus), 0 calc(var(--orb) * 0.012) calc(var(--orb) * 0.035) rgba(0, 0, 0, 0.55);
}

/* The window into the dark liquid. */
.window {
  left: 3.25%;
  top: 3.25%;
  width: 93.5%;
  height: 93.5%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #0c2019 0%, #06110c 50%, #020604 100%);
  clip-path: circle(50% at 50% 50%);
}
.window > span { position: absolute; display: block; }
.liquid { inset: -4%; will-change: transform; }
.particles { position: absolute; inset: 0; width: 100%; height: 100%; }
.murk {
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(15, 42, 34, 0.75), rgba(3, 9, 6, 0.97) 70%);
  opacity: 0;
}
.window-glass {
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 calc(var(--orb) * 0.042) calc(var(--orb) * 0.1) rgba(0, 0, 0, 0.85);
}

/* WebGL version of the liquid and glass (gl.js, on with ?gl=1). Its canvases replace these layers. */
.gl-back, .gl-front, .gl-die { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.gl .murk, .gl .window-glass { display: none; }
.gl .particles, .gl .die { visibility: hidden; }  /* the hidden die still lays out the words for gl.js */

/* The answer die: an iridescent triangle with the words on its face. */
.die {
  position: absolute;
  left: 6%;
  top: 17%;
  width: 88%;
  aspect-ratio: 100 / 90;
  transform-origin: 50% 40%;
  opacity: 0;  /* hidden until the first answer; app.js drives it from here */
  will-change: transform, opacity, filter;
}
.die-shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.die-text {
  position: absolute;
  left: 0;
  top: 11%;
  width: 100%;
  height: 68%;
  overflow: hidden;
  text-align: center;
  /* Lettering molded into the die: condensed, bold capitals, like stamped type. */
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--bg);
  hyphens: manual;
  overflow-wrap: normal;
}
/* Two floats shaped like the triangle's sides, so the words wrap inside it. */
.wrap-l, .wrap-r { height: 100%; width: 50%; }
/* Pushes the words down so the block sits centred on the triangle (app.js sets its height). */
.die-pad { display: block; height: 0; }
.wrap-l { float: left;  shape-outside: polygon(0 0, 22% 0, 91% 100%, 0 100%); }
.wrap-r { float: right; shape-outside: polygon(78% 0, 100% 0, 100% 100%, 9% 100%); }

/* ---------- Under the orb ---------- */
/* The hole sits in the middle: an empty space above it matches the space below, and the
   read-aloud button is centred in the space below, between the hole and the footer. The space
   is kept while the button is hidden, so nothing shifts when it appears. */
/* ---------- Above the orb ---------- */
/* The opening prompt: a heading and a little shaking phone, centred in the space above the
   hole. It fades away on the first shake (or click) and doesn't come back. The space stays,
   so the hole never moves. */
.lead {
  flex: 1;
  margin-bottom: calc(-1 * var(--gap));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}
/* Leaving: shaken off. The words get jolted side to side as if the shake knocked them loose,
   then fly up off the top of the screen, going murky (blurring and fading) on the way. The
   shake hint follows a beat behind. */
.lead.is-gone { pointer-events: none; }
.lead.is-gone > * { animation: lead-shaken-off 0.8s both; }
.lead.is-gone > .lead-shake { animation-delay: 0.06s; }
@keyframes lead-shaken-off {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; filter: blur(0); animation-timing-function: ease-in-out; }
  10%  { transform: translate(-11px, 0) rotate(-3deg); }
  20%  { transform: translate(10px, 0) rotate(2.5deg); }
  29%  { transform: translate(-6px, 3px) rotate(-1.5deg); opacity: 1; filter: blur(0); animation-timing-function: cubic-bezier(0.45, 0, 0.8, 0.4); }
  100% { transform: translate(4px, -45vh) rotate(4deg); opacity: 0; filter: blur(8px); }
}
.lead-title {
  font-weight: 600;
  font-size: clamp(24px, 7.5vw, 32px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.lead-shake {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.lead-shake svg { transform-origin: 50% 70%; animation: lead-wiggle 2.6s ease-in-out infinite; }
.lead-wave { animation: lead-wave 2.6s ease-in-out infinite; }
@keyframes lead-wiggle {
  0%, 55%, 100% { transform: rotate(0); }
  60% { transform: rotate(-14deg); }
  67% { transform: rotate(12deg); }
  74% { transform: rotate(-10deg); }
  81% { transform: rotate(7deg); }
  88% { transform: rotate(-3deg); }
}
@keyframes lead-wave {
  0%, 55%, 95%, 100% { opacity: 0; }
  62%, 85% { opacity: 1; }
}
/* Phones say "Shake"; anything with a mouse says how to shake with it. */
.shake-touch, .shake-hold { display: none; }
@media (hover: none) and (pointer: coarse) {
  .shake-touch { display: inline; }
  .shake-mouse { display: none; }
  /* A phone that said no to motion: holding the ball is the way to shake it. */
  .no-motion .shake-touch { display: none; }
  .no-motion .shake-hold { display: inline; }
}

/* iPhones only switch motion on from a tap, so until then the hint is a button. Tapping it
   brings up the system's own Allow prompt; once answered it turns back into the hint. */
.motion-ask { display: none; }
.ask-motion .lead-shake { display: none; }
.ask-motion .motion-ask {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--mint);
  color: var(--bg);
  font-family: inherit; font-weight: 600; font-size: 16px; line-height: 1.2; letter-spacing: -0.01em;
  box-shadow: 0 8px 26px rgba(124, 242, 198, 0.22);
  cursor: pointer;
}
.motion-ask svg { transform-origin: 50% 70%; animation: lead-wiggle 2.6s ease-in-out infinite; }
.motion-ask:active { transform: scale(0.97); }
.motion-ask:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.slot {
  flex: 1;
  min-height: 76px;
  /* Reach right from the hole down to the footer's top edge (the footer is --footer-h tall,
     sitting max(12px, safe area) up from the bottom), so the button lands exactly halfway. */
  margin-top: calc(-1 * var(--gap));
  margin-bottom: calc(max(12px, env(safe-area-inset-bottom)) + var(--footer-h) - max(44px, calc(env(safe-area-inset-bottom) + 28px)));
  width: min(100%, 420px);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.slot > * { grid-area: 1 / 1; pointer-events: auto; }
.slot > .is-hidden { pointer-events: none; }

/* Frosted glass circle (Glass/Frost), just the speaker icon. */
.speak {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  color: var(--ink);
  font-family: inherit; font-weight: 500; font-size: 16px; line-height: 1.2;
  cursor: pointer;
  transition: opacity 0.35s, transform 0.35s;
}
.speak:active { transform: scale(0.97); background: var(--glass-pressed); }
.speak.is-hidden { opacity: 0; pointer-events: none; transform: translateY(6px); }

/* While the answer is being said: the icon turns mint, its sound waves pulse outward one after
   the other, and two soft rings ripple out from the button. */
.speak { position: relative; }
.speak svg { transition: color 0.25s; }
.speak::before, .speak::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1.5px solid var(--mint);
  opacity: 0;
  pointer-events: none;
}
.speak.is-speaking { color: var(--mint); border-color: rgba(124, 242, 198, 0.45); }
.speak.is-speaking::before { animation: speak-ripple 1.6s ease-out infinite; }
.speak.is-speaking::after { animation: speak-ripple 1.6s ease-out 0.8s infinite; }
.speak.is-speaking .speak-wave { animation: speak-wave 0.9s ease-in-out infinite; }
.speak.is-speaking .speak-wave + .speak-wave { animation-delay: 0.15s; }
@keyframes speak-ripple {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(1.7); opacity: 0; }
}
@keyframes speak-wave {
  0%, 100% { opacity: 0.25; }
  45% { opacity: 1; }
}

.speak:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  padding: 0 16px;
  display: flex;
  justify-content: center;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}
/* Wide screens: one line, the voice credit after a dot. Phones: the credit on its own line. */
.footer #credit[hidden] { display: none; }
.footer #credit::before { content: "·"; margin: 0 0.9em; }
@media (max-width: 600px) {
  .footer { flex-direction: column; align-items: center; }
  .footer #credit::before { content: none; }
  .stage:has(#credit:not([hidden])) { --footer-h: 26px; }
}
/* The credit's domain stays lowercase, as ElevenLabs asks for it. */
.credit-domain { text-transform: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .speak { transition: none; }
  .lead.is-gone > * { animation: lead-fade 0.3s ease both; }
  @keyframes lead-fade { to { opacity: 0; } }
  .lead-shake svg, .motion-ask svg, .lead-wave { animation: none; }
  .lead-wave { opacity: 1; }
  .speak.is-speaking::before, .speak.is-speaking::after, .speak.is-speaking .speak-wave { animation: none; }
}
