:root {
  --bg-deep: #0a0620;
  --bg-panel: #1a1240;
  --bg-panel-light: #241a54;
  --pink: #ff6ec7;
  --cyan: #4dd8ff;
  --lime: #b6ff3c;
  --orange: #ffb84d;
  --violet: #c58bff;
  --yellow: #ffe066;
  --mint: #5cffa8;
  --coral: #ff7a90;
  --skyblue: #7ec8ff;
  --indigo: #a685ff;
  --white: #f2f2f5;
  --spring: #baff87;
  --royal: #5c7aff;
  --gold: #e6b800;
  --red: #ff5c5c;
  --text-light: #f5f0ff;
  --text-dim: #b9aee0;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 20% 0%, #241a54 0%, var(--bg-deep) 55%);
  color: var(--text-light);
  font-family: "Segoe UI", "Trebuchet MS", Verdana, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

h1, h2 {
  margin: 0;
}

/* ---------- Pantalla de login ---------- */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--bg-panel);
  border: 2px solid var(--violet);
  border-radius: 24px;
  padding: 36px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(197, 139, 255, 0.35);
}

.login-card h1 {
  font-size: 2rem;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-dim);
  margin: 0 0 24px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#login-name, #save-name-input {
  font-size: 1.1rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--bg-panel-light);
  background: var(--bg-deep);
  color: var(--text-light);
  text-align: center;
}

#login-name:focus, #save-name-input:focus {
  outline: none;
  border-color: var(--cyan);
}

.error-msg {
  color: var(--orange);
  min-height: 1.2em;
  font-weight: bold;
}

/* ---------- Botones ---------- */

.btn-primary, .btn-secondary, .btn-small {
  font-family: inherit;
  font-weight: bold;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn-primary:active, .btn-secondary:active, .btn-small:active, .play-btn:active {
  transform: scale(0.95);
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), var(--violet));
  color: #1a0a2e;
  padding: 12px 20px;
  font-size: 1.05rem;
}

.btn-secondary {
  background: var(--bg-panel-light);
  color: var(--text-light);
  padding: 10px 16px;
  font-size: 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover, .btn-primary:hover {
  filter: brightness(1.15);
}

.btn-primary:disabled, .btn-secondary:disabled, .btn-small:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.btn-small {
  background: var(--bg-panel-light);
  color: var(--text-light);
  padding: 6px 10px;
  font-size: 0.9rem;
}

/* ---------- App principal ---------- */

#app-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 18px;
  background: var(--bg-panel);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  flex-wrap: wrap;
  gap: 8px;
}

.app-header h1 {
  font-size: 1.1rem;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
}

.app-main {
  flex: 1;
  padding: 6px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.transport {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--bg-panel);
  border-radius: 14px;
  padding: 8px 16px;
}

.play-btn {
  font-size: 1.05rem;
  font-weight: bold;
  padding: 9px 20px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--lime), var(--cyan));
  color: #0a2410;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(182, 255, 60, 0.45);
  touch-action: manipulation;
}

.play-btn.is-playing {
  background: linear-gradient(135deg, var(--pink), var(--orange));
  box-shadow: 0 0 18px rgba(255, 110, 199, 0.5);
  color: #2a0a1a;
}

.tempo-control {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-weight: bold;
}

#tempo-slider {
  width: 140px;
  accent-color: var(--cyan);
}

#tempo-value {
  min-width: 72px;
  color: var(--text-light);
}

.duration-control {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-weight: bold;
}

#duration-label {
  color: var(--text-light);
  min-width: 90px;
}

.transport-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

/* ---------- Secuenciador ---------- */

.sequencer-grid {
  background: var(--bg-panel);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-x: auto;
}

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

.row-label {
  flex: 0 0 auto;
  width: 150px;
  font-weight: bold;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 10px;
  background: var(--bg-panel-light);
  position: sticky;
  left: 0;
  z-index: 2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-steps {
  display: grid;
  gap: 5px;
  flex: 1;
  --cell-min: 26px;
  /* grid-template-columns y min-width se fijan por JS (game.js),
     porque el número de pasos es dinámico (32..128). */
}

.step-cell {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(0.55rem, 2.2vw, 0.8rem);
  color: rgba(255, 255, 255, 0.85);
  line-height: 1;
  transition: filter 0.08s ease, transform 0.08s ease;
}

.step-cell.block-b {
  background: rgba(255, 255, 255, 0.08);
}

.step-cell.compas-end {
  margin-right: 6px;
  border-right: 3px solid rgba(255, 255, 255, 0.35);
}

.step-cell:hover {
  filter: brightness(1.3);
}

.step-cell.playhead {
  filter: brightness(1.9) saturate(1.4);
  transform: scale(1.08);
}

.seq-row.row-marimba { --row-color: var(--pink); }
.seq-row.row-celesta { --row-color: var(--cyan); }
.seq-row.row-bajo { --row-color: var(--lime); }
.seq-row.row-percusion { --row-color: var(--orange); }
.seq-row.row-kalimba { --row-color: var(--violet); }
.seq-row.row-vibrafono { --row-color: var(--yellow); }
.seq-row.row-pajarito { --row-color: var(--mint); }
.seq-row.row-organo { --row-color: var(--coral); }
.seq-row.row-campana { --row-color: var(--skyblue); }
.seq-row.row-gota { --row-color: var(--indigo); }
.seq-row.row-piano { --row-color: var(--white); }
.seq-row.row-flauta { --row-color: var(--spring); }
.seq-row.row-clarinete { --row-color: var(--royal); }
.seq-row.row-saxofon { --row-color: var(--gold); }
.seq-row.row-trompeta { --row-color: var(--red); }

.seq-row .row-label {
  color: var(--row-color);
  border: 1px solid var(--row-color);
}

.step-cell.active {
  background: var(--row-color);
  border-color: var(--row-color);
  color: #1a0a2e;
  box-shadow: 0 0 10px var(--row-color), 0 0 18px var(--row-color);
}

/* ---------- Panel de melodías ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 2, 20, 0.6);
  z-index: 10;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(340px, 88vw);
  background: var(--bg-panel);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5);
  z-index: 11;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 14px;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#melodies-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.melody-item {
  background: var(--bg-panel-light);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.melody-item .melody-name {
  font-weight: bold;
}

.melody-item .melody-tempo {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.melody-actions {
  display: flex;
  gap: 8px;
}

#melodies-list li.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 20px 0;
}

/* ---------- Modal guardar ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 2, 20, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

.modal-content {
  background: var(--bg-panel);
  border: 2px solid var(--pink);
  border-radius: 20px;
  padding: 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 0 40px rgba(255, 110, 199, 0.35);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---------- Modal de nota por casilla ---------- */

.note-modal-content {
  max-width: 420px;
  border-color: var(--modal-accent, var(--pink));
  box-shadow: 0 0 40px var(--modal-accent, rgba(255, 110, 199, 0.35));
}

.note-modal-sub {
  margin: -8px 0 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.note-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.note-btn {
  font-family: inherit;
  padding: 14px 4px;
  border-radius: 12px;
  border: 2px solid var(--btn-color, var(--violet));
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-light);
  font-weight: bold;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: filter 0.1s ease, transform 0.08s ease;
}

.note-btn:hover {
  filter: brightness(1.3);
}

.note-btn:active {
  transform: scale(0.94);
}

.note-btn.selected {
  background: var(--btn-color, var(--violet));
  color: #1a0a2e;
  box-shadow: 0 0 12px var(--btn-color, var(--violet));
}

/* ---------- Responsive / Android ---------- */

@media (max-width: 700px) {
  .transport {
    flex-direction: column;
    align-items: stretch;
  }

  .transport-actions {
    margin-left: 0;
    justify-content: center;
  }

  .play-btn {
    width: 100%;
    text-align: center;
  }

  .tempo-control {
    justify-content: center;
  }

  .duration-control {
    justify-content: center;
  }

  .row-label {
    width: 100px;
    font-size: 0.72rem;
  }

  .row-steps {
    --cell-min: 22px;
  }

  .note-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
}
