/* Custom Animations and Specific Styling for CatCrush v2.2 */

.gem {
    width: 12.5%;
    height: 12.5%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    touch-action: none; /* Crucial for custom touch events */
    will-change: transform;
}

.gem:active {
    cursor: grabbing;
}

.gem-content {
    font-size: clamp(1.5rem, 8vw, 2.5rem); /* Emoji scaling */
    line-height: 1;
    filter: drop-shadow(0px 3px 3px rgba(0, 0, 0, 0.2));
    transition: transform 0.15s ease, filter 0.15s ease;
    pointer-events: none; /* Keep drag events on parent wrapper */
    display: flex;
    justify-content: center;
    align-items: center;
}

.gem:hover .gem-content {
    transform: scale(1.1);
}

.gem.selected .gem-content {
    transform: scale(1.2) rotate(10deg);
    filter: drop-shadow(0px 0px 8px rgba(255, 255, 255, 0.9));
}

.gem.popping .gem-content {
    animation: pop 0.4s ease-out forwards;
}

@keyframes pop {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.8; filter: brightness(1.2); }
    100% { transform: scale(0); opacity: 0; }
}

.gem.falling {
    transition: transform 0.35s cubic-bezier(0.55, 0.085, 0.68, 0.53);
}

.color-blast {
    animation: magic-blast 0.6s ease-in-out forwards;
    z-index: 30;
}

@keyframes magic-blast {
    0% { transform: scale(1) rotate(0deg); opacity: 1; filter: brightness(1); }
    50% { transform: scale(2.5) rotate(180deg); opacity: 0.9; filter: brightness(2) drop-shadow(0 0 20px white); }
    100% { transform: scale(0) rotate(360deg); opacity: 0; filter: brightness(3) drop-shadow(0 0 50px white); }
}

.gem.line-clear-h .gem-content {
    animation: blast-horizontal 0.4s ease forwards;
}

.gem.line-clear-v .gem-content {
    animation: blast-vertical 0.4s ease forwards;
}

@keyframes blast-horizontal {
    0% { transform: scaleX(1); opacity: 1; }
    50% { transform: scaleX(2.5) scaleY(0.5); opacity: 0.8; }
    100% { transform: scaleX(0); opacity: 0; }
}

@keyframes blast-vertical {
    0% { transform: scaleY(1); opacity: 1; }
    50% { transform: scaleY(2.5) scaleX(0.5); opacity: 0.8; }
    100% { transform: scaleY(0); opacity: 0; }
}

/* Background grid cells */
.grid-cell {
    width: 100%;
    height: 100%;
    border-right: 1px solid rgba(255,255,255,0.15);
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

/* --- Replaced Tailwind Styles --- */
:root {
  --color-indigo-300: #a5b4fc;
  --color-purple-300: #d8b4fe;
  --color-pink-300: #f9a8d4;
  --color-pink-500: #ec4899;
  --color-pink-600: #db2777;
  --color-yellow-300: #fde047;
  --color-yellow-500: #eab308;
  --color-indigo-800: #3730a3;
  --color-indigo-600: #4f46e5;
  --color-indigo-500: #6366f1;
  --color-rose-400: #fb7185;
  --color-fuchsia-500: #d946ef;
  --color-red-400: #f87171;
  --color-gray-100: #f3f4f6;
  --color-gray-700: #374151;
  --color-yellow-100: #fef08a;
  --color-red-100: #fee2e2;
  --color-blue-100: #dbeafe;
}

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 1rem 0.5rem;
    width: 100%;
    height: 100%;
    position: relative;
    background: linear-gradient(to bottom right, var(--color-indigo-300), var(--color-purple-300), var(--color-pink-300));
}

.app-container {
    width: 100%;
    max-width: 28rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    z-index: 10;
    height: 100%;
    max-height: 90vh;
}

.header-container {
    text-align: center;
    width: 100%;
    position: relative;
}

.title {
    font-size: 2.25rem;
    font-weight: 800;
    color: transparent;
    background-clip: text;
    -webkit-background-clip: text;
    background-image: linear-gradient(to right, var(--color-pink-500), var(--color-yellow-500));
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    margin: 0;
    -webkit-text-stroke: 1px white;
}
@media (min-width: 640px) {
    .title { font-size: 3rem; }
}

.version-badge {
    position: absolute;
    right: 0.5rem;
    top: 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    background-color: rgba(236, 72, 153, 0.8);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.stats-container {
    display: flex;
    width: 100%;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0 0.5rem;
}

.stat-box {
    flex: 1;
    background-color: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(12px);
    border-radius: 1rem;
    padding: 0.5rem 1rem;
    box-shadow: inset 0 2px 10px rgba(255,255,255,0.8), 0 4px 10px rgba(0,0,0,0.1);
    border: 1px solid rgba(255, 255, 255, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-indigo-800);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.8;
}

.score-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-pink-600);
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.05));
}

.combo-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-yellow-500);
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.05));
}

@media (min-width: 640px) {
    .score-value, .combo-value { font-size: 1.875rem; }
}

.board-wrapper {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    margin-top: 0.25rem;
}

.board-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(24px);
    border-radius: 1.5rem;
    box-shadow: inset 0 4px 20px rgba(255,255,255,0.8);
    border: 4px solid rgba(255, 255, 255, 0.7);
    margin: -0.25rem;
    pointer-events: none;
}

#game-board {
    width: 100%;
    height: 100%;
    position: relative;
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    gap: 0;
    border-radius: 1rem;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.05);
    touch-action: none;
}

.controls-container {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.info-btn {
    width: 3rem;
    height: 3rem;
    background-color: rgba(255, 255, 255, 0.6);
    border-radius: 9999px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-indigo-600);
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: transform 0.15s, background-color 0.15s;
    cursor: pointer;
}
.info-btn:hover { background-color: rgba(255, 255, 255, 1); }
.info-btn:active { transform: scale(0.95); }

.restart-btn {
    flex: 1;
    height: 3rem;
    background-image: linear-gradient(to right, var(--color-rose-400), var(--color-fuchsia-500), var(--color-indigo-500));
    border-radius: 9999px;
    font-weight: 700;
    color: white;
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.4);
    font-size: 1.125rem;
    letter-spacing: 0.05em;
    transition: transform 0.15s;
    border: 2px solid rgba(255, 255, 255, 0.3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.restart-btn:active { transform: scale(0.95); }

.overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.3s;
    z-index: 50;
}
.overlay.active {
    opacity: 1;
    transform: scale(1);
}

.overlay h2 {
    font-size: 3rem;
    font-weight: 800;
    color: white;
    text-align: center;
    filter: drop-shadow(0 8px 8px rgba(0,0,0,0.5));
    padding: 0 1rem;
    -webkit-text-stroke: 2px #ec4899;
}
@media (min-width: 640px) {
    .overlay h2 { font-size: 4.5rem; }
}

.text-yellow-300 { color: var(--color-yellow-300) !important; }
.text-red-400 { color: var(--color-red-400) !important; }
.text-pink-300 { color: var(--color-pink-300) !important; }

/* Modal Styles */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
.modal-overlay.active {
    pointer-events: auto;
    opacity: 1;
}

.modal-content {
    background-color: white;
    border-radius: 1.5rem;
    padding: 1.5rem;
    margin: 1rem;
    max-width: 28rem;
    width: 100%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.95);
    transition: transform 0.3s;
}
.modal-content.active {
    transform: scale(1);
}

.modal-title {
    font-weight: 700;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    margin-top: 0;
    text-align: center;
    color: var(--color-indigo-600);
}

.modal-list {
    font-size: 1rem;
    margin: 0;
    padding: 0;
    line-height: 1.5;
    font-weight: 500;
    color: var(--color-gray-700);
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modal-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modal-icon {
    font-size: 1.875rem;
    line-height: 1;
}
.modal-icon-bg {
    width: 2rem;
    text-align: center;
    border-radius: 0.5rem;
    padding: 0.25rem 0;
    display: inline-block;
}
.bg-gray-100 { background-color: var(--color-gray-100); }
.bg-yellow-100 { background-color: var(--color-yellow-100); }
.bg-red-100 { background-color: var(--color-red-100); }
.bg-blue-100 { background-color: var(--color-blue-100); }

.modal-btn {
    margin-top: 1.5rem;
    width: 100%;
    padding: 0.75rem 0;
    background-color: var(--color-indigo-500);
    color: white;
    border-radius: 0.75rem;
    font-weight: 700;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: none;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.15s, background-color 0.15s;
}
.modal-btn:hover { background-color: var(--color-indigo-600); }
.modal-btn:active { transform: scale(0.95); }
