:root {
  --bg: #c9f7e9;
  --ink: #0a0a0a;
  --accent: #7c5cff;
  --topbar-h: 3.75rem;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  touch-action: manipulation;
  overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease;
}

#tap-area {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8vh 6vw;
  user-select: none;
  cursor: pointer;
  background-color: var(--bg);
  transition: background-color 0.4s ease-out;
}

#tap-area.pressed {
  background-color: var(--accent);
  transition: background-color 0.08s ease-in;
}

header {
  text-align: center;
}

h1 {
  font-family: 'Archivo Black', sans-serif;
  font-size: clamp(2.5rem, 8vw, 5rem);
  margin: 0;
  letter-spacing: -0.02em;
}

#hint {
  margin: 0.75rem 0 0;
  color: var(--accent);
  font-weight: 800;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
}

#display {
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.08s ease-out;
}

#display.pulse {
  transform: scale(1.06);
}

#bpm {
  font-family: 'Archivo Black', sans-serif;
  font-size: clamp(6rem, 28vw, 14rem);
  line-height: 1;
}

#bpm-label {
  font-family: 'Archivo Black', sans-serif;
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  margin-top: 0.5rem;
}

#bars-info {
  margin-top: 1.5rem;
  text-align: center;
}

#bars-info[hidden] {
  display: none;
}

#bars-count {
  font-family: 'Archivo Black', sans-serif;
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  margin: 0;
}

#bars-detail {
  margin: 0.25rem 0 0;
  font-weight: 700;
  opacity: 0.7;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
}

#bars-milestone {
  margin: 0.5rem 0 0;
  min-height: 1.4em;
  font-weight: 800;
  color: var(--accent);
  font-size: clamp(0.85rem, 2vw, 1rem);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#bars-milestone.show {
  opacity: 1;
}

footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

#reset-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  background: transparent;
  border: 2px solid var(--ink);
  color: var(--ink);
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  cursor: pointer;
}

#reset-btn:active {
  background: var(--ink);
  color: var(--bg);
}

#tap-count {
  margin: 0;
  opacity: 0.6;
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 1.2em;
}

/* --- Barra superior (menú global, común a toda la ventana) --- */

#app-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg) 92%, black 8%);
  border-bottom: 2px solid var(--ink);
  z-index: 15;
}

#app-topbar[hidden] {
  display: none;
}

#app-logo {
  font-family: 'Archivo Black', sans-serif;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

body.has-topbar #tap-area {
  padding-top: calc(8vh + var(--topbar-h));
}

body.has-topbar #home-grid {
  top: var(--topbar-h);
}

body.has-topbar #top-actions {
  top: calc(var(--topbar-h) + 1rem);
}

/* El blog reutiliza la misma barra superior que la app, pero siempre
   visible (páginas estáticas, sin modo rejilla) y con espacio debajo para
   que no tape la cabecera propia del blog. */
body.blog-body {
  padding-top: var(--topbar-h);
}

/* --- Configuración de apariencia --- */

#top-actions {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.6rem;
  z-index: 10;
}

#top-actions[hidden],
#tap-area[hidden] {
  display: none;
}

.menu-group {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 15rem;
  max-width: 80vw;
  padding: 0.5rem;
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 0.9rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
}

.menu-dropdown[hidden] {
  display: none;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.9rem;
  background: transparent;
  border: none;
  color: var(--ink);
  padding: 0.65rem 0.7rem;
  border-radius: 0.6rem;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  white-space: nowrap;
}

.menu-item:hover,
.menu-item:active {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
}

.menu-item[hidden] {
  display: none;
}

/* --- Panel dividido (varias pantallas en la propia index.html) --- */

#home-grid {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  background: #000;
}

#home-grid[hidden] {
  display: none;
}

.home-pane {
  flex: 1 1 0;
  min-width: 340px;
  height: 100%;
  border: none;
  border-right: 2px solid #000;
}

.home-pane:last-child {
  border-right: none;
}

.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.icon-btn[hidden] {
  display: none;
}

.deck-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.deck-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.deck-swatch {
  flex: 0 0 auto;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

.deck-label-input {
  flex: 1;
  min-width: 0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  padding: 0.4rem 0.6rem;
  border-radius: 0.5rem;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
}

.deck-open-btn,
.deck-remove-btn {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.deck-open-btn:active,
.deck-remove-btn:active {
  background: var(--ink);
  color: var(--bg);
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(20rem, 85vw);
  background: var(--bg);
  color: var(--ink);
  border-left: 2px solid var(--ink);
  padding: 5rem 1.5rem 1.5rem;
  z-index: 20;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.side-panel[hidden] {
  display: none;
}

.side-panel h2 {
  margin: 0;
  font-family: 'Archivo Black', sans-serif;
  font-size: 1.5rem;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.settings-label {
  font-weight: 800;
  font-size: 0.9rem;
  opacity: 0.7;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.theme-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.9rem;
  background: transparent;
  border: 2px solid var(--ink);
  color: var(--ink);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
}

.theme-btn.active,
.swatch-btn.active {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.swatch-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 2px solid var(--ink);
  cursor: pointer;
  padding: 0;
}

.custom-row {
  flex-direction: column;
  gap: 0.75rem;
}

.custom-row label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.custom-row input[type='color'] {
  width: 2.5rem;
  height: 2rem;
  border: 2px solid var(--ink);
  border-radius: 0.4rem;
  background: none;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}

.toggle-row input[type='checkbox'] {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
  cursor: pointer;
}

/* --- Micrófono (Fase 2) --- */

#mic-btn.listening {
  color: var(--accent);
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { background: color-mix(in srgb, var(--accent) 12%, transparent); }
  50% { background: transparent; }
}

.wide-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  background: transparent;
  border: 2px solid var(--ink);
  color: var(--ink);
  padding: 0.65rem 1rem;
  border-radius: 0.6rem;
  cursor: pointer;
  display: block;
  text-align: center;
  text-decoration: none;
}

.wide-btn:active {
  background: var(--ink);
  color: var(--bg);
}

.wide-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#mic-lock-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

#mic-device-select {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
}

.mic-level-track {
  height: 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  overflow: hidden;
}

.mic-level-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.05s linear;
}

#mic-sensitivity {
  width: 100%;
  accent-color: var(--accent);
}

/* --- Analizar archivo (Fase 3) --- */

.file-drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 6rem;
  padding: 1rem;
  border: 2px dashed color-mix(in srgb, var(--ink) 40%, transparent);
  border-radius: 0.75rem;
  font-weight: 700;
  font-size: 0.9rem;
  opacity: 0.8;
  cursor: pointer;
}

.file-drop-zone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  opacity: 1;
}

.file-result-bpm {
  font-family: 'Archivo Black', sans-serif;
  font-size: 2.5rem;
  margin: 0;
  line-height: 1;
}

#file-result[hidden],
#item-name-group[hidden] {
  display: none;
}

#global-settings-close,
#item-settings-close,
#help-close,
#mic-close,
#file-close {
  margin-top: auto;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  background: var(--ink);
  color: var(--bg);
  border: none;
  padding: 0.7rem;
  border-radius: 0.6rem;
  cursor: pointer;
}

#app-version {
  margin: 0;
  text-align: center;
  opacity: 0.5;
  font-size: 0.75rem;
  font-weight: 600;
}

.bpm-reference-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--ink);
  border-radius: 0.75rem;
  max-height: min(45vh, 16rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}

.bpm-reference-list::-webkit-scrollbar {
  width: 8px;
}

.bpm-reference-list::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 999px;
}

.bpm-reference-list::-webkit-scrollbar-track {
  background: transparent;
}

.bpm-reference-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
  font-weight: 700;
  font-size: 0.95rem;
}

.bpm-reference-list li:last-child {
  border-bottom: none;
}

.bpm-reference-list li span:last-child {
  opacity: 0.7;
  font-weight: 600;
}

.help-note {
  margin: 0;
  opacity: 0.6;
  font-size: 0.85rem;
}

.beat-diagram {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.diagram-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
}

.diagram-label {
  flex: 0 0 3.25rem;
  min-width: 0;
  display: flex;
  align-items: center;
  font-weight: 800;
  font-size: 0.6rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.6;
}

.diagram-cells {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 1px;
}

/* fila de pulso: barras sin número (32 celdas no caben legibles en el panel) */
.pulso-cells {
  align-items: flex-end;
  height: 1.4rem;
}

.beat-cell {
  flex: 1;
  min-width: 0;
  height: 0.55rem;
  border-radius: 1px;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
}

.beat-cell.alt {
  background: color-mix(in srgb, var(--ink) 32%, transparent);
}

.beat-cell.downbeat {
  height: 100%;
  background: var(--accent);
}

.bar-cell,
.phrase-cell {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0;
  border-radius: 0.25rem;
  font-weight: 800;
  font-size: 0.7rem;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.bar-cell.alt {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}

.phrase-cell {
  background: color-mix(in srgb, var(--accent) 55%, transparent);
  font-size: 0.65rem;
}
