:root {
  --bg: #111111;
  --fg: #f2f2f2;
  --muted: #8c8c8c;
  --accent: #dfff00;
  --font: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --fs: clamp(11px, 0.72vw, 14px);
  --pad: clamp(8px, 0.6vw, 12px);
  --sq: clamp(18px, 1.45vw, 30px);
  --ring: clamp(56px, 4.2vw, 84px);
  --pad-w: clamp(180px, 14vw, 280px);
  --pad-h: clamp(96px, 7.2vw, 144px);
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--fs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

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

/* Hide the system cursor on mouse devices — the ring (C) replaces it */
@media (hover: hover) and (pointer: fine) {
  html, body, a, .timeline { cursor: none; }
}

/* ---------- Hero / video (A) ---------- */
.hero {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: #000;
}

/* Subtle vignette over the video (under the controls) */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 75% 75% at 50% 45%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.38) 100%);
}

.hero video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* Timeline hit area: full-width strip at the bottom of the video */
.timeline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--sq) * 3);
  z-index: 2;
  touch-action: none;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}

.playhead {
  position: absolute;
  bottom: 0;
  left: 0;
  width: var(--sq);
  height: 100%;
  will-change: transform;
}

.square {
  position: absolute;
  bottom: 0;
  left: 0;
  width: var(--sq);
  height: var(--sq);
  background: var(--accent);
  transition: width 0.15s ease, left 0.15s ease, height 0.15s ease, transform 0.15s ease;
}

/* While dragging, A becomes a thin line (same width as the AM/FQ stroke, 0.75px),
   120% tall, centred where the square was. */
.timeline.dragging .square {
  width: 0.75px;
  left: calc(50% - 0.375px);
  height: calc(var(--sq) * 1.2);
}
.timeline:focus-visible:not(.dragging) .square { transform: scaleY(1.2); transform-origin: bottom; }

/* B: frame counter that rides above the square */
.frame {
  position: absolute;
  bottom: calc(var(--sq) + 1.6em);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--accent);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

/* ---------- Auto-scratch control ---------- */
.scratch {
  position: absolute;
  left: var(--pad);
  bottom: calc(var(--sq) * 3 + 1em);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  user-select: none;
  -webkit-user-select: none;
}

.scratch-toggle {
  all: unset;
  align-self: start;
  color: var(--muted);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
  transition: color 0.2s;
}
.scratch-toggle:hover,
.scratch-toggle:focus-visible { color: var(--fg); }
.scratch-toggle .state { color: var(--fg); }
.scratch.on #scratchToggle .state { color: var(--accent); }

.scratch-row {
  display: flex;
  align-items: center;
  gap: 1.6em;
}

/* Sound on/off: same "< … STATE >" style, with a speaker icon */
.sound-toggle { display: inline-flex; align-items: center; gap: 0.5em; }
.sound-icon {
  width: 1.25em;
  height: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: square;
  stroke-linejoin: miter;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.6));
}
.sound-icon .spk { fill: currentColor; stroke: none; }
.sound-icon .waves { display: none; }
.sound-toggle.on .sound-icon .waves { display: inline; }
.sound-toggle.on .sound-icon .cross { display: none; }
.sound-toggle.on .state,
.sound-toggle.on .sound-icon { color: var(--accent); }
.sound-toggle.loading .state { opacity: 0.5; }

/* Random: small square icon button (dice-like pips) */
.scratch-icons { display: inline-flex; align-items: center; gap: 1.6em; }

.rand-btn {
  all: unset;
  display: inline-flex;
  width: 1.5em;
  height: 1.5em;
  color: var(--muted);
  transition: color 0.2s;
}
.rand-btn svg { width: 100%; height: 100%; display: block; overflow: visible;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.6)); }
.rand-btn .box { fill: none; stroke: currentColor; stroke-width: 1.3; }
.rand-btn .pip { fill: currentColor; }
.rand-btn:hover,
.rand-btn:focus-visible { color: var(--fg); }
.rand-btn.on { color: var(--accent); }
.rand-btn.on .box { fill: var(--accent); }
.rand-btn.on .pip { fill: #111; }

/* Reset: same square icon style, circular arrow inside */
.reset-btn .arrow { fill: none; stroke: currentColor; stroke-width: 1.3; }
.reset-btn:active { color: var(--accent); }

/* HD toggle */
.hd-toggle.on .state { color: var(--accent); }
.hd-toggle.loading .state { opacity: 0.5; }

.scratch-pad {
  display: block;
  width: var(--pad-w);
  height: var(--pad-h);
  touch-action: none;
  outline: none;
}
.scratch-pad:focus-visible { outline: 1px dashed var(--muted); outline-offset: 4px; }

.scratch-values {
  display: flex;
  gap: 1.6em;
  color: var(--accent);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

/* ---------- Info panel ---------- */
.info {
  position: relative;
  min-height: 40vh;
  min-height: 40svh;
  padding-bottom: 4em;
  background: var(--bg);
}

.info-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
}

.tag {
  justify-self: start;
  background: var(--fg);
  color: #111;
  font-weight: 500;
  padding: 0.85em var(--pad) 0.8em;
  line-height: 1;
}
.info-top .tag:last-child { justify-self: end; }

.switch {
  color: var(--muted);
  padding-top: 0.85em;
  line-height: 1;
  white-space: nowrap;
}
.switch .mob { display: none; }

.meta {
  margin: 1.4em var(--pad) 0;
  color: var(--muted);
  line-height: 1.3;
}

.mail {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 1.6em;
  color: var(--muted);
  transition: color 0.2s;
}
.mail:hover { color: var(--fg); }

/* ---------- C + D: cursor ---------- */
.cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;   /* fade out after idle */
  will-change: transform;
}
.cursor.visible { opacity: 1; transition-duration: 0.15s; } /* quick fade in */

.ring {
  position: absolute;
  width: var(--ring);
  height: var(--ring);
  left: calc(var(--ring) / -2);
  top: calc(var(--ring) / -2);
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.cursor.down .ring { transform: scale(0.8); }

.cursor-label {
  position: absolute;
  left: 0;
  top: calc(var(--ring) / -2 - 2.6em);
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9em;
  transition: opacity 0.2s;
}
.cursor.no-label .cursor-label { opacity: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
  :root {
    --fs: min(12px, 2.85vw);
    --pad: 8px;
    --sq: 20px;
    --ring: 76px;
    --pad-w: 160px;
    --pad-h: 96px;
  }
  html, body { letter-spacing: 0.05em; }
  .tag { padding: 1em var(--pad) 0.9em; white-space: nowrap; }
  .switch { padding-top: 1em; }
  .switch .desk { display: none; }
  .switch .mob { display: inline; }
  .info { min-height: 30svh; }
  .cursor-label { display: none; }

  /* Touch ring: fades in and out with a 0.5 s ease-in-out */
  .cursor, .cursor.visible { transition: opacity 0.5s ease-in-out; }

  .meta { font-size: 1.3em; }

  /* Controls stack on the right: random, reset, auto-scratch, HD, sound, line, values */
  .scratch {
    left: auto;
    right: 25px;
    bottom: 150px;
    width: var(--pad-w);
    align-items: flex-end;
    gap: 1.65em;
  }
  .scratch-row { display: contents; }
  .scratch-icons { order: 0; flex-direction: column; gap: 1.65em; }
  #scratchToggle { order: 1; }
  #hdToggle      { order: 2; }
  #soundToggle   { order: 3; }
  .scratch-icons, .scratch-toggle { align-self: flex-end; margin-right: 1.6em; }
  .scratch-pad    { order: 4; align-self: flex-start; margin-top: -0.7em; }  /* ~10 px below the sound toggle */
  .scratch-values { order: 5; align-self: flex-start; }                    /* full 1.65em gap above the values */
}

@media (prefers-reduced-motion: reduce) {
  .square, .ring, .cursor { transition: none; }
}
