:root {
  --gold: #D4AF37;
  --gold-light: #F5D978;
  --gold-dark: #9A7D1E;
  --indigo: #6C5CE7;
  --indigo-light: #a29bfe;
  --indigo-dark: #4834B8;
  --bg: #080A14;
  --surface: rgba(255,255,255,0.04);
  --surface-hover: rgba(255,255,255,0.07);
  --glass: rgba(255,255,255,0.05);
  --glass-border: rgba(255,255,255,0.1);
  --text: #EEE8FF;
  --muted: rgba(255,255,255,0.38);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
}

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

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ===== Noise texture ===== */
.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

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

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.2;
  animation: drift 20s ease-in-out infinite alternate;
}

.orb-1 {
  width: 500px; height: 500px;
  background: var(--indigo);
  top: -150px; left: -150px;
  animation-duration: 18s;
}

.orb-2 {
  width: 400px; height: 400px;
  background: var(--gold);
  bottom: -100px; right: -100px;
  opacity: 0.15;
  animation-duration: 22s;
  animation-delay: -5s;
}

.orb-3 {
  width: 300px; height: 300px;
  background: #00CEC9;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.08;
  animation-duration: 15s;
  animation-delay: -10s;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(40px, 30px) scale(1.08); }
}

/* ===== App ===== */
.app {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  animation: fadeSlideDown 0.7s cubic-bezier(.22,1,.36,1) both;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 52px; height: 52px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 18px rgba(212,175,55,0.4));
  animation: pulse-glow 4s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 14px rgba(212,175,55,0.35)); }
  50%       { filter: drop-shadow(0 0 28px rgba(212,175,55,0.6)); }
}

.logo-title {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(125deg, #F5D978 10%, #D4AF37 40%, #a29bfe 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.lang-chips {
  display: flex;
  gap: 6px;
}

.chip {
  font-family: 'Sora', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  padding: 5px 12px;
  border-radius: 50px;
  border: 1px solid var(--glass-border);
  color: var(--muted);
  background: var(--glass);
  cursor: default;
  transition: all 0.2s;
}

.chip.active {
  background: rgba(212,175,55,0.15);
  border-color: rgba(212,175,55,0.4);
  color: var(--gold-light);
}

/* ===== Lang selector bar ===== */
.lang-selector-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 1.8rem;
  animation: fadeSlideDown 0.7s 0.1s cubic-bezier(.22,1,.36,1) both;
}

.selector-group {
  flex: 1;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.selector-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  padding-right: 4px;
}

.selector-input {
  appearance: none;
  -webkit-appearance: none;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 1rem;
  font-family: 'Cairo', sans-serif;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  outline: none;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.selector-input:hover {
  border-color: rgba(212,175,55,0.35);
  background: var(--surface-hover);
}

.selector-input:focus {
  border-color: rgba(212,175,55,0.55);
  box-shadow: 0 0 0 3px rgba(212,175,55,0.1);
}

.selector-input option { background: #12152A; }

.swap-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, var(--indigo), var(--indigo-dark));
  border: none;
  border-radius: 50px;
  padding: 12px 20px;
  color: #fff;
  font-family: 'Cairo', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 22px;
  transition: all 0.3s cubic-bezier(.4,2,.6,1);
  box-shadow: 0 4px 20px rgba(108,92,231,0.4);
  flex-shrink: 0;
}

.swap-pill:hover {
  box-shadow: 0 6px 28px rgba(108,92,231,0.6);
  transform: translateY(-1px);
}

.swap-pill.spinning svg {
  animation: spin-anim 0.5s ease;
}

@keyframes spin-anim {
  from { transform: rotate(0deg); }
  to   { transform: rotate(180deg); }
}

/* ===== Panels ===== */
.panels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  align-items: stretch;
  animation: fadeSlideUp 0.7s 0.2s cubic-bezier(.22,1,.36,1) both;
  min-height: 380px;
}

.panel {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.panel:focus-within {
  border-color: rgba(212,175,55,0.3);
  box-shadow: 0 0 0 3px rgba(212,175,55,0.07), 0 12px 40px rgba(0,0,0,0.3);
}

.panel-source { border-radius: var(--radius-lg) var(--radius-sm) var(--radius-sm) var(--radius-lg); }
.panel-result { border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-sm); }

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.02);
}

.panel-lang-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-family: 'Sora', sans-serif;
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-lang-tag::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}

.panel-lang-tag.accent { color: var(--indigo-light); }
.panel-lang-tag.accent::before { background: var(--indigo-light); box-shadow: 0 0 8px var(--indigo-light); }

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

.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 50px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--muted);
  font-family: 'Cairo', sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  border-color: rgba(212,175,55,0.35);
  color: var(--gold-light);
  background: rgba(212,175,55,0.08);
}

.action-btn.success {
  border-color: rgba(0,210,164,0.4);
  color: #00D4AA;
  background: rgba(0,210,164,0.08);
}

.action-btn.speaking {
  border-color: rgba(108,92,231,0.4);
  color: var(--indigo-light);
  background: rgba(108,92,231,0.1);
}

.panel-input {
  flex: 1;
  width: 100%;
  padding: 20px 22px;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Cairo', sans-serif;
  font-size: 1.08rem;
  line-height: 1.9;
  color: var(--text);
}

.panel-input::placeholder { color: var(--muted); }

.char-count {
  padding: 8px 22px 14px;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: 'Sora', sans-serif;
  text-align: left;
}

html[dir="rtl"] .char-count { text-align: right; }

/* ===== Divider ===== */
.panel-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  gap: 0;
}

.divider-line {
  flex: 1;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--glass-border) 40%, var(--glass-border) 60%, transparent);
}

.divider-badge {
  position: relative;
  width: 44px; height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  flex-shrink: 0;
  margin: 10px 0;
}

.arrow-icon { color: var(--gold); }

.spinner-ring {
  display: none;
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--gold);
  border-right-color: rgba(212,175,55,0.3);
  animation: spin-ring 0.8s linear infinite;
}

.spinner-ring.active { display: block; }

@keyframes spin-ring {
  to { transform: rotate(360deg); }
}

/* ===== Result area ===== */
.panel-output {
  flex: 1;
  padding: 20px 22px;
  position: relative;
}

.loading-dots {
  display: none;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.loading-dots.active { display: flex; }

.loading-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--indigo-light);
  animation: bounce-dot 1s infinite ease-in-out;
}

.loading-dots span:nth-child(2) { animation-delay: 0.15s; background: var(--gold); }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; background: #00D4AA; }

@keyframes bounce-dot {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50%       { transform: translateY(-8px); opacity: 1; }
}

.result-text {
  font-family: 'Cairo', sans-serif;
  font-size: 1.08rem;
  line-height: 1.9;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 200px;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.result-text.fade-in { animation: fadeIn 0.5s ease forwards; }

.placeholder-hint {
  color: var(--muted);
  font-size: 0.92rem;
  font-style: italic;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0,212,170,0.15);
  border: 1px solid rgba(0,212,170,0.35);
  color: #00D4AA;
  padding: 12px 28px;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 600;
  backdrop-filter: blur(20px);
  transition: transform 0.35s cubic-bezier(.22,1,.36,1), opacity 0.35s;
  opacity: 0;
  z-index: 100;
}

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

/* ===== Animations ===== */
@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

  .panel-divider {
    flex-direction: row;
    padding: 0;
  }

  .divider-line {
    flex: 1;
    height: 1px;
    width: auto;
    background: linear-gradient(to right, transparent, var(--glass-border) 40%, var(--glass-border) 60%, transparent);
  }

  .panel-source { border-radius: var(--radius-lg); }
  .panel-result { border-radius: var(--radius-lg); }

  .header {
    flex-direction: column;
    gap: 14px;
    align-items: flex-start;
  }

  .lang-selector-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .selector-group { max-width: 100%; }

  .swap-pill { align-self: center; margin-top: 0; }

  .logo-title { font-size: 1.6rem; }
}
