* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    position: fixed;
    display: flex;
    overflow: hidden;
    font-family: "Chiron GoRound TC", sans-serif;
    font-optical-sizing: auto;
    font-weight: 400;
    font-style: normal;
    user-select: none;

    /* Ensure content respects safe areas */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}
/* Language Dropdown */

#language-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7) !important;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    appearance: none;
    background-position: calc(100% - 10px) center;
    background-size: 16px;
    width: 50px;
    display: none; 
}

#language-toggle:hover {
    background: linear-gradient(135deg, #ffd93d 0%, #f39c12 100%);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

#language-toggle:active {
    transform: scale(0.95);
}

#language-toggle option:hover {
    box-shadow: 0 0 10px 100px red inset !important;
}



#viewport {
    position: relative; 
    width: calc(100vw - 300px);
    height: 100vh;
    transition: transform 0.2s linear;
}

#game-area {
    position: absolute;
    width: 100%;
    height: 100%;
    outline: var(--game-area-border, 20px) solid #3e3e3e;
    background-color: white;
    background-image: 
        linear-gradient(to right, #ddd 1px, transparent 1px),
        linear-gradient(to bottom, #ddd 1px, transparent 1px);
    background-size: var(--cell-size, 10px) var(--cell-size, 10px);
    transform-origin: 0 0;
}

#player {
    background-image: url(player_snake_head.png);
    background-size: cover;
    /*background-color: red;*/
    position: absolute;
    border-radius: 0px 50% 50% 0px;
    transition: transform 0.2s linear;
}

.npc-head {
    position: absolute;
    border-radius: 0px 50% 50% 0px;
    transition: transform 0.2s linear;
    background-image: url(enemy_snake_head.png);
    background-size: cover;
    background-position: center;
}

.food, .body-segment {
    color: black;
    border-radius: 40%;
    position: absolute; 
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;   
    font-weight: bold;
    transition: transform 0.2s linear;
    font-size: calc(var(--cell-size) - 10px);
}

.food{
   border: 2px solid #333;
}

.point-letter, .point-word, .point-kill{
    
    font-size: 4cqh;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 1000;    
    background: none !important;
    width: max-content !important;
    font-weight: bold;
    opacity: 0.3;
}

.point-letter{
    color: #6bcb77;
    transition: transform 0.7s ease-out, opacity 0.7s ease-out !important;
}

.point-word{
    color: #ffd93d;
    transition: transform 0.7s ease-out, opacity 0.7s ease-out !important;
}

.point-kill{
    color: #ff4444;
    opacity: 1;
}

@keyframes pointPopup {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(100%);
    }
}

#word-list-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 450px);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

#word-headers {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr;
    gap: 10px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 10px;
    margin-bottom: 10px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

#word-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
    padding-right: 5px;
}

#word-rows::-webkit-scrollbar {
    width: 8px;
}

#word-rows::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#word-rows::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 4px;
}

#word-rows::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.6);
}

.word-row {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr;
    gap: 10px;
    background: rgba(255, 255, 255, 0.15);
    padding: 10px;
    border-radius: 10px;
    color: white;
    transition: transform 0.2s, background 0.2s;
    animation: fadeIn 0.3s ease-out;
    font-weight: bold;;
}

.word-row:hover {
    transform: translateX(-5px);
    background: rgba(255, 255, 255, 0.25);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#points-container {
    position: absolute;
    left: 0;
    bottom: 0px;
    width: 100vw;
    transition: 0.2s;
    display: flex;
    flex-direction: row;
    justify-content: right;
    gap: 20px;
    
}

#points-container.hidden{
        bottom: -150px;
}

#points-container > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 12px 15px;
    border-radius: 12px 12px 0px 0px;
    color: white;
    font-size: 0.9rem;
    font-weight: bold;
    box-shadow: 0px 0px 7px grey;
    transition: transform 0.2s, background 0.2s;
}


#points-container > div > div.value {
    font-size: 20px;
    font-weight: bold;
    margin-left: 10px;
}

#letter-points {
    border-left: 4px solid #6bcb77;
    
}

#letter-points > div {
    color: #6bcb77;
    
}

#word-points {
    border-left: 4px solid #ffd93d;
}

#word-points > div {
    color: #ffd93d;
}

#bonus-points {
    border-left: 4px solid #ff6b6b;
}

#bonus-points > div {
    color: #ff6b6b;
}

#total-points {
    border-left: 4px solid #ffd700;
    background: rgba(255, 215, 0, 0.2);
    font-size: 16px;
}

#total-points > div {
    color: #ffd700;
    font-size: 24px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

#final-score{
   color: #ffd700;
   font-size: 24px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

#best-score {
    border-left: 4px solid #f39c12;
    background: rgba(243, 156, 18, 0.15);
}

#best-score > div {
    color: #f39c12;
    font-size: 22px;
    text-shadow: 0 0 8px rgba(243, 156, 18, 0.4);
}

.points-update {
    animation: pointsScale 0.5s ease-out;
}

@keyframes pointsScale {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.5);
    }
    100% {
        transform: scale(1);
    }
}

#game-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100%;
    display: flex;
    flex-direction: row;
    color: white;
}

.popup{
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: max-content;
    height: max-content;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(135deg, rgba(102, 126, 234) 0%, rgba(118, 75, 162) 100%);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    min-width: 450px;
    color: white;
    z-index: 2000;
}

.popup h2 {   
    font-size: 3rem;
    margin-bottom: 20px;
}

#manual, #leaderboard{
    position: absolute;
    top:80px;
    padding: 20px 0px;
    width: 570px;
    color: white;
    transition: 0.2s;
}

#leaderboard{
    z-index: 1;
}

#manual p {
    margin: 10px 0px 30px 0px;
    line-height: 1.5;
}

#manual ul {
    margin: 12px 0;
    padding-left: 20px;
}

#manual li {
    margin: 8px 0;
}

#manual strong{
    background-color: #11111173; 
    padding: 5px;
    color: #ffd93d;
}

/* Leaderboard container styling */
#menu-container {
    background: linear-gradient(135deg, rgba(102, 126, 234) 0%, rgba(118, 75, 162) 100%);
    border-radius: 20px 0px 0px 20px;
    padding: 30px;
    width: 600px;
    height: 100%;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: fixed;
    top: 0px;
    right: 0px;
    transition: 0.5s;
    font-size: 16px;
}

#menu-container.hidden{
    right: -600px;
}

#leaderboard-link {  
    right: 400px;
}

#manual-link {  
    right: 220px;
}

.menu-link{
    box-shadow: 0px 0px 5px white;
    padding: 20px;
    border-radius: 20px;
    position: fixed;
    top: 10px;
    height: max-content;
    z-index: 2;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transform: scale(1);
    transition: 0.2s;
}

.menu-link:hover{
    transform: scale(1.05);
}

.menu-link.active{
    border: 2px solid gold;
    box-shadow: none;
}


#leaderboard.hidden, #manual.hidden{
    opacity: 0;
}


#menu-leaderboard-headers {
    display: grid;
    grid-template-columns: 20px 25% 17% 50%;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.9);
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 20px 25% 17% 50%;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.2s;
    overflow-x: hidden;
}

.leaderboard-row:hover {
    background: rgba(255, 255, 255, 0.1);
}

.leaderboard-rank {
    font-weight: bold;
    text-align: left;
}

.leaderboard-rank.rank-gold {
    color: #ffd93d;
}

.leaderboard-rank.rank-silver {
    color: #c0c0c0;
}

.leaderboard-rank.rank-bronze {
    color: #cd7f32;
}

.leaderboard-nickname {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    text-align: left;
    font-weight: bold;
}

.leaderboard-word {
    text-align: left;
    font-size: 14px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.8);
}

#game-settings {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(135deg, rgba(102, 126, 234) 0%, rgba(118, 75, 162) 100%);
    border-radius: 0px 20px 20px 0px;
    padding: 20px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    min-width: 320px;
    overflow-y: auto;
}

#game-settings h2 {
    text-align: center;
    font-size: 32px;
    margin: 0 0 15px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.mode-selection {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
}


.btn-cta{   
    width: 100%;
    padding: 18px 30px;
    font-size: 22px;
    font-weight: bold;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 4px 15px rgba(255, 217, 61, 0.4);
}

.btn-cta:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 217, 61, 0.6);
}

.btn-gold{
    background: linear-gradient(135deg, #ffd93d 0%, #f39c12 100%);
}

.btn-red{
    margin-top: 10px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
}



.mode-btn {
    flex: 1;
    padding: 15px 20px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.mode-btn:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.mode-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.option-group {
    margin-bottom: 20px;  
}

.option-group label {
    color: white;
    font-size: 16px;
    font-weight: bold;
    display: block;
    margin-bottom: 10px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffd93d;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffd93d;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider {
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.slider-display {
    color: #ffd93d;
    font-weight: bold;
    font-size: 18px;
}


.difficulty-buttons {
    display: flex;
    gap: 10px;
}

.diff-btn {
    flex: 1;
    padding: 10px 15px;
    font-size: 14px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.diff-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.diff-btn.active {
    box-shadow: 0 4px 15px rgba(107, 203, 119, 0.4);
}

.diff-btn[data-difficulty="easy"].active {
    background: #6bcb77;
    box-shadow: 0 4px 15px rgba(107, 203, 119, 0.4);
}

.diff-btn[data-difficulty="medium"].active {
    background: #ffd93d;
    box-shadow: 0 4px 15px rgba(255, 217, 61, 0.4);
}

.diff-btn[data-difficulty="hard"].active {
    background: #f39c12;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

.diff-btn[data-difficulty="impossible"].active {
    background: #ff4757;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
}




#nickname-input {
    width: 100%;
    padding: 15px;
    font-size: 18px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    outline: none;
    transition: all 0.3s;
}

#nickname-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

#nickname-input:focus {
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.3);
}

#nickname-input.error {
    background: rgba(255, 107, 107, 0.2);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.3);
}

#nickname-input.error:focus {
    background: rgba(255, 107, 107, 0.3);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.5);
}

#nickname-error {
    opacity: 0;
    height: 20px;
    color: #ff6b6b;
    font-size: 14px;
    margin: 5px 0;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.5s ease-in;
    transition: 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

#nickname-input.shake {
    animation: shake 0.5s ease-in-out;
}

  #mobile-exit-to-menu{
    cursor: pointer;
}


/* Mobile adjustments */
@media (max-width: 768px) {
    #viewport {
        width: 100vw;
        height: 100vh;
    }

    #game-menu{
        justify-content: space-evenly;
        background: linear-gradient(135deg, rgba(102, 126, 234) 0%, rgba(118, 75, 162) 100%);
    }

    #game-settings{
        width: 100vw;
        padding-top: 70px;
        border-radius: 0;
        left: 0;
        transition: 0.2s;
    }

    #game-settings.hidden{
        left: -100%;
    }

    #game-settings h2{
        display: none;
    }

    #menu-container {
        background: none;
        box-shadow: none;
        width: 100vw;
        height: calc(100vh - 70px);
        left: 100%;
        top: 65px;
        border-radius: 0px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #menu-container.shown{
        left: 0;
    }


    #menu-links-container{
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        width: 100vw;
        height: 60px;
        position: fixed;
        top: 0px;
        left: 0px;
        background: linear-gradient(135deg, rgba(102, 126, 234) 0%, rgba(118, 75, 162) 100%);
        box-shadow: 0px -4px 14px #333;
    }

    .menu-link{
        position: static;
        padding: 10px 25px;
        font-size: 1.2em;
    }

    .menu-link.active{
        transform: scale(1.1);
    }

    #leaderboard-link, #manual-link{
        right: 0;
    }

    #leaderboard, #manual{
        width: 100vw;
        padding: 0px 20px;
        left: 0;
        top: 0;
    }

    #leaderboar.hidden, #manual.hidden{
        opacity: 1;
        left: 100%;
    }
    

   #points-container{
        bottom: 50px;
        height: 60px;
        justify-content: space-between;
        gap: 0px;
    }

    
    #longest-word, #mobile-tutorial{
        position: absolute;
        bottom: -50px;
        width: 100%;
        height: 60px;
        box-shadow: 0px 0px 10px black;
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-bottom: none;
    }

    #mobile-tutorial{
        z-index: 5;
        font-size: 1.1rem !important;
        justify-content: center !important;        
        animation: tutorialEffect 2s ease-in-out infinite !important;
        transition: 0.5s;
    }

    @keyframes tutorialEffect {
    0% {
        box-shadow: 0px 0px 10px black;       
    }
    50% {
         box-shadow: 0px 0px 10px orange;
    }
    100%{
        box-shadow: 0px 0px 10px black;
    }
}

    #mobile-tutorial.hidden{
        bottom: -150px;
    }

    .popup{
        position: absolute;
        min-width: fit-content;
        width: 90vw;
    }

}

@media (min-width: 768px) {
    #game-link, #mobile-tutorial{
        display: none !important;
    }

    #leaderboard-link::after{
        content: "Leaderboard";
    }    
    
    #manual-link::before{
         content: "How to play";
    }

    #longest-word {
        border-left: 4px solid #9b59b6 !important;
    }

    #menu-leaderboard-rows {
        height: calc(100vh - 140px);
        overflow-y: auto;
        scrollbar-color: #ffffffb0 transparent;
    }
}
