/* CSS Variables for theming */
:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --light-text-color: #999999;
    --cell-bg-color: #f0f0f0;
    --cell-border-color: #0000001a;
    --correct-color: #6fb05c;
    --incorrect-color: #edeff1;
    --partial-color: #e9ba3a;
}

.dark-mode {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --light-text-color: #bbbbbb;
    --cell-bg-color: #333333;
    --cell-border-color: #ffffff1a;
    --correct-color: #449235;
    --incorrect-color: #2a2a2a;
    --partial-color: #cb9f27;
}

/* Base styles */
body {
    font-family: 'Nunito Sans', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    margin: 0;
    box-sizing: border-box;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	-o-user-select: none;
	user-select: none;
}

.container {
    max-width: 90vw;
    width: 440px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    width: 100%;
}

.menu-left, .menu-right {
    display: flex;
    gap: 10px;
}

.icon-button {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px;
    color: var(--text-color);
}

/* Typography */
h1 {
    font-size: 1.8em;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--text-color);
}

h2 {
    font-weight: normal;
    font-size: 1em;
    text-align: center;
    margin-bottom: 10px;
    color: var(--light-text-color);
}

h3 {
    text-align: center;
}

.light-text {
    color: var(--light-text-color);
    font-size: 1.1em;
    font-weight: normal;
    margin: 10px 0;
}

#daily-puzzle {
    font-size: 1em;
}

/* Grid styles */
#grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1vmin;
    width: 100%;
    aspect-ratio: 1 / 1;
    margin-top: 20px;
}

.cell {
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8em;
    font-weight: 700;
    border-radius: 12%;
    padding: 5px;
    box-sizing: border-box;
    min-width: 40px;
    min-height: 40px;
    transition: all 0.3s ease;
    user-select: none;
}

.cell:not(.empty):not(.result):not(.empty-result) {
    background-color: var(--cell-bg-color);
    border-bottom: 0.5vmin solid var(--cell-border-color);
    cursor: move;
}

.result {
    background-color: transparent;
    color: var(--light-text-color);
    font-weight: normal;
}

.empty, .empty-result {
    background-color: transparent;
    border: 1px dashed transparent;
    visibility: visible;
}

/* Status message */
#status-message {
    margin-top: 1em;
    font-weight: bold;
    color: var(--text-color);
}

.swaps-count {
    font-weight: bold;
    color: var(--text-color);
    font-size: 1.1em;
}

/* Author credit */
#author {
    margin-top: 2em;
    font-style: italic;
    color: var(--light-text-color);
}

/* Responsive adjustments */
@media (max-height: 600px) {
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 2em;
    }

    h2 {
        font-size: 1em;
    }

    .light-text {
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .container {
        width: 95vw;
    }

    .cell {
        font-size: 1.8em;
    }
}

/* Game state styles */
.cell[draggable="true"]:hover {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.cell[draggable="true"]:active {
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transform: scale(0.95);
}

/* Color styles for correct and incorrect placements */
.cell.correct {
    background-color: var(--correct-color) !important;
    color: white !important;
}

.cell.incorrect {
    background-color: var(--incorrect-color) !important;
    color: var(--text-color) !important;
}

.cell.partial {
    background-color: var(--partial-color) !important;
    color: white !important;
}

/* Additional styles for better visibility */
.cell.result, .cell.empty-result {
    font-size: 1.8em;
}

/* Improve contrast for operators */
.cell:not(.empty):not(.result):not(.empty-result):not(.correct):not(.partial):not(.incorrect) {
    color: var(--text-color);
}

/* Statistics Popup Styles */
.stats-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.stats-content {
    position: relative;
    background-color: var(--bg-color);
    padding: 20px;
    border-radius: 10px;
    width: 350px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.stats-content h2 {
    text-align: center;
    margin-bottom: 20px;
}

.close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: var(--text-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
}

.stat-label {
    font-size: 0.8em;
    color: var(--light-text-color);
}

.star-distribution {
    margin-top: 10px;
    margin-bottom: 20px;
}

.star-distribution {
    margin-top: 10px;
}

.star-row {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.star-label {
    width: 30px;
    text-align: right;
    margin-right: 10px;
}

.star-bar {
    height: 20px;
    background-color: var(--correct-color);
    border-radius: 5px;
    transition: width 0.3s ease;
}

.star-count {
    width: 30px;
    text-align: right;
    margin-left: 10px;
}

#game-over-container {
    text-align: center;
    margin-top: 20px;
    margin-bottom: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-over-message {
    font-size: 1.5em;
    font-weight: bold;
    margin-bottom: 10px;
}

#game-over-subtitle {
    font-size: 1em;
    margin-bottom: 20px;
}

#game-over-star {
    font-size: 2em;
    color: gold;
    margin-bottom: 20px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

#next-maffle {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 20px;
    justify-content: space-between;
    margin-bottom: 30px;
}

.next-maffle-row {
    margin-top: 20px;
    font-size: 1em;
    display: flex;
    flex-direction: column;
}

#next-maffle-time {
    font-size: 1.8em;
}

#share-button {
    margin-top: 20px;
    padding: 15px 30px;
    font-size: 1em;
    background-color: var(--correct-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.share-button i {
    font-size: 1.2em;
    margin-left: 10px;
}

.solution-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1vmin;
    width: 100%;
    aspect-ratio: 1 / 1;
    margin: 20px 0;
}

.solution-grid .cell {
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8em;
    font-weight: 700;
    border-radius: 12%;
    padding: 5px;
    box-sizing: border-box;
}

.solution-grid .cell.result,
.solution-grid .cell.empty {
    background-color: transparent;
    border: none;
}

.solution-grid .cell.result {
    color: var(--light-text-color);
    font-weight: normal;
}

.solution-grid .cell.empty {
    color: transparent;
    visibility: hidden; 
}

.solution-grid .cell.correct {
    background-color: var(--correct-color);
    color: white;
}

.instructions-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.instructions-content {
    background-color: var(--bg-color);
    padding: 20px;
    border-radius: 10px;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    position: relative;
}

.instructions-content h3 {
    margin-bottom: 15px;
}

.instructions-content p, .instructions-content ul {
    margin-bottom: 10px;
}

.instructions-content .close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
}

.instructions-content p, .instructions-content ul {
    text-align: left;
    line-height: 1.5;
}

.instructions-content ul {
    padding-left: 20px;
}

.instructions-content li {
    margin-bottom: 10px;
}

.show-solution-button {
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 15px 30px;
    font-size: 1em;
    background-color: var(--correct-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.show-solution-button i {
    font-size: 1.2em;
    margin-left: 10px;
}