/* ==========================================================================
   1. Base & Global Styles
   ========================================================================== */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #121212;
    color: #E0E0E0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
}

/* Keyframes for the background animation */
@keyframes move { 100% { transform: translate3d(0, 0, 1px) rotate(360deg); } }

/* Keyframes for the modal border animation */
@keyframes modalRotatingImg { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Keyframes for the modal pop-in animation */
@keyframes modalPop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ==========================================================================
   2. Layout Styles
   ========================================================================== */

.container,
.game-container {
    text-align: center;
    background-color: #1E1E1E;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
}

.header,
.log-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1rem 0;
    gap: 1rem;
}

.log-container {
    justify-content: center;
}

.home-footer {
    position: absolute;
    bottom: 10px;
    width: 100%;
    text-align: center;
    color: #aaa;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 2rem;
}

.home-footer a {
    display: inline-block;
    background-color: #ffffeb;
    border-radius: 50%;
    padding: 8px;
    outline: 2px solid #444;
    transition: all 0.2s ease-in-out;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.home-footer a:hover {
    transform: scale(1.1) translateY(-2px);
    outline-color: #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.home-footer img {
    width: 24px;
    height: 24px;
    vertical-align: middle;
}


/* ==========================================================================
   3. Component Styles
   ========================================================================== */

/* --- Forms & Buttons --- */
#setup-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.label-p1 { 
    color: #1479EA; 
    margin-bottom: 5px;
    font-weight: bold;
}
.label-p2 { 
    color: #b0305c; 
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="text"] {
    padding: 0.5rem;
    border: 1px solid #444;
    background-color: #333;
    color: #E0E0E0;
    border-radius: 5px;
}

.setup-button {
    width: 100%;
    position: relative;
    height: 3.5em;
    outline: none;
    background-color: transparent;
    color: white;
    transition: 1s;
    border-radius: 0.3em;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 3rem;
}

.setup-button::before {
    content: "";
    transform-origin: center;
    position: absolute;
    top: 80%;
    left: 3%;
    width: 95%;
    height: 40%;
    background-color: #242424;
    transition: 0.5s;
}

.setup-button::after {
    content: "";
    position: absolute;
    top: -10px;
    left: 3%;
    width: 95%;
    height: 40%;
    background-color: #242424;
    transition: 0.5s;
    transform-origin: center;
}

.setup-button:hover::before,
.setup-button:hover::after {
    transform: scale(0);
}

.setup-button#leaderboard-btn:hover,
.setup-button#home-screen-btn:hover {
    box-shadow: inset 0px 0px 25px #1479EA;
}

.setup-button#start-game-btn:hover,
.setup-button#play-again-btn:hover {
    box-shadow: inset 0px 0px 25px #86ea14;
}

.setup-button#tutorial-btn:hover {
    box-shadow: inset 0px 0px 25px #f2a65e;
}

#leaderboard-btn,
#home-screen-btn {
    border: 3px ridge #41a6f6;
}

#start-game-btn,
#play-again-btn {
    border: 3px ridge #14ea6d;
}

#tutorial-btn {
    border: 3px ridge #ffe478;
}

#play-again-btn,
#home-screen-btn,
#tutorial-btn {
    background-color: #242424;
}

#start-game-btn {
    margin-top: 15px;
    width: 100%;
}

.button-group {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    margin-top: 1rem;
}

/* --- Cards --- */
.score-card,
.timer,
.events-log {
    background-color: #2a2a2a;
    padding: 1rem;
    border-radius: 8px;
    flex: 1;
}

.score-card.highlight {
    border: 2px solid #FFD700;
    transform: scale(1.02);
    transition: all 0.3s ease;
}

.player-stats {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-top: 0.5rem;
}

.stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2em;
    font-weight: bold;
}

.stat img {
    width: 32px;
    height: 32px;
}

/* --- Tables & Lists --- */
table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.5rem;
    border-bottom: 1px solid #444;
    text-align: left;
}

th {
    background-color: #242424;
}

ul {
    list-style-type: none;
    padding: 0;
    height: 100px;
    overflow-y: auto;
    text-align: left;
}

li {
    padding: 0.2rem;
    border-bottom: 1px dotted #444;
}

/* ==========================================================================
   4. Modal Styles
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #242424;
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    min-height: 700px;
    padding: 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    animation: modalPop 0.3s ease-out;
}

.modal-content::before {
    content: '';
    position: absolute;
    top: -50%;
    left: 40%;
    width: 120px;
    height: 200%;
    background-image: linear-gradient(180deg, rgb(0, 183, 255), rgb(255, 48, 255));
    animation: modalRotatingImg 4s linear infinite;
    transition: all 0.2s linear;
}

.modal-content::after {
    content: '';
    position: absolute;
    background: #242424;
    inset: 5px;
    border-radius: 15px;
}

.modal-body {
    position: relative;
    z-index: 1;
    padding: 20px;
    color: white;
    text-align: center;
}

.close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 25px;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2;
}

.close-btn:hover,
.close-btn:focus {
    color: white;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Tutorial Modal */
.controls-container {
    display: flex;
    justify-content: space-around;
    margin: 2rem 0;
}
.control-panel {
    flex: 1;
}
.key-images, .key-descriptions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}
.key-images img {
    width: 64px;
    height: 64px;
}
.key-descriptions {
    font-size: 0.9em;
    color: #ccc;
}
.key-descriptions span {
    width: 64px;
    text-align: center;
}

/* ==========================================================================
   5. Page-Specific Styles
   ========================================================================== */

/* --- Home Page --- */
.logo {
    max-width: 80%;
    height: auto;
    margin-bottom: 1rem;
}

.home-container {
    background-color: #242424;
    max-width: 600px;
}

/* --- Game Page --- */
body.game-page {
    display: block;
    height: auto;
    padding-top: 1rem;
}

.game-container {
    margin: 0 auto;
    width: fit-content;
}

#gameCanvas {
    background-color: #000;
    border: 2px solid #4CAF50;
}

.log-container .events-log {
    flex-grow: 2;
    max-width: 60%;
}

#game-over-modal .modal-content {
    min-height: 400px;
    max-width: 400px;
}

#game-over-modal .modal-content .modal-buttons {
    flex-direction: column;
    gap: 1rem;
}

.modal-body.center-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* --- Effects Canvas --- */
#effectsCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99;
    pointer-events: none;
}

/* ==========================================================================
   6. Animation Styles
   ========================================================================== */

.background {
    position: fixed;
    width: 100vw;
    height: 100vh;
    top: 0;
    left: 0;
    background: #121212;
    overflow: hidden;
    z-index: -1;
}

.background span {
    width: 20vmin;
    height: 20vmin;
    border-radius: 20vmin;
    backface-visibility: hidden;
    position: absolute;
    animation: move;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

/* --- Animated Background Keyframes --- */
.background span:nth-child(1) { color: #b0305c; top: 88%; left: 22%; animation-duration: 100s; animation-delay: -109s; transform-origin: -8vw -18vh; box-shadow: -40vmin 0 5.449143888516775vmin currentColor; }
.background span:nth-child(2) { color: #4b5bab; top: 42%; left: 84%; animation-duration: 130s; animation-delay: -105s; transform-origin: 10vw 16vh; box-shadow: 40vmin 0 5.996823133154462vmin currentColor; }
.background span:nth-child(3) { color: #4b5bab; top: 64%; left: 9%; animation-duration: 53s; animation-delay: -31s; transform-origin: 12vw 18vh; box-shadow: -40vmin 0 5.12787488641108vmin currentColor; }
.background span:nth-child(4) { color: #4b5bab; top: 87%; left: 91%; animation-duration: 81s; animation-delay: -63s; transform-origin: 25vw 16vh; box-shadow: 40vmin 0 5.303143069726858vmin currentColor; }
.background span:nth-child(5) { color: #b0305c; top: 13%; left: 33%; animation-duration: 97s; animation-delay: -110s; transform-origin: -7vw 19vh; box-shadow: 40vmin 0 5.14941307060694vmin currentColor; }
.background span:nth-child(6) { color: #b0305c; top: 51%; left: 55%; animation-duration: 42s; animation-delay: -4s; transform-origin: 19vw 19vh; box-shadow: 40vmin 0 5.320991554006219vmin currentColor; }
.background span:nth-child(7) { color: #3ca370; top: 87%; left: 40%; animation-duration: 33s; animation-delay: -12s; transform-origin: -5vw 22vh; box-shadow: 40vmin 0 5.443037029588766vmin currentColor; }
.background span:nth-child(8) { color: #b0305c; top: 79%; left: 86%; animation-duration: 79s; animation-delay: -15s; transform-origin: -21vw -3vh; box-shadow: -40vmin 0 5.756207912956031vmin currentColor; }
.background span:nth-child(9) { color: #4b5bab; top: 77%; left: 38%; animation-duration: 7s; animation-delay: -111s; transform-origin: 1vw 21vh; box-shadow: -40vmin 0 5.9760072970297635vmin currentColor; }
.background span:nth-child(10) { color: #4b5bab; top: 47%; left: 85%; animation-duration: 96s; animation-delay: -98s; transform-origin: 16vw 3vh; box-shadow: 40vmin 0 5.365779878364202vmin currentColor; }
.background span:nth-child(11) { color: #3ca370; top: 23%; left: 32%; animation-duration: 64s; animation-delay: -74s; transform-origin: -24vw 10vh; box-shadow: 40vmin 0 5.037593213196882vmin currentColor; }
.background span:nth-child(12) { color: #b0305c; top: 99%; left: 97%; animation-duration: 73s; animation-delay: -83s; transform-origin: 17vw -3vh; box-shadow: 40vmin 0 5.035794816638403vmin currentColor; }
.background span:nth-child(13) { color: #4b5bab; top: 77%; left: 13%; animation-duration: 81s; animation-delay: -44s; transform-origin: 3vw -14vh; box-shadow: -40vmin 0 5.90008000809153vmin currentColor; }
.background span:nth-child(14) { color: #3ca370; top: 17%; left: 74%; animation-duration: 49s; animation-delay: -49s; transform-origin: -17vw -19vh; box-shadow: -40vmin 0 5.947481840931473vmin currentColor; }
.background span:nth-child(15) { color: #b0305c; top: 55%; left: 53%; animation-duration: 61s; animation-delay: -39s; transform-origin: 23vw -18vh; box-shadow: -40vmin 0 5.66850381738075vmin currentColor; }
.background span:nth-child(16) { color: #4b5bab; top: 76%; left: 59%; animation-duration: 55s; animation-delay: -54s; transform-origin: 8vw -12vh; box-shadow: -40vmin 0 5.118406598980054vmin currentColor; }
.background span:nth-child(17) { color: #4b5bab; top: 28%; left: 87%; animation-duration: 68s; animation-delay: -24s; transform-origin: 14vw 24vh; box-shadow: 40vmin 0 5.147595177031727vmin currentColor; }
.background span:nth-child(18) { color: #3ca370; top: 3%; left: 65%; animation-duration: 51s; animation-delay: -40s; transform-origin: -5vw -24vh; box-shadow: 40vmin 0 5.707023002960579vmin currentColor; }
.background span:nth-child(19) { color: #4b5bab; top: 81%; left: 57%; animation-duration: 21s; animation-delay: -31s; transform-origin: -15vw 19vh; box-shadow: 40vmin 0 5.27730769961146vmin currentColor; }
.background span:nth-child(20) { color: #b0305c; top: 40%; left: 60%; animation-duration: 27s; animation-delay: -103s; transform-origin: 24vw 11vh; box-shadow: 40vmin 0 5.889731124649764vmin currentColor; }
.background span:nth-child(21) { color: #b0305c; top: 33%; left: 25%; animation-duration: 134s; animation-delay: -131s; transform-origin: 3vw 13vh; box-shadow: -40vmin 0 5.957517165287437vmin currentColor; }
.background span:nth-child(22) { color: #b0305c; top: 78%; left: 62%; animation-duration: 21s; animation-delay: -111s; transform-origin: 2vw -11vh; box-shadow: -40vmin 0 5.073132140952468vmin currentColor; }
.background span:nth-child(23) { color: #3ca370; top: 65%; left: 49%; animation-duration: 136s; animation-delay: -138s; transform-origin: -13vw 16vh; box-shadow: 40vmin 0 5.168717365879176vmin currentColor; }
.background span:nth-child(24) { color: #b0305c; top: 56%; left: 43%; animation-duration: 141s; animation-delay: -24s; transform-origin: 0vw -13vh; box-shadow: 40vmin 0 5.953998768089019vmin currentColor; }
.background span:nth-child(25) { color: #4b5bab; top: 44%; left: 8%; animation-duration: 31s; animation-delay: -147s; transform-origin: -14vw -22vh; box-shadow: 40vmin 0 5.466050658486476vmin currentColor; }