/* ==========================================================================
   Games shared styles — game page shell, controls board, rules modal
   ========================================================================== */

.game-page { padding: 26px 0 40px; }

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 20px;
}

.game-head h1 {
  font-size: clamp(1.6rem, 3.6vw, 2.15rem);
  margin: 0;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: -0.5px;
}
.game-head h1 .emoji {
  font-size: 1.7rem;
  filter: drop-shadow(0 3px 6px rgba(99, 102, 241, 0.35));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-4px) rotate(-4deg); }
}

.game-head .back {
  color: var(--text-soft);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}
.game-head .back:hover { color: var(--primary-dark); background: rgba(99, 102, 241, 0.1); }

/* --------------------------------------------------------------------------
   Control bar
   -------------------------------------------------------------------------- */
.controls {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.controls .group { display: flex; align-items: center; gap: 8px; }
.controls .spacer { flex: 1; }

.difficulty {
  display: inline-flex;
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 5px;
  gap: 2px;
  border: 1px solid var(--border);
}
.difficulty button {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.18s ease, transform 0.1s ease;
}
.difficulty button:hover { color: var(--primary-dark); }
.difficulty button.active {
  color: #fff;
  background: var(--grad-warm);
  box-shadow: 0 4px 12px -4px rgba(99, 102, 241, 0.7);
}

/* Stat chips (timer, counters) */
.stat {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: linear-gradient(150deg, #1e293b, #0f172a);
  color: var(--text-invert);
  border-radius: 12px;
  padding: 7px 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 92px;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), var(--shadow-sm);
}
.stat .label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  opacity: 0.6;
  font-weight: 700;
}
.stat .value { font-size: 1.15rem; line-height: 1.1; }

/* --------------------------------------------------------------------------
   Board wrapper
   -------------------------------------------------------------------------- */
.board-wrap {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  overflow: auto;
}

.status-line {
  min-height: 24px;
  font-weight: 700;
  color: var(--text-soft);
  text-align: center;
  transition: color 0.2s ease;
}
.status-line.win {
  color: var(--success);
  animation: celebrate 0.6s ease;
}
.status-line.lose { color: var(--danger); animation: shake 0.4s ease; }
@keyframes celebrate {
  0% { transform: scale(0.9); opacity: 0.4; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* --------------------------------------------------------------------------
   Modal (game rules)
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; animation: fadein 0.2s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 86vh;
  overflow: auto;
  box-shadow: 0 30px 60px -15px rgba(2, 6, 23, 0.5);
  animation: pop 0.24s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop {
  from { transform: translateY(16px) scale(0.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.modal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  position: sticky;
  top: 0;
  color: #fff;
  background: var(--grad);
}
.modal .modal-head h2 { margin: 0; font-size: 1.28rem; font-weight: 800; }
.modal .close {
  border: none;
  background: rgba(255, 255, 255, 0.22);
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 1.05rem;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s ease, transform 0.15s ease;
}
.modal .close:hover { background: rgba(255, 255, 255, 0.35); transform: rotate(90deg); }

.modal .modal-body { padding: 22px 24px 26px; }
.modal .modal-body h3 {
  margin: 20px 0 6px;
  font-size: 1.04rem;
  display: flex; align-items: center; gap: 8px;
}
.modal .modal-body h3::before {
  content: "";
  width: 4px; height: 16px;
  border-radius: 2px;
  background: var(--grad-warm);
}
.modal .modal-body h3:first-child { margin-top: 0; }
.modal .modal-body p,
.modal .modal-body li { color: var(--text-soft); font-size: 0.95rem; }
.modal .modal-body ul { margin: 6px 0; padding-left: 22px; }
.modal .modal-body li { margin: 3px 0; }
.modal .modal-body kbd {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 0.82rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------------
   MINESWEEPER
   -------------------------------------------------------------------------- */
.ms-board {
  display: grid;
  gap: 3px;
  background: #94a3b8;
  padding: 3px;
  border-radius: 10px;
  box-shadow: inset 0 2px 6px rgba(2, 6, 23, 0.2);
  user-select: none;
  touch-action: manipulation;
}
.ms-cell {
  width: var(--cell, 30px); height: var(--cell, 30px);
  background: linear-gradient(150deg, #e2e8f0, #cbd5e1);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), inset 0 -2px 0 rgba(2,6,23,0.12);
  transition: background 0.1s ease, transform 0.05s ease;
}
.ms-cell:hover:not(.revealed) {
  background: linear-gradient(150deg, #eef2f7, #d5dde8);
  transform: translateY(-1px);
}
.ms-cell:active:not(.revealed) { transform: translateY(0); }
.ms-cell.revealed {
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(148,163,184,0.25);
  cursor: default;
  animation: reveal 0.18s ease;
}
@keyframes reveal {
  from { transform: scale(0.85); }
  to { transform: scale(1); }
}
.ms-cell.flag { font-size: 1rem; animation: plant 0.2s ease; }
@keyframes plant {
  from { transform: scale(0.3) rotate(-30deg); }
  to { transform: scale(1) rotate(0); }
}
.ms-cell.mine { background: radial-gradient(circle at 50% 40%, #fecaca, #ef4444); }
.ms-cell.mine-hit {
  background: radial-gradient(circle at 50% 40%, #fca5a5, #b91c1c);
  animation: boom 0.4s ease;
}
@keyframes boom {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); box-shadow: 0 0 20px rgba(239, 68, 68, 0.8); }
  100% { transform: scale(1); }
}
.ms-cell.wrong { background: #fecaca; }
/* number colors */
.ms-cell.n1 { color: #2563eb; }
.ms-cell.n2 { color: #16a34a; }
.ms-cell.n3 { color: #dc2626; }
.ms-cell.n4 { color: #7c3aed; }
.ms-cell.n5 { color: #b45309; }
.ms-cell.n6 { color: #0891b2; }
.ms-cell.n7 { color: #334155; }
.ms-cell.n8 { color: #6b7280; }

/* --------------------------------------------------------------------------
   SUDOKU
   -------------------------------------------------------------------------- */
.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(92vw, 468px);
  aspect-ratio: 1 / 1;
  background: #334155;
  border: 3px solid #334155;
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
  box-shadow: var(--shadow-sm);
}
.sk-cell {
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: clamp(1rem, 4.5vw, 1.5rem);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  transition: background 0.12s ease;
}
/* thicker 3x3 block borders */
.sk-cell { border-right: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0; }
.sk-cell[data-col="2"], .sk-cell[data-col="5"] { border-right: 2px solid #334155; }
.sk-cell[data-col="8"] { border-right: none; }
.sk-cell[data-row="2"], .sk-cell[data-row="5"] { border-bottom: 2px solid #334155; }
.sk-cell[data-row="8"] { border-bottom: none; }

.sk-cell.given { color: var(--text); cursor: default; font-weight: 800; }
.sk-cell.user  { color: var(--primary-dark); }
.sk-cell.peer { background: #eef2ff; }                 /* indigo-50 */
.sk-cell.same { background: #c7d2fe; }                 /* indigo-200 */
.sk-cell.selected {
  background: #e0e7ff;
  box-shadow: inset 0 0 0 2px var(--primary);
}
.sk-cell.error { color: var(--danger); background: #fee2e2; animation: shake 0.35s ease; }
.sk-cell.hint-fill { animation: hintflash 0.9s ease; }
@keyframes hintflash {
  0% { background: #86efac; transform: scale(0.7); }
  50% { background: #bbf7d0; transform: scale(1.05); }
  100% { background: var(--surface); transform: scale(1); }
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px;
  width: min(92vw, 468px);
}
.number-pad button {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  background: linear-gradient(150deg, #ffffff, #f1f5f9);
  border-radius: var(--radius-sm);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary-dark);
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.number-pad button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px -6px rgba(99, 102, 241, 0.5);
  background: #ffffff;
}
.number-pad button:active { transform: translateY(0); }
.number-pad button.erase { color: var(--text-soft); font-size: 1rem; }

/* --------------------------------------------------------------------------
   TRIPLE TILE
   -------------------------------------------------------------------------- */
.tt-stage {
  position: relative;
  width: min(94vw, 70vh, 480px);
  aspect-ratio: 1 / 1;   /* always a square coordinate space */
  margin: 0 auto;
}
.tt-card {
  position: absolute;
  border-radius: 14px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 4px 10px rgba(2, 6, 23, 0.18), inset 0 1px 0 rgba(255,255,255,0.9);
  background: linear-gradient(155deg, #ffffff, #eef2f7);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.22s ease, filter 0.2s ease;
  will-change: transform;
}
.tt-card .tt-glyph {
  transition: transform 0.12s ease;
  filter: drop-shadow(0 1px 2px rgba(2,6,23,0.15));
}
.tt-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(2, 6, 23, 0.25), inset 0 1px 0 rgba(255,255,255,0.9);
}
.tt-card:hover .tt-glyph { transform: scale(1.12); }
.tt-card.covered {
  cursor: not-allowed;
  filter: brightness(0.55) saturate(0.6);
}
.tt-card.covered:hover { transform: none; box-shadow: 0 4px 10px rgba(2, 6, 23, 0.18); }
.tt-card.covered:hover .tt-glyph { transform: none; }
.tt-card.removing {
  transform: scale(0.3) rotate(12deg);
  opacity: 0;
}

/* Slot tray */
.tt-tray {
  display: flex;
  gap: 7px;
  padding: 11px;
  background: linear-gradient(150deg, #eef2f7, #e2e8f0);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 66px;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 6px rgba(2, 6, 23, 0.12);
}
.tray-slot {
  width: 46px; height: 46px;
  border-radius: 11px;
  background: rgba(148, 163, 184, 0.22);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  transition: background 0.15s ease, transform 0.15s ease;
}
.tray-slot.filled {
  background: linear-gradient(155deg, #ffffff, #eef2f7);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.9);
  animation: dropin 0.22s cubic-bezier(.2,.9,.3,1.3);
}
@keyframes dropin {
  from { transform: translateY(-10px) scale(0.7); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}

/* --------------------------------------------------------------------------
   Responsive tweaks for game shell
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .controls { padding: 12px; gap: 10px; }
  .difficulty button { padding: 6px 12px; font-size: 0.8rem; }
  .stat { min-width: 74px; padding: 6px 10px; }
  .stat .value { font-size: 1.02rem; }
  .ms-board { --cell: 26px; }
  .ms-cell { font-size: 0.85rem; }
  .board-wrap { padding: 14px; }
  .tray-slot { width: 40px; height: 40px; font-size: 1.3rem; }
}

@media (max-width: 400px) {
  .ms-board { --cell: 22px; }
  .ms-cell { font-size: 0.75rem; }
}
