/* ═══════════════════════════════════════════════
   Animal Translator — Design System & Styles
   ═══════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────── */
:root {
  /* Palette — dark mode (default) */
  --bg-base: #0f0f1a;
  --bg-surface: #1a1a2e;
  --bg-surface-hover: #24243e;
  --bg-card: rgba(30, 30, 55, 0.85);
  --text-primary: #eaeaff;
  --text-secondary: #a0a0c0;
  --text-muted: #6a6a8a;
  --accent: #7c5cfc;
  --accent-light: #9b7dff;
  --accent-glow: rgba(124, 92, 252, 0.35);
  --danger: #ff5c8a;
  --success: #5cffa0;
  --border: rgba(255, 255, 255, 0.06);
  --glass: rgba(255, 255, 255, 0.04);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

  /* Typography */
  --font: 'Outfit', system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 9999px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 0.25s;
}

[data-theme="light"] {
  --bg-base: #f4f2ff;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f0eeff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --text-primary: #1a1a2e;
  --text-secondary: #55557a;
  --text-muted: #9999b0;
  --border: rgba(0, 0, 0, 0.07);
  --glass: rgba(124, 92, 252, 0.04);
  --shadow: 0 8px 32px rgba(100, 80, 180, 0.1);
}

/* ── Reset & Base ───────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  overflow-x: hidden;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

select,
input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* ── Splash Screen ──────────────────────────── */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0f0f1a 0%, #1e1040 50%, #0f0f1a 100%);
  z-index: 100;
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}

.splash.fade-out {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}

.splash-content {
  text-align: center;
  position: relative;
  z-index: 2;
}

.splash-icon {
  font-size: 4rem;
  animation: bounce 2s ease-in-out infinite;
}

.splash-title {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-light), #ff7eb3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0.4rem 0 0.2rem;
}

.splash-subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  font-weight: 300;
  margin-bottom: 2rem;
}

.floating-emoji {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-size: 2.2rem;
  animation: float 5s ease-in-out infinite;
  animation-delay: var(--delay);
  opacity: 0.5;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-12px);
  }
}

@keyframes float {

  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }

  33% {
    transform: translate(8px, -14px) rotate(6deg);
  }

  66% {
    transform: translate(-6px, 8px) rotate(-4deg);
  }
}

/* ── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1.6rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--dur) var(--ease);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #9b6dff);
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn-glow {
  box-shadow: 0 0 24px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
}

.btn-ghost {
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--text-primary);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.btn-xs {
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
}

.btn-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  transition: background var(--dur) var(--ease);
}

.btn-icon:hover {
  background: var(--glass);
}

/* ── Top Bar ────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  font-size: 1.4rem;
}

.logo-text {
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar-right {
  display: flex;
  gap: 0.25rem;
}

/* ── Animal Bar ─────────────────────────────── */
.animal-bar {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.animal-bar::-webkit-scrollbar {
  display: none;
}

.animal-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--glass);
  border: 1.5px solid transparent;
  color: var(--text-secondary);
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
  cursor: pointer;
}

.animal-chip:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.animal-chip.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text-primary);
}

.animal-chip-emoji {
  font-size: 1.15rem;
}

/* ── Main Content ───────────────────────────── */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Recorder ───────────────────────────────── */
.recorder-section {
  text-align: center;
}

.visualiser {
  width: 100%;
  height: 120px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  margin-bottom: 1.2rem;
}

.recorder-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.btn-record {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff5c8a, #ff3d6e);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 0 rgba(255, 92, 138, 0.4);
  transition: all var(--dur) var(--ease);
  position: relative;
}

.btn-record:hover {
  transform: scale(1.06);
}

.btn-record.recording {
  animation: pulse-ring 1.5s ease-out infinite;
}

.record-icon {
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: all var(--dur) var(--ease);
}

.btn-record.recording .record-icon {
  border-radius: 4px;
  width: 18px;
  height: 18px;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 92, 138, 0.5);
  }

  100% {
    box-shadow: 0 0 0 20px rgba(255, 92, 138, 0);
  }
}

.recorder-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

.recorder-timer {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--danger);
}

/* ── Playback ───────────────────────────────── */
.playback-section {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ── Result ──────────────────────────────────── */
.result-section {
  animation: slideUp 0.5s var(--ease);
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  text-align: center;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.result-avatar {
  width: 100px;
  height: 90px;
  margin: 0 auto 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Animated SVG Avatars ────────────────────── */
.animal-avatar {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.animal-avatar .avatar-body {
  transition: fill 0.3s var(--ease);
}

.animal-avatar .avatar-mouth {
  transition: d 0.2s var(--ease);
}

.animal-avatar .avatar-eye {
  transition: r 0.2s var(--ease);
}

/* Idle: gentle floating */
.avatar-idle {
  animation: avatar-float 3s ease-in-out infinite;
  transform-origin: center;
}

/* Talking: gentle wobble */
.avatar-talk {
  animation: avatar-wobble 0.8s ease-in-out infinite;
  transform-origin: center;
}

/* Excited: energetic bounce */
.avatar-bounce {
  animation: avatar-jump 0.5s ease-in-out infinite;
  transform-origin: center;
}

@keyframes avatar-float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}

@keyframes avatar-wobble {

  0%,
  100% {
    transform: rotate(0deg) translateY(0);
  }

  25% {
    transform: rotate(-2deg) translateY(-1px);
  }

  75% {
    transform: rotate(2deg) translateY(-1px);
  }
}

@keyframes avatar-jump {

  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-6px) scale(1.05);
  }
}

.result-text {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.5;
  font-style: italic;
  color: var(--text-primary);
  margin: 0.8rem 0;
  border: none;
  padding: 0;
}

.result-text::before {
  content: '"';
  color: var(--accent-light);
}

.result-text::after {
  content: '"';
  color: var(--accent-light);
}

.confidence-badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent-light);
}

/* ── Mood badge ─────────────────────────────────── */
.mood-badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(92, 255, 160, 0.15);
  color: var(--success);
}

.result-meta {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.2rem;
}

/* ── Rhythm badge ──────────────────────────────── */
.rhythm-badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(255, 126, 179, 0.15);
  color: #ff7eb3;
}

.rhythm-badge:empty {
  display: none;
}

/* ── Result actions row ────────────────────────── */
.result-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ── Share button ───────────────────────────────── */
.result-share-btn {
  margin-top: 1rem;
  transition: all var(--dur) var(--ease);
}

.result-share-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ── Result text container ──────────────────────── */
.result-text-container {
  min-height: 2.5rem;
}

/* ── Skeleton loading shimmer ───────────────────── */
.skeleton-loading {
  position: relative;
  overflow: hidden;
}

.skeleton-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
      transparent 0%,
      var(--glass) 20%,
      rgba(124, 92, 252, 0.08) 40%,
      var(--glass) 60%,
      transparent 100%);
  animation: shimmer 1.5s infinite;
}

.skeleton-loading .result-animal-icon::before {
  content: '🔮';
  animation: pulse 1s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── History ─────────────────────────────────── */
.history-section {
  border-top: 1px solid var(--border);
  padding-top: 1.2rem;
}

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

.history-title {
  font-size: 1rem;
  font-weight: 600;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.7rem 0.9rem;
  background: var(--glass);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: background var(--dur) var(--ease);
}

.history-item:hover {
  background: var(--bg-surface-hover);
}

.history-item-emoji {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.history-item-body {
  flex: 1;
  min-width: 0;
}

.history-item-text {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.history-empty {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.history-empty-icon {
  font-size: 2rem;
  display: inline-block;
  animation: bounce 2s ease-in-out infinite;
  opacity: 0.6;
}

/* ── Modal / Overlay ─────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s var(--ease);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
  animation: slideUp 0.35s var(--ease);
}

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

.modal-header h2 {
  font-size: 1.15rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.setting-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.setting-select,
.setting-input {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: var(--bg-base);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: border-color var(--dur) var(--ease);
}

.setting-select:focus,
.setting-input:focus {
  outline: none;
  border-color: var(--accent);
}

.setting-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.setting-hint.error {
  color: var(--danger);
}

/* Permission modal */
.permission-modal {
  text-align: center;
}

.permission-icon {
  font-size: 3rem;
  margin-bottom: 0.6rem;
}

.permission-modal h2 {
  margin-bottom: 0.5rem;
}

.permission-modal p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.2rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 480px) {
  .main-content {
    padding: 1rem 0.75rem 2rem;
  }

  .visualiser {
    height: 90px;
  }

  .btn-record {
    width: 64px;
    height: 64px;
  }

  .result-text {
    font-size: 1.1rem;
  }
}