/* --- 1. Base Logic & Animations --- */
.home-btn {
    position: absolute;
    top: 2vh;
    left: 2vh;
    background: #fff;
    color: #007bff;
    border: 0.2vh solid #007bff;
    border-radius: 0.8vh;
    padding: 1vh 2vh;
    font-size: 1.8vh;
    font-family: inherit;
    text-decoration: none;
    font-weight: bold;
    box-shadow: 0 0.2vh 0.8vh rgba(0,0,0,0.07);
    z-index: 1000;
    transition: background 0.2s, color 0.2s;
}

.home-btn:hover {
    background: #007bff;
    color: #fff;
}

.fade-letter {
    display: inline-block;
    opacity: 0;
    transition: opacity 0.35s linear;
}

.cell.removing {
    animation: cellRemove 0.35s forwards;
}

@keyframes cellRemove {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.2); }
}

.cell.falling {
    transition: transform 0.4s cubic-bezier(0.4, 0.8, 0.5, 1.2);
    will-change: transform;
    z-index: 1;
}

/* --- 2. Global Layout (No Scroll) --- */
html, body {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Mobile browser support */
    margin: 0;
    padding: 0;
    overflow: hidden; 
    background: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.app {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    height: 98dvh;
    padding: 1vh 0;
    box-sizing: border-box;
    justify-content: space-evenly; 
}

/* --- 3. Typography & Message Containers --- */
h1 {
    font-family: 'Luckiest Guy', 'Comic Sans MS', 'Comic Sans', sans-serif;
    text-align: center;
    color: #222;
    margin: 0;
    letter-spacing: 1px;
    font-size: 5vh;
}

.subtitle {
    text-align: center;
    font-size: 1.8vh;
    color: #666;
    margin: 0;
    line-height: 1.2;
}

.tip-message {
    text-align: center;
    font-size: 1.4vh;
    color: #2f2f2f;
    margin-bottom: 0;
    padding: 0 10px;
}

#selected-word, #message, #answer {
    text-align: center;
    color: #007bff;
    font-weight: 500;
    height: 2.5vh; 
    line-height: 2.5vh;
    margin: 0.5vh 0;
    font-size: 2vh;
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* --- 4. Board Scaling --- */
.board {
    display: grid;
    gap: 0.5vh;
    /* Scales based on height (vh) OR width (vw) to prevent overflow on narrow phones */
    height: min(85vw, 45vh); 
    aspect-ratio: 4 / 7;
    margin: 0 auto;
    padding: 0.5vh;
    background: #e8e8e8;
    border-radius: 1vh;
    border: 0.2vh solid #d8d8d8;
    box-shadow: 0 0.2vh 1vh rgba(0,0,0,0.07);
    box-sizing: border-box;
}

.cell {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5vh;
    font-weight: bold;
    border-radius: 0.5vh;
    border: 0.2vh solid #d8d8d8;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    aspect-ratio: 1 / 1;
}

.cell.selected {
    background: #e3f0ff;
    border: 0.3vh solid #007bff;
    transform: scale(1.05);
    z-index: 2;
}

/* Orphan cell styling */
.cell.orphan {
    color: #9b9b9b;
    border: 0.2vh solid #cccccc;
    background: #fff;
    filter: none;
    opacity: 1;
}
.cell.orphan.selected {
    background: #e3f0ff;
    border: 0.3vh solid #007bff;
    transform: scale(1.05);
    z-index: 2;
}

/* --- 5. Controls & Buttons --- */
#submit-row, .controls {
    display: flex;
    gap: 1vh;
    justify-content: center;
    width: 100%;
}

button {
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 1vh;
    padding: 1vh 2vh;
    font-size: 1.8vh;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 0.2vh 0.8vh rgba(0,0,0,0.04);
}

button:hover {
    background: #0056b3;
    transform: translateY(-0.2vh);
}