/* ─── Tokens ─── */
:root {
  --bg: #0c0b0f;
  --surface: #15141a;
  --surface-hover: #1c1b22;
  --border: #2a2831;
  --border-accent: #3d3a47;
  --text: #e8e6ed;
  --text-muted: #8b8895;
  --text-dim: #5c5968;
  --gold: #c9a84c;
  --gold-light: #e2c972;
  --gold-dim: #8a7333;
  --accent: #c9a84c;
  --danger: #e05252;
  --radius: 16px;
  --radius-sm: 10px;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

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

/* ─── App container ─── */
.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  padding:
    max(24px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  animation: fadeUp 0.8s var(--ease) both;
}

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

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
  animation: fadeUp 0.8s var(--ease) 0.1s both;
}

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

.logo-icon {
  font-size: 28px;
  color: var(--gold);
  filter: drop-shadow(0 0 8px rgba(201, 168, 76, 0.3));
}

.logo-text {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.5;
}

.logo-text em {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  letter-spacing: 1px;
  color: var(--gold);
  text-transform: none;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4caf50;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
  50%      { opacity: 0.7; box-shadow: 0 0 0 6px rgba(76, 175, 80, 0); }
}

.update-time {
  font-variant-numeric: tabular-nums;
}

/* ─── Converter card ─── */
.converter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  position: relative;
  animation: fadeUp 0.8s var(--ease) 0.2s both;
  transition: border-color 0.3s ease;
}

.converter-card:hover {
  border-color: var(--border-accent);
}

.converter-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.15), transparent 50%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* ─── Input groups ─── */
.input-group {
  margin-bottom: 8px;
}

.input-group--to {
  position: relative;
  margin-bottom: 0;
  margin-top: 8px;
}

.input-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.amount-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-family: var(--font-display);
  font-size: clamp(22px, 5.2vw, 32px);
  font-weight: 600;
  color: var(--text);
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  -moz-appearance: textfield;
  appearance: textfield;
  min-width: 0;
  width: 100%;
}

.amount-input::-webkit-inner-spin-button,
.amount-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.amount-input:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.1);
}

.amount-input::placeholder {
  color: var(--text-dim);
}

.result-display {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-family: var(--font-display);
  font-size: clamp(22px, 5.2vw, 32px);
  font-weight: 600;
  color: var(--gold-light);
  min-height: 68px;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.3s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}

.result-display:hover {
  border-color: var(--gold-dim);
}

.result-display:focus-visible {
  outline: none;
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

.result-display.result-copied {
  animation: copyPulse 0.95s var(--ease) forwards;
}

@keyframes copyPulse {
  0% {
    background: rgba(201, 168, 76, 0.22);
    border-color: var(--gold);
    box-shadow:
      0 0 0 2px rgba(201, 168, 76, 0.35),
      0 0 28px rgba(201, 168, 76, 0.2);
    color: #f8efd8;
  }
  55% {
    background: rgba(201, 168, 76, 0.1);
    border-color: var(--gold-dim);
    box-shadow: 0 0 0 1px rgba(201, 168, 76, 0.2);
    color: var(--gold-light);
  }
  100% {
    background: var(--bg);
    border-color: var(--border);
    box-shadow: none;
    color: var(--gold-light);
  }
}

.copy-toast {
  margin: 0;
  padding: 0;
  min-height: 1.25em;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
  opacity: 0;
  transform: translateY(-6px);
  transition:
    opacity 0.25s var(--ease),
    transform 0.25s var(--ease);
  pointer-events: none;
}

.copy-toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.copy-toast.copy-toast--error {
  color: var(--danger);
  letter-spacing: 0.06em;
  text-transform: none;
  font-weight: 500;
  font-size: 11px;
}

@media (prefers-reduced-motion: reduce) {
  .result-display.result-copied {
    animation: none;
    background: rgba(201, 168, 76, 0.18);
    border-color: var(--gold);
  }

  .copy-toast {
    transition: opacity 0.15s ease;
  }
}

/* ─── Currency select ─── */
.currency-select-wrapper {
  position: relative;
  flex-shrink: 0;
}

.currency-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 36px 16px 16px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  width: 110px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238b8895' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.currency-select:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.1);
}

.currency-select option {
  background: var(--surface);
  color: var(--text);
}

/* ─── Swap button ─── */
.swap-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--gold);
  cursor: pointer;
  transition: all 0.3s var(--ease);
  position: relative;
  z-index: 2;
}

.swap-btn:hover {
  background: var(--surface-hover);
  border-color: var(--gold-dim);
  transform: rotate(180deg);
  box-shadow: 0 0 20px rgba(201, 168, 76, 0.15);
}

.swap-btn:active {
  transform: rotate(180deg) scale(0.92);
}

/* ─── Rate info ─── */
.rate-info {
  text-align: center;
  margin-top: 24px;
  animation: fadeUp 0.8s var(--ease) 0.3s both;
}

.rate-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 10px 24px;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  transition: all 0.3s ease;
}

.rate-badge:hover {
  border-color: var(--border-accent);
}

/* ─── Popular currencies ─── */
.popular-currencies {
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  animation: fadeUp 0.8s var(--ease) 0.4s both;
}

.popular-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.popular-card:hover {
  border-color: var(--gold-dim);
  background: var(--surface-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.popular-card-code {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  color: var(--text);
}

.popular-card-name {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.popular-card-rate {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--gold);
  text-align: right;
}

/* ─── Footer ─── */
.footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  animation: fadeUp 0.8s var(--ease) 0.5s both;
}

.footer a {
  color: var(--gold-dim);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer a:hover {
  color: var(--gold);
}

/* ─── Loading state ─── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Result animation ─── */
.result-animate {
  animation: resultPop 0.35s var(--ease);
}

@keyframes resultPop {
  0%   { opacity: 0.5; transform: scale(0.97); }
  100% { opacity: 1; transform: scale(1); }
}

/* ─── Error state ─── */
.error-state .result-display {
  color: var(--danger);
  font-size: 16px;
  font-family: var(--font-body);
  font-weight: 500;
}

/* ─── Responsive ─── */
@media (max-width: 540px) {
  .app-container {
    padding:
      max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }

  .converter-card {
    padding: 24px 20px;
  }

  .amount-input,
  .result-display {
    padding: 14px 16px;
  }

  .currency-select {
    width: 104px;
    padding: 14px 30px 14px 12px;
    font-size: 16px;
  }

  .input-row {
    gap: 10px;
  }

  .popular-currencies {
    grid-template-columns: 1fr;
  }

  .header {
    margin-bottom: 28px;
  }
}

/* Pantallas muy pequeñas (iPhone SE, Galaxy A10, etc.) */
@media (max-width: 380px) {
  .converter-card {
    padding: 20px 16px;
  }

  .amount-input,
  .result-display {
    padding: 12px 14px;
  }

  .currency-select {
    width: 92px;
    padding: 12px 28px 12px 10px;
    background-position: right 10px center;
  }

  .input-row {
    gap: 8px;
  }

  .swap-btn {
    width: 42px;
    height: 42px;
  }

  .rate-badge {
    padding: 8px 18px;
    font-size: 12px;
  }

  .logo-text {
    font-size: 10px;
  }

  .logo-text em {
    font-size: 15px;
  }
}

/* Landscape en móviles: reducir animaciones verticales excesivas */
@media (max-height: 500px) and (orientation: landscape) {
  .app-container {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .header {
    margin-bottom: 16px;
  }

  .rate-info {
    margin-top: 16px;
  }

  .popular-currencies {
    margin-top: 20px;
    grid-template-columns: repeat(3, 1fr);
  }

  .footer {
    margin-top: 20px;
    padding-top: 16px;
  }
}

/* Respeta la preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .swap-btn:hover {
    transform: none;
  }
}
