@import './tokens.css';

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  touch-action: manipulation;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea { font: inherit; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
  letter-spacing: -0.01em;
}

h1 { font-size: var(--text-4xl); font-weight: var(--weight-extrabold); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }

p { line-height: var(--leading-relaxed); }

/* ── Layout ───────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 768px) {
  .container { padding-inline: var(--space-6); }
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--touch-min);
  padding-inline: var(--space-6);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-dark); box-shadow: var(--shadow-md); }

.btn-accent { background: var(--color-accent); color: var(--color-on-accent); }
.btn-accent:hover { background: var(--color-accent-dark); box-shadow: var(--shadow-md); }

.btn-outline { border: 2px solid var(--color-primary); color: var(--color-primary); background: transparent; }
.btn-outline:hover { background: var(--color-bg-tint); }

.btn-ghost { color: var(--color-text-muted); background: transparent; }
.btn-ghost:hover { color: var(--color-text); background: var(--color-surface-raised); }

.btn-sm { height: 2.25rem; padding-inline: var(--space-4); font-size: var(--text-sm); }
.btn-lg { height: 3.25rem; padding-inline: var(--space-8); font-size: var(--text-lg); }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-body { padding: var(--space-4); }

/* ── Figurita card ────────────────────────────────────────── */
.fig-card {
  position: relative;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  min-height: 80px;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.fig-card:active { transform: scale(0.95); }

.fig-card.tengo    { border-color: var(--color-success); background: #F0FDF4; }
.fig-card.repetida { border-color: var(--color-accent);  background: #EFF6FF; }
.fig-card.falta    { border-color: var(--color-border);  opacity: 0.65; }

.fig-card .fig-numero {
  font-family: var(--font-heading);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--color-text-muted);
}

.fig-card .fig-nombre {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.fig-card .fig-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: var(--weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fig-card.tengo    .fig-badge { background: var(--color-success); color: #fff; }
.fig-card.repetida .fig-badge { background: var(--color-accent);  color: #fff; }

.fig-card[data-rareza="bronce"] { box-shadow: 0 0 0 2px #CD7F32 inset; }
.fig-card[data-rareza="plata"]  { box-shadow: 0 0 0 2px #94A3B8 inset; }
.fig-card[data-rareza="oro"]    { box-shadow: 0 0 0 2px var(--color-gold) inset; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--space-1); }

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.form-input {
  width: 100%;
  height: var(--touch-min);
  padding-inline: var(--space-4);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease-out);
  outline: none;
}

.form-input:focus     { border-color: var(--color-primary); }
.form-input::placeholder { color: var(--color-text-faint); }
.form-input.error     { border-color: var(--color-danger); }

.form-error { font-size: var(--text-xs); color: var(--color-danger); margin-top: var(--space-1); }
.form-hint  { font-size: var(--text-xs); color: var(--color-text-faint); }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  height: 1.375rem;
  padding-inline: var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.badge-primary { background: var(--color-bg-tint);  color: var(--color-primary); }
.badge-success { background: #DCFCE7; color: #15803D; }
.badge-accent  { background: #DBEAFE; color: #1D4ED8; }
.badge-warning { background: #FEF3C7; color: #B45309; }
.badge-gold    { background: #FEF9C3; color: #854D0E; }

/* ── Notification dot ─────────────────────────────────────── */
.notif-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 8px; height: 8px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  border: 2px solid var(--color-bg);
}

/* ── Bottom nav ───────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: var(--z-sticky);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding-block: var(--space-2);
  min-height: var(--touch-min);
  color: var(--color-text-faint);
  position: relative;
  transition: color var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item.active { color: var(--color-primary); }

.bottom-nav-item span {
  font-size: 10px;
  font-weight: var(--weight-medium);
  font-family: var(--font-heading);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Top bar ──────────────────────────────────────────────── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding-block: var(--space-3);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0));
}

.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

/* ── Progress bar ─────────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light));
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

/* ── Toast ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--touch-min) * 2 + var(--space-4));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  animation: toast-in var(--duration-normal) var(--ease-out) forwards;
}

.toast.out { animation: toast-out var(--duration-fast) var(--ease-in) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)  scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(4px) scale(0.97); }
}

/* ── Modal / bottom sheet ─────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: var(--space-6);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0));
  animation: modal-in var(--duration-normal) var(--ease-out) forwards;
}

@media (min-width: 640px) {
  .modal { border-radius: var(--radius-xl); }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(32px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-5);
}

/* ── Page content padding (below bottom nav) ──────────────── */
.page-content {
  padding-bottom: calc(var(--touch-min) + var(--space-8) + env(safe-area-inset-bottom, 0));
}

/* ── Figuritas grid ───────────────────────────────────────── */
.fig-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: var(--space-2);
}

@media (min-width: 480px) {
  .fig-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}

/* ── Search bar ───────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface-raised);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 0 var(--space-4);
  height: var(--touch-min);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.search-bar:focus-within { border-color: var(--color-primary); }
.search-bar input { flex: 1; background: none; border: none; outline: none; font-size: var(--text-base); color: var(--color-text); }

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

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

/* ── Utilities ────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}
.text-center     { text-align: center; }
.text-muted      { color: var(--color-text-muted); }
.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.mt-4   { margin-top: var(--space-4); }
.mt-6   { margin-top: var(--space-6); }
.mt-8   { margin-top: var(--space-8); }
.w-full { width: 100%; }
