:root {
  --bg: #fff7fb;
  --surface: #ffffff;
  --text: #2b1b3d;
  --muted: #7a6a8a;
  --primary: #7b2cbf;
  --primary-strong: #5a189a;
  --accent: #ff5d8f;
  --gold: #ffb703;
  --radius: 18px;
  --shadow: 0 6px 18px rgba(91, 24, 154, 0.12);
  --tap: 52px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, #ffe3ef 0, transparent 40%),
    radial-gradient(circle at 100% 30%, #efe1ff 0, transparent 45%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding:
    calc(16px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

[hidden] { display: none !important; }

h1 { font-size: 1.6rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 28px 0 12px; }
.muted { color: var(--muted); text-align: center; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- Botones ---------- */
.btn {
  display: block;
  width: 100%;
  min-height: var(--tap);
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-strong); transform: scale(0.98); }
.btn-ghost { background: transparent; color: var(--primary); }

.link-btn {
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 0.95rem;
  padding: 8px 0;
  min-height: 44px;
  text-decoration: underline;
}

/* ---------- Vista nombre ---------- */
.view-name {
  min-height: calc(100dvh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
}
.hero { text-align: center; }
.hero-emoji { font-size: 4.5rem; }
.hero p { color: var(--muted); margin: 8px 0 0; }

.name-form { display: flex; flex-direction: column; gap: 12px; }
.name-form label { font-weight: 700; font-size: 1.1rem; }
.name-form input {
  min-height: var(--tap);
  border: 2px solid #e4d5f5;
  border-radius: 14px;
  padding: 0 16px;
  font: inherit;
  font-size: 16px; /* evita el zoom automático de iOS */
  color: var(--text);
}
.name-form input:focus { outline: none; border-color: var(--primary); }
.form-error { color: #c1121f; margin: 0; font-size: 0.95rem; }

/* ---------- Vista inicio ---------- */
.home-header { display: flex; flex-direction: column; gap: 2px; }

.games-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.game-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  min-height: 84px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
}
.game-card:active { transform: scale(0.98); }
.game-icon {
  flex: none;
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 1.8rem;
  border-radius: 14px;
  background: #f3e8ff;
}
.game-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.game-title { font-size: 1.05rem; }
.game-desc { color: var(--muted); font-size: 0.88rem; }
.game-best {
  flex: none;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary);
  background: #f3e8ff;
  border-radius: 999px;
  padding: 6px 10px;
}

/* ---------- Ranking ---------- */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px 12px;
  padding: 0 16px 4px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  min-height: 40px;
  padding: 0 16px;
  border: 2px solid #e4d5f5;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  touch-action: manipulation;
}
.tab[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

.ranking-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ranking-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.ranking-row .pos { width: 32px; text-align: center; font-weight: 700; font-size: 1.1rem; }
.ranking-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-row .points { font-weight: 800; color: var(--primary); }
.ranking-row.is-me { outline: 3px solid var(--accent); }
