:root {
  --bg:           #06080f;
  --surface:      rgba(255, 255, 255, 0.04);
  --surface-mid:  rgba(255, 255, 255, 0.07);
  --border:       rgba(255, 255, 255, 0.08);
  --border-accent:rgba(100, 255, 218, 0.22);
  --accent:       #64ffda;
  --accent-dim:   rgba(100, 255, 218, 0.12);
  --accent-glow:  rgba(100, 255, 218, 0.25);
  --danger:       #ff6464;
  --danger-dim:   rgba(255, 100, 100, 0.12);
  --text:         #c8d3e0;
  --text-dim:     #525e6e;
  --text-bright:  #eaf0f8;
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    18px;
  --neo-shadow:   3px 3px 10px rgba(0,0,0,.45), -1px -1px 5px rgba(255,255,255,.025);
  --neo-inset:    inset 2px 2px 6px rgba(0,0,0,.4), inset -1px -1px 4px rgba(255,255,255,.02);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ── Background orbs ───────────────────────────────────────────── */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
}

.orb-1 {
  width: 480px; height: 480px;
  background: radial-gradient(circle, rgba(100,255,218,.18), transparent 70%);
  top: -160px; left: -140px;
  animation: drift1 18s ease-in-out infinite alternate;
}

.orb-2 {
  width: 560px; height: 560px;
  background: radial-gradient(circle, rgba(124,58,237,.16), transparent 70%);
  bottom: -180px; right: -160px;
  animation: drift2 22s ease-in-out infinite alternate;
}

.orb-3 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(56,189,248,.1), transparent 70%);
  top: 50%; left: 55%;
  animation: drift3 15s ease-in-out infinite alternate;
}

@keyframes drift1 { to { transform: translate(40px, 30px); } }
@keyframes drift2 { to { transform: translate(-35px, -25px); } }
@keyframes drift3 { to { transform: translate(-20px, 30px); } }

/* ── Layout ────────────────────────────────────────────────────── */
.container {
  position: relative;
  z-index: 1;
  max-width: 860px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.signal-bars {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 4px;
  height: 36px;
  margin-bottom: 1.1rem;
}

.signal-bars span {
  width: 4px;
  background: var(--accent);
  border-radius: 3px;
  animation: pulse 1.4s ease-in-out infinite;
}

.signal-bars span:nth-child(1) { height: 10px; animation-delay: 0s; }
.signal-bars span:nth-child(2) { height: 20px; animation-delay: .18s; }
.signal-bars span:nth-child(3) { height: 30px; animation-delay: .36s; }
.signal-bars span:nth-child(4) { height: 36px; animation-delay: .54s; }

@keyframes pulse {
  0%, 100% { opacity: .25; }
  50%       { opacity: 1;   }
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -.025em;
  color: var(--text-bright);
}

header p {
  color: var(--text-dim);
  font-size: .9rem;
  margin-top: .4rem;
  letter-spacing: .01em;
}

/* ── Glass base ────────────────────────────────────────────────── */
.glass {
  background: var(--surface);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ── Mode toggle ───────────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  width: fit-content;
  margin: 0 auto 1.75rem;
  gap: 3px;
}

.mode-btn {
  padding: .45rem 1.4rem;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .88rem;
  font-family: inherit;
  transition: color .2s, background .2s, box-shadow .2s;
}

.mode-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--border-accent);
}

.mode-btn:not(.active):hover { color: var(--text); }

/* ── Panels ────────────────────────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 1fr 48px 1fr;
  gap: .75rem;
  margin-bottom: 1.25rem;
  align-items: stretch;
}

.panel {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
}

.panel-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-dim);
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, background .2s, border-color .2s, box-shadow .2s;
  /* neumorphic feel */
  box-shadow: var(--neo-shadow);
}

.icon-btn:hover {
  background: var(--surface-mid);
  color: var(--accent);
  border-color: var(--border-accent);
}

textarea#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-bright);
  font-family: inherit;
  font-size: .98rem;
  resize: none;
  line-height: 1.7;
  min-height: 160px;
}

textarea#input::placeholder { color: var(--text-dim); opacity: .7; }

.output-area {
  flex: 1;
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 1.05rem;
  line-height: 2;
  letter-spacing: .14em;
  color: var(--accent);
  word-break: break-all;
  min-height: 160px;
  overflow-y: auto;
  padding: 2px 0;
}

.char-count {
  font-size: .72rem;
  color: var(--text-dim);
  text-align: right;
  margin-top: .6rem;
}

/* ── Divider arrow ─────────────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrow-wrap {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(255,255,255,.03);
  box-shadow: var(--neo-shadow);
  color: var(--text-dim);
  font-size: 1rem;
  flex-shrink: 0;
}

/* ── Audio controls ────────────────────────────────────────────── */
.audio-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 1.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.play-btn {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .6rem 1.3rem;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: .88rem;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
  transition: all .2s;
  box-shadow: var(--neo-shadow);
}

.play-btn:hover {
  background: rgba(100,255,218,.18);
  box-shadow: 0 0 18px var(--accent-glow), var(--neo-shadow);
}

.play-btn.playing {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(255,100,100,.3);
}

.play-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
  box-shadow: none;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex: 1;
  min-width: 200px;
}

.speed-label {
  font-size: .75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: box-shadow .2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 16px var(--accent-glow), 0 0 4px var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.speed-val {
  color: var(--accent);
  font-weight: 700;
  font-size: .8rem;
  min-width: 58px;
  text-align: right;
}

/* ── Reference table ───────────────────────────────────────────── */
.ref-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .8rem 1.25rem;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  font-size: .88rem;
  letter-spacing: .02em;
  transition: color .2s;
  margin-bottom: .6rem;
  border-radius: var(--radius-md) !important;
}

.ref-toggle:hover { color: var(--text); }

.ref-table {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: .45rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
}

.ref-table.open { display: grid; }

.ref-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .5rem .35rem;
  background: rgba(255,255,255,.025);
  border: 1px solid rgba(255,255,255,.04);
  border-radius: var(--radius-sm);
  gap: 3px;
  transition: background .15s, border-color .15s;
}

.ref-item:hover {
  background: var(--accent-dim);
  border-color: rgba(100,255,218,.15);
}

.ref-char {
  font-weight: 700;
  color: var(--text-bright);
  font-size: .88rem;
}

.ref-code {
  font-family: 'Courier New', monospace;
  font-size: .7rem;
  color: var(--accent);
  letter-spacing: .1em;
}

/* ── Toast notification ────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(100,255,218,.15);
  border: 1px solid var(--border-accent);
  color: var(--accent);
  padding: .6rem 1.4rem;
  border-radius: 50px;
  font-size: .85rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .panels {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .divider {
    justify-content: center;
    padding: .2rem 0;
  }

  .arrow-wrap {
    transform: rotate(90deg);
  }

  h1 { font-size: 1.5rem; }

  .audio-controls {
    flex-direction: column;
    align-items: stretch;
    gap: .9rem;
  }

  .play-btn { justify-content: center; }

  .speed-control { min-width: unset; }

  .ref-table {
    grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  }
}
