/* ─── Tipografía (self-hosted, subset latin) ─────────────────────────── */

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/Fraunces-600-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/Fraunces-700-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/Fraunces-600-italic.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/Fraunces-700-italic.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-500-normal.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-600-normal.woff2") format("woff2");
}

/* ─── Paleta ──────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;
  --ink: #f3ead8;
  --muted: #a89a7e;
  --faint: #6f6450;
  --bg: #0b0a08;
  --panel: #1b1712;
  --panel-2: #241e15;
  --bezel: #0a0907;
  --line: #3c3322;
  --line-soft: rgba(232, 185, 91, 0.16);
  --amber: #e8b95b;
  --amber-hot: #ffd27a;
  --red: #ff4a3d;
  --red-deep: #a8231b;
  --green: #69d99c;
  --serif: "Fraunces", ui-serif, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-family: var(--serif);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
audio {
  font: inherit;
}

/* ─── Atmósfera: glow tungsteno + grano ──────────────────────────────── */

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60rem 38rem at 18% -8%, rgba(232, 185, 91, 0.13), transparent 62%),
    radial-gradient(46rem 30rem at 88% 108%, rgba(255, 74, 61, 0.07), transparent 60%),
    radial-gradient(70rem 50rem at 50% 50%, rgba(38, 30, 18, 0.55), transparent 75%);
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  opacity: 0.5;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='linear' slope='0.14'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ─── Layout ──────────────────────────────────────────────────────────── */

.shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: clamp(18px, 4vw, 56px);
}

.console {
  width: min(940px, 100%);
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(160deg, rgba(255, 240, 205, 0.045), rgba(255, 255, 255, 0) 42%),
    linear-gradient(180deg, var(--panel-2), var(--panel) 30%);
  box-shadow:
    0 40px 110px rgba(0, 0, 0, 0.6),
    0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 240, 205, 0.07);
  padding: clamp(22px, 4.5vw, 48px);
}

/* Tornillos de consola */
.screw {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #4d4332, #211c13 70%);
  box-shadow:
    inset 0 1px 1px rgba(255, 240, 205, 0.22),
    0 1px 2px rgba(0, 0, 0, 0.6);
}

.screw::after {
  content: "";
  position: absolute;
  left: 1.5px;
  right: 1.5px;
  top: 50%;
  height: 1px;
  background: rgba(0, 0, 0, 0.65);
}

.screw-tl { top: 13px; left: 13px; }
.screw-tr { top: 13px; right: 13px; }
.screw-bl { bottom: 13px; left: 13px; }
.screw-br { bottom: 13px; right: 13px; }
.screw-tl::after { transform: rotate(38deg); }
.screw-tr::after { transform: rotate(-21deg); }
.screw-bl::after { transform: rotate(81deg); }
.screw-br::after { transform: rotate(-64deg); }

/* ─── Topline: eyebrow + indicadores ─────────────────────────────────── */

.topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: clamp(26px, 4vw, 40px);
}

.eyebrow,
.state,
.onair,
.label,
.message,
.screen-caption,
.meter-label,
.progress-time,
.colophon {
  font-family: var(--mono);
}

.eyebrow {
  margin: 0;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.74rem;
  font-weight: 500;
}

.eyebrow .dim {
  color: var(--faint);
  letter-spacing: 0.16em;
}

.indicators {
  display: flex;
  align-items: center;
  gap: 10px;
}

.state {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: color 200ms ease, border-color 200ms ease, background 200ms ease;
}

body.recording .state {
  color: var(--ink);
  border-color: rgba(255, 74, 61, 0.6);
  background: rgba(255, 74, 61, 0.1);
}

/* Lámpara ON AIR */
.onair {
  margin: 0;
  border: 1px solid #4a2018;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: #57231b;
  background: linear-gradient(180deg, #1d100c, #160b08);
  transition: all 250ms ease;
}

body.recording .onair {
  color: #ffe9e2;
  border-color: rgba(255, 110, 95, 0.8);
  background: linear-gradient(180deg, #e23a2b, var(--red-deep));
  text-shadow: 0 0 12px rgba(255, 235, 225, 0.9);
  box-shadow:
    0 0 22px rgba(255, 74, 61, 0.55),
    0 0 60px rgba(255, 74, 61, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  animation: lamp-flicker 2.4s infinite;
}

@keyframes lamp-flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  94% { opacity: 0.82; }
  96% { opacity: 1; }
}

/* ─── Masthead ───────────────────────────────────────────────────────── */

.masthead {
  max-width: 700px;
}

h1 {
  margin: 0;
  font-size: clamp(2.7rem, 7.5vw, 5.6rem);
  line-height: 0.92;
  font-weight: 700;
  letter-spacing: -0.015em;
}

h1 em {
  font-style: italic;
  color: var(--amber);
}

.masthead p {
  max-width: 540px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  line-height: 1.55;
}

/* ─── Pantalla + VU ──────────────────────────────────────────────────── */

.meter-panel {
  margin-top: clamp(28px, 5vw, 46px);
}

.screen {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bezel);
  padding: 10px;
  box-shadow:
    inset 0 2px 14px rgba(0, 0, 0, 0.85),
    0 1px 0 rgba(255, 240, 205, 0.05);
}

.screen::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.16) 0px,
      rgba(0, 0, 0, 0.16) 1px,
      transparent 1px,
      transparent 3px
    );
  box-shadow: inset 0 0 42px rgba(0, 0, 0, 0.55);
}

canvas {
  width: 100%;
  height: clamp(140px, 24vw, 190px);
  display: block;
  border-radius: 6px;
  background:
    radial-gradient(70% 120% at 50% 50%, #14110b 0%, #0c0a07 100%);
}

.screen-caption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  padding: 0 4px;
  color: var(--faint);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.caption-mid {
  text-align: center;
  flex: 1;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.meter-label {
  color: var(--faint);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
}

.meter-track {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 3px;
  background: #0d0b08;
  border: 1px solid rgba(232, 185, 91, 0.2);
  overflow: hidden;
}

#levelBar {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green) 0%, var(--green) 55%, var(--amber) 75%, var(--red) 92%);
  transition: width 80ms linear;
  /* segmentos LED */
  -webkit-mask-image: repeating-linear-gradient(90deg, #000 0 6px, transparent 6px 9px);
  mask-image: repeating-linear-gradient(90deg, #000 0 6px, transparent 6px 9px);
}

#peakMarker {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 2px;
  background: var(--amber-hot);
  box-shadow: 0 0 6px rgba(255, 210, 122, 0.8);
  opacity: 0;
  transition: left 90ms linear, opacity 300ms ease;
}

body.recording #peakMarker,
body.playing #peakMarker {
  opacity: 1;
}

/* ─── Patch bay: selección de entrada/salida ─────────────────────────── */

.device-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 48px;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 10, 8, 0.48);
}

.device-field {
  min-width: 0;
}

.device-field .label {
  margin-bottom: 7px;
}

select {
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #17130d, #100e0a);
  color: var(--ink);
  padding: 0 36px 0 12px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.2;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--amber) 50%),
    linear-gradient(135deg, var(--amber) 50%, transparent 50%),
    linear-gradient(180deg, #17130d, #100e0a);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 13px) 19px,
    0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
}

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

select:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.device-refresh {
  width: 48px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #2b2418, #1a1610 80%);
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: inset 0 1px 0 rgba(255, 240, 205, 0.1);
  transition: transform 140ms ease, border-color 140ms ease, color 140ms ease;
}

.device-refresh:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(232, 185, 91, 0.6);
  color: var(--amber-hot);
}

.device-refresh:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.device-note {
  grid-column: 1 / -1;
  margin: -2px 0 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--faint);
}

/* ─── Readout ────────────────────────────────────────────────────────── */

.readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  background: rgba(11, 10, 8, 0.55);
  min-width: 0;
}

.label {
  display: block;
  color: var(--faint);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-bottom: 8px;
}

.cell strong {
  display: block;
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(1.3rem, 4vw, 2.1rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

#clipMeta {
  color: var(--muted);
  font-weight: 400;
  font-size: clamp(1rem, 3vw, 1.35rem);
  line-height: 1.9;
}

/* ─── Controles ──────────────────────────────────────────────────────── */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-top: 24px;
}

button {
  border: 0;
  color: var(--ink);
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 4px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.record-button {
  min-height: 62px;
  min-width: min(100%, 220px);
  border-radius: 999px;
  display: inline-flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 0 30px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.12rem;
  letter-spacing: 0.01em;
  background: linear-gradient(180deg, #ff5d4e, #d92b1f 82%);
  border: 1px solid rgba(255, 145, 130, 0.35);
  box-shadow:
    0 16px 38px rgba(217, 43, 31, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.record-button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.record-button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow:
    0 8px 22px rgba(217, 43, 31, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 2px 6px rgba(0, 0, 0, 0.3);
}

.record-button[aria-pressed="true"] {
  background: linear-gradient(180deg, #c3271c, #8c1c14 85%);
  border-color: rgba(255, 110, 95, 0.5);
}

.record-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 rgba(243, 234, 216, 0.5);
}

.record-button[aria-pressed="true"] .record-dot {
  animation: pulse 1.1s infinite;
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 12px rgba(243, 234, 216, 0); }
}

.icon-button {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #2b2418, #1a1610 80%);
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 205, 0.1),
    0 4px 14px rgba(0, 0, 0, 0.4);
  transition: transform 140ms ease, border-color 140ms ease, color 140ms ease;
}

.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(232, 185, 91, 0.6);
  color: var(--amber-hot);
}

.icon-button:active:not(:disabled) {
  transform: translateY(1px);
}

.icon {
  width: 24px;
  height: 24px;
}

.icon-pause {
  display: none;
}

.icon-button.playing .icon-play {
  display: none;
}

.icon-button.playing .icon-pause {
  display: block;
}

/* ─── Player dock ────────────────────────────────────────────────────── */

.player-dock {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 10, 8, 0.55);
}

.player-dock[hidden] {
  display: none;
}

audio {
  display: none;
}

.progress-track {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: #0d0b08;
  border: 1px solid rgba(232, 185, 91, 0.18);
  overflow: hidden;
}

#progressFill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--amber), var(--amber-hot));
  box-shadow: 0 0 8px rgba(232, 185, 91, 0.45);
}

.progress-time {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

/* ─── Mensaje + colofón ──────────────────────────────────────────────── */

.message {
  min-height: 1.4em;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.message::before {
  content: "▸ ";
  color: var(--amber);
}

.message.error {
  color: #ff9b90;
}

.message.error::before {
  color: var(--red);
}

.colophon {
  margin: 0;
  color: var(--faint);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  text-align: center;
}

/* ─── Entrada escalonada ─────────────────────────────────────────────── */

.reveal {
  animation: rise 640ms cubic-bezier(0.2, 0.7, 0.25, 1) both;
}

.r1 { animation-delay: 60ms; }
.r2 { animation-delay: 140ms; }
.r3 { animation-delay: 230ms; }
.r4 { animation-delay: 310ms; }
.r5 { animation-delay: 390ms; }
.r6 { animation-delay: 470ms; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    animation: none;
  }

  body.recording .onair {
    animation: none;
  }

  .record-button[aria-pressed="true"] .record-dot {
    animation: none;
  }
}

/* ─── Mobile ─────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .readout {
    grid-template-columns: 1fr;
  }

  .record-button {
    flex: 1 1 100%;
  }

  .icon-button {
    flex: 1 1 0;
    border-radius: 12px;
  }

  .screen-caption .caption-mid {
    display: none;
  }

  .device-panel {
    grid-template-columns: 1fr;
  }

  .device-refresh {
    width: 100%;
  }
}
