:root {
  --yellow: #ffc42b;
  --yellow-dark: #f0a800;
  --bg: #fbf8f1;
  --card-bg: #ffffff;
  --text: #2b2a26;
  --text-muted: #7a7568;
  --border: #efe9d8;
  --shadow: 0 8px 30px rgba(43, 42, 38, 0.06);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", "Noto Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
}

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

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

.brand-name {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lang-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.lang-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  text-align-last: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237a7568' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.lang-select:hover,
.lang-select:focus {
  border-color: var(--yellow);
  outline: none;
}

.swap-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--yellow);
  color: #2b2a26;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.25s ease, background 0.15s ease;
}

.swap-btn:hover {
  background: var(--yellow-dark);
}

.swap-btn.spin {
  transform: rotate(180deg);
}

.voice-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
}

.mic-btn {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: var(--yellow);
  color: #2b2a26;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 196, 43, 0.35);
  transition: transform 0.15s ease, background 0.15s ease;
}

.mic-btn:hover {
  background: var(--yellow-dark);
}

.mic-btn:active {
  transform: scale(0.96);
}

.mic-btn.recording {
  background: #ff5a4e;
  box-shadow: 0 10px 24px rgba(255, 90, 78, 0.4);
}

.mic-btn.busy {
  opacity: 0.6;
  pointer-events: none;
}

.mic-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid var(--yellow);
  opacity: 0;
}

.mic-btn.recording .mic-ring {
  opacity: 1;
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.9);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

.engine-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--yellow-dark);
  background: #fff6df;
  border: 1px solid #ffe9ae;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.mic-status {
  min-height: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.text-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.source-text {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s ease;
}

.source-text:focus {
  border-color: var(--yellow);
}

.translate-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--yellow);
  color: #2b2a26;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.translate-btn:hover {
  background: var(--yellow-dark);
}

.translate-btn:active {
  transform: scale(0.985);
}

.translate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.result-section {
  border-top: 1px dashed var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadein 0.25s ease;
}

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

.result-text {
  margin: 0;
  font-size: 17px;
  line-height: 1.5;
  font-weight: 600;
  word-break: break-word;
  white-space: pre-wrap;
}

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

.icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--yellow);
}

.history-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.clear-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.history-item:hover {
  border-color: var(--yellow);
}

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-source {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-translated {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #2b2a26;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

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

@media (min-width: 540px) {
  .app {
    padding-top: 40px;
  }
}
