*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; background: #000; overflow: hidden; }

#top-gradient {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 280px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.6) 40%, rgba(0,0,0,0) 100%);
  pointer-events: none;
  z-index: 5;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 1;
}

/* ═══════════════════════════════
    COUNTER
════════════════════════════════ */
#counter {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  user-select: none;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 440px; /* Base container width to balance the lines */
}

.h-row {
  width: 100%;
  font-family: 'Geist Mono', monospace;
}

.h-title {
  font-size: 18px;
  font-weight: 100;
  color: #a1a1a1;
  text-transform: none; /* Respecting casing */
  letter-spacing: 0.18em;
  margin-bottom: 12px;
}

.h-main {
  font-size: 38px;
  font-weight: 200;
  color: #fff;
  margin-bottom: 6px;
  transition: opacity 0.8s ease;
  min-height: 44px; /* Prevent collapse */
}

#count-main {
  width: 100%;
  min-height: 44px;
  color: #fff;
  font-family: 'Geist Mono', monospace;
  font-size: 38px;
  font-weight: 400;
  letter-spacing: normal;
  text-align: center;
}
.h-sep {
  width: 100%;
  height: 1px;
  background: rgba(255,255,255,0.4);
  margin-bottom: 8px;
}

.h-sub {
  font-size: 11px;
  font-weight: 200;
  color: #a1a1a1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

#count-bar-wrap {
  width: 100%;
  height: 2px;
  background: rgba(255,255,255,0.05);
  margin-top: 4px;
}
#count-bar-fill { height: 100%; background: #fff; width: 0%; }

/* ═══════════════════════════════
    TOOLTIP
════════════════════════════════ */
#tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 40;
  opacity: 0;
  transition: opacity 0.15s ease;
}
#tooltip.visible { opacity: 1; }
#tooltip-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  letter-spacing: 0.03em;
  white-space: nowrap;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 4px;
}
#tooltip-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  margin-top: 2px;
  padding-left: 6px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* ═══════════════════════════════
    BOTTOM BAR
════════════════════════════════ */
#bottom-bar {
  position: fixed;
  bottom: 0; left: 0; width: 100%;
  padding: 12px 40px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.7) 40%, rgba(0,0,0,0) 100%);
  z-index: 10;
  pointer-events: none; /* Let clicks pass through empty parts */
}

/* ═══════════════════════════════
    TRANSITIONS
════════════════════════════════ */
.ui-hidden { opacity: 0; pointer-events: none; transform: translateY(10px); transition: all 1.2s cubic-bezier(0.16, 1, 0.3, 1); }
.ui-visible { opacity: 1; pointer-events: all; transform: translateY(0); }

/* Completion — preserve translateX(-50%) in both states */
#completion-overlay.ui-hidden {
  opacity: 0; pointer-events: none;
  transform: translateY(10px) translateX(-50%);
}
#completion-overlay.ui-visible {
  opacity: 1;
  transform: translateY(0) translateX(-50%);
  transition: opacity 3s cubic-bezier(0.16, 1, 0.3, 1), transform 3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Hidden state for credits needs to be more subtle */
#credits.ui-hidden { opacity: 0; pointer-events: none; transform: translateY(5px) translateX(-50%); }
#credits.ui-visible { opacity: 0.3; pointer-events: none; transform: translateY(0) translateX(-50%); }

/* ═══════════════════════════════
    PORTAL & COMPLETION
════════════════════════════════ */
#portal {
  position: fixed; inset: 0; width: 100%; height: 100%;
  background: transparent; /* Canvas + idle particles show through */
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  transition: opacity 2.5s cubic-bezier(0.16, 1, 0.3, 1), visibility 2.5s;
}
/* Dark radial vignette — keeps text readable, dissolves with the portal */
#portal::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 80% 70% at 50% 50%,
    rgba(0,0,0,0.88) 0%,
    rgba(0,0,0,0.55) 45%,
    rgba(0,0,0,0) 100%);
  pointer-events: none;
}
#portal.faded { opacity: 0; visibility: hidden; }

#portal-content {
  position: relative; /* sit above the ::before vignette */
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 40px;
}

#portal-title {
  font-family: 'Geist Mono', monospace;
  font-size: 28px; font-weight: 400; color: #fff;
  letter-spacing: 0.3em;
}

#btn-start {
  background: none; border: 1px solid rgba(255,255,255,0.3);
  color: #fff; padding: 12px 32px;
  font-family: 'Geist Mono', monospace; font-size: 14px; letter-spacing: 0.2em;
  cursor: pointer; transition: all 0.3s ease;
}
#btn-start:hover {
  background: #fff; color: #000; border-color: #fff; letter-spacing: 0.4em;
}

#completion-overlay {
  position: fixed;
  bottom: 160px; left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  text-align: center;
  pointer-events: none;
}

#btn-restart-prominent {
  background: #000; color: #fff; border: 1px solid rgba(255,255,255,0.4);
  padding: 8px 20px;
  font-family: 'Geist Mono', monospace; font-size: 10px; font-weight: 200;
  letter-spacing: 0.2em; cursor: pointer; pointer-events: all;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}
#btn-restart-prominent:hover {
  background: #fff; color: #000; border-color: #fff; letter-spacing: 0.35em;
}


#credits {
  position: fixed;
  bottom: 10px; left: 50%;
  transform: translateX(-50%);
  font-family: 'Geist Mono', monospace;
  font-size: 8px; letter-spacing: 0.05em;
  color: #fff;
  z-index: 15;
  white-space: nowrap;
  pointer-events: none;
}
#credits a {
  color: #fff; text-decoration: underline; text-underline-offset: 2px;
}

.p-col {
  flex: 0 0 140px;
  display: flex;
  flex-direction: column;
  pointer-events: all;
}

.curve-col {
  flex: 0 0 200px;
}

.action-col {
  flex: 0 0 110px;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 8px 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.6);
  border-radius: 6px;
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.2s ease;
}
.action-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.p-title {
  font-family: 'Geist Mono', monospace;
  font-size: 9px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(255,255,255,0.18);
  margin-bottom: 12px;
}

.p-lbl { display: flex; justify-content: space-between; margin-bottom: 6px; align-items: flex-end; }
.p-lbl span:first-child {
  font-family: 'Geist Mono', monospace;
  font-size: 9px; color: rgba(255,255,255,0.3);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.p-val {
  font-family: 'Geist Mono', monospace;
  font-size: 9px; color: rgba(255,255,255,0.15);
}

input[type="range"] {
  width: 100%; height: 0.5px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.2); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 7px; height: 7px; border-radius: 50%;
  background: #fff; cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 7px; height: 7px; border-radius: 50%;
  background: #fff; border: none; cursor: pointer;
}

.p-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 13px 0; display: none; }

#curve-wrap {
  width: 100%; height: 60px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  margin-top: 8px;
  position: relative;
}
#curve-canvas {
  width: 100%; height: 100%;
  position: absolute; inset: 0;
  pointer-events: none;
}
.curve-handle {
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: grab;
  box-shadow: 0 0 10px rgba(255,255,255,0.3);
  z-index: 2;
}
.curve-handle:active { cursor: grabbing; box-shadow: 0 0 14px rgba(255,255,255,0.6); }
.curve-line {
  position: absolute;
  background: rgba(255,255,255,0.2);
  transform-origin: 0 50%;
  height: 1px;
  pointer-events: none;
}

.seed-row { display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.seed-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: rgba(255,255,255,0.18); flex-shrink: 0;
}
#seed-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: rgba(255,255,255,0.45);
  flex: 1; text-align: center;
}
.s-btn {
  width: 24px; height: 24px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.06); border: none; cursor: pointer;
  transition: all 0.2s;
}
.s-btn:hover {
  color: #fff; background: rgba(255,255,255,0.2);
}
.s-btn:active {
  background: rgba(255,255,255,0.3);
}

/* ═══════════════════════════════
    MOBILE RESPONSIVE
════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Counter ── */
  #counter {
    top: 28px;
    width: calc(100% - 40px);
    max-width: 320px;
  }
  .h-title { font-size: 13px; margin-bottom: 8px; letter-spacing: 0.18em; }
  .h-main  { font-size: 28px; min-height: 32px; }
  #count-main { font-size: 28px; min-height: 32px; }
  .h-sub   { font-size: 7px; letter-spacing: 0.06em; }

  /* ── Bottom bar: 2-column grid ── */
  #bottom-bar {
    padding: 14px 16px 16px;
    gap: 14px 12px;
    align-items: flex-start;
    justify-content: flex-start;
  }

  /* All controls: 2-column, equal width */
  .p-col {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }

  /* Curve: full width, simpler height */
  .curve-col {
    flex: 1 1 100%;
    order: 10;
  }
  #curve-wrap { height: 44px; margin-top: 4px; }

  /* Download button: full width */
  .action-col {
    flex: 1 1 100%;
    order: 11;
  }
  .action-btn { padding: 10px 0; font-size: 9px; }

  /* ── REPETIR button: below counter, above bar ── */
  #completion-overlay {
    bottom: auto;
    top: 160px;
    left: 50%;
    transform: translateX(-50%);
  }

  /* ── Credits ── */
  #credits { font-size: 7px; bottom: 6px; }

  /* ── Portal ── */
  #portal-title { font-size: 20px; letter-spacing: 0.2em; }
}

/* ═══════════════════════════════
    RECORD HUD
════════════════════════════════ */
#record-hud {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 99;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  backdrop-filter: blur(8px);
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.65);
  pointer-events: none;
  user-select: none;
  /* Hidden by default */
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
#record-hud.hud-visible {
  opacity: 1;
  transform: translateY(0);
}
/* Active recording dot — pulsing red */
#record-hud[data-state='recording'] .rec-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #ff3b3b;
  animation: rec-pulse 1.1s ease-in-out infinite;
  flex-shrink: 0;
}
/* Done state: no dot, text changes via JS */
#record-hud[data-state='done'] .rec-dot { display: none; }
#record-hud[data-state='done'] .rec-label { color: rgba(255, 255, 255, 0.4); }

@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.75); }
}

