/* ============================================================
   WORD SLIDE - STYLES
   ============================================================ */

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

:root {
  --bg: #1a1a2e;
  --bg-light: #16213e;
  --accent: #e94560;
  --accent-light: #ff6b81;
  --text: #eee;
  --text-dim: #888;
  --wall: #2d2d52;
  --empty: #181830;
  --tile-bg: #3a86ff;
  --tile-text: #fff;
  --tile-target: #ffbe0b;
  --tile-selected: #ff006e;
  --goal-bg: #06d6a0;
  --goal-glow: rgba(6, 214, 160, 0.4);
  --group-border: rgba(255,255,255,0.5);
  --cell-size: 48px;
  --cell-gap: 2px;
  --radius: 6px;
}

html, body {
  width: 100%; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
#game-board {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  width: 100%; height: 100%;
  flex-direction: column;
  align-items: center;
  position: absolute; top: 0; left: 0;
}
.screen.active { display: flex; }

/* ===== HOME SCREEN ===== */
.home-inner {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 32px; padding: 40px 20px;
  width: 100%; max-width: 400px;
  height: 100%;
}
.home-logo { text-align: center; }
.logo-icon { font-size: 48px; margin-bottom: 8px; }
.logo-title { font-size: 32px; font-weight: 800; letter-spacing: -1px; }
.logo-subtitle { font-size: 14px; color: var(--text-dim); margin-top: 4px; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
}
.level-btn {
  aspect-ratio: 1;
  border: none; border-radius: var(--radius);
  background: var(--bg-light);
  color: var(--text);
  font-size: 18px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s, background 0.2s;
}
.level-btn:active { transform: scale(0.92); }
.level-btn.completed {
  background: var(--goal-bg);
  color: #000;
}
.level-btn.locked {
  background: var(--wall);
  color: var(--text-dim);
  cursor: default;
}

/* ===== GAME HEADER ===== */
.game-header {
  display: flex; align-items: center;
  width: 100%; max-width: 500px;
  padding: 12px 16px; gap: 12px;
}
.btn-back {
  background: none; border: none;
  color: var(--text); font-size: 24px;
  cursor: pointer; padding: 4px 8px;
}
.header-info {
  flex: 1;
  display: flex; flex-direction: column;
}
.level-name { font-size: 16px; font-weight: 700; }
.move-counter { font-size: 12px; color: var(--text-dim); }
.header-actions { display: flex; gap: 8px; }
.btn-icon {
  background: var(--bg-light); border: none;
  color: var(--text); font-size: 20px;
  width: 40px; height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.btn-icon:active { background: var(--accent); }
.btn-icon:disabled { opacity: 0.3; cursor: default; }

/* ===== HINT ===== */
.game-hint {
  font-size: 13px; color: var(--text-dim);
  padding: 0 16px 8px; text-align: center;
  max-width: 500px; width: 100%;
}

/* ===== BOARD ===== */
.board-wrapper {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 8px;
}
.board-container {
  display: flex; align-items: center; justify-content: center;
}
#game-board {
  display: grid;
  gap: var(--cell-gap);
}

/* ===== CELLS ===== */
.cell {
  width: var(--cell-size); height: var(--cell-size);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800;
  transition: transform 0.15s ease, background 0.15s ease;
  position: relative;
}

.cell-wall {
  background: var(--wall);
  border: 1px solid rgba(255,255,255,0.05);
}
.cell-empty {
  background: var(--empty);
  border: 1px solid rgba(255,255,255,0.03);
}
.cell-goal {
  background: var(--empty);
  box-shadow: inset 0 0 0 2px var(--goal-bg), 0 0 12px var(--goal-glow);
}
.cell-goal::after {
  content: "\2605";
  color: var(--goal-bg);
  font-size: 16px;
  opacity: 0.5;
  position: absolute;
}
.cell-letter {
  background: var(--tile-bg);
  color: var(--tile-text);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
/* Frozen letters: ungrouped, can't move */
.cell-letter.frozen {
  background: #3a3a5c;
  color: #888;
  cursor: default;
  box-shadow: none;
  opacity: 0.7;
}
.cell-letter.frozen.target {
  background: #5a5030;
  color: #aa9040;
  opacity: 0.85;
}
.cell-letter.on-goal {
  box-shadow: 0 0 0 2px var(--goal-bg), 0 2px 4px rgba(0,0,0,0.3);
}
.cell-letter.on-goal::after { display: none; }

.cell-letter.target {
  background: var(--tile-target);
  color: #222;
}
.cell-letter.selected {
  box-shadow: 0 0 0 3px var(--tile-selected), 0 0 16px rgba(255,0,110,0.4);
  transform: scale(1.05);
  z-index: 2;
  animation: pulse 0.8s ease-in-out infinite alternate;
}
@keyframes pulse {
  from { box-shadow: 0 0 0 3px var(--tile-selected), 0 0 12px rgba(255,0,110,0.3); }
  to   { box-shadow: 0 0 0 3px var(--tile-selected), 0 0 20px rgba(255,0,110,0.6); }
}

/* Group connectors: remove border-radius and margin between adjacent grouped tiles */
.cell-letter.group-connect-right {
  border-top-right-radius: 0; border-bottom-right-radius: 0;
  margin-right: -1px; padding-right: 1px;
}
.cell-letter.group-connect-left {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  margin-left: -1px; padding-left: 1px;
}
.cell-letter.group-connect-down {
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  margin-bottom: -1px; padding-bottom: 1px;
}
.cell-letter.group-connect-up {
  border-top-left-radius: 0; border-top-right-radius: 0;
  margin-top: -1px; padding-top: 1px;
}

/* ===== SLIDE ANIMATION ===== */
.cell-sliding {
  transition: transform 0.12s ease-out;
  z-index: 10;
}

/* ===== D-PAD ===== */
.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 20px;
  gap: 4px;
}
.dpad-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.dpad-center {
  width: 48px; height: 48px;
}
.dpad-btn {
  width: 48px; height: 48px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-light);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, transform 0.1s;
}
.dpad-btn:active {
  background: var(--accent);
  transform: scale(0.9);
}

/* ===== WIN MODAL ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
  background: var(--bg-light);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 320px; width: 90%;
  animation: popIn 0.3s ease;
}
@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-icon {
  font-size: 48px; color: var(--goal-bg);
  margin-bottom: 12px;
}
.modal-content h2 {
  font-size: 24px; margin-bottom: 8px;
}
.modal-moves {
  color: var(--text-dim); margin-bottom: 24px;
}
.modal-buttons {
  display: flex; flex-direction: column; gap: 10px;
}
.btn-primary {
  background: var(--accent);
  color: #fff; border: none;
  padding: 14px 24px; border-radius: var(--radius);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:active { background: var(--accent-light); }
.btn-secondary {
  background: none;
  color: var(--text-dim); border: 1px solid var(--text-dim);
  padding: 12px 24px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}

/* ===== RESPONSIVE ===== */
@media (max-height: 600px) {
  :root { --cell-size: 36px; }
  .game-header { padding: 8px 12px; }
}
@media (max-width: 360px) {
  :root { --cell-size: 38px; }
}
