:root {
  --sky-top: #87ceeb;
  --sky-bottom: #b8e6ff;
  --sun: #ffd93d;
  --coral: #ff6b8a;
  --mint: #5ee0b0;
  --lavender: #b39ddb;
  --card: rgba(255, 255, 255, 0.92);
  --card-border: rgba(255, 255, 255, 0.8);
  --text: #2d3a4a;
  --text-soft: #6b7c93;
  --shadow: 0 12px 40px rgba(46, 120, 180, 0.18);
  --radius: 24px;
  --font-display: 'ZCOOL KuaiLe', 'Fredoka', cursive;
  --font-body: 'Fredoka', system-ui, sans-serif;
}

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

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--text);
  background: linear-gradient(165deg, var(--sky-top) 0%, var(--sky-bottom) 45%, #e8f7ff 100%);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Animated sky background ── */
.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 50px;
  filter: blur(1px);
  animation: drift linear infinite;
}

.cloud::before,
.cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 {
  width: 90px;
  height: 32px;
  top: 8%;
  left: -100px;
  animation-duration: 28s;
}

.cloud-1::before { width: 44px; height: 44px; top: -22px; left: 12px; }
.cloud-1::after { width: 56px; height: 36px; top: -16px; left: 36px; }

.cloud-2 {
  width: 70px;
  height: 26px;
  top: 18%;
  left: -80px;
  animation-duration: 35s;
  animation-delay: -12s;
  opacity: 0.7;
}

.cloud-2::before { width: 36px; height: 36px; top: -18px; left: 8px; }
.cloud-2::after { width: 44px; height: 30px; top: -12px; left: 28px; }

.cloud-3 {
  width: 110px;
  height: 36px;
  top: 5%;
  left: -120px;
  animation-duration: 42s;
  animation-delay: -20s;
  opacity: 0.55;
}

.cloud-3::before { width: 50px; height: 50px; top: -26px; left: 16px; }
.cloud-3::after { width: 62px; height: 40px; top: -18px; left: 44px; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 200px)); }
}

.bubble {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.9), rgba(255,255,255,0.15));
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  animation: float-up ease-in-out infinite;
}

.b1 { width: 18px; height: 18px; left: 12%; bottom: -20px; animation-duration: 9s; }
.b2 { width: 12px; height: 12px; left: 35%; bottom: -20px; animation-duration: 11s; animation-delay: -3s; }
.b3 { width: 22px; height: 22px; left: 68%; bottom: -20px; animation-duration: 13s; animation-delay: -6s; }
.b4 { width: 10px; height: 10px; left: 82%; bottom: -20px; animation-duration: 8s; animation-delay: -2s; }
.b5 { width: 16px; height: 16px; left: 52%; bottom: -20px; animation-duration: 10s; animation-delay: -8s; }

@keyframes float-up {
  0% { transform: translateY(0) scale(1); opacity: 0; }
  10% { opacity: 0.7; }
  90% { opacity: 0.5; }
  100% { transform: translateY(-100dvh) scale(0.6); opacity: 0; }
}

/* ── App layout ── */
.app {
  position: relative;
  z-index: 1;
  max-width: 420px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 12px) 20px max(env(safe-area-inset-bottom), 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100dvh;
}

/* ── Header ── */
.header {
  animation: pop-in 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mascot-face {
  font-size: 1.6rem;
  line-height: 1;
  animation: wiggle 3s ease-in-out infinite;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-3deg) scale(1); }
  50% { transform: rotate(3deg) scale(1.05); }
}

.title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--coral), #ff9a5c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

/* ── Input card ── */
.input-card {
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: slide-up 0.6s 0.1s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.input-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 10px;
}

.textarea-wrap {
  position: relative;
}

textarea {
  width: 100%;
  border: 2.5px solid #e2edf5;
  border-radius: 16px;
  padding: 14px 16px 28px;
  font-family: var(--font-body);
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
  background: #f8fcff;
  resize: none;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}

textarea:focus {
  border-color: var(--mint);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(94, 224, 176, 0.25);
}

textarea::placeholder {
  color: #b0bec9;
  font-weight: 400;
}

.char-count {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: 0.72rem;
  color: #b0bec9;
  font-weight: 500;
}

.lang-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-soft);
  font-weight: 500;
  transition: color 0.3s;
}

.lang-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d0dce6;
  transition: background 0.3s, transform 0.3s;
}

.lang-hint.zh .lang-dot {
  background: var(--coral);
  transform: scale(1.2);
}

.lang-hint.en .lang-dot {
  background: var(--mint);
  transform: scale(1.2);
}

/* ── Translate button ── */
.translate-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 18px 24px;
  border: none;
  border-radius: 20px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(135deg, var(--coral) 0%, #ff9a5c 50%, var(--sun) 100%);
  background-size: 200% 200%;
  box-shadow: 0 8px 24px rgba(255, 107, 138, 0.4), 0 2px 0 rgba(255,255,255,0.3) inset;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: slide-up 0.6s 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  -webkit-user-select: none;
  user-select: none;
}

.translate-btn:active {
  transform: scale(0.96);
  box-shadow: 0 4px 12px rgba(255, 107, 138, 0.3);
}

.translate-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.translate-btn.loading .btn-text::after {
  content: '…';
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

.btn-icon {
  font-size: 1.4rem;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.translate-btn:not(:disabled):hover .btn-icon,
.translate-btn:not(:disabled):active .btn-icon {
  transform: rotate(-15deg) scale(1.15);
}

.btn-shine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shine 3s ease-in-out infinite;
}

@keyframes shine {
  0%, 100% { left: -100%; }
  50% { left: 150%; }
}

/* ── Result card ── */
.result-card {
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: result-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.result-card.hidden {
  display: none;
}

@keyframes result-pop {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.result-block + .result-block {
  margin-top: 0;
}

.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

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

.result-divider {
  text-align: center;
  font-size: 1.1rem;
  color: var(--lavender);
  margin: 14px 0;
  opacity: 0.7;
}

.result-badge-target {
  background: linear-gradient(135deg, rgba(255, 107, 138, 0.15), rgba(255, 154, 92, 0.15));
  color: #c44d6a;
}

.result-text-target {
  color: #1a2a3a;
}

.phonetic-text {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(94, 224, 176, 0.12), rgba(179, 157, 219, 0.1));
  font-family: 'Fredoka', Georgia, serif;
  font-size: 0.95rem;
  font-weight: 500;
  color: #4a6a7a;
  letter-spacing: 0.02em;
  word-break: break-word;
}

.phonetic-text.hidden {
  display: none;
}

.speak-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #6ec6ff, #5ee0b0);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(94, 224, 176, 0.35);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.speak-btn:active {
  transform: scale(0.92);
}

.speak-btn.speaking {
  background: linear-gradient(135deg, var(--coral), #ff9a5c);
  box-shadow: 0 4px 12px rgba(255, 107, 138, 0.4);
  animation: pulse-speak 1s ease-in-out infinite;
}

@keyframes pulse-speak {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.result-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, rgba(94,224,176,0.2), rgba(179,157,219,0.2));
  color: #3d8b6e;
}

.copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 12px;
  background: #f0f6fb;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.copy-btn:active {
  transform: scale(0.9);
  background: var(--mint);
  color: #fff;
}

.copy-btn.copied {
  background: var(--mint);
  color: #fff;
}

.result-text {
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
}

/* ── Error toast ── */
.error-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(255, 107, 138, 0.12);
  border: 1.5px solid rgba(255, 107, 138, 0.3);
  color: #d44;
  font-size: 0.9rem;
  font-weight: 500;
  animation: shake 0.4s ease;
}

.error-toast.hidden {
  display: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ── Footer ── */
.footer {
  margin-top: auto;
  text-align: center;
  padding-top: 8px;
  animation: slide-up 0.6s 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.footer p {
  font-size: 0.78rem;
  color: rgba(107, 124, 147, 0.7);
  font-weight: 500;
}

/* ── Shared animations ── */
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.8) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
