/* ============================================================
   Definición — hoja de estilos
   Minimalista, moderna, mobile-first. Sin dependencias.
   ============================================================ */

:root {
  --bg:        #f6f7fb;
  --surface:   #ffffff;
  --text:      #1e2330;
  --text-soft: #5b6478;
  --muted:     #8a92a6;
  --line:      #e7e9f0;
  --accent:    #4f46e5;
  --accent-dk: #4338ca;
  --accent-sf: #eef0fe;
  --danger:    #e11d48;
  --shadow:    0 6px 24px rgba(20, 24, 40, 0.08);
  --radius:    18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1117;
    --surface:   #181b24;
    --text:      #eef0f6;
    --text-soft: #aab2c5;
    --muted:     #7c849a;
    --line:      #2a2e3c;
    --accent:    #7c75ff;
    --accent-dk: #6a63f0;
    --accent-sf: #20223a;
    --shadow:    0 6px 24px rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

/* ---------- Estructura general ---------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  z-index: 10;
}

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lang-toggle {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.lang-btn.is-active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Escenario / resultados ---------- */
.stage {
  flex: 1;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
}

.hint {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
  padding: 40px 10px;
}
.hint em { color: var(--text-soft); font-style: normal; font-weight: 600; }

.results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Tarjeta ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  animation: rise 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-word {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  word-break: break-word;
}

.card-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.card-pos {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: lowercase;
  color: var(--accent);
  background: var(--accent-sf);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.speak-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.1s;
}
.speak-btn:hover { background: var(--accent-sf); }
.speak-btn:active { transform: scale(0.92); }
.speak-btn.is-speaking { background: var(--accent); color: #fff; }
.speak-btn svg { width: 20px; height: 20px; fill: currentColor; }

.card-pron {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.95rem;
  font-style: italic;
}

.card-block { margin-top: 16px; }

.card-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 5px;
}

.card-text {
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--text);
}

.card-etymology .card-text,
.card-usage .card-text { color: var(--text-soft); }
.card-example .card-text { font-style: italic; color: var(--text-soft); }
.card-translation .card-text { font-weight: 600; }

.card-cols {
  display: flex;
  gap: 14px;
  margin-top: 16px;
}
.card-cols .card-block { margin-top: 0; flex: 1; min-width: 0; }

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

.chip {
  font-size: 0.86rem;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text-soft);
  padding: 4px 10px;
  border-radius: 999px;
}
.chip.is-empty { color: var(--muted); font-style: italic; border-style: dashed; }

/* Estado de carga dentro de una tarjeta */
.card.is-loading { display: flex; align-items: center; gap: 12px; }
.card.is-loading .card-word { font-size: 1.2rem; }
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--accent-sf);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card.is-error {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}
.card.is-error .card-word { font-size: 1.05rem; color: var(--danger); }

/* ---------- Zona del micrófono ---------- */
.mic-area {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 20px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.status {
  font-size: 0.9rem;
  color: var(--text-soft);
  min-height: 1.2em;
  text-align: center;
  font-weight: 500;
}

.mic-btn {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform 0.12s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.mic-btn:active { transform: scale(0.94); }
.mic-btn:disabled { background: var(--muted); box-shadow: none; cursor: not-allowed; }

.mic-icon {
  width: 34px;
  height: 34px;
  fill: currentColor;
  z-index: 1;
}

.mic-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
}

.mic-btn.is-listening { background: var(--danger); box-shadow: 0 10px 30px color-mix(in srgb, var(--danger) 45%, transparent); }
.mic-btn.is-listening .mic-pulse {
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0%   { opacity: 0.5; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.9); }
}

.text-fallback {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.86rem;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-fallback:hover { color: var(--text-soft); }

/* ---------- Responsive: pantallas grandes ---------- */
@media (min-width: 560px) {
  .card-word { font-size: 1.9rem; }
  .stage { padding-left: 24px; padding-right: 24px; }
}

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