* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top, #eef6ff 0%, #dbeafe 42%, #bfdbfe 100%);
  color: #111827;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overscroll-behavior: none;
}

.game-shell {
  width: 100%;
  max-width: 520px;
  min-height: 100dvh;
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header {
  text-align: center;
  margin-bottom: 6px;
  flex: 0 0 auto;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(1.55rem, 6.5vw, 2.15rem);
  letter-spacing: 1px;
  color: #0f172a;
  line-height: 1.02;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: #475569;
}

.top-panel {
  width: 100%;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid rgba(15, 23, 42, 0.08);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 7px 18px rgba(15, 23, 42, 0.11);
  margin-bottom: 7px;
  flex: 0 0 auto;
}

.timer-box {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 7px;
}

.label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
}

#timer {
  font-size: 1.15rem;
  font-weight: 900;
  color: #0f172a;
}

.found-words {
  display: flex;
  justify-content: center;
  gap: 7px;
  flex-wrap: wrap;
}

.word-slot {
  min-width: 76px;
  text-align: center;
  padding: 6px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #64748b;
  font-size: 0.84rem;
  font-weight: 900;
  letter-spacing: 1px;
  transition: all 0.25s ease;
}

.word-slot.found {
  background: #2563eb;
  color: white;
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.45);
}

button {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 900;
}

.main-btn,
.how-to-btn {
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.95rem;
}

.main-btn {
  background: #2563eb;
  color: white;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.32);
}

.how-to-btn {
  background: rgba(255, 255, 255, 0.9);
  color: #1d4ed8;
  border: 2px solid rgba(37, 99, 235, 0.25);
  padding: 7px 14px;
  font-size: 0.82rem;
  margin-bottom: 7px;
  flex: 0 0 auto;
}

.main-btn:active,
.how-to-btn:active {
  transform: scale(0.96);
}

.grid {
  width: var(--grid-size, min(94vw, 480px));
  height: var(--grid-size, min(94vw, 480px));
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: #111827;
  border: 3px solid #111827;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
  transition: opacity 0.4s ease, transform 0.4s ease;
  flex: 0 0 auto;
}

.grid.finished {
  opacity: 0;
  transform: scale(0.94);
  pointer-events: none;
}

.tile {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: white;
  border: 1px solid #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.05rem, 6vw, 2.25rem);
  font-weight: 900;
  color: #020617;
  line-height: 1;
  user-select: none;
  touch-action: manipulation;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    transform 0.16s ease,
    box-shadow 0.18s ease,
    opacity 0.35s ease;
}

.tile:active {
  transform: scale(0.92);
}

.tile.correct {
  background: #dbeafe;
  color: #1d4ed8;
  box-shadow:
    inset 0 0 0 4px #3b82f6,
    0 0 18px rgba(59, 130, 246, 0.85);
  z-index: 2;
}

.tile.wrong {
  background: #fee2e2;
  color: #b91c1c;
  box-shadow:
    inset 0 0 0 4px #ef4444,
    0 0 16px rgba(239, 68, 68, 0.6);
  z-index: 2;
}

.tile.removed {
  opacity: 0;
  transform: scale(0.3) rotate(8deg);
  pointer-events: none;
}

.copyright-footer {
  width: 100%;
  text-align: center;
  font-size: 0.72rem;
  color: #475569;
  padding: 7px 0 2px;
  flex: 0 0 auto;
}

.complete-panel {
  width: 100%;
  margin-top: 10px;
  padding: 22px 16px;
  border-radius: 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
  border: 2px solid rgba(37, 99, 235, 0.18);
  animation: popIn 0.45s ease forwards;
}

.hidden {
  display: none;
}

.medal {
  font-size: 4rem;
  margin-bottom: 4px;
}

.complete-panel h2 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  color: #0f172a;
}

.complete-panel p {
  color: #475569;
}

.final-words {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 16px 0;
}

.final-word {
  padding: 10px 16px;
  border-radius: 999px;
  background: #2563eb;
  color: white;
  font-weight: 900;
  letter-spacing: 1px;
}

.final-time {
  margin: 16px 0;
}

.share-btn {
  margin-top: 6px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 18px;
}

.overlay.hidden {
  display: none;
}

.instructions-card {
  width: min(92vw, 430px);
  background: rgba(255, 255, 255, 0.97);
  border-radius: 26px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  animation: popIn 0.35s ease forwards;
}

.instructions-card h2 {
  margin: 0 0 12px;
  color: #0f172a;
  font-size: 1.8rem;
}

.instructions-card p {
  margin: 8px 0;
  color: #475569;
  line-height: 1.4;
}

.instructions-card ul {
  list-style: none;
  margin: 16px 0;
  padding: 0;
  text-align: left;
}

.instructions-card li {
  margin: 9px 0;
  color: #334155;
  line-height: 1.35;
}

.blue-dot,
.red-dot {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  margin-right: 5px;
  vertical-align: -1px;
}

.blue-dot {
  background: #3b82f6;
}

.red-dot {
  background: #ef4444;
}

.start-btn {
  margin-top: 8px;
  width: 100%;
  max-width: 260px;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 420px) {
  .game-shell {
    padding: 7px 8px 8px;
  }

  .game-header h1 {
    font-size: clamp(1.45rem, 7vw, 1.9rem);
  }

  .word-slot {
    min-width: 70px;
    padding: 5px 7px;
    font-size: 0.78rem;
  }

  .tile {
    font-size: clamp(1rem, 6.4vw, 2rem);
  }

  .instructions-card {
    padding: 22px 18px;
  }
}

@media (max-height: 640px) {
  .game-header h1 {
    font-size: 1.35rem;
  }

  .subtitle {
    font-size: 0.72rem;
  }

  .top-panel {
    padding: 6px;
    margin-bottom: 5px;
  }

  .timer-box {
    margin-bottom: 5px;
  }

  #timer {
    font-size: 1rem;
  }

  .word-slot {
    padding: 4px 7px;
    font-size: 0.74rem;
  }

  .how-to-btn {
    padding: 5px 12px;
    margin-bottom: 5px;
  }

  .copyright-footer {
    padding-top: 5px;
    font-size: 0.68rem;
  }
}