html, body {
    touch-action: manipulation; /* disables pinch-zoom and double-tap-to-zoom in many browsers */
    -ms-touch-action: manipulation;
}

/* Disable text selection everywhere except form controls and contenteditable */
html, body, *:not(input):not(textarea):not(select):not([contenteditable]) {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-tap-highlight-color: transparent; /* mobile tap highlight */
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    background-color: #2a2a2a;
    font-family: 'Mulish', sans-serif;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(var(--board-size, 5), 1fr);
    grid-template-rows: repeat(var(--board-size, 5), 1fr);
    gap: 1%;
    padding: 10px;
    background-color: #ffffff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    box-sizing: border-box;
}

.grid-box {
    background-color: #2d5232; /* default darker green */
    aspect-ratio: 1;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box; /* Ensure borders don't affect size */
    container-type: inline-size;
}

/* Alternating chess squares pattern */
.grid-box:nth-child(odd) {
    background-color: #6b8e70; /* much lighter green squares */
}

.grid-box:nth-child(even) {
    background-color: #2d5232; /* much darker green squares */
}

.box-label {
    font-size: 5px;
    color: #ffffff;
    padding: 1px;
    position: absolute;
    bottom: 2px;
    left: 2px;
}

.chess-knight {
    font-size: 64cqw;
    color: #ffd700;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: grab;
    user-select: none;
    z-index: 10;
}

.chess-knight:active {
    cursor: grabbing;
}

/* Different colors for multiple knights */
.chess-knight[id="knight-0"] {
    color: #ffd700; /* Gold yellow - primary knight */
}

.chess-knight[id="knight-1"] {
    color: #ffb347; /* Peach yellow - secondary knight */
}

.chess-knight[id="knight-2"] {
    color: #ffa500; /* Orange yellow - tertiary knight */
}

.chess-knight[id="knight-3"] {
    color: #daa520; /* Goldenrod yellow - quaternary knight */
}

/* Highlight active knight */
.chess-knight.active {
    transform: scale(1.1);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.8));
}

/* Selected knight styling */
.chess-knight.selected {
    transform: scale(1.1);
}

.grid-box.valid-move {
    box-shadow: inset 0 0 0 2px #e33e3e, 0 0 12px #e33e3e;
    cursor: pointer;
}

/* Knight move arrows */
.knight-arrow {
    position: absolute;
    height: 3px;
    background: linear-gradient(to right, 
        rgba(227, 62, 62, 0.8) 0%, 
        rgba(227, 62, 62, 0.6) 85%, 
        transparent 100%);
    transform-origin: left center;
    pointer-events: none;
    z-index: 10;
    transition: all 0.2s ease;
}

.knight-arrow::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    width: 0;
    height: 0;
    border-left: 12px solid rgba(227, 62, 62, 0.7);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    transform: translateY(-50%);
}

.center-letter {
    font-family: 'Roboto Slab', sans-serif;
    font-size: 64cqw;
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0px 0px 5px rgba(0, 12, 0, 0.9);
    z-index: 1;
    pointer-events: none;
}

.message-container {
    margin-top: 15px;
    text-align: center;
    font-family: 'Mulish', sans-serif;
}

.button-container {
    display: flex;
    gap: 3%;
    margin: 15px 0 0;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
}

#total-moves-display {
    position: absolute;
    left: 0;
    color: white;
    font-size: 15px;
    background-color: none;
}

#game-id-display {
    position: absolute;
    right: 0;
    color: white;
    font-size: 15px;
    background-color: none;
}

.reset-btn {
    padding: 0;
    width: 40px;
    height: 40px;
    background-color: #8b4513;
    color: #f5f5dc;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reset-btn .material-icons {
    font-size: 20px;
}

.undo-btn {
    padding: 0;
    width: 40px;
    height: 40px;
    background-color: #cd853f;
    color: #654321;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.undo-btn .material-icons {
    font-size: 20px;
}

.undo-btn:disabled {
    background-color: #d3d3d3;
    color: #999;
    cursor: not-allowed;
}

.share-btn {
    padding: 0;
    width: 40px;
    height: 40px;
    background-color: #20b2aa;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#bottom-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1200px;
    padding: 10px 0;
}

#help-button {
    color: white;
    flex: 2;
    max-width: 500px;
    cursor: pointer;
}

.share-btn .material-icons {
    font-size: 20px;
}

.moves-btn {
    padding: 0;
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    background-color: #6c757d;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    cursor: default;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}

.moves-btn:disabled {
    opacity: 1;
    cursor: default;
}

.consumed-letters-container {
    text-align: center;
    width: 100%;
    font-size: 35px;
    font-weight: bold;
    color: #fff;
    font-family: 'Roboto Slab', sans-serif;
    font-weight: 500;
    padding: 10px 0 10px;
}

/* Responsive game layout */
.game-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 90vw;
    max-width: 500px;
    position: relative;
    gap: 10%;
}

.game-board-area {
    display: flex;
    flex: 2;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 700px
}

#words-container {
    padding: 10px;
    text-align: center;
    font-family: 'Mulish', sans-serif;
    background-color: rgba(245, 245, 220, 0.95);
    width: 100%;
    box-sizing: border-box;
    margin: 5% 0;
    display: flex;
    flex-direction: column;
}

#words-container h3 {
    margin: 0 0 10px 0;
    color: #654321;
    font-size: 18px;
}

#words-list {
    font-size: 12px;
    font-weight: bold;
    width: 100%;
    padding: 5px;
    background-color: rgba(255, 255, 255, 0.3);
    box-sizing: border-box; /* Ensure borders don't affect size */
    text-align: center;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    max-height: 90px;
    overflow-y: auto;
}

#words-list.empty {
    font-size: 12px;
    font-style: italic;
    color: #999;
}

#no-words {
    font-size: 12px;
    font-style: italic;
    color: #999;
    margin: 6px;
    padding: 3px 5px;
}

.word-item {
    display: inline-block;
    margin: 6px;
    padding: 3px 5px;
    background-color: #f0e68c;
    font-size: 12px;
    border-radius: 4px;
}

/* Special styling for 5-letter words */
.word-item.five-letter-word {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

@keyframes wordPulse {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#progress-container {
    margin-top: 10px;
    text-align: center;
    font-family: 'Mulish', sans-serif;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
}

#progress-container h3 {
    margin: 0 0 10px 0;
    color: #654321;
    font-size: 18px;
}
#checkmate {
    display: none;
    margin-top: 10px;
    font-weight: 700;
}
#progress-display {
    font-size: 16px;
    font-weight: bold;
    color: #654321;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Progress completion styling */
#progress-display.complete {
    color: #006400 !important;
}

#progress-bar {
    flex: 1;
    height: 20px;
    background-color: rgba(245, 245, 220, 0.5);
    border-radius: 10px;
    border: 2px solid #8b7355;
    overflow: hidden;
    box-sizing: border-box;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #daa520, #b8860b);
    border-radius: 8px;
    width: 0%;
    transition: width 0.5s ease-in-out;
    box-shadow: 0 2px 4px rgba(218, 165, 32, 0.3);
}

/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex !important;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    position: relative;
    max-height: 90%;
    max-width: 750px;
}

.modal-content {
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    position: absolute;
    padding: 16px;
    box-sizing: border-box;
    max-width: 90%;
    width: 90%;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
.instructions-section {
    display: flex;
    flex-direction: column;
}

.instructions-section li {
    padding: 5px;
}

.instructions-section li::marker {
    content: '♞';
}

.instructions-section h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #2a2a2a;
    font-size: 18px;
    font-weight: 600;
}

.instructions-section p {
    margin-top: 10px;
    color: #555;
    font-size: 14px;
}

.gif-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #2a2a2a;
    padding: 5px;
}

.help-gif {
    max-height: 90%;
    max-width: 90%;
    border-radius: 4px;
}

.clickable-gif {
    cursor: pointer;
    transition: opacity 0.2s;
}

.clickable-gif:hover {
    opacity: 0.9;
}

.modal-close {
    position: absolute;
    right: 20px;
    top: 20px;
    color: #999;
    font-size: 36px;
    font-weight: bold;
    border: none;
    background: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.modal-close:hover,
.modal-close:focus {
    color: #333;
}

.modal-btn {
    background-color: #2d5232;
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
    font-family: 'Mulist', sans-serif;
    display: flex;
    align-items: center;
    align-self: flex-end;
    margin: 25px 0 0;
}

.modal-page {
    animation: fadeInPage .5s ease;
    flex-grow: 5;
    line-height: 1.5;
}

@keyframes fadeInPage {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-direction: row;
}

.page-indicator {
    color: #666;
    font-weight: 600;
    white-space: nowrap;
}

#current-page {
    color: #6b8e70;
    font-weight: bold;
}

.modal-nav-btn {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    font-family: 'Mulish', sans-serif;
    border: none;
    background-color: transparent;
    flex-grow: 2;
}

.modal-nav-btn:active:not(:disabled) {
    transform: translateY(0);
}

.modal-nav-btn:disabled {
    color: #655f5f;
    cursor: not-allowed;
    box-shadow: none;
    visibility: hidden;
}

/* Special styling for 5-letter words in toast */
.toast-word.five-letter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-size: 20px;
    padding: 16px 32px;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.5);
    animation: toastCelebrate 0.6s ease;
}

@keyframes toastCelebrate {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-30px) scale(0.8);
    }
    50% {
        transform: translateX(-50%) translateY(5px) scale(1.1);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* Toast moving to words list animation */
.toast-word.moving-to-list {
    animation: moveToWordsList 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes moveToWordsList {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
    50% {
        opacity: 0.8;
        transform: translate(calc(-50% + var(--move-x, 0px) * 0.5), calc(0px + var(--move-y, 0px) * 0.5)) scale(0.7);
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--move-x, 0px)), calc(0px + var(--move-y, 0px))) scale(0.3);
    }
}

/* Old toast styling - keeping for backwards compatibility */
.toast {
    position: fixed;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(74, 144, 226, 0.95);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: 'Mulish', sans-serif;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    animation: toastSlideIn 0.3s ease;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Special styling for 5-letter words */
.toast.five-letter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-size: 20px;
    padding: 16px 32px;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.5);
    animation: toastCelebrate 0.6s ease;
}

@keyframes toastCelebrate {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-30px) scale(0.8);
    }
    50% {
        transform: translateX(-50%) translateY(5px) scale(1.1);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* Toast moving to words list animation */
.toast.moving-to-list {
    animation: moveToWordsList 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes moveToWordsList {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
    50% {
        opacity: 0.8;
        transform: translate(calc(-50% + var(--move-x, 0px) * 0.5), calc(0px + var(--move-y, 0px) * 0.5)) scale(0.7);
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--move-x, 0px)), calc(0px + var(--move-y, 0px))) scale(0.3);
    }
}

/* Celebration Toast */
.celebration-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 95%;
    max-width: 500px;
}

.celebration-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    animation: celebrationBounce 0.8s ease;
}

.celebration-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    text-align: center;
    box-shadow: 0 20px 60px rgba(102, 126, 234, 0.6),
                0 0 0 1px rgba(255, 255, 255, 0.2) inset;
    position: relative;
    overflow: hidden;
    padding: 20px;
    border-radius: 10px;
}

.celebration-content::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 70%
    );
    animation: shine 2s infinite;
}

@keyframes shine {
    0% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }
    100% {
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

.celebration-emoji {
    font-size: 80px;
    margin-bottom: 16px;
    animation: emojiFloat 1s ease-in-out infinite alternate;
}

@keyframes emojiFloat {
    from {
        transform: translateY(0px);
    }
    to {
        transform: translateY(-10px);
    }
}

.celebration-text {
    font-family: 'Moul', cursive;
    font-size: 40px;
    font-weight: 700;
    color: white;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3),
                 0 2px 4px rgba(0, 0, 0, 0.2);
    margin-bottom: 8px;
    letter-spacing: 2px;
}

.celebration-subtext {
    font-family: 'Mulish', sans-serif;
    font-size: 24px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

@keyframes celebrationBounce {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3) rotate(-10deg);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1) rotate(5deg);
    }
    70% {
        transform: translate(-50%, -50%) scale(0.95) rotate(-3deg);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
}

/* Feedback Form Styles */
#feedback-button {
    color: #00aaff;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

#feedback-button:hover {
    background-color: rgba(0, 170, 255, 0.1);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #2a2a2a;
    font-weight: 600;
    font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-family: 'Mulish', sans-serif;
    font-size: 14px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #00aaff;
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

#feedback-form .modal-footer {
    margin-top: 24px;
}
