/* Detox AI — "Slow on purpose": WebGL keyboard that assembles and types the Type-it-out passage.
   js/keys.js drives the text + --hd / --sc; js/gl/gl.js draws the keyboard and adds .gl-on. */

.keys {
  --hd: 1;
  --sc: 0;
  position: relative;
  height: 420vh;
  background:
    radial-gradient(ellipse 70% 55% at 50% 62%, rgba(47, 212, 198, 0.1), transparent 70%),
    #04070b;
}

.keys-pin {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  min-height: 600px;
  overflow: hidden;
}
/* phone in landscape: never taller than the screen, or the typed card and keyboard fall off the bottom */
@media (max-height: 600px) {
  .keys-pin { min-height: 0; }
}

.keys-gl {
  position: absolute;
  inset: 0;
  z-index: 0;
}

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

.keys-head {
  position: absolute;
  z-index: 2;
  left: max(1.25rem, calc((100vw - var(--max-w)) / 2));
  top: calc(var(--nav-h) + 4vh);
  max-width: min(520px, 88vw);
  opacity: calc(0.15 + var(--hd) * 0.85);
  transform: translateY(calc((1 - var(--hd)) * -22px));
}

.keys-title {
  margin: 0.35rem 0 0.8rem;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(2.5rem, 5.6vw, 5rem);
  line-height: 0.97;
  letter-spacing: -0.035em;
  color: var(--mist50);
}

.keys-title em {
  font-style: normal;
  background: linear-gradient(135deg, #fff 10%, var(--teal) 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.keys-sub {
  margin: 0;
  max-width: 40ch;
  color: var(--mist300);
  font-size: clamp(0.95rem, 1.15vw, 1.08rem);
}

/* the phone-style card the passage is typed into */
.keys-screen {
  position: absolute;
  z-index: 2;
  right: max(1.25rem, calc((100vw - var(--max-w)) / 2));
  top: calc(var(--nav-h) + 4vh);
  width: min(430px, 38vw);
  padding: 1rem 1.15rem 1rem;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(17, 30, 46, 0.86), rgba(8, 13, 21, 0.86));
  border: 1px solid rgba(47, 212, 198, 0.22);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  opacity: var(--sc);
  transform: translateY(calc((1 - var(--sc)) * 24px)) scale(calc(0.97 + var(--sc) * 0.03));
  transition: border-color 0.4s var(--ease-soft), box-shadow 0.4s var(--ease-soft);
}

.keys.is-done .keys-screen {
  border-color: rgba(47, 212, 198, 0.7);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), 0 0 40px rgba(47, 212, 198, 0.25);
}

.keys-screen-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.7rem;
  font: 600 0.7rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mist300);
}

.keys-screen-top b {
  color: var(--teal);
  font-weight: 600;
  display: inline-block;
  min-width: 3ch;
  text-align: right;
}

.keys-typed {
  margin: 0;
  min-height: 6.6em;
  font-size: 1.02rem;
  line-height: 1.62;
  color: var(--mist50);
}

.keys-ghost { color: rgba(159, 176, 201, 0.26); }

.keys-caret {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  margin: 0 1px;
  vertical-align: -0.2em;
  background: var(--teal);
  box-shadow: 0 0 10px var(--teal);
  animation: keys-blink 1s steps(1) infinite;
}

.keys.is-typing .keys-caret { animation: none; }

@keyframes keys-blink { 50% { opacity: 0; } }

.keys-progress {
  height: 3px;
  margin-top: 0.85rem;
  border-radius: 2px;
  background: rgba(159, 176, 201, 0.15);
  overflow: hidden;
}

.keys-progress i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal-deep), var(--teal));
  box-shadow: 0 0 10px var(--teal-glow);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.keys-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.keys-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  color: var(--mist200);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.keys-pill-up {
  color: var(--teal);
  border-color: rgba(47, 212, 198, 0.3);
}

.keys-foot {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 4.5vh;
  margin: 0;
  transform: translateX(-50%);
  font: 600 0.72rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mist300);
  text-align: center;
  white-space: nowrap;
}

.keys-foot-done { display: none; color: var(--teal); }
.keys-foot-touch { display: none; }
.keys.is-done .keys-foot-pc, .keys.is-done .keys-foot-touch { display: none; }
.keys.is-done .keys-foot-done { display: inline; }
html.exp-mobile .keys-foot-pc { display: none; }
/* phones: the keys answer a tap (js/gl/gl.js), so say so */
html.exp-mobile .keys.gl-on:not(.is-done) .keys-foot-touch { display: inline; }

/* no WebGL: keep the story readable without the keyboard */
.keys:not(.gl-on) .keys-screen {
  top: 50%;
  right: 50%;
  transform: translate(50%, -30%);
  width: min(520px, 90vw);
}
.keys:not(.gl-on) .keys-head { opacity: 1; transform: none; }
/* once the keyboard is on screen the heading fades out completely: a 15% ghost of the subtitle lay over the
   number row. And while it is up, keys flying in pass BEHIND a soft dark backing, never across the words. */
.keys.gl-on .keys-head { opacity: var(--hd); }
.keys.gl-on .keys-head::before {
  content: "";
  position: absolute;
  inset: -2.5rem -3.5rem -3rem -2.5rem;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 62% 58% at 42% 48%, rgba(4, 7, 11, 0.86) 0%, rgba(4, 7, 11, 0.62) 48%, transparent 78%);
}

@media (max-width: 900px) {
  .keys { height: 380vh; }
  .keys-head { top: calc(var(--nav-h) + 2.2vh); opacity: var(--hd); }
  .keys-title { font-size: clamp(2.3rem, 11vw, 3.4rem); }
  .keys-sub { font-size: 0.92rem; }
  .keys-screen {
    left: 1.25rem;
    right: 1.25rem;
    width: auto;
    top: calc(var(--nav-h) + 2.2vh);
    padding: 0.85rem 1rem;
  }
  .keys-typed { font-size: 0.95rem; min-height: 5.2em; }
  .keys-pill-up { display: none; }
  .keys-foot { bottom: calc(86px + env(safe-area-inset-bottom, 0px)); white-space: normal; width: 86vw; }
}

/* phone in landscape: a two-line card so the keyboard stays in view (the dock is hidden here) */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .keys-screen { padding: 0.6rem 0.9rem; top: calc(var(--nav-h) + 0.6rem); }
  .keys-screen-top { margin-bottom: 0.4rem; }
  .keys-typed { font-size: 0.88rem; line-height: 1.5; min-height: 3em; }
  .keys-progress { margin-top: 0.5rem; }
  .keys-meta { display: none; }
  .keys-foot { bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  .keys { height: auto; }
  .keys-pin { position: relative; height: auto; min-height: 0; padding: calc(var(--nav-h) + 2rem) 1.25rem 4rem; }
  .keys-head, .keys-screen, .keys-foot { position: relative; inset: auto; left: auto; right: auto; top: auto; bottom: auto; transform: none; opacity: 1; }
  .keys-head { margin: 0 auto 2rem; max-width: var(--max-w); }
  .keys-screen { margin: 0 auto; width: auto; max-width: 560px; }
  .keys-foot { margin-top: 1.5rem; white-space: normal; }
}
