/* ============================================================
   LLUVIA DE TECLAS - Estilos
   ============================================================ */

:root {
  /* Atardecer lluvioso */
  --sky-top: #2a1d4a;
  --sky-mid: #6b3d6e;
  --sky-low: #d4825f;
  --sky-horizon: #f4b067;
  --sun: #ffd89b;
  --water: #1a2a4a;
  --water-light: #3d5a8a;
  --puddle: #2d3f5e;
  --rain: rgba(180, 200, 230, 0.6);
  --ink: #fff8eb;
  --ink-soft: #ffe5c0;
  --ink-muted: #c9a888;
  --accent: #ffb96b;
  --accent-bright: #ffd89b;
  --danger: #ff6b9b;
  --success: #95e8b8;
  --bubble: rgba(255, 240, 220, 0.95);
  --bubble-glow: rgba(255, 217, 155, 0.8);
  --shadow-soft: 0 4px 20px rgba(42, 29, 74, 0.4);
  --shadow-strong: 0 8px 40px rgba(42, 29, 74, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Outfit', sans-serif;
  color: var(--ink);
  user-select: none;
  background: linear-gradient(180deg,
    var(--sky-top) 0%,
    var(--sky-mid) 35%,
    var(--sky-low) 70%,
    var(--sky-horizon) 100%);
  position: relative;
}

/* === SOL DE FONDO === */
.sun {
  position: fixed;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-bright) 0%, var(--sun) 30%, transparent 65%);
  filter: blur(2px);
  pointer-events: none;
  z-index: 0;
  animation: sunPulse 6s ease-in-out infinite;
}
@keyframes sunPulse {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: .85; }
  50% { transform: translateX(-50%) scale(1.05); opacity: 1; }
}

/* === MONTAÑAS DECORATIVAS === */
.mountains {
  position: fixed;
  bottom: 12%;
  left: 0; right: 0;
  height: 30%;
  pointer-events: none;
  z-index: 1;
}
.mountains svg { width: 100%; height: 100%; }

/* === LLUVIA AMBIENTAL DE FONDO === */
.ambient-rain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.raindrop {
  position: absolute;
  width: 1px;
  height: 60px;
  background: linear-gradient(180deg, transparent, var(--rain));
  opacity: .4;
  animation: ambientFall linear infinite;
}
@keyframes ambientFall {
  from { transform: translateY(-100px); }
  to { transform: translateY(110vh); }
}

/* === GAME CONTAINER === */
.game-container {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  z-index: 5;
}

/* === HEADER (HUD) === */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(42,29,74,.5), transparent);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 24px;
}
.hud-center { gap: 32px; }

.lives {
  display: flex;
  gap: 6px;
  align-items: center;
}
.life {
  width: 24px;
  height: 30px;
  transition: all .4s cubic-bezier(.34,1.56,.64,1);
}
.life.lost {
  opacity: .25;
  transform: scale(.7);
  filter: grayscale(.7);
}
.life svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 6px rgba(0,0,0,.3)); }

.stat-block {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-block-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.stat-block-value {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0,0,0,.3);
  font-feature-settings: "tnum" 1;
}
.stat-block-value.accent { color: var(--accent-bright); }

.level-badge {
  background: linear-gradient(135deg, rgba(255,217,155,.15), rgba(255,217,155,.05));
  border: 1px solid rgba(255,217,155,.3);
  border-radius: 100px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--ink-soft);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 8px;
}
.level-badge .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-bright);
  box-shadow: 0 0 12px var(--accent-bright);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  cursor: pointer;
  display: grid; place-items: center;
  transition: all .2s ease;
  backdrop-filter: blur(8px);
}
.icon-btn:hover {
  background: rgba(255,255,255,.15);
  border-color: var(--accent-bright);
  transform: translateY(-1px);
}
.icon-btn svg { width: 18px; height: 18px; }

/* === PLAY AREA === */
.play-area {
  position: absolute;
  top: 80px;
  left: 0; right: 0;
  bottom: 130px;
  overflow: hidden;
}

/* === GOTA / DROP === */
.drop {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  will-change: transform;
  transform: translateY(-100px);
}
.drop-bubble {
  position: relative;
  width: 64px;
  height: 76px;
  display: grid;
  place-items: center;
}
.drop-bubble svg.shape {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.25));
}
.drop-key {
  position: relative;
  z-index: 2;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 28px;
  color: var(--water);
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.drop-trail {
  width: 2px;
  height: 24px;
  background: linear-gradient(180deg, var(--rain), transparent);
  opacity: .5;
  margin-top: -2px;
}
.drop.hit {
  animation: dropHit .5s ease-out forwards;
}
@keyframes dropHit {
  0% { transform: translateY(var(--y, 0)) scale(1); opacity: 1; }
  100% { transform: translateY(var(--y, 0)) scale(1.8); opacity: 0; }
}
.drop.miss {
  animation: dropMiss .4s ease-in forwards;
}
@keyframes dropMiss {
  0% { transform: translateY(var(--y, 0)) scale(1); }
  100% { transform: translateY(calc(var(--y, 0) + 30px)) scale(1.4, .4); opacity: 0; }
}

/* === SPLASH === */
.splash {
  position: absolute;
  pointer-events: none;
  width: 80px; height: 80px;
  transform: translate(-50%, -50%);
}
.splash-particle {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-bright);
  box-shadow: 0 0 8px var(--accent-bright);
  animation: splashOut .6s cubic-bezier(.5,0,.75,0) forwards;
}
@keyframes splashOut {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0); opacity: 0; }
}

/* === CHARCO INFERIOR === */
.puddle {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 130px;
  overflow: hidden;
  z-index: 6;
  pointer-events: none;
}
.puddle-water {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 0%;
  background: linear-gradient(180deg, var(--water-light), var(--water));
  transition: height .8s cubic-bezier(.34,1.56,.64,1);
  border-top: 2px solid rgba(255,255,255,.2);
}
.puddle-water::before {
  content: '';
  position: absolute;
  top: -3px;
  left: 0; right: 0;
  height: 6px;
  background: linear-gradient(180deg, rgba(255,255,255,.4), transparent);
  animation: ripple 3s ease-in-out infinite;
}
@keyframes ripple {
  0%, 100% { transform: translateX(0) scaleY(1); }
  50% { transform: translateX(-4px) scaleY(1.5); }
}
.ground {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 130px;
  background: linear-gradient(180deg,
    rgba(45, 63, 94, .85) 0%,
    rgba(26, 42, 74, 1) 100%);
  z-index: 5;
  border-top: 1px solid rgba(255,255,255,.15);
}
.ground::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-bright), transparent);
  opacity: .4;
}

.ring {
  position: absolute;
  bottom: 50px;
  width: 60px; height: 60px;
  border: 2px solid var(--accent-bright);
  border-radius: 50%;
  transform: translate(-50%, 50%);
  animation: ringExpand 1s ease-out forwards;
  pointer-events: none;
}
@keyframes ringExpand {
  0% { width: 20px; height: 20px; opacity: 1; }
  100% { width: 200px; height: 60px; opacity: 0; }
}

/* === MENU / SCREENS === */
.screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(20px);
  background: linear-gradient(135deg, rgba(42,29,74,.85), rgba(107,61,110,.7));
  animation: screenFadeIn .5s ease both;
}
@keyframes screenFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.screen.hidden { display: none; }
.panel {
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 28px;
  padding: 40px;
  max-width: 580px;
  width: 100%;
  box-shadow: var(--shadow-strong);
  text-align: center;
  animation: panelIn .6s cubic-bezier(.34,1.56,.64,1) both;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes panelIn {
  0% { transform: scale(.9) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.panel-title {
  font-family: 'Fraunces', serif;
  font-size: clamp(40px, 7vw, 64px);
  font-weight: 500;
  line-height: 1;
  margin-bottom: 8px;
  color: var(--ink);
  font-style: italic;
}
.panel-title em {
  font-style: normal;
  font-weight: 900;
  color: var(--accent-bright);
  background: linear-gradient(135deg, var(--accent-bright), var(--sun));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.panel-sub {
  font-size: 14px;
  color: var(--ink-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 32px;
}
.menu-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.menu-btn {
  background: linear-gradient(135deg, rgba(255,217,155,.15), rgba(255,217,155,.05));
  border: 1px solid rgba(255,217,155,.3);
  border-radius: 16px;
  padding: 18px 24px;
  color: var(--ink);
  font-family: 'Outfit', sans-serif;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all .25s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}
.menu-btn:hover {
  background: linear-gradient(135deg, rgba(255,217,155,.3), rgba(255,217,155,.15));
  border-color: var(--accent-bright);
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}
.menu-btn-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: rgba(255,217,155,.2);
  display: grid; place-items: center;
  color: var(--accent-bright);
  flex-shrink: 0;
}
.menu-btn-icon svg { width: 20px; height: 20px; }
.menu-btn-text { flex: 1; margin-left: 14px; }
.menu-btn-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 2px;
}
.menu-btn-desc {
  font-size: 12px;
  color: var(--ink-muted);
}
.menu-btn-arrow {
  color: var(--accent-bright);
  font-size: 22px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: var(--water);
  border: none;
  padding: 16px 36px;
  border-radius: 100px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all .25s ease;
  box-shadow: 0 8px 24px rgba(255,185,107,.4);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(255,185,107,.6);
}
.btn-primary:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid rgba(255,255,255,.15);
  padding: 14px 28px;
  border-radius: 100px;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all .2s ease;
}
.btn-ghost:hover {
  background: rgba(255,255,255,.08);
  color: var(--ink);
}
.btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Level grid */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.level-card {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  padding: 14px 8px;
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
}
.level-card:hover {
  background: rgba(255,217,155,.15);
  border-color: var(--accent-bright);
  transform: translateY(-2px);
}
.level-card-num {
  font-family: 'Fraunces', serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-bright);
  line-height: 1;
}
.level-card-name {
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 4px;
  letter-spacing: .5px;
}
.level-card.locked {
  opacity: .4;
  cursor: not-allowed;
}
.level-card.locked::before {
  content: '🔒';
  position: absolute;
  top: 6px; right: 8px;
  font-size: 12px;
}
.level-card.completed::after {
  content: '✓';
  position: absolute;
  top: 4px; right: 8px;
  color: var(--success);
  font-weight: 800;
  font-size: 14px;
}

/* Name input */
.name-input {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 12px;
  padding: 14px 18px;
  color: var(--ink);
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 4px;
  width: 100%;
  margin-bottom: 16px;
  outline: none;
  transition: border-color .2s ease;
  text-align: center;
  text-transform: uppercase;
}
.name-input:focus { border-color: var(--accent-bright); }
.name-input::placeholder { color: var(--ink-muted); letter-spacing: 4px; }

.form-error {
  background: rgba(255, 107, 155, 0.15);
  border: 1px solid rgba(255, 107, 155, 0.4);
  color: #ffb3cc;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 12px;
}

.top-banner {
  background: linear-gradient(135deg, rgba(255, 217, 155, 0.25), rgba(255, 185, 107, 0.15));
  border: 1px solid var(--accent-bright);
  border-radius: 14px;
  padding: 14px;
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--accent-bright);
  margin-bottom: 12px;
  animation: bannerPulse 2s ease-in-out infinite;
}
@keyframes bannerPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 217, 155, 0.4); }
  50% { box-shadow: 0 0 24px 4px rgba(255, 217, 155, 0.3); }
}

/* Game over stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0;
}
.stat-tile {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  padding: 16px;
}
.stat-tile-label {
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.stat-tile-value {
  font-family: 'Fraunces', serif;
  font-size: 32px;
  font-weight: 500;
  color: var(--accent-bright);
  line-height: 1;
}
.stat-tile-value small {
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  color: var(--ink-muted);
  margin-left: 4px;
  font-weight: 400;
}
.key-failed {
  display: inline-block;
  background: var(--danger);
  color: white;
  padding: 4px 10px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  margin-top: 4px;
}

/* Ranking */
.ranking {
  margin: 16px 0 24px;
  text-align: left;
}
.ranking-row {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  align-items: center;
  font-size: 14px;
}
.ranking-row:nth-child(odd) { background: rgba(255,255,255,.04); }
.ranking-row.me {
  background: linear-gradient(90deg, rgba(255,217,155,.2), rgba(255,217,155,.05));
  border: 1px solid rgba(255,217,155,.4);
}
.ranking-pos {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  color: var(--accent-bright);
  font-size: 18px;
}
.ranking-name {
  color: var(--ink);
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 1px;
}
.ranking-score {
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink);
  font-weight: 700;
}
.ranking-meta {
  font-size: 11px;
  color: var(--ink-muted);
}
.ranking-empty {
  text-align: center;
  color: var(--ink-muted);
  padding: 20px;
  font-style: italic;
}

/* Pause indicator */
.paused-banner {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(42,29,74,.8);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.15);
  padding: 32px 48px;
  border-radius: 24px;
  z-index: 50;
  text-align: center;
  box-shadow: var(--shadow-strong);
}
.paused-banner h2 {
  font-family: 'Fraunces', serif;
  font-size: 36px;
  font-weight: 500;
  margin-bottom: 8px;
}
.paused-banner p {
  color: var(--ink-muted);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Toast */
.toast {
  position: fixed;
  top: 100px; left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: rgba(42,29,74,.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,217,155,.4);
  color: var(--ink);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  z-index: 200;
  transition: transform .4s cubic-bezier(.34,1.56,.64,1);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.streak { border-color: var(--success); }
.toast.levelup {
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: var(--water);
  border-color: var(--accent-bright);
  font-weight: 700;
}

/* Lightning effect */
.lightning {
  position: fixed;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 99;
}
.lightning.flash {
  animation: lightningFlash .3s ease;
}
@keyframes lightningFlash {
  0%, 100% { opacity: 0; }
  20%, 60% { opacity: .6; }
  40% { opacity: .2; }
}

/* Responsive */
@media (max-width: 600px) {
  .hud { padding: 14px 16px; }
  .hud-center { gap: 16px; }
  .stat-block-value { font-size: 22px; }
  .life { width: 20px; height: 24px; }
  .panel { padding: 28px 20px; }
}
