/* ============================================
   ✦ Estilo.css — Reconocimiento de Escritura
   Tema oscuro · Diseño moderno · UX refinada
   ============================================ */

/* ─── Variables ─── */
:root {
  --bg-primary: #0c0c14;
  --bg-secondary: #11111e;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.07);
  --border-active: rgba(255, 255, 255, 0.15);
  --accent: #fbbf24;
  --accent-glow: rgba(251, 191, 36, 0.25);
  --accent-secondary: #34d399;
  --text-primary: #f1f1f1;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-tertiary: rgba(255, 255, 255, 0.3);
  --canvas-bg: #ffffff;
  --canvas-shadow: rgba(0, 0, 0, 0.5);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --font-display: 'Sora', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-card: 0 8px 48px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--border);
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* ─── Background animated glow ─── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(251, 191, 36, 0.06), transparent),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(52, 211, 153, 0.04), transparent),
    radial-gradient(ellipse 50% 60% at 20% 70%, rgba(139, 92, 246, 0.04), transparent);
  animation: bgShift 20s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes bgShift {
  0%   { opacity: 0.6; }
  50%  { opacity: 1; }
  100% { opacity: 0.6; }
}

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

/* ─── Header ─── */
header {
  position: relative;
  z-index: 10;
  width: 100%;
  padding: 1rem 2rem;
  display: flex;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 12, 20, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

header nav {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  height: 36px;
  width: auto;
  opacity: 0.9;
  border-radius: 4px;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-xs);
  transition: all var(--transition);
}

.back-link:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.back-arrow {
  font-size: 1.2rem;
  line-height: 1;
}

/* ─── Main layout ─── */
main {
  position: relative;
  z-index: 10;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 520px;
}

/* ─── Card ─── */
.card {
  width: 100%;
  background: var(--surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 2.5rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  animation: cardIn 0.6s ease-out both;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ─── Canvas wrapper ─── */
.canvas-wrapper {
  position: relative;
  width: 240px;
  height: 240px;
  flex-shrink: 0;
}

#drawingCanvas {
  display: block;
  width: 240px;
  height: 240px;
  border-radius: var(--radius-sm);
  background: var(--canvas-bg);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.3),
    inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  cursor: crosshair;
  touch-action: none;
  transition: box-shadow var(--transition);
}

#drawingCanvas:active {
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.4),
    0 0 0 2px var(--accent-glow),
    inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.canvas-hint {
  position: absolute;
  bottom: -1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 400;
  white-space: nowrap;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.canvas-hint.hidden {
  opacity: 0;
}

/* ─── Buttons ─── */
.actions {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius-xs);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  overflow: hidden;
  letter-spacing: 0.01em;
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary */
.btn-primary {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0c0c14;
  box-shadow: 0 2px 16px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 24px var(--accent-glow);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 8px var(--accent-glow);
}

/* Secondary */
.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
  transform: translateY(-1px);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-icon {
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0.8;
}

/* ─── Loading ─── */
.loading {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 1rem 0;
}

.loading.active {
  display: flex;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-error {
  color: #f87171;
  font-size: 0.8rem;
  text-align: center;
  margin-top: 0.25rem;
}

.loading-error a {
  color: var(--accent);
  text-decoration: underline;
}

/* ─── Result ─── */
.result-container {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  animation: resultIn 0.5s ease-out both;
}

.result-container.active {
  display: flex;
}

@keyframes resultIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.result-digit {
  font-family: var(--font-display);
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.04em;
  text-shadow: 0 0 40px var(--accent-glow);
  animation: digitPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes digitPop {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.result-confidence-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.result-confidence-text strong {
  color: var(--accent);
  font-weight: 600;
}

/* ─── Confidence Distribution ─── */
.confidence-distribution {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 0.25rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 20px 1fr 32px;
  align-items: center;
  gap: 6px;
}

.bar-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-align: right;
  font-family: var(--font-display);
  transition: color var(--transition);
}

.bar-row.highlighted .bar-label {
  color: var(--accent);
}

.bar-track {
  height: 5px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.15);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  width: 0%;
}

.bar-row.highlighted .bar-fill {
  background: linear-gradient(90deg, var(--accent), #f59e0b);
  box-shadow: 0 0 8px var(--accent-glow);
}

.bar-value {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-align: right;
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  transition: color var(--transition);
}

.bar-row.highlighted .bar-value {
  color: var(--accent);
}

/* ─── Empty result state ─── */
.result-empty {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem;
}

/* ─── Responsive ─── */
@media (max-width: 540px) {
  header {
    padding: 0.75rem 1rem;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .back-text {
    display: none;
  }

  main {
    padding: 1rem;
  }

  .card {
    padding: 1.5rem 1.25rem 1.25rem;
    gap: 1.25rem;
    border-radius: 12px;
  }

  .canvas-wrapper {
    width: 200px;
    height: 200px;
  }

  #drawingCanvas {
    width: 200px;
    height: 200px;
  }

  .result-digit {
    font-size: 3.5rem;
  }

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

@media (max-width: 380px) {
  .canvas-wrapper {
    width: 170px;
    height: 170px;
  }

  #drawingCanvas {
    width: 170px;
    height: 170px;
  }

  .result-digit {
    font-size: 2.8rem;
  }
}
