/* ==========================================================================
   VINCENT AHLÉN CREATES
   Full-bleed ASCII video stage with a HUD, hero and keycap controls.
   ========================================================================== */

:root {
  --bg: #050705;
  --fg: #e8eee2;
  --dim: rgba(232, 238, 226, 0.56);
  --faint: rgba(232, 238, 226, 0.22);
  --accent: #9bf00b;
  --accent-ink: #0b1400;
  --key-bg: rgba(255, 255, 255, 0.06);
  --key-on: #e8eee2;
  --key-on-ink: #050705;
  --shade-strong: rgba(5, 7, 5, 0.94);
  --shade-mid: rgba(5, 7, 5, 0.55);
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --gutter: clamp(16px, 3.2vw, 48px);
  --ease: cubic-bezier(.2, .7, .1, 1);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #e9ebe4;
  --fg: #101410;
  --dim: rgba(16, 20, 16, 0.62);
  --faint: rgba(16, 20, 16, 0.25);
  --accent: #9bf00b;
  --key-bg: rgba(0, 0, 0, 0.06);
  --key-on: #101410;
  --key-on-ink: #e9ebe4;
  --shade-strong: rgba(233, 235, 228, 0.95);
  --shade-mid: rgba(233, 235, 228, 0.5);
  color-scheme: light;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

body {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}

button { font: inherit; color: inherit; }

/* --- Stage --------------------------------------------------------------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}

#ascii {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#video {
  position: absolute;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

/* Fallback when WebGL is missing: show the real video, dimmed. */
.no-gl #video {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .5;
  filter: saturate(1.2) contrast(1.1);
}

/* Fog that keeps the hero copy readable; it lifts in focus mode. */
.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, var(--shade-mid) 0%, transparent 42%);
  transition: opacity .8s var(--ease);
}

.crt-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.55) 100%);
  mix-blend-mode: multiply;
}
.crt-fx::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 18vh;
  top: -20vh;
  background: linear-gradient(180deg, transparent, rgba(155, 240, 11, .05), transparent);
  animation: sweep 7s linear infinite;
}
.is-crt .crt-fx { opacity: 1; }
.is-crt .stage { animation: flicker 5s steps(1) infinite; }
:root[data-theme="light"] .crt-fx { opacity: 0; }

@keyframes sweep { to { transform: translateY(140vh); } }
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: .96; }
  42% { opacity: 1; }
  77% { opacity: .97; }
  78% { opacity: 1; }
}

/* --- Mark ---------------------------------------------------------------- */

.mark {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  z-index: 5;
  width: 34px;
  height: 34px;
  color: var(--fg);
  transition: transform .4s var(--ease), color .2s;
}
.mark svg { width: 100%; height: 100%; display: block; }
.mark:hover { color: var(--accent); transform: rotate(-8deg) scale(1.06); }

/* --- HUD ----------------------------------------------------------------- */

.hud {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  font-size: 10.5px;
  line-height: 1.55;
  text-transform: uppercase;
  color: var(--fg);
}
.hud b { font-weight: 400; }
.hud-block { text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg), 0 0 1px var(--bg); }

.hud-block {
  position: absolute;
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
.hud-block span { display: block; }

.hud-sys   { top: 23vh; left: var(--gutter); color: var(--dim); }
.hud-clip  { top: 24.4vh; left: 37vw; padding-left: 16px; border-left: 1px solid var(--faint); }
.hud-stats { top: 23vh; right: var(--gutter); padding-left: 16px; border-left: 1px solid var(--faint); min-width: 13ch; }
.hud-player{ bottom: 13vh; right: calc(var(--gutter) + 9vw); padding-left: 16px; border-left: 1px solid var(--faint); }

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

.hero {
  text-shadow: 0 0 18px var(--bg), 0 0 6px var(--bg), 0 0 2px var(--bg);
  position: fixed;
  z-index: 4;
  left: calc(var(--gutter) + 2.6vw);
  top: 50%;
  transform: translateY(-38%);
  max-width: min(600px, 48vw);
  transition: opacity .7s var(--ease), transform .7s var(--ease), filter .7s var(--ease);
}

.eyebrow {
  margin: 0 0 .1em;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(26px, 3.6vw, 52px);
  letter-spacing: -0.02em;
  line-height: 1;
}

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(46px, 7.2vw, 112px);
  line-height: .92;
  letter-spacing: -0.035em;
}
.wm-line {
  text-shadow: none;
  filter: drop-shadow(0 0 10px var(--bg)) drop-shadow(0 0 3px var(--bg));
  display: inline-block;
  padding-right: .04em;
  /* scanline fill, like a CRT phosphor */
  background: repeating-linear-gradient(180deg, var(--fg) 0 3px, transparent 3px 4px);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 1.6em 0 0;
  font-size: clamp(12px, 1.05vw, 15px);
  letter-spacing: .42em;
  text-transform: uppercase;
}

.lede {
  margin: 1.1em 0 0;
  max-width: 42ch;
  font-size: 12.5px;
  line-height: 1.65;
  letter-spacing: 0;
  color: var(--dim);
}

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
  /* Let the button row run past the copy column so all three sit on one line. */
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter) - 2.6vw);
}

.btn-primary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  height: 50px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 0;
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: .02em;
  cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s, transform .2s var(--ease);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary svg { width: 16px; height: 16px; transition: transform .25s var(--ease); }
.btn-primary:hover svg { transform: translateX(4px); }
.btn-primary:hover { background: #b4ff2e; }
.btn-ghost {
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-color: var(--faint);
  color: var(--fg);
}
.btn-ghost:hover { border-color: var(--fg); }
.btn-yt { text-decoration: none; }
.btn-yt svg { width: 22px; height: auto; flex: none; transition: transform .25s var(--ease); }
.btn-yt:hover svg { transform: scale(1.12); }
.btn-primary:active, .btn-ghost:active { transform: translateY(1px); }

.fineprint {
  margin: 14px 0 0;
  color: var(--dim);
  font-size: 10.5px;
}
.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--accent); }

.rec {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff3b3b;
  box-shadow: 0 0 10px #ff3b3b;
  animation: rec 1.4s steps(1) infinite;
}
@keyframes rec { 50% { opacity: .25; } }

/* Live webcam: red tally light on the player index. */
.is-live .player-idx { color: #ff3b3b; }
.is-live .player-idx::before { content: "● "; }

/* --- Cheat code ---------------------------------------------------------- */

.cheat {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
  color: #3dff6e;
  text-shadow: 0 0 24px rgba(61, 255, 110, .6);
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .78) 0%, transparent 70%);
  animation: cheat-in 2.6s var(--ease) forwards;
}
.cheat[hidden] { display: none; }
.cheat p { margin: 0; }
.cheat-kicker { letter-spacing: .5em; font-size: 12px; }
.cheat-title {
  position: relative;
  margin: 14px 0 !important;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(40px, 8vw, 120px);
  letter-spacing: -.03em;
  line-height: 1;
}
.cheat-title::before, .cheat-title::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  animation: glitch .32s steps(2) infinite;
}
.cheat-title::before { color: #ff2bd6; transform: translate(-3px, 0); clip-path: inset(0 0 55% 0); mix-blend-mode: screen; }
.cheat-title::after  { color: #2be9ff; transform: translate(3px, 0); clip-path: inset(50% 0 0 0); mix-blend-mode: screen; animation-delay: -.16s; }
.cheat-sub { font-size: 11px; letter-spacing: .3em; opacity: .8; }
.cheat.is-off .cheat-title { color: var(--fg); }

@keyframes glitch {
  0%   { transform: translate(-4px, -1px); }
  50%  { transform: translate(4px, 2px); }
  100% { transform: translate(-2px, 1px); }
}
@keyframes cheat-in {
  0%   { opacity: 0; transform: scale(1.3); filter: blur(10px); }
  12%  { opacity: 1; transform: scale(1); filter: blur(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Secret mode: UI accent turns phosphor green. */
.is-secret { --accent: #3dff6e; }
.is-secret .wm-line { filter: drop-shadow(0 0 12px rgba(61, 255, 110, .55)); }

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

/* --- Keycaps ------------------------------------------------------------- */

.keys {
  position: fixed;
  z-index: 6;
  right: var(--gutter);
  bottom: var(--gutter);
  display: flex;
  gap: 6px;
}

.key {
  display: inline-flex;
  align-items: stretch;
  height: 22px;
  padding: 0;
  border: 0;
  background: var(--key-bg);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color .2s, color .2s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.key kbd {
  display: grid;
  place-items: center;
  min-width: 22px;
  padding: 0 6px;
  font: inherit;
  color: var(--dim);
}
.key > span, .key > :not(kbd) { display: grid; place-items: center; padding: 0 9px 0 4px; }
.key:hover { background: var(--faint); }
.key[aria-pressed="true"] > span { background: var(--key-on); color: var(--key-on-ink); padding-left: 8px; }

/* --- Focus mode player --------------------------------------------------- */

.player {
  position: fixed;
  z-index: 5;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--gutter) + 40px);
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 22px;
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity .5s var(--ease), transform .5s var(--ease);
  text-transform: uppercase;
}
.player-meta { display: flex; gap: 14px; white-space: nowrap; }
.player-idx { color: var(--accent); }
.player-bar {
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  white-space: nowrap;
  color: var(--fg);
}
.bar-text { letter-spacing: 0; font-size: 12px; }
.bar-text i { font-style: normal; color: var(--faint); }
.player-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.player-keys { display: flex; gap: 6px; }

.is-focus .hero {
  opacity: 0;
  transform: translateY(-38%) translateX(-40px);
  filter: blur(6px);
  pointer-events: none;
}
.is-focus .shade { opacity: 0; }
.is-ready.is-focus .hud-clip,
.is-ready.is-focus .hud-sys,
.is-ready.is-focus .hud-player { opacity: 0; transform: translateY(-8px); }
.is-focus .hud-stats { top: calc(var(--gutter) + 4px); }
.is-focus .player { opacity: 1; transform: none; pointer-events: auto; }
.is-focus .keys .key[data-key="h"] { display: none; }

/* Idle in focus mode: everything but the picture fades away. */
.is-focus.is-idle .player,
.is-focus.is-idle .keys,
.is-focus.is-idle .hud,
.is-focus.is-idle .mark { opacity: 0; transition-duration: 1.2s; }
.is-focus.is-idle { cursor: none; }

/* --- Drop overlay & toast ------------------------------------------------ */

.drop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(5, 7, 5, .72);
  backdrop-filter: blur(3px);
}
.drop[hidden] { display: none; }
.drop-box {
  padding: 48px 64px;
  border: 1px dashed var(--accent);
  text-align: center;
  color: #e8eee2;
  animation: pulse 1.2s ease-in-out infinite alternate;
}
.drop-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(22px, 3vw, 40px);
  color: var(--accent);
}
.drop-sub { margin: 12px 0 0; opacity: .7; }
@keyframes pulse { to { border-color: rgba(155, 240, 11, .25); } }

.toast {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: calc(var(--gutter) + 52px);
  transform: translate(-50%, 10px);
  padding: 9px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 20;
  color: var(--fg);
}

/* --- Entrance ------------------------------------------------------------ */

.js .hero > *, .js .hud-block, .js .keys, .js .mark {
  opacity: 0;
  translate: 0 12px;
}
.is-ready .hero > *, .is-ready .hud-block, .is-ready .keys, .is-ready .mark {
  opacity: 1;
  translate: 0 0;
  transition: opacity .9s var(--ease), translate .9s var(--ease), transform .6s var(--ease);
}
.is-ready .hero > :nth-child(2) { transition-delay: .08s; }
.is-ready .hero > :nth-child(3) { transition-delay: .16s; }
.is-ready .hero > :nth-child(4) { transition-delay: .22s; }
.is-ready .hero > :nth-child(5) { transition-delay: .28s; }
.is-ready .hero > :nth-child(6) { transition-delay: .34s; }
.is-ready .hud-block { transition-delay: .4s; }
.is-ready .keys { transition-delay: .55s; }

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 1100px) {
  .hud-clip { left: auto; right: calc(var(--gutter) + 20ch); }
  .hud-player { right: var(--gutter); }
}

@media (max-width: 760px) {
  .shade {
    background:
      linear-gradient(0deg, var(--shade-mid) 10%, transparent 60%);
  }
  .hud { font-size: 9.5px; }
  .hud-sys, .hud-player { display: none; }
  .hud-clip { top: calc(var(--gutter) + 52px); left: var(--gutter); right: auto; }
  .hud-stats { top: calc(var(--gutter) + 52px); right: var(--gutter); }
  .hero {
    top: auto;
    bottom: calc(var(--gutter) + 46px);
    left: var(--gutter);
    right: var(--gutter);
    max-width: none;
    transform: none;
  }
  .is-focus .hero { transform: translateY(20px); }
  .tagline { letter-spacing: .28em; margin-top: 1.1em; }
  .lede { font-size: 12px; }
  .cta { margin-top: 20px; width: auto; max-width: none; }
  .btn-yt { order: 1; }
  #btn-cam { order: 2; }
  .btn-primary, .btn-ghost { height: 46px; padding: 0 16px; font-size: 13px; }
  .fineprint { display: none; }

  .keys {
    left: var(--gutter);
    right: var(--gutter);
    justify-content: space-between;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .keys::-webkit-scrollbar { display: none; }
  .keys { gap: 4px; }
  .key { flex: none; font-size: 9.5px; letter-spacing: .06em; }
  .key kbd { display: none; }
  .key > span { padding: 0 6px !important; }

  .player {
    grid-template-columns: 1fr auto;
    gap: 10px 14px;
    bottom: calc(var(--gutter) + 34px);
  }
  .player-bar { grid-column: 1 / -1; grid-row: 2; }
  .player-keys { grid-column: 1 / -1; }
  .player-keys .key kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
