/* ============================================================
   style.css — Wordmala Game Styles
   Design: deep-purple glassmorphism, amber accents
   ============================================================ */

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

/* ── CSS Variables ── */
:root {
  --bg-start:   #1E1B3A;
  --bg-mid:     #251E4A;
  --bg-end:     #2B2252;
  --card-bg:    rgba(52, 44, 108, 0.70);
  --card-border: rgba(75, 63, 163, 0.60);
  --card-hover:  #40368A;
  --tile-sel-bg: rgba(255, 183, 3, 0.18);
  --tile-sel-border: #FFB703;
  --amber:      #FFB703;
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
}

/* ── Base ── */
body {
  font-family: 'Noto Sans Devanagari', 'Mangal', Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-mid) 50%, var(--bg-end) 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  padding: 24px 16px 100px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  position: relative;
}

/* Animated radial-gradient overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(75,63,163,0.35), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(64,54,138,0.25), transparent 50%),
    radial-gradient(circle at 40% 80%, rgba(30,27,58,0.30), transparent 50%);
  animation: gradientShift 15s ease infinite;
  pointer-events: none;
  z-index: 0;
}

/* All content above the overlay */
.container { position: relative; z-index: 1; max-width: 448px; margin: 0 auto; }

/* ── Keyframes ── */
@keyframes gradientShift {
  0%,100% { opacity:1; transform:scale(1); }
  50%      { opacity:0.8; transform:scale(1.1); }
}
@keyframes fadeIn   { from{opacity:0} to{opacity:1} }
@keyframes scaleIn  { from{opacity:0;transform:scale(0.9)} to{opacity:1;transform:scale(1)} }
@keyframes slideUp  { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }
@keyframes shake {
  0%,100% { transform:translateX(-50%); }
  15%,45%,75% { transform:translateX(calc(-50% - 8px)); }
  30%,60%,90% { transform:translateX(calc(-50% + 8px)); }
}
@keyframes spin  { to{transform:rotate(360deg)} }
@keyframes mergeIn {
  0%   { opacity:0; transform:scaleX(0.3) scaleY(0.7); filter:brightness(1.8); }
  50%  { opacity:1; transform:scaleX(1.04) scaleY(1.05); filter:brightness(1.3); }
  70%  { transform:scaleX(0.98) scaleY(0.98); filter:brightness(1.1); }
  100% { opacity:1; transform:scaleX(1) scaleY(1); filter:brightness(1); }
}
@keyframes shimmerSweep {
  0%   { transform:translateX(-100%) skewX(-15deg); opacity:0.7; }
  100% { transform:translateX(300%) skewX(-15deg);  opacity:0; }
}
@keyframes submitPulse {
  0%,100% { background-color:#FFB703; box-shadow:0 0 0 0 rgba(255,183,3,0.55); }
  50%     { background-color:#e6a500; box-shadow:0 0 0 8px rgba(255,183,3,0); }
}
@keyframes hint-glow {
  0%,100% { box-shadow:0 0 0 2px rgba(255,183,3,0.50), 0 0 14px rgba(255,183,3,0.25); border-color:#FFB703; }
  50%     { box-shadow:0 0 0 4px rgba(255,183,3,0.80), 0 0 24px rgba(255,183,3,0.55); border-color:#f59e0b; }
}
@keyframes ping {
  75%,100% { transform:scale(2.2); opacity:0; }
}
@keyframes sparkle {
  0%,100% { opacity:0; transform:scale(0) rotate(0deg); }
  50%      { opacity:1; transform:scale(1) rotate(180deg); }
}
.sparkle-emoji {
  position:absolute; font-size:2rem; pointer-events:none;
  animation:sparkle 0.8s ease-out both;
}
.sparkle-emoji:nth-child(1) { top:-12px; left:-12px; animation-delay:0s; }
.sparkle-emoji:nth-child(2) { top:-12px; right:-12px; animation-delay:0.2s; }
.sparkle-emoji:nth-child(3) { bottom:-12px; left:-12px; animation-delay:0.4s; }
.sparkle-emoji:nth-child(4) { bottom:-12px; right:-12px; animation-delay:0.6s; }

/* ── Header ── */
.game-header { text-align:center; margin-bottom:18px; }

.game-title {
  font-size:1.9rem; font-weight:800; margin-bottom:6px;
  color:#fff; letter-spacing:0.01em;
}
.game-title .title-red { color:#ef4444; }

.game-instructions { color:var(--text-muted); font-size:0.875rem; line-height:1.5; }

/* ── Lives + Counter ── */
.header-status { display:flex; align-items:center; justify-content:center; gap:16px; margin-top:10px; }
.lives-row { display:flex; align-items:center; gap:6px; }
.life-dot  { width:11px; height:11px; border-radius:50%; background:#ef4444; transition:background 0.3s; }
.life-dot.lost { background:#342C6C; border:1px solid rgba(75,63,163,0.5); }
.solved-counter { font-size:0.85rem; font-weight:600; color:var(--amber); background:rgba(52,44,108,0.7); border:1px solid rgba(255,183,3,0.35); border-radius:20px; padding:2px 12px; }

/* ── Hint Timer ── */
.hint-timer { margin-bottom:14px; }
.hint-timer-head { display:flex; align-items:center; justify-content:space-between; font-size:0.82rem; color:var(--text-muted); margin-bottom:6px; }
.hint-timer-label { display:flex; align-items:center; gap:5px; font-weight:600; color:var(--text); }
.hint-secs     { transition:color 0.3s; }
.hint-secs.low { color:var(--amber); font-weight:700; }
.hint-bar-bg   { height:7px; background:rgba(42,37,85,0.8); border-radius:999px; overflow:hidden; }
.hint-bar      { height:100%; border-radius:999px; background:var(--amber); transition:width 1s linear; }
.hint-bar.low  { background:#f59e0b; }

/* ── Hint Popup — fixed bottom ── */
.hint-popup {
  position:fixed; bottom:24px; left:16px; right:16px;
  max-width:448px; margin:0 auto;
  z-index:30;
  background:rgba(30,20,60,0.96); border:1px solid rgba(255,183,3,0.55);
  border-radius:12px; padding:14px 42px 14px 14px;
  animation:slideUp 300ms ease both;
  backdrop-filter:blur(12px);
  box-shadow:0 8px 32px rgba(0,0,0,0.5);
}
.hint-close { position:absolute; top:10px; right:12px; background:none; border:none; color:var(--text-muted); font-size:1.2rem; line-height:1; cursor:pointer; padding:0; transition:color 0.2s; }
.hint-close:hover { color:#fff; }
.hint-label { color:var(--text-muted); font-size:0.78rem; font-weight:500; margin-bottom:8px; }
.hint-words { color:#fff; font-size:1.15rem; font-weight:700; text-align:center; }
.hint-cat   { color:var(--amber); font-size:0.82rem; font-style:italic; text-align:center; margin-top:4px; }

/* ── Game Grid ── */
.game-grid {
  display:grid; grid-template-columns:repeat(3,1fr);
  gap:1rem; width:100%; margin-bottom:12px;
  align-items:stretch;
}
@media (min-width: 768px) {
  .game-grid { gap:1.25rem; }
}

.solved-groups { display:none; }

/* ── Tile ── */
.tile {
  background:var(--card-bg);
  border:2px solid var(--card-border);
  border-radius:1rem; padding:8px;
  cursor:pointer; text-align:center;
  font-family:inherit; font-size:1.125rem; font-weight:600; color:var(--text);
  aspect-ratio:1; min-height:60px; width:100%;
  display:flex; align-items:center; justify-content:center;
  position:relative; user-select:none; -webkit-user-select:none;
  backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px);
  transition: background-color 200ms, border-color 200ms, transform 150ms, box-shadow 150ms;
}
@media (min-width: 768px) {
  .tile { font-size:1.25rem; }
}
.tile:hover:not(.solved):not(:disabled) {
  background:var(--card-hover);
  border-color:rgba(75,63,163,0.9);
  box-shadow:0 4px 16px rgba(0,0,0,0.35);
  transform:translateY(-1px);
}
.tile:active:not(.solved):not(:disabled) { transform:scale(0.95); }

.tile.selected {
  background:var(--tile-sel-bg);
  border-color:var(--tile-sel-border);
  border-width:2px;
  transform:scale(1.02);
}
.tile.selected::after {
  content:''; position:absolute; bottom:5px; right:5px;
  width:6px; height:6px; border-radius:50%; background:var(--amber);
}

.tile.solved { cursor:default; color:#111827; font-weight:700; border-color:transparent; }

/* Hint tile — amber glow + ping dot */
.tile.hint-word {
  border-color:var(--amber);
  border-width:2px;
  animation:hint-glow 1s ease-in-out infinite;
}
.tile.hint-word::before {
  content:''; position:absolute; top:6px; right:6px;
  width:8px; height:8px; border-radius:50%;
  background:var(--amber); animation:ping 1s ease-in-out infinite;
}
.tile.hint-word::after {
  content:''; position:absolute; top:9px; right:9px;
  width:6px; height:6px; border-radius:50%;
  background:var(--amber); opacity:0.9;
}

.tile:disabled { opacity:0.50; cursor:not-allowed; }

/* ── Selection Count ── */
.sel-count { text-align:center; font-size:0.875rem; color:var(--text-muted); min-height:1.3em; margin-bottom:6px; }

/* ── Submit Button ── */
.submit-btn {
  display:block; width:auto; min-width:160px; padding:12px 36px;
  background:var(--amber); color:#1E1B3A;
  border:none; border-radius:999px;
  font-family:inherit; font-size:1rem; font-weight:700;
  cursor:pointer; margin:0 auto 10px;
  transition:background-color 200ms, transform 150ms;
}
.submit-btn:not(:disabled) { animation:submitPulse 1.8s ease-in-out infinite; }
.submit-btn:hover:not(:disabled) { background:#e6a500; animation:none; }
.submit-btn:active:not(:disabled) { transform:scale(0.98); }
.submit-btn:disabled { opacity:1; cursor:not-allowed; animation:none; background:rgba(52,44,108,0.8); color:rgba(148,163,184,0.7); border:1px solid rgba(75,63,163,0.4); }

.spinner {
  display:inline-block; width:16px; height:16px;
  border:2px solid rgba(30,27,58,0.3); border-top-color:#1E1B3A;
  border-radius:50%; animation:spin 0.6s linear infinite;
  vertical-align:middle; margin-right:6px;
}

/* ── Solved Groups ── */
.solved-groups { margin-top:20px; display:flex; flex-direction:column; gap:10px; }

.solved-group {
  grid-column: 1 / -1;
  aspect-ratio: 3;
  border-radius:1rem; padding:8px 24px;
  position:relative; overflow:hidden;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  animation:mergeIn 0.55s cubic-bezier(0.34,1.56,0.64,1) both;
}

.solved-group.no-anim { animation:none; }
.solved-group.no-anim::after { animation:none; }

/* shimmer sweep after merge */
.solved-group::after {
  content:''; position:absolute; inset:0;
  background:linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.45) 50%, transparent 100%);
  transform:translateX(-100%) skewX(-15deg);
  animation:shimmerSweep 0.7s ease-out 0.3s forwards;
  pointer-events:none; border-radius:inherit;
}

.solved-group-name {
  color:#111827; font-weight:700; text-align:center;
  font-size:0.88rem; margin-bottom:6px; letter-spacing:0.03em;
}

/* Word chips row */
.merged-words {
  display:flex; flex-wrap:wrap;
  align-items:center; justify-content:center;
  gap:6px;
}
.merged-word {
  display:inline-flex; align-items:center;
  background:rgba(0,0,0,0.18); color:#fff;
  font-size:0.85rem; font-weight:700;
  padding:3px 12px; border-radius:8px;
  border:1px solid rgba(255,255,255,0.6);
  box-shadow:0 1px 4px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.18);
  white-space:nowrap;
}

/* ── Error Toast (recreated in DOM each time for animation replay) ── */
.error-toast {
  position:fixed; bottom:220px; left:50%; transform:translateX(-50%);
  z-index:40; animation:shake 500ms ease;
}
.error-toast-inner {
  background:rgba(239,68,68,0.92); color:#fff;
  padding:11px 22px; border-radius:10px;
  box-shadow:0 6px 22px rgba(0,0,0,0.45);
  font-weight:600; font-size:1.05rem; white-space:nowrap;
}

/* ── Game Over Modal ── */
.modal-overlay {
  position:fixed; inset:0; z-index:50;
  display:flex; align-items:center; justify-content:center; padding:16px;
  background:rgba(0,0,0,0.75); animation:fadeIn 300ms ease;
}
.modal-box {
  width:100%; max-width:340px;
  background:linear-gradient(135deg,#251E4A,#2B2252);
  border-radius:16px; padding:28px 22px;
  border:2px solid transparent;
  animation:scaleIn 300ms ease;
  backdrop-filter:blur(20px);
}
.modal-box.won  { border-color:#22c55e; }
.modal-box.lost { border-color:#ef4444; }

.modal-icon {
  width:62px; height:62px; border-radius:50%;
  display:flex; align-items:center; justify-content:center; margin:0 auto 16px;
}
.modal-icon.won  { background:rgba(34,197,94,0.15); }
.modal-icon.lost { background:rgba(239,68,68,0.15); }
.modal-icon svg  { width:36px; height:36px; }

.modal-title { font-size:1.9rem; font-weight:800; text-align:center; margin-bottom:8px; }
.modal-title.won  { color:#4ade80; }
.modal-title.lost { color:#f87171; }
.modal-subtitle { color:#cbd5e1; text-align:center; margin-bottom:20px; font-size:0.92rem; }

.modal-stats {
  background:rgba(0,0,0,0.25); border-radius:10px; padding:14px;
  margin-bottom:20px; display:grid; grid-template-columns:1fr 1fr; gap:12px; text-align:center;
}
.stat-label { color:var(--text-muted); font-size:0.78rem; margin-bottom:4px; }
.stat-value { color:#fff; font-size:1.35rem; font-weight:700; }

.play-again-btn {
  width:100%; padding:13px; border-radius:12px; border:none;
  font-family:inherit; font-size:1.05rem; font-weight:800; cursor:pointer;
  transition:background-color 200ms;
}
.play-again-btn.won  { background:#22c55e; color:#fff; }
.play-again-btn.won:hover  { background:#16a34a; }
.play-again-btn.lost { background:#ef4444; color:#fff; }
.play-again-btn.lost:hover { background:#dc2626; }

.rank-badge {
  margin-top:14px;
  background:rgba(255,183,3,0.15); border:1px solid rgba(255,183,3,0.45);
  border-radius:10px; padding:10px;
  text-align:center; color:#fcd34d; font-size:0.82rem; font-weight:600;
}

/* ── Focus ring ── */
*:focus-visible { outline:2px solid var(--amber); outline-offset:2px; }

/* ── Utility ── */
.hidden { display:none !important; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:0.01ms !important;
    animation-iteration-count:1 !important;
    transition-duration:0.01ms !important;
  }
}
.play-again-btn.won {
  margin-top: 20px;
}
.reward-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  color: #fff;
  width: 100%;
  justify-content: space-between;
} 
.count {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.coin-reward {
  display: flex;
  align-items: center;
  gap: 4px;
}
.coin-box {
  width: 24px;
  height: 24px;

  background: #ff3a3a;
  border-radius: 4px;

  display: flex;
  align-items: center;
  justify-content: center;
}
.coin-box img {
  width: 18px;
  height: auto;
}
.coin-reward span {
  font-size: 18px;
  font-weight: 700;
}