* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #fff5f7;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    background-color: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(220, 53, 88, 0.1);
    max-width: 95vw;
    overflow-x: auto;
    position: relative;
    transition: padding 0.5s ease;
}

.container.completed {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

h1 {
    text-align: center;
    color: #e91e63;
    margin-bottom: 20px;
    font-size: 2.2rem;
}

.game-container {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "empty-top col-clues"
        "row-clues grid";
    gap: 2px;
    width: max-content;
    margin: 0 auto;
    transition: all 0.5s ease;
}

.game-container.completed {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0;
}

/* Empty top-left corner */
.empty-top {
    grid-area: empty-top;
    width: 200px; /* Adjusted for max row clues */
    height: 90px; /* Adjusted for max col clues */
    transition: opacity 0.5s ease;
}

/* Column clues - above the grid */
.col-clues-container {
    grid-area: col-clues;
    display: grid;
    grid-template-columns: repeat(64, 18px);
    grid-template-rows: repeat(5, 18px); /* maxColClues is 5 */
    gap: 1px;
    transition: opacity 0.5s ease;
}

.col-clue-cell {
    width: 18px;
    height: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    font-weight: bold;
    color: #d63384;
    background-color: #fff0f6;
    border: 1px solid #ffccd5;
    text-align: center;
}

/* Row clues - to the left of the grid */
.row-clues-container {
    grid-area: row-clues;
    display: grid;
    grid-template-columns: repeat(22, 18px); /* maxRowClues is 22 */
    grid-template-rows: repeat(15, 18px);
    gap: 1px;
    justify-content: end; /* Right-align clues so last clue is near grid */
    transition: opacity 0.5s ease;
}

.row-clue-cell {
    width: 18px;
    height: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    font-weight: bold;
    color: #d63384;
    background-color: #fff0f6;
    border: 1px solid #ffccd5;
    text-align: center;
}

/* Main grid */
.nonogram-grid {
    grid-area: grid;
    display: grid;
    grid-template-columns: repeat(64, 18px);
    grid-template-rows: repeat(15, 18px);
    gap: 1px;
    background-color: #ddd;
    border: 2px solid #aaa;
    transition: all 0.5s ease;
}

.nonogram-grid.completed-grid {
    background-color: transparent;
    border: 2px solid transparent;
    gap: 0;
    margin: 0 auto;
    transform-origin: center;
}

.cell {
    width: 18px;
    height: 18px;
    background-color: white;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s ease;
}

.cell:hover {
    background-color: #fff0f6;
}

.cell.filled {
    background-color: #e91e63;
}

.cell.marked {
    background-color: white;
    position: relative;
}

.cell.marked::after {
    content: "✕";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-size: 12px;
    transition: opacity 0.3s ease;
}

.cell.completed-zero {
    background-color: #e91e63;
    animation: pulse 0.5s ease;
}

.cell.completed-one {
    background-color: white;
    animation: pulse 0.5s ease;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.controls {
    margin-top: 30px;
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    transition: opacity 0.5s ease;
}

.controls.hidden {
    opacity: 0;
    pointer-events: none;
}

.control-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    background-color: #e91e63;
    color: white;
    cursor: pointer;
    font-weight: bold;
    font-size: 15px;
    transition: all 0.2s;
}

.control-btn:hover {
    background-color: #d81b60;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(233, 30, 99, 0.2);
}

.clear-btn {
    background-color: #ff9800;
}

.clear-btn:hover {
    background-color: #e68900;
}

.solve-btn {
    background-color: #4caf50;
}

.solve-btn:hover {
    background-color: #45a049;
}

.mode-btn {
    padding: 14px 28px;
    border: none;
    border-radius: 8px;
    background-color: #9c27b0;
    color: white;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    transition: all 0.2s;
    min-width: 140px;
}

.mode-btn:hover {
    background-color: #8a1ba1;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(156, 39, 176, 0.2);
}

.mode-btn.filling {
    background-color: #e91e63;
}

.mode-btn.filling:hover {
    background-color: #d81b60;
}

.mode-btn.crossing {
    background-color: #6c757d;
}

.mode-btn.crossing:hover {
    background-color: #5a6268;
}

.message {
    margin-top: 20px;
    padding: 15px;
    background-color: #fff0f6;
    border-radius: 8px;
    text-align: center;
    color: #d63384;
    font-weight: bold;
    display: none;
    border: 2px solid #ffccd5;
    transition: opacity 0.5s ease;
}

.completion-message {
    text-align: center;
    color: #e91e63;
    font-size: 1.5rem;
    margin-bottom: 20px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s ease;
}

.completion-message.show {
    opacity: 1;
    transform: translateY(0);
}

.celebration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    display: none;
}

.heart {
    position: absolute;
    font-size: 24px;
    color: #e91e63;
    animation: floatUp 2s ease-in forwards;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

.completion-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    opacity: 0;
    transform: scale(0.9);
    transition: all 0.5s ease;
}

.completion-container.show {
    opacity: 1;
    transform: scale(1);
}