/* ============================== */
/* ROOT VARIABLES */
:root {
  --primary-color: #00e385;
  --primary-button-top: #00c878;
  --primary-button-bottom: #00a45e;
  --primary-button-border: #008f55;
  --secondary-color: #303030;
  --dash-color: #606060;
  --background-color: #1a1a1a;
  --grid-size: 32px;
  --grid-line: rgba(255, 255, 255, 0.03);
  --grid-line-major: rgba(255, 255, 255, 0.06);
  --screen-color: #0a0a0a;
  --shadow-color: rgba(0, 0, 0, 0.6);
  --text-color: #d0d0d0;
  --section-padding: 12px 10px;
  --metal-gradient: linear-gradient(145deg, #303030, #252525);
  --screen-shader: repeating-linear-gradient(to bottom, transparent 0, transparent 2px, rgba(0, 227, 133, 0.025) 2px, rgba(0, 227, 133, 0.025) 3px);
  --screen-glow: 0 0 5px rgba(0, 227, 133, 0.4);
}

/* ============================== */
/* RESET */
* {
  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;
}

/* ============================== */
/* BASE LAYOUT */
body {
  background-color: var(--background-color);
  background-image: repeating-linear-gradient(to right, var(--grid-line-major) 0 1px, transparent 1px calc(var(--grid-size) * 4)), repeating-linear-gradient(to bottom, var(--grid-line-major) 0 1px, transparent 1px calc(var(--grid-size) * 4)), repeating-linear-gradient(to right, var(--grid-line) 0 1px, transparent 1px var(--grid-size)), repeating-linear-gradient(to bottom, var(--grid-line) 0 1px, transparent 1px var(--grid-size));
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  color: var(--text-color);
}

/* ============================== */
/* CONTAINER */
.container {
  max-width: 1440px;
  width: 100%;
  background: var(--metal-gradient);
  box-shadow:
    0 18px 34px var(--shadow-color),
    inset 0 1px rgba(255, 255, 255, 0.04);
  padding: 28px;
  border: 1px solid #4a4a4a;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
.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);
}
.container::after {
  display: none;
}

/* ============================== */
/* TYPOGRAPHY */
h1 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 0;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 3px;
  text-shadow: 0 0 5px rgba(0, 227, 133, 0.6);
  border-bottom: 2px solid #404040;
  padding-bottom: 15px;
}
h1::after {
  display: none;
}
h2 {
  color: var(--primary-color);
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}
h3 {
  color: var(--primary-color);
  margin-bottom: 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
h4 {
  font-size: 12px;
  color: var(--text-color);
  border-bottom: 1px solid #404040;
  padding-bottom: 5px;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

/* ============================== */
/* TRANSLATOR BOX */
.content-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: stretch;
  min-width: 0;
}
.primary-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.translator-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.translator-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.input-area,
.output-area {
  background: linear-gradient(145deg, #2b2b2b, #222);
  padding: var(--section-padding);
  border: 1px solid #484848;
  border-radius: 8px;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.04),
    0 3px 8px rgba(0, 0, 0, 0.28);
}
.audio-controls {
  background: #1e1e1e;
  border: 1px solid #404040;
  border-radius: 8px;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.03),
    0 3px 8px rgba(0, 0, 0, 0.24);
  padding: var(--section-padding);
}
.audio-controls-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.audio-controls-header h2 {
  margin: 0;
}
.audio-controls-header span {
  color: #888;
  font-size: 12px;
}
label {
  display: block;
  margin-bottom: 9px;
  color: var(--primary-color);
  font-weight: bold;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
textarea {
  width: 100%;
  min-height: 112px;
  padding: 12px;
  font-size: 16px;
  font-family: "Courier New", monospace;
  border: 1px solid #444;
  border-radius: 6px;
  background-color: var(--screen-color);
  background-image: var(--screen-shader);
  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;
}

/* ============================== */
/* CONTROLS */
.output-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px solid #404040;
  padding-bottom: 12px;
}
.output-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.output-actions .btn {
  height: 40px;
  min-height: 40px;
  white-space: nowrap;
}
.controls-container {
  background: #1e1e1e;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  border: 0;
  box-shadow: none;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #2a2a2a;
  padding: 8px 6px;
  border: 1px solid #444;
  border-radius: 6px;
  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;
  border-radius: 5px;
  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;
  border-radius: 5px;
  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);
}

/* ============================== */
/* BUTTONS */
.btn {
  --button-top: #3b3b3b;
  --button-bottom: #252525;
  --button-border: #4b4b4b;
  --button-text: var(--primary-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  background: linear-gradient(to bottom, var(--button-top), var(--button-bottom));
  background-clip: padding-box;
  -webkit-appearance: none;
  appearance: none;
  color: var(--button-text);
  cursor: pointer;
  font:
    700 14px/1 "Courier New",
    monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition:
    transform 0.1s ease,
    filter 0.1s ease,
    box-shadow 0.1s ease;
}
.btn:hover {
  filter: brightness(1.12);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.btn:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 3px;
}
.btn:disabled {
  --button-top: #2a2a2a;
  --button-bottom: #202020;
  --button-border: #303030;
  --button-text: #666;
  cursor: not-allowed;
  filter: none;
  box-shadow: none;
}
.btn--primary {
  --button-top: var(--primary-button-top);
  --button-bottom: var(--primary-button-bottom);
  --button-border: var(--primary-button-border);
  --button-text: #062116;
}
.btn--primary:hover {
  --button-top: #22f39b;
  --button-bottom: #00b86f;
}
.btn--secondary {
  --button-top: #3b3b3b;
  --button-bottom: #252525;
  --button-border: #4b4b4b;
  --button-text: var(--primary-color);
}
.btn.is-success {
  --button-top: var(--primary-button-top);
  --button-bottom: var(--primary-button-bottom);
  --button-border: var(--primary-button-border);
  --button-text: #062116;
}
.btn--toggle {
  min-height: 34px;
  padding: 8px 12px;
  font-size: 12px;
  letter-spacing: 0.5px;
}
.btn--toggle.is-active {
  --button-top: var(--primary-button-top);
  --button-bottom: var(--primary-button-bottom);
  --button-border: var(--primary-button-border);
  --button-text: #062116;
}
.btn--wide {
  width: 100%;
}
.btn--support {
  --button-top: #ff7043;
  --button-bottom: #e64a19;
  --button-border: #bf360c;
  --button-text: #fff;
}
.btn--primary.is-playing {
  --button-top: #e53935;
  --button-bottom: #c62828;
  --button-border: #b71c1c;
  --button-text: #fff;
}

/* ============================== */
/* COPY BUTTON */

/* ============================== */
/* MORSE VISUAL */
.morse-visual {
  min-height: 58px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin-bottom: 12px;
  padding: 14px;
  background-color: var(--screen-color);
  background-image: var(--screen-shader);
  border: 1px solid #444;
  border-radius: 6px;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
  position: relative;
  overflow-x: auto;
}
.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;
}
.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;
}
.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 */
.morse-text {
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: var(--primary-color);
  word-break: break-all;
  line-height: 1.6;
  min-height: 52px;
  padding: 14px;
  background-color: var(--screen-color);
  background-image: var(--screen-shader);
  border: 1px solid #444;
  border-radius: 6px;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
  letter-spacing: 2px;
  margin-bottom: 10px;
}

/* ============================== */
/* INFO BOX */
.info-box {
  margin-top: 0;
  background: #1e1e1e;
  padding: var(--section-padding);
  border: 1px solid #404040;
  border-radius: 8px;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.03),
    0 3px 8px rgba(0, 0, 0, 0.28);
}
.morse-guide {
  display: flex;
  gap: 20px;
}
.dot-example,
.dash-example {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-color);
}

/* ============================== */
/* 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;
}
::-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 */
::selection,
::-moz-selection {
  background: var(--primary-color);
  color: #000;
  text-shadow: none;
}

/* ============================== */
/* RESPONSIVE 600PX */
@media (max-width: 600px) {
  .container {
    padding: 18px 12px 12px;
  }
  .morse-guide {
    flex-direction: column;
    gap: 10px;
  }
  .controls-container {
    grid-template-columns: 1fr;
  }
  .output-header {
    align-items: flex-start;
  }
  .output-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .output-actions .btn {
    width: 100%;
    padding-inline: 8px;
    font-size: 12px;
  }
  .btn--support {
    width: 100%;
    justify-content: center;
  }
}
@media (max-width: 360px) {
  .output-actions {
    gap: 6px;
  }
  .output-actions .btn {
    padding-inline: 6px;
    font-size: 10px;
    letter-spacing: 0.5px;
  }
}

/* ============================== */
/* RESPONSIVE 601PX */
@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 */
.reference-section {
  margin-top: 0;
  border-radius: 0;
  padding: 0;
  min-width: 0;
}
.reference-section .btn--toggle {
  justify-content: center;
  text-align: center;
}
.instructions-box {
  background: #1e1e1e;
  padding: var(--section-padding);
  border: 1px solid #404040;
  border-radius: 8px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.28);
  margin-bottom: 20px;
}
.instructions-list {
  display: grid;
  gap: 8px;
  padding: 0;
  list-style: none;
  color: var(--text-color);
  font-size: 14px;
}
.instructions-list li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  background: #252525;
  border: 1px solid #444;
  border-radius: 6px;
}
.instruction-number {
  color: var(--primary-color);
  font-weight: bold;
}
.instruction-text {
  min-width: 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.symbol-reference {
  background: #1e1e1e;
  padding: var(--section-padding);
  border: 1px solid #404040;
  border-radius: 8px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.28);
}
.reference-category {
  margin-top: 15px;
}

/* ============================== */
/* REFERENCE GRID */
.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 15px;
}
.ref-item {
  display: flex;
  overflow: hidden;
  border: 1px solid #333;
  border-radius: 5px;
  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;
}
.reference-grid.hidden {
  display: none;
}

/* ============================== */
/* WORD SEPARATOR OVERRIDES */
.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 */
.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;
}

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

/* ============================== */
/* MODE SWITCH */
.mode-switch-container {
  display: flex;
  justify-content: flex-start;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.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: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.toggle-buttons .btn {
  width: 100%;
}

/* ============================== */
/* ENHANCED INPUT VALIDATION */
textarea:focus {
  border-color: var(--primary-color) !important;
  box-shadow: 0 0 5px rgba(0, 227, 133, 0.3);
}

/* ============================== */
/* MOBILE LAYOUT */
@media (max-width: 768px) {
  body {
    align-items: flex-start;
    padding: 12px;
  }
  .content-columns {
    gap: 18px;
  }
  .letters-section h4 {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .toggle-buttons-container {
    justify-content: center;
  }
  .toggle-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
  }
  .btn--toggle {
    width: 100%;
    padding: 9px 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
  }
  .reference-section {
    border-radius: 0;
    background: transparent;
    padding: 0;
    max-height: none;
    overflow: visible;
    position: static;
  }
  .footer {
    margin-top: 4px;
  }
}

/* ============================== */
/* DESKTOP LAYOUT */
@media (min-width: 1024px) {
  .container {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
    grid-template-areas:
      "header header"
      "content content"
      "footer footer";
    align-items: start;
  }
  h1 {
    grid-area: header;
  }
  .content-columns {
    grid-area: content;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
    grid-template-rows: min-content;
    align-items: stretch;
    min-height: 0;
  }
  .primary-column {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .reference-section {
    grid-column: 2;
    grid-row: 1;
    height: 100%;
    min-height: 0;
    max-height: none;
    align-self: stretch;
    contain: size;
    margin-top: 0;
    border-radius: 8px;
    background: transparent;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    position: sticky;
    top: 20px;
  }
  .instructions-box,
  .symbol-reference {
    padding: var(--section-padding);
    box-shadow: none;
  }
  .reference-section > .instructions-box > h3,
  .reference-section > .symbol-reference > h3 {
    text-align: center;
  }
  .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;
  }
}
