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

/*Color variables*/
:root {
    --color-correct: rgb(45, 202, 45);
    --color-present: #e9c46a;
    --color-absent: gray; 
    --color-background: #0F172A;
    --color-text: #7DD3FC; 
    --color-tile-border: #334155;
    --color-accent: #00b4d8;
    --color-stats-theme: #c084fc;
}

body {
    background-color: var(--color-background);
    color: var(--color-text);
    font-family: 'Helvetica Neue', Arial, sans-serif;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    
    margin: 0; 
    padding: 0;
    height: 100dvh;
    overflow: hidden;
}

button, .key {
    transition: all 0.2s ease;
}

h1 {
    font-size: 2.5rem;
    letter-spacing: 2px;
    margin-bottom: 5px;
}

h2 {
    font-size: 1rem;
    font-weight: normal;
    margin-bottom: 30px;
    color: #888;
}

/*-------Game Board----------------*/
#game-board {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.board-row {
    display: flex;
    justify-content: center; 
    gap: 3px;

    /*Animated reveal*/
    max-height: 60px;
    opacity: 1;
    transition: max-height 0.5s ease-out, opacity 0.6s ease-out, margin 0.5s ease-out;
}

.row-collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: -5px; /*Negates the 5px gap so it sits flat */
    overflow: hidden; /*Hides the bubbles while the row is squished */
}

.tile {
    width: 55px;
    height: 55px;
    border: none;
    border-radius: 50%;

    background-color: #6caef0;
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    font-size: 2rem;
    font-weight: bold;
    text-transform: uppercase;
    color: black;

    /*For shine depth depth*/
    position: relative; 
    box-shadow: inset -4px -4px 10px rgba(0, 0, 0, 0.15);
}

/* The shiny bubble reflection */
.tile::after {
    content: ""; /*Ghost element*/
    position: absolute;
    top: 6px;
    left: 9px;
    width: 12px;
    height: 6px;
    background-color: rgba(255, 255, 255, 0.7); /*Translucent white shine */
    border-radius: 50%; /*Make it an oval*/
    transform: rotate(-30deg); /*Tilt the shine*/
    pointer-events: none; /*Can't click the shine*/
}


/*--------Keyboard-------------------*/
#keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 500px;
    padding: 10px 10px 2px 10px;

    margin-bottom: 0px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.key {
    background-color: #334155; /*Unguessed keys */
    color: var(--color-text);
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 4px; /*Rounds key edges*/
    height: 58px;
    
    flex: 1; 
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    cursor: pointer; /*Turns mouse into pointing hand when hovering*/
    user-select: none; 
    text-transform: uppercase;
}

.wide-key {
    flex: 1.5;
    font-size: 0.9rem;
}

.spacer {
    flex: 0.5; /*For either end of middle row*/
}

.correct {
background-color: var(--color-correct) !important;
color: var(--color-background) !important;
color: black !important;
}

.present {
background-color: var(--color-present) !important;
color: var(--color-background) !important;
color: black !important;
}

.absent {
background-color: var(--color-absent) !important;
}

#announcement-modal,
#win-modal, 
#lose-modal, 
#choose-player-modal, 
#player-modal,
#how-to-play-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100; /*On top of all other content*/
}

.hidden {
    display: none !important;
}

.modal-content {
    background-color: var(--color-tile-border);
    padding: 30px;
    border-radius: 12px;
    border: 2px solid var(--color-accent);
    text-align: center;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
}

#new-word-input {
    padding: 10px;
    font-size: 1.5rem;
    text-align: center;
    text-transform: uppercase;
    border-radius: 6px;
    border: none;
    outline: none;
}

#submit-new-word {
    padding: 12px;
    font-size: 1.2rem;
    background-color: var(--color-accent);
    color: var(--color-background);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.lose-content {
    border-color: #ff4d4d;
}

#try-again-btn {
    padding: 12px;
    font-size: 1.2rem;
    background-color: #ff4d4d;
    color: var(--color-background);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

#home-screen {
    height: 100%;
    justify-content: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 300px;
}

.menu-buttons button {
    padding: 15px;
    font-size: 1.2rem;
    background-color: var(--color-tile-border);
    color: var(--color-text);
    border: 2px solid var(--color-accent);
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.menu-buttons button:hover {
    background-color: var(--color-accent);
    color: var(--color-background);
}

#game-screen {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    height: 100%;
}

/*BUBBLE IDLE ANIMATION---------------------*/

/*Define the floating motion */
@keyframes idleBob {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

/*Apply the animation to all tiles*/
.tile {
    animation: idleBob 3s ease-in-out infinite; 
}

/*Stagger the timing with negative delays*/
.tile:nth-child(1) { animation-delay: -0.2s; }
.tile:nth-child(2) { animation-delay: -1.4s; }
.tile:nth-child(3) { animation-delay: -0.8s; }
.tile:nth-child(4) { animation-delay: -2.1s; }
.tile:nth-child(5) { animation-delay: -1.1s; }

/*Break the columns by altering the duration of different rows*/
.board-row:nth-child(even) .tile { animation-duration: 3.4s; }
.board-row:nth-child(3n) .tile { animation-duration: 2.7s; }
.board-row:nth-child(5n) .tile { animation-duration: 3.1s; }


/*LEADERBOARD SCREEN*/
#leaderboard-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-align: center;
    padding-top: 60px;
}

.leaderboard-container {
    background-color: var(--color-tile-border);
    border: 2px solid var(--color-accent);
    border-radius: 12px;
    padding: 0 20px 20px 0;
    width: 90%;
    max-width: 800px;
    margin-bottom: 30px;
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--color-text);
}

#leaderboard-table th {
    padding: 20px 15px 10px 15px; /* Added 20px top padding */
    border-bottom: none;
    box-shadow: inset 0 -2px 0 var(--color-accent); /* Added: Inset shadow so it sticks */
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

#leaderboard-table td {
    padding: 12px 15px;
    font-size: 1.2rem;
    font-weight: bold;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

/*Top 3 ranks have special colors*/
.rank-1 { color: #ffd700; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.menu-return-btn {
    padding: 15px 30px;
    font-size: 1.2rem;
    background-color: transparent;
    color: var(--color-accent);
    border: 2px solid var(--color-accent);
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.menu-return-btn:hover {
    background-color: var(--color-accent);
    color: var(--color-background);
}

.key.absent {
    background-color: #1e293b !important;
    color: #475569 !important;
}

.shark-display {
    color: var(--color-present);
    margin-bottom: 20px;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.close-modal-x {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.8rem;
    color: #888;
    cursor: pointer;
    line-height: 1;
    user-select: none;
    transition: color 0.2s ease;
}

.close-modal-x:hover {
    color: var(--color-accent);
}

#player-modal {
    z-index: 100;
}

.player-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-height: 140px;
    overflow-y: auto;
    padding: 5px;
}

.player-grid button {
    padding: 8px 12px;
    font-size: 1rem;
    background-color: var(--color-background);
    color: var(--color-text);
    border: 1px solid var(--color-accent);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.player-grid button:hover {
    background-color: var(--color-accent);
    color: var(--color-background);
}

#new-player-input {
    width: 100%;
    padding: 10px;
    font-size: 1.2rem;
    text-align: center;
    border-radius: 6px;
    border: 2px solid var(--color-accent);
    outline: none;
    background-color: var(--color-background);
    color: var(--color-text);
}

#create-player-btn {
    width: 100%;
    padding: 12px;
    font-size: 1.1rem;
    background-color: var(--color-correct);
    color: var(--color-background);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}



.shake {
    animation: shake 0.4s;
}

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

.modal-content h2 {
    font-size: 2.2rem;
    font-weight: bold;
    color: var(--color-present);
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
}

.lose-content h2 {
    color: #ff4d4d; 
}

/*Default UI blue*/
#how-to-play-modal h2 {
    color: var(--color-text);
}

.secondary-modal-btn {
    padding: 12px;
    font-size: 1.1rem; 
    background-color: transparent;
    color: #888;
    border: 2px solid #888;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
}

.secondary-modal-btn:hover {
    color: var(--color-text);
    border-color: var(--color-text);
    background-color: rgba(125, 211, 252, 0.1); 
}

/* Disabled Button State */
button:disabled {
    background-color: #1e293b !important;
    color: #475569 !important;
    border-color: #1e293b !important;
    cursor: not-allowed !important;
}

button:disabled:hover {
    background-color: #1e293b !important;
    color: #475569 !important;
}

#close-how-to-play-btn {
    padding: 15px 25px;
    font-size: 1.3rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--color-background);
    background: linear-gradient(45deg, var(--color-accent), #6caef0);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 180, 216, 0.3);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    animation: pulse-attention 2s infinite;
}

#close-how-to-play-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 180, 216, 0.3);
}

/* Word Suggestions */
.suggestion-btn {
    padding: 8px 15px;
    font-size: 1rem;
    background-color: var(--color-background);
    color: var(--color-present);
    border: 1px solid var(--color-present);
    border-radius: 20px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
    transition: all 0.2s ease;
}

.suggestion-btn:hover {
    background-color: var(--color-present);
    color: var(--color-background);
}

#toast-container {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 1000; /* Keeps it above everything, including modals */
    pointer-events: none; /* Lets users click through the gap between toasts */
}

.toast {
    background-color: var(--color-text); /* Light blue from your theme */
    color: var(--color-background); /* Dark navy background */
    padding: 12px 20px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    opacity: 1;
    transition: opacity 0.4s ease;
    white-space: pre-wrap; 
    text-align: center;
}

.toast.fade-out {
    opacity: 0;
}

/* ==========================================
   SPRITES
   ========================================== */

#top-shark {
    position: absolute;
    top: -30px; /* Locks it to the top of the game screen */
    width: 180px; /* Adjust based on your image size */
    z-index: 10; /* Ensures it stays on top of the bubbles/fish */
    
    /* Reuses your existing bubble animation to make it float menacingly! */
    animation: idleBob 4s ease-in-out infinite alternate;
}

#board-fish {
    width: 80px; /* Adjust based on your image size */
    align-self: center; /* Centers it above the bubbles */
    margin-bottom: -15px; /* The gap between the fish and the top row */
    z-index: 5;
    
    /* Reuses your animation so the fish swims in place */
    animation: idleBob 2.5s ease-in-out infinite;
}

.circle-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: transparent;
    color: var(--color-accent); 
    border: 2px solid var(--color-accent);
    cursor: pointer;
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    transition: all 0.2s ease;
}

.circle-btn:hover {
    background-color: var(--color-accent);
    color: var(--color-background);
    transform: scale(1.05);
}

/* Discord Menu Button Styles */
#discord-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px; /* Space between logo and text */
    background-color: #5865F2 !important; /* !important forces it to ignore the default button color */
    color: white !important;
    border: none;
    margin-top: 0; 
}

#discord-menu-btn:hover {
    background-color: #4752C4 !important; /* Darker Blurple for hover state */
}

.discord-btn:active {
    transform: translateY(0px); /* Pushes down when clicked */
}

/* ==========================================
   PRESENCE INDICATOR
   ========================================== */

.presence-container {
    position: fixed;
    top: 15px;
    right: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--color-tile-border);
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--color-accent);
    z-index: 1000; /* Stays on top of everything */
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--color-text);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.presence-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--color-correct); /* Green */
}

.presence-dot.inactive {
    background-color: var(--color-absent); /* Gray */
    animation: none;
}

.presence-dot.active {
    background-color: var(--color-correct);
    animation: pulse-green 1.5s infinite;
}

@keyframes pulse-green {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(45, 202, 45, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(45, 202, 45, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(45, 202, 45, 0); }
}

@media (max-width: 500px) {
    .presence-container {
        top: 10px;
        right: 10px;
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

.toast-highlight {
    color: #ff4444;
    font-weight: 900;
}

.prev-winner-crown {
    position: absolute;
    top: -24px; /* Adjust this to move the crown higher/lower */
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.3rem; /* Adjust crown size */
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    cursor: default;
    user-select: none;
}

/* Gives extra headroom specifically for the row with the crown */
tr.has-crown td {
    padding-top: 30px !important; /* Normal is 12px, giving the crown 18px of space */
}

#player-stats-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-align: center;
    padding-top: 60px;
}

#player-stats-screen h1 {
    color: var(--color-stats-theme);
}

.stats-container {
    background-color: var(--color-tile-border);
    border: 2px solid var(--color-stats-theme);
    border-radius: 12px;
    padding: 0 20px 20px 0;
    width: 90%;
    max-width: 800px;
    margin-bottom: 30px;
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
}

#player-stats-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--color-stats-theme);
}

#player-stats-table th {
    padding: 20px 15px 10px 15px; /* Changed: Added 20px top padding */
    border-bottom: none; /* Changed: Removed border */
    box-shadow: inset 0 -2px 0 var(--color-stats-theme); /* Added: Inset shadow so it sticks */
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-stats-theme);
    white-space: nowrap;
}

#player-stats-table td {
    padding: 12px 15px;
    font-size: 1.2rem;
    font-weight: bold;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

.stats-return-btn {
    padding: 15px 30px;
    font-size: 1.2rem;
    background-color: transparent;
    color: var(--color-stats-theme);
    border: 2px solid var(--color-stats-theme);
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
}

.stats-return-btn:hover {
    background-color: var(--color-stats-theme);
    color: var(--color-background);
}

#stats-sort-select {
    background-color: var(--color-background);
    color: var(--color-stats-theme);
    border: 2px solid var(--color-stats-theme);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 1rem;
    font-weight: bold;
    outline: none;
    cursor: pointer;
    text-transform: uppercase;
}

#stats-sort-select option {
    background-color: var(--color-background);
    color: var(--color-stats-theme);
}

/* Mobile table adjustments */
@media (max-width: 500px) {
    h1 {
        font-size: 1.8rem;
    }

    .stats-controls label, #stats-sort-select {
        font-size: 0.85rem;
    }

    .leaderboard-container, .stats-container {
        padding: 0 2px 10px 0;
        width: 98%; /* Maximize available screen width */
    }

     #leaderboard-table th, 
    #leaderboard-table td,
    #player-stats-table th,
    #player-stats-table td {
        padding: 6px 15px; /* Enforced column gap */
        font-size: 0.85rem; /* Slightly smaller data text */
        white-space: nowrap; /* Forces horizontal scrolling */
    }

    #leaderboard-table th,
    #player-stats-table th {
        padding: 16px 15px 6px 15px;
        font-size: 0.7rem; /* Shrink headers just a bit more */
        line-height: 1.1; /* Keeps the stacked header text (Fish/Eaten) close together */
    }
}

/* Adds extra space between the Player and Time columns in the Leaderboard */
#leaderboard-table th:first-child,
#leaderboard-table td:first-child {
    padding-right: 50px; /* Adjust this value up or down to dial in the exact spacing you want */
}

.sorted-column {
    background-color: rgba(192, 132, 252, 0.1);
}

/* 1. Enable vertical scrolling inside your table containers */
.leaderboard-container, 
.stats-container {
    max-height: 60vh; /* Restricts height so it scrolls. Adjust as needed! */
    overflow-y: auto; 
}

/* 2. Pin the headers and give them a solid background */
#leaderboard-table th,
#player-stats-table th {
    position: sticky;
    top: 0;
    
    /* Matches the container background so rows hide behind the header */
    background-color: var(--color-tile-border); 
    
    /* Forces the header to stay strictly above the scrolling data */
    z-index: 10; 
}

/* Make ONLY the player names sticky on the left */
#leaderboard-table td:first-child,
#player-stats-table td:first-child {
    position: sticky;
    left: 0;
    background-color: var(--color-tile-border);
    z-index: 5; 
}

/* Absorbs the 20px of left padding removed from the container */
#leaderboard-table th:first-child,
#leaderboard-table td:first-child,
#player-stats-table th:first-child,
#player-stats-table td:first-child {
    padding-left: 17px !important;
}