* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0a0a0a;
  color: #e0e0e0;
  overflow: hidden;
}

/* OUTPUT */
.output {
  position: absolute;
  top: 5%;
  width: 100%;
  max-height: 50%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 20px;
  text-align: center;
}

.block { 
  margin: 10px 0; 
  transition: all 0.3s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.morse { 
  font-size: 20px; 
  letter-spacing: 2px;
  font-family: monospace;
}

.text { 
  font-size: 16px; 
  font-weight: 500;
  text-transform: uppercase;
}

.current .morse {
  color: #00ffc3;
  font-size: 26px;
  text-shadow: 0 0 10px rgba(0, 255, 195, 0.3);
}

.current .text {
  color: #fff;
  font-size: 20px;
}

.history { 
  color: #ffffff;
  padding-right: 40px;
}

.play-btn {
  position: absolute;
  right: 10%;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: rgba(0, 255, 195, 0.15);
  border: 1px solid rgba(0, 255, 195, 0.4);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.play-btn:hover {
  background: rgba(0, 255, 195, 0.3);
  transform: translateY(-50%) scale(1.1);
}

.play-btn::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid #00ffc3;
  margin-left: 3px;
}

.current .play-btn {
  display: none;
}

.fade1 { opacity: 0.6; transform: scale(0.98); }
.fade2 { opacity: 0.3; transform: scale(0.96); }
.fade3 { opacity: 0.1; transform: scale(0.94); }

/* BOTÓN */
#morseBtn {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 4px solid rgba(0, 255, 195, 0.3);
  background: #00ffc3;
  color: #000;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0 30px rgba(0, 255, 195, 0.2);
  transition: all 0.05s ease-out;
  z-index: 1;
}

#morseBtn:active {
  transform: translateX(-50%) scale(0.88);
  background: #00aa88;
  box-shadow: 0 0 40px rgba(0, 255, 195, 0.6), inset 0 0 20px rgba(0, 0, 0, 0.3);
  border-color: rgba(0, 255, 195, 0.8);
}

#morseBtn:hover:not(:active) {
  box-shadow: 0 0 40px rgba(0, 255, 195, 0.4);
  border-color: rgba(0, 255, 195, 0.6);
}

/* CONTROLES */
.controls {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 15px;
  background: rgba(255,255,255,0.08);
  padding: 12px 20px;
  border-radius: 40px;
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255,255,255,0.1);
  z-index: 1;
}

.controls button {
  padding: 8px 16px;
  border-radius: 20px;
  border: none;
  background: transparent;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.controls button:hover {
  background: rgba(255,255,255,0.15);
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.modal-content {
  width: 98%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-content h2 {
  margin-top: 0;
  color: #00ffc3;
  text-align: center;
  font-size: 1.5rem;
  border-bottom: 1px solid #333;
  padding-bottom: 10px;
}

.modal-content h3 {
  color: #aaa;
  font-size: 1rem;
  margin-top: 20px;
  margin-bottom: 10px;
  text-transform: uppercase;
  text-align: center;
}

/* TREE VISUAL LAYOUT */
.tree-visual-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 10px 0;
}

.tree-level {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tree-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 8px 4px;
  min-width: 45px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.2s;
}

.tree-node:hover {
  background: rgba(0, 255, 195, 0.1);
  border-color: #00ffc3;
  transform: scale(1.05);
}

.node-morse {
  font-family: monospace;
  color: #00ffc3;
  font-size: 0.8rem;
  font-weight: bold;
  margin-bottom: 2px;
}

.node-key {
  font-weight: bold;
  color: #fff;
  font-size: 1rem;
}

/* Niveles */
.level-1 { background: rgba(0, 255, 195, 0.15); border-color: rgba(0, 255, 195, 0.3); min-width: 60px; }
.level-2 { min-width: 55px; }
.level-3 { min-width: 45px; }
.level-4 { min-width: 40px; padding: 6px 2px; }

.level-4-group {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: max-content;
  padding: 10px;
}

.tree-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #00ffc3 transparent;
}

.tree-scroll-wrapper::-webkit-scrollbar {
  height: 4px;
}

.tree-scroll-wrapper::-webkit-scrollbar-thumb {
  background: #00ffc3;
  border-radius: 10px;
}

.node-spacer {
  width: 20px;
}

/* NUMBERS & CODES */
.tree-container {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.tree-col {
  flex: 1;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  font-family: monospace;
  margin-bottom: 4px;
}

.item-row .key { font-weight: bold; color: #fff; }
.item-row .val { color: #00ffc3; }

.code-list { width: 100%; }
.code-item {
  display: grid;
  grid-template-columns: 80px 120px 1fr;
  padding: 10px;
  border-bottom: 1px solid #222;
  align-items: center;
}
.code-item .code-key { font-weight: bold; color: #fff; }
.code-item .code-morse { color: #00ffc3; font-family: monospace; }
.code-item .code-desc { color: #888; font-size: 0.85rem; }

@media (max-width: 600px) {
  .level-4-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .tree-node {
    min-width: 38px;
    padding: 5px 2px;
  }
  .node-morse { font-size: 0.7rem; }
  .node-key { font-size: 0.9rem; }
  
  .code-item {
    grid-template-columns: 60px 90px 1fr;
    font-size: 0.8rem;
  }
}
