:root {
  --primary-color: #00e385;
  --secondary-color: #303030;
  --dash-color: #606060;
  --background-color: #1a1a1a;
  --panel-color: #252525;
  --screen-color: #0a0a0a;
  --shadow-color: rgba(0, 0, 0, 0.6);
  --text-color: #d0d0d0;
  --metal-gradient: linear-gradient(145deg, #303030, #252525);
  --screen-glow: 0 0 5px rgba(0, 227, 133, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Courier New", monospace;
  scrollbar-width: thin;
  scrollbar-color: #333 #1a1a1a;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

body {
  background-color: var(--background-color);
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23303030' fill-opacity='0.3' fill-rule='evenodd'%3E%3Cpath d='M0 20L20 0h20v20L20 40H0z'/%3E%3C/g%3E%3C/svg%3E");
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  color: var(--text-color);
}

::selection {
  background-color: #00e385;
  color: #0a0a0a;
}

.container {
  max-width: 1400px;
  width: 100%;
  background: var(--metal-gradient);
  box-shadow: 0 10px 20px var(--shadow-color);
  padding: 25px;
  border: 1px solid #404040;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(90deg, var(--secondary-color), var(--secondary-color) 10px, #404040 10px, #404040 12px);
}

h1 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 25px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 0 0 5px rgba(0, 227, 133, 0.6);
  border-bottom: 2px solid #404040;
  padding-bottom: 15px;
}

h1::after {
  display: none;
}

.translator-box {
  display: flex;
  flex-direction: column;
  gap: 17px;
}

.input-area,
.output-area {
  background-color: var(--panel-color);
  padding: 15px;
  border: 1px solid #404040;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
}

label {
  display: block;
  margin-bottom: 10px;
  color: var(--primary-color);
  font-weight: bold;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

textarea {
  width: 100%;
  min-height: 100px;
  padding: 10px;
  font-size: 16px;
  font-family: "Courier New", monospace;
  border: 1px solid #444;
  background-color: var(--screen-color);
  color: var(--primary-color);
  resize: vertical;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5), var(--screen-glow);
}

textarea::selection {
  background-color: var(--primary-color);
  color: #000;
}

.output-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 1px solid #404040;
  padding-bottom: 10px;
}

.controls-container {
  background: #1e1e1e;
  padding: 15px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  border: 1px solid #404040;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #2a2a2a;
  padding: 10px;
  border: 1px solid #444;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  background: #000;
  outline: none;
  border: 1px solid #444;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 22px;
  background: linear-gradient(to bottom, #666, #333);
  border: 1px solid #222;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 22px;
  background: linear-gradient(to bottom, #666, #333);
  cursor: pointer;
  border: 1px solid #222;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

select {
  padding: 8px 10px;
  border: 1px solid #444;
  background: #111 url("data:image/svg+xml;utf8,<svg fill='%23888' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>") no-repeat right 10px center;
  color: var(--text-color);
  font: 14px "Courier New", monospace;
  outline: none;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
  -webkit-appearance: none;
  appearance: none;
}

select:focus {
  border-color: var(--primary-color);
}

h2 {
  color: var(--primary-color);
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}

button {
  background: linear-gradient(to bottom, #333, #222);
  color: var(--primary-color);
  border: 1px solid #444;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  text-transform: uppercase;
  letter-spacing: 1px;
}

button:hover {
  background: linear-gradient(to bottom, #444, #333);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

button:disabled {
  background: #2a2a2a;
  color: #666;
  cursor: not-allowed;
  box-shadow: none;
}

/* Style for the stop button */
button.playing {
  background: linear-gradient(to bottom, #e53935, #c62828);
  color: white;
  border-color: #b71c1c;
}

button.playing:hover {
  background: linear-gradient(to bottom, #f44336, #d32f2f);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

button.playing:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Download button container for better placement */
.download-btn-container {
  display: flex;
  justify-content: center;
  padding: 15px 0;
  background: #1e1e1e;
  border: 1px solid #404040;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
}

#download-btn {
  background: linear-gradient(to bottom, #333, #222);
  color: var(--primary-color);
  border: 1px solid #444;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  text-transform: uppercase;
  letter-spacing: 1px;
  width: auto;
  min-width: 200px;
  justify-content: center;
  margin-left: 0;
}

.morse-visual {
  min-height: 50px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin-bottom: 15px;
  padding: 12px;
  background-color: var(--screen-color);
  border: 1px solid #444;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
  position: relative;
  overflow-x: auto;
}

/* Clean dots and dashes */
.dot {
  width: 4px;
  height: 4px;
  background-color: var(--primary-color);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 3px var(--primary-color);
  margin: 0 1px;
}

.dash {
  width: 12px;
  height: 4px;
  background-color: var(--dash-color);
  display: inline-block;
  box-shadow: 0 0 3px var(--primary-color);
  margin: 0 1px;
}

/* Simple letter container */
.letter-container {
  display: inline-flex;
  align-items: center;
  height: 16px;
  margin: 0;
  padding: 2px 3px;
  background-color: transparent;
}

.letter-space {
  width: 4px;
  display: inline-block;
}

/* Improved word separator */
.word-separator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 8px;
  height: 16px;
  position: relative;
}

.word-separator::after {
  content: "";
  width: 2px;
  height: 16px;
  background: var(--primary-color);
  box-shadow: 0 0 4px rgba(0, 227, 133, 0.6);
}

.morse-text {
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: var(--primary-color);
  word-break: break-all;
  line-height: 1.6;
  padding: 15px;
  background-color: var(--screen-color);
  border: 1px solid #444;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
  letter-spacing: 2px;
  margin-bottom: 10px;
}

.copy-btn {
  background: linear-gradient(to bottom, #333, #222);
  color: var(--primary-color);
  border: 1px solid #444;
  padding: 10px 20px;
  cursor: pointer;
  font: bold 12px/1 "Courier New", monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.copy-btn:hover {
  background: linear-gradient(to bottom, #444, #333);
}

.copy-btn:active {
  transform: none;
  background: linear-gradient(to bottom, #222, #111);
}

.copy-btn.copied {
  background: linear-gradient(to bottom, var(--primary-color), #00c374);
  color: #000;
}

.info-box {
  margin-top: -5px;
  background: #1e1e1e;
  padding: 15px;
  border: 1px solid #404040;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
}

h3 {
  color: var(--primary-color);
  margin-bottom: 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.morse-guide {
  display: flex;
  gap: 20px;
}

.dot-example,
.dash-example {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-color);
}

/* Add scan lines effect to screens */
.morse-visual::before,
.morse-text::before,
textarea::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, transparent 0%, rgba(0, 227, 133, 0.02) 50%, transparent 100%);
  background-size: 100% 2px;
  pointer-events: none;
  z-index: 2;
}

.container::after {
  display: none;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
  background: #1a1a1a;
}
::-webkit-scrollbar-track {
  background: #1a1a1a;
  border: 1px solid #333;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
::-webkit-scrollbar-thumb {
  background: linear-gradient(to right, #252525, #333);
  border: 1px solid #444;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(to right, #333, #444);
}
::-webkit-scrollbar-corner {
  background: #1a1a1a;
}

/* Add scanline effect to the scrollbar thumb for extra tactical feel */
::-webkit-scrollbar-thumb::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(to bottom, transparent, transparent 2px, rgba(0, 227, 133, 0.05) 2px, rgba(0, 227, 133, 0.05) 4px);
  pointer-events: none;
}

/* Selection styling */
::selection,
::-moz-selection {
  background: var(--primary-color);
  color: #000;
  text-shadow: none;
}

@media (max-width: 600px) {
  .container {
    padding: 10px 5px;
  }

  .morse-guide {
    flex-direction: column;
    gap: 10px;
  }

  .controls-container {
    grid-template-columns: 1fr;
  }

  .output-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .output-header button {
    margin-top: 5px;
    width: 100%;
    justify-content: center;
  }

  #download-btn {
    margin-left: 0;
  }

  .bmc-button {
    width: 100%;
    justify-content: center;
  }
}

@media (min-width: 601px) {
  .reference-table td {
    padding: 8px 12px;
    font-size: 15px;
  }

  .ref-char {
    padding: 4px 8px;
    font-size: 15px;
    min-width: 24px;
  }

  .ref-code {
    font-size: 15px;
    letter-spacing: 2px;
  }
}

/* Reference section styles */
.reference-section {
  margin-top: 0;
  border-top: 2px solid #404040;
  padding-top: 20px;
}

.instructions-box {
  background: #1e1e1e;
  padding: 15px;
  padding-left: 30px;
  padding-bottom: 0px;
  border: 1px solid #404040;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
  margin-bottom: 20px;
}

.instructions-list {
  padding-left: 25px;
  color: var(--text-color);
  line-height: 1.6;
}

.instructions-list li {
  margin-bottom: 8px;
}

.symbol-reference {
  background: #1e1e1e;
  padding: 15px;
  border: 1px solid #404040;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.4);
}

.reference-category {
  margin-top: 15px;
}

h4 {
  font-size: 12px;
  color: var(--text-color);
  border-bottom: 1px solid #404040;
  padding-bottom: 5px;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

/* Reference Grid Styles */
.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 15px;
}

.ref-item {
  display: flex;
  border: 1px solid #333;
  background: #252525;
  align-items: stretch;
}

.ref-char {
  background: #333;
  color: var(--primary-color);
  padding: 8px 10px;
  font-weight: bold;
  min-width: 40px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid #444;
}

.ref-code {
  padding: 8px 10px;
  color: var(--text-color);
  font-family: monospace;
  flex-grow: 1;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* Word separator styles */
.word-separator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 4px;
  height: 16px;
}

.slash-char {
  color: var(--primary-color);
  font-size: 16px;
  font-weight: bold;
  opacity: 0.7;
  text-shadow: 0 0 4px var(--primary-color);
}

/* Footer styles */
.footer {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid #404040;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.footer .eng {
  color: var(--text-color);
  font-size: 14px;
  text-align: center;
  letter-spacing: 1px;
}

.footer .heart {
  color: #00e385;
  font-size: 16px;
  animation: pulse 1.5s infinite;
  display: inline-block;
}

.bmc-button {
  background: linear-gradient(to bottom, #ff5722, #e64a19);
  color: white;
  border: 1px solid #bf360c;
  padding: 10px 20px;
  margin-bottom: -4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: transform 0.1s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.bmc-button:hover {
  background: linear-gradient(to bottom, #ff7043, #f4511e);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.bmc-button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* Mode switch and toggle buttons */
.mode-switch-container {
  display: flex;
  justify-content: center;
}

.letters-section {
  margin-bottom: 20px;
}

.letters-section h4 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.toggle-buttons-container {
  margin-bottom: 10px;
  display: flex;
}

.toggle-buttons {
  display: flex;
  gap: 8px;
}

.toggle-btn {
  background: linear-gradient(to bottom, #333, #222);
  color: var(--text-color);
  border: 1px solid #444;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s ease;
}

.toggle-btn:hover {
  background: linear-gradient(to bottom, #444, #333);
  color: var(--primary-color);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.toggle-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.toggle-btn.active {
  background: linear-gradient(to bottom, var(--primary-color), #00c374);
  color: var(--background-color);
  font-weight: bold;
}

.toggle-btn.active:hover {
  background: linear-gradient(to bottom, #00f599, var(--primary-color));
  color: var(--background-color);
}

.reference-grid.hidden {
  display: none;
}

/* Enhanced input validation feedback */
textarea:focus {
  border-color: var(--primary-color) !important;
  box-shadow: 0 0 5px rgba(0, 227, 133, 0.3);
}

/* Mobile Styles */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .letters-section h4 {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .toggle-buttons-container {
    justify-content: center;
  }

  .toggle-buttons {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .toggle-btn {
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }
}

/* Desktop Layout */
@media (min-width: 1024px) {
  .container {
    grid-template-columns: 1fr 420px;
    grid-template-areas:
      "header header"
      "translator reference"
      "info reference"
      "footer footer";
    align-items: start;
  }

  h1 {
    grid-area: header;
  }

  .translator-box {
    grid-area: translator;
  }

  .info-box {
    grid-area: info;
    margin-top: 0;
  }

  .reference-section {
    grid-area: reference;
    margin-top: 0;
    border-top: none;
    border-left: 2px solid #404040;
    padding-top: 0;
    padding-left: 20px;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    position: sticky;
    top: 20px;
  }

  .reference-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .ref-char {
    min-width: 30px;
    padding: 4px 6px;
  }

  .ref-code {
    padding: 4px 6px;
  }

  .footer {
    grid-area: footer;
  }
}
