/* vhsvomit — Fauxmoni internal product visual language */

@property --hue {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

@keyframes hue-cycle {
  to { --hue: 360; }
}

@keyframes marquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  10% { transform: translate(-3px, -2px) rotate(-1deg); }
  20% { transform: translate(3px, 1px) rotate(1deg); }
  30% { transform: translate(-2px, 2px) rotate(-1deg); }
  40% { transform: translate(2px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(3px, -2px) rotate(1deg); }
  70% { transform: translate(-3px, 1px) rotate(-1deg); }
  80% { transform: translate(2px, -3px) rotate(1deg); }
  90% { transform: translate(-2px, 2px) rotate(-1deg); }
}

:root {
  --bg: #000;
  --neon: hsl(var(--hue), 100%, 50%);
  --neon-soft: hsla(var(--hue), 100%, 50%, 0.18);
  --neon-trace: hsla(var(--hue), 100%, 50%, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--neon);
  font-family: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
  animation: hue-cycle 36s linear infinite;
}
html::-webkit-scrollbar, body::-webkit-scrollbar { display: none; }

body {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}

/* ============ MARQUEES ============ */

.marquee {
  display: flex;
  overflow: hidden;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  padding: 6px 0;
  white-space: nowrap;
}
.marquee-track {
  display: inline-flex;
  gap: 2em;
  animation: marquee 40s linear infinite;
  padding-right: 2em;
}
.marquee-track > span { flex-shrink: 0; }
.marquee.reverse .marquee-track { animation-direction: reverse; animation-duration: 55s; }

/* ============ HEADER ============ */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 2px solid currentColor;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-mark {
  letter-spacing: -2px;
  font-size: 22px;
}
.brand-name {
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.brand-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  opacity: 0.55;
}

.actions {
  display: flex;
  gap: 10px;
}

/* ============ BRUTALIST BUTTONS ============ */

button,
.file span {
  background: transparent;
  color: currentColor;
  border: 2px solid currentColor;
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
button:hover:not(:disabled),
.file:hover span {
  transform: translate(3px, -3px);
  box-shadow: -3px 3px 0 0 currentColor;
}
button:active:not(:disabled),
.file:active span {
  transform: translate(0, 0);
  box-shadow: none;
}
button:disabled { opacity: 0.3; cursor: not-allowed; }
button.busy { animation: shake 0.4s ease-in-out infinite; }

.file { display: inline-flex; }

/* ============ STAGE ============ */

.stage {
  display: grid;
  grid-template-columns: 1fr 460px;
  min-height: 0;
  min-width: 0;
}

.screen {
  position: relative;
  background: #000;
  border-right: 2px solid currentColor;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 3px,
      var(--neon-trace) 3px,
      var(--neon-trace) 4px
    );
  pointer-events: none;
  z-index: 1;
}

#canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  background: #000;
  position: relative;
  z-index: 0;
}
#video { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.overlay.hidden { display: none; }
.overlay-inner { text-align: center; }
.overlay-mark {
  font-size: 56px;
  letter-spacing: -8px;
  margin-bottom: 14px;
  animation: shake 0.6s ease-in-out infinite;
}
.overlay-text {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  opacity: 0.7;
}
.overlay-text b { font-weight: 900; opacity: 1; }

.hud {
  position: absolute;
  bottom: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  pointer-events: none;
  text-shadow: 0 0 6px #000, 0 0 2px #000;
  z-index: 3;
}

/* ============ EXPORT OVERLAY ============ */

@keyframes bar-shimmer {
  0% { background-position: 0 0; }
  100% { background-position: 32px 0; }
}

.export-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10;
  pointer-events: all;
  padding: 16px;
  box-sizing: border-box;
}
.export-overlay[hidden] { display: none; }

.export-card {
  width: 100%;
  max-width: 640px;
  box-sizing: border-box;
  border: 3px solid currentColor;
  background: #000;
  padding: 28px 24px 24px;
  box-shadow: 0 0 0 1px #000, 0 0 40px var(--neon-soft), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  position: relative;
}
.export-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 3px,
      var(--neon-trace) 3px,
      var(--neon-trace) 4px
    );
  pointer-events: none;
}

.export-stage {
  font-size: clamp(22px, 5vw, 44px);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.1;
  margin-bottom: 22px;
  text-align: center;
  position: relative;
  word-break: break-word;
}

.export-bar {
  position: relative;
  width: 100%;
  height: 28px;
  border: 2px solid currentColor;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 7px,
      rgba(255, 255, 255, 0.06) 7px,
      rgba(255, 255, 255, 0.06) 8px
    );
  overflow: hidden;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.8);
}

.export-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background:
    linear-gradient(
      90deg,
      transparent 0,
      transparent 6px,
      currentColor 6px,
      currentColor 14px,
      transparent 14px,
      transparent 16px,
      currentColor 16px,
      currentColor 28px,
      transparent 28px,
      transparent 32px
    );
  background-size: 32px 100%;
  animation: bar-shimmer 0.7s linear infinite;
  box-shadow: 0 0 16px currentColor, inset 0 0 8px currentColor;
  transition: width 0.18s linear;
}

.export-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 14px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums;
  gap: 12px;
}

.export-pct {
  font-size: 18px;
  font-weight: 900;
  flex-shrink: 0;
}

.export-sub {
  margin-top: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  line-height: 1.6;
  opacity: 0.85;
  text-align: center;
  position: relative;
  min-height: 1.2em;
  max-width: 100%;
  word-break: break-word;
}

.export-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  position: relative;
}
.export-actions[hidden] { display: none; }

.export-save,
.export-close {
  flex: 1;
  background: transparent;
  color: currentColor;
  border: 2px solid currentColor;
  padding: 14px 16px;
  font: inherit;
  font-weight: 900;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.export-save {
  background: var(--neon);
  color: #000;
  border-color: var(--neon);
  flex: 2;
}
.export-save:hover {
  transform: translate(3px, -3px);
  box-shadow: -3px 3px 0 0 var(--neon);
}
.export-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.export-close:hover {
  transform: translate(3px, -3px);
  box-shadow: -3px 3px 0 0 currentColor;
}

/* ============ CONTROLS ============ */

.controls {
  padding: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  height: 100%;
  scrollbar-width: thin;
  scrollbar-color: currentColor transparent;
  /* Grid 2-col: fieldsets pequenos parados lado a lado, audio interface vibes */
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;
  gap: 12px;
  align-content: start;
}
.controls::-webkit-scrollbar { width: 6px; }
.controls::-webkit-scrollbar-track { background: transparent; }
.controls::-webkit-scrollbar-thumb { background: currentColor; }

/* Fieldsets marcados como 'full' ocupam as 2 colunas (export, presets, glow) */
fieldset.full { grid-column: 1 / -1; }

/* Drawer backdrop (só aparece em mobile) */
.controls-backdrop {
  display: none;
}

/* Abinha lateral pro drawer mobile (só aparece em mobile) */
.drawer-tab { display: none; }

fieldset {
  border: 2px solid currentColor;
  margin: 0;
  padding: 10px 12px 14px;
  background: transparent;
}
legend {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.25em;
  font-weight: 900;
  padding: 0 6px;
}

fieldset.export-block {
  background: var(--neon-soft);
  border-width: 3px;
}

fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-start;
  justify-content: center;
}
fieldset > legend { flex-basis: 100%; }

/* Fieldsets que têm selects ou presets (não knob) voltam ao layout em bloco */
fieldset:has(select),
fieldset:has(.presets) {
  display: block;
}
fieldset:has(select) label {
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

fieldset label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-weight: 700;
  opacity: 0.9;
  min-width: 64px;
}

/* Color picker dentro de fieldset com knobs quebra linha e vai full-width */
fieldset label:has(input[type="color"]) {
  flex-basis: 100%;
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 10px;
}

.knob-hidden-input {
  position: absolute !important;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ============ ANALOG KNOBS ============ */

.knob-wrap {
  --knob-size: 58px;
  --arc-frac: 0;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.knob {
  position: relative;
  width: var(--knob-size);
  height: var(--knob-size);
  cursor: grab;
  user-select: none;
  touch-action: none;
  outline: none;
}
.knob[data-dragging="true"] { cursor: grabbing; }
.knob:focus-visible .knob-cap {
  box-shadow:
    inset 0 -4px 8px rgba(0, 0, 0, 0.7),
    inset 0 3px 4px rgba(255, 255, 255, 0.06),
    0 0 0 1px #000,
    0 0 14px currentColor;
}

/* Arc de progresso ao redor do knob (conic-gradient mascarado em anel) */
.knob-arc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from 225deg,
    currentColor 0,
    currentColor calc(var(--arc-frac) * 270deg),
    rgba(255, 255, 255, 0.06) calc(var(--arc-frac) * 270deg),
    rgba(255, 255, 255, 0.06) 270deg,
    transparent 270deg 360deg
  );
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 60%, #000 100%);
          mask: radial-gradient(circle, transparent 60%, #000 60%, #000 100%);
  pointer-events: none;
  filter: drop-shadow(0 0 4px currentColor);
}

/* Cap interno: disco preto com leve highlight, borda neon */
.knob-cap {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 2px solid currentColor;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 1) 65%),
    #000;
  box-shadow:
    inset 0 -4px 8px rgba(0, 0, 0, 0.7),
    inset 0 3px 4px rgba(255, 255, 255, 0.06),
    0 0 0 1px #000,
    0 2px 6px rgba(0, 0, 0, 0.9);
}

/* Tick indicador apontando pra fora */
.knob-tick {
  position: absolute;
  top: 4%;
  left: 50%;
  width: 3px;
  height: 38%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor, 0 0 12px currentColor;
  transform-origin: 50% calc(100% + 12%);
  transform: translateX(-50%) rotate(-135deg);
  pointer-events: none;
}

/* Pontinho central */
.knob-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 4px currentColor;
  pointer-events: none;
}

/* Valor numérico embaixo */
.knob-value {
  font-size: 10px;
  letter-spacing: 0.15em;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  min-width: 2ch;
  text-align: center;
}

.knob[data-dragging="true"] .knob-cap {
  box-shadow:
    inset 0 -4px 8px rgba(0, 0, 0, 0.7),
    inset 0 3px 4px rgba(255, 255, 255, 0.06),
    0 0 0 1px #000,
    0 0 18px currentColor;
}

select {
  background: transparent;
  color: currentColor;
  border: 2px solid currentColor;
  padding: 6px 8px;
  font: inherit;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  width: 100%;
  cursor: pointer;
}
select option {
  background: #000;
  color: #fff;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  background: #111;
  border: 2px solid currentColor;
  width: 100%;
  height: 32px;
  padding: 3px;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; }
input[type="color"]::-moz-color-swatch { border: none; }

.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}
.presets button {
  padding: 8px 6px;
  font-size: 11px;
}

.dragover {
  outline: 4px dashed currentColor;
  outline-offset: -10px;
  animation: shake 0.4s ease-in-out infinite;
}

/* ============ RESPONSIVE ============ */

@media (max-width: 880px) {
  .stage {
    grid-template-columns: 1fr;
  }
  .screen {
    border-right: none;
    border-bottom: 2px solid currentColor;
    min-height: 0;
    height: 100%;
  }
  .marquee { font-size: 12px; }
  .brand-name { font-size: 18px; }
  .brand-sub { display: none; }
  .bar { padding: 10px 12px; }
  .actions { gap: 6px; }
  button, .file span { padding: 6px 10px; font-size: 11px; }

  /* Abinha lateral colada na borda direita, vertical center */
  .drawer-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    width: 34px;
    height: 76px;
    background: #000;
    color: currentColor;
    border: 2px solid currentColor;
    border-right: none;
    border-radius: 6px 0 0 6px;
    cursor: pointer;
    padding: 0;
    font: inherit;
    font-weight: 900;
    font-size: 22px;
    line-height: 1;
    letter-spacing: 0;
    text-transform: none;
    z-index: 40;
    transition: right 280ms cubic-bezier(0.32, 0.72, 0.27, 1);
    box-shadow: -4px 4px 0 -1px var(--neon-trace), 0 0 14px var(--neon-soft);
  }
  .drawer-tab:hover { transform: translateY(-50%); box-shadow: -4px 4px 0 -1px var(--neon-soft), 0 0 18px currentColor; }
  /* Quando o drawer está aberto, a abinha desliza pra junto da borda interna do drawer */
  .drawer-tab.open {
    right: min(420px, 92vw);
    border-radius: 6px 0 0 6px;
    box-shadow: none;
  }

  /* Drawer slide-from-right */
  .controls {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 92vw);
    height: 100vh; /* fallback */
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 30;
    background: #000;
    border-left: 2px solid currentColor;
    box-shadow: -8px 0 0 -1px var(--neon-soft), 0 0 40px var(--neon-soft);
    transform: translateX(100%);
    -webkit-transform: translateX(100%);
    transition: transform 260ms cubic-bezier(0.32, 0.72, 0.27, 1);
    padding: 18px 16px 60px;
    grid-template-columns: 1fr 1fr;
    /* iOS smooth scroll */
    -webkit-overflow-scrolling: touch;
  }
  .controls.open {
    transform: translateX(0);
    -webkit-transform: translateX(0);
  }

  /* Backdrop semi-transparente cobre canvas quando drawer aberto */
  .controls-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 20;
    opacity: 0;
    transition: opacity 260ms ease;
    pointer-events: none;
  }
  .controls-backdrop:not([hidden]) {
    opacity: 1;
    pointer-events: all;
  }
}

/* Em telas bem estreitas, drawer vai pra 1-col interna */
@media (max-width: 480px) {
  .controls {
    grid-template-columns: 1fr;
    padding: 16px 14px 60px;
  }
  .knob-wrap { --knob-size: 54px; }
}
