:root {
    --bg-color: #111;
    --nes-black: #000;
    --nes-green: #83d313;
    /* Duck Hunt Grass Greenish */
    --nes-sky: #64b9fc;
    --nes-text: #ffffff;
    --nes-accent: #ff0000;
    /* Hit marker red */
    --font-nes: 'Press Start 2P', cursive;
}

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

body {
    background-color: var(--bg-color);
    color: var(--nes-text);
    font-family: var(--font-nes);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    /* Prevent scrolling entirely */
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    -webkit-text-size-adjust: none;
    -ms-text-size-adjust: none;
}

#nes-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 640px;
    height: 480px;
    background: #000;
    border: 4px solid #333;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    /* Hidden initially */
    transition: opacity 1.5s ease-in;
}

#game-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-image: url('../images/background.png');
    background-size: cover;
    background-position: bottom center;
    background-repeat: no-repeat;
    background-color: var(--nes-sky);
    /* Fallback */
    image-rendering: pixelated;
}

canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    /* Below HUD, Above Background */
    pointer-events: auto;
    /* Ensure clicks pass to canvas or are handled if needed */
    background: transparent;
    /* Transparent so we see bg and HUD if needed */
    image-rendering: pixelated;
}

/* UI Layer overrides */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Covers everything including HUD for overlays */
    pointer-events: none;
}

/* NES HUD */
#nes-hud {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    /* Fixed height for HUD */
    background-color: var(--nes-black);
    border-top: 4px solid var(--nes-green);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    font-size: 0.9rem;
    color: var(--nes-green);
    z-index: 10;
    /* Above Canvas */
}

#leaderboard-hud {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: var(--nes-black);
    border-top: 4px solid var(--nes-green);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    z-index: 260;
    /* Above leaderboard content */
}

.hud-section {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hud-section.right {
    align-items: flex-end;
    text-align: right;
}

.hud-label {
    background-color: #fc9838;
    /* That classic orange/tan label bg */
    color: #000;
    padding: 2px 4px;
    margin-bottom: 4px;
    font-size: 0.7rem;
    display: inline-block;
    border-radius: 2px;
}

.hit-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

#hit-markers {
    display: flex;
    gap: 5px;
}

.hit-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #fff;
    opacity: 0.3;
}

.hit-marker.active {
    opacity: 1;
    background-color: var(--nes-accent);
}

/* Wallet and Buttons */
/* Wallet andButtons */
#wallet-container {
    /* Grid positioning handled in #nes-header */
    position: relative;
    display: flex;
    align-items: center;
    font-size: 0.7rem;
    pointer-events: auto;
}

/* .btn-wallet is now styled with .header-btn above for uniformity */

#wallet-popup {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 5px;
    background: #000;
    border: 2px solid #fff;
    padding: 10px;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 50;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
}

#popup-balance {
    color: var(--nes-green);
    text-align: center;
    border-bottom: 2px solid #333;
    padding-bottom: 5px;
}

#disconnect-btn {
    background: #f00 !important;
    border-color: #fff !important;
    font-size: 0.6rem !important;
    padding: 5px !important;
    margin: 0 !important;
}

#disconnect-btn:hover {
    background: #fff !important;
    color: #f00 !important;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Cover whole game area */
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    text-align: center;
    z-index: 250;
}

#pause-screen {
    cursor: pointer;
}

.overlay.hidden {
    display: none;
}

#start-screen {
    background: rgba(0, 0, 0, 0.4);
    /* Slight tint for readability, but mostly visible */
    z-index: 190;
    /* Below header (200) so buttons work */
}


.title {
    font-size: 2.5rem;
    color: #ffd700;
    text-shadow: 4px 4px #c25f00;
    margin-bottom: 20px;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.9rem;
    color: #fff;
    margin-bottom: 30px;
}

.btn-primary {
    background: #83d313;
    /* NES Green */
    border: 4px solid #fff;
    color: #000;
    padding: 15px 30px;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    text-transform: uppercase;
}

.btn-primary:hover {
    background: #fff;
    color: #000;
    border-color: #83d313;
}

.btn-primary:disabled {
    background: #555;
    color: #888;
    border-color: #555;
    cursor: not-allowed;
}

.btn-secondary {
    background: #000;
    border: 4px solid #fff;
    color: #fff;
    padding: 10px 20px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    text-transform: uppercase;
    margin-top: 10px;
}

.btn-secondary:hover {
    background: #fff;
    color: #000;
}

/* Gray Start Button (Connect State) */
.btn-connect-start {
    background: #555 !important;
    border-color: #777 !important;
    color: #aaa !important;
    cursor: not-allowed !important;
}

/* Override overlay alignment for leaderboard */
#leaderboard-screen {
    justify-content: flex-start;
    padding-top: 10px;
    padding-bottom: 80px;
    /* 60px HUD + 20px space */
}

/* Leaderboard */
#leaderboard-list {
    width: 80%;
    margin-bottom: 20px;
    border: 4px solid #fff;
    padding: 10px;
    background: #000;
}

/* Leaderboard Layout */
.leaderboard-header,
.leaderboard-row {
    display: grid;
    grid-template-columns: 60px 1fr 80px;
    /* Rank, Name, Score */
    gap: 10px;
    align-items: center;
    border-bottom: 2px solid #333;
    /* Use consistent internal borders */
    padding: 5px 0;
}

.leaderboard-header {
    border-bottom: 2px solid #fff;
    margin-bottom: 10px;
    color: var(--nes-green);
    text-transform: uppercase;
    font-size: 0.8rem;
}

.leaderboard-row {
    font-size: 0.75rem;
    /* Slightly smaller (~1px less) */
    border-bottom: 1px dashed #333;
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-row span,
.leaderboard-header span {
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Specific alignments */
.leaderboard-row span:nth-child(1),
.leaderboard-header span:nth-child(1) {
    text-align: left;
    padding-left: 10px;
}

.leaderboard-row span:nth-child(2),
.leaderboard-header span:nth-child(2) {
    text-align: center;
}

.leaderboard-row span:nth-child(3),
.leaderboard-header span:nth-child(3) {
    text-align: right;
    padding-right: 10px;
}

/* Reusable Box Style for FAQ/Leaderboard content */
.leaderboard-box {
    border: 2px solid #fff;
    background: #000;
    /* Ensure opaque background */
    padding: 10px;
    margin: 0 auto;
    width: 100%;
    max-width: 90%;
}

.faq-list-item {
    font-size: 0.6rem;
    line-height: 1.6;
    margin-bottom: 8px;
    color: #ccc;
    border-bottom: 1px dotted #333;
    padding-bottom: 5px;
}

.faq-list-item:last-child {
    border-bottom: none;
}

.faq-question {
    color: #83d313;
    /* Green Question */
    margin-bottom: 4px;
    text-transform: uppercase;
}


#footer {
    margin-top: 10px;
    color: #555;
    font-size: 0.6rem;
    text-align: center;
}

/* NES Header */
#nes-header {
    width: 100%;
    height: 40px;
    background-color: var(--nes-black);
    border-bottom: 2px solid #555;
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* Left, Right */
    align-items: center;
    padding: 0 10px;
    z-index: 200;
}

#header-left {
    justify-self: start;
    display: flex;
    align-items: center;
}

/* Common Header Button Style */
.header-btn,
.btn-wallet {
    background: #000;
    border: 2px solid #fff;
    color: #fff;
    padding: 0;
    height: 28px;
    width: 140px;
    /* Fixed width */
    font-family: inherit;
    font-size: 0.65rem;
    cursor: pointer;
    text-transform: uppercase;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
}

.header-btn:hover,
.btn-wallet:hover {
    background: #fff;
    color: #000;
}

/* Ensure Leaderboard stays left */
#leaderboard-btn {
    justify-self: start;
}

/* Ensure Wallet stays right */
#wallet-container {
    justify-self: end;
    position: relative;
    display: flex;
    align-items: center;
}

/* UI Layer overrides */


/* Timer */
#timer-display {
    font-size: 0.9rem;
    color: var(--nes-green);
    text-shadow: 1px 1px #000;
    margin: 0;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Settings Popup */
.settings-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #000;
    border: 4px solid #fff;
    padding: 20px;
    width: 300px;
    z-index: 250;
    /* Above Header which is 200 */
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.5);
}

.settings-title {
    color: var(--nes-sky);
    font-size: 1rem;
    text-align: center;
    border-bottom: 2px solid #555;
    padding-bottom: 10px;
    margin-bottom: 5px;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 0.8rem;
}

/* Slider Styling */
.slide-container {
    width: 60%;
}

.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    background: #333;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
}

.slider:hover {
    opacity: 1;
}

/* Leaderboard List - Expanded */
#leaderboard-list {
    flex: 1;
    overflow-y: hidden;
    /* Pagination used instead */
    width: 90%;
    margin-bottom: 10px;
    border: 4px solid #fff;
    padding: 10px;
    background: #000;
}



#leaderboard-controls button {
    font-size: 0.6rem;
    padding: 8px 12px;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--nes-green);
    cursor: pointer;
    border: 2px solid #fff;
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--nes-green);
    cursor: pointer;
    border: 2px solid #fff;
}

/* Close Button */
.settings-popup .btn-secondary.small {
    align-self: center;
    padding: 8px 16px;
    font-size: 0.7rem;
    width: auto;
    margin-top: 0;
}

/* Select Box Styling */
.nes-select {
    background: #000;
    color: var(--nes-green);
    border: 2px solid #fff;
    padding: 5px;
    font-family: inherit;
    font-size: 0.8rem;
    width: 60px;
}

/* Pagination Arrows */
.nav-arrow {
    background: transparent;
    color: #fff;
    border: none;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
}

.nav-arrow:hover {
    color: var(--nes-green);
}

/* Leaderboard Rows - Compact */
.leaderboard-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    /* Tight padding */
    border-bottom: 0px dotted #333;
    margin: 2px;
    font-size: 10px;
    /* Small font to fit 10 items */
    color: #fff;
    font-family: var(--font-nes);
}

.leaderboard-row span:nth-child(1) {
    width: 10%;
    text-align: left;
    color: #666;
}

/* Rank */
.leaderboard-row span:nth-child(2) {
    width: 60%;
    text-align: center;
}

/* Name */
.leaderboard-row span:nth-child(3) {
    width: 30%;
    text-align: right;
    color: var(--nes-green);
}

/* Score */

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    padding-bottom: 5px;
    margin-bottom: 5px;
    border-bottom: 2px solid #fff;
    font-size: 0.75rem;
    color: var(--nes-sky);
    font-family: var(--font-nes);
}

.leaderboard-header span:nth-child(1) {
    width: 10%;
    text-align: left;
}

.leaderboard-header span:nth-child(2) {
    width: 60%;
    text-align: center;
}

.leaderboard-header span:nth-child(3) {
    width: 30%;
    text-align: right;
}



.nav-arrow:hover {
    opacity: 1;
    color: var(--nes-green);
}

.nav-arrow:disabled {
    opacity: 0.5;
    cursor: default;
    color: #777;
}

/* Consistent Button Widths for Game Over Screen */
#game-over-screen button {
    display: block;
    /* Stack them */
    width: 250px;
    /* Fixed uniform width */
    margin: 10px auto;
    /* Centered with vertical spacing */
    box-sizing: border-box;
}

#submit-score-container,
#game-over-menu {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Footer Links */
.footer-link {
    color: inherit;
    text-decoration: none;
    opacity: 1;
    transition: color 0.2s;
}

.footer-link:hover {
    color: #fff;
    text-decoration: underline;
}

/* FAQ Tabs */
.faq-tabs {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

/* FAQ Content Box */
.faq-content-box::-webkit-scrollbar {
    width: 6px;
}

.faq-content-box::-webkit-scrollbar-track {
    background: #000;
}

.faq-content-box::-webkit-scrollbar-thumb {
    background: #fff;
    border-radius: 3px;
}

/* FAQ Content */
.faq-section {
    font-family: var(--font-nes);
    font-size: 0.6rem;
    line-height: 1.8;
}

/* Reusable Box Style for FAQ/Leaderboard content */
.leaderboard-box {
    border: 2px solid #fff;
    background: #000;
    /* Ensure opaque background */
    padding: 10px;
    margin: 0 auto;
    width: 100%;
    max-width: 90%;
    font-family: var(--font-nes);
    /* Force Font */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.faq-list-item {
    font-family: var(--font-nes);
    /* Double Force Font */
    font-size: 0.55rem;
    /* Smaller to fit */
    line-height: 1.6;
    margin-bottom: 8px;
    color: #ccc;
    border-bottom: 1px dotted #333;
    padding-bottom: 5px;
}

.faq-list-item:last-child {
    border-bottom: none;
}

.faq-question {
    color: #83d313;
    /* Green Question */
    margin-bottom: 4px;
    text-transform: uppercase;
}

/* Tabs rely on btn-secondary, we just style active state and hover */
.faq-tab {
    flex: 1;
    /* Scale to fill space */
    margin: 0;
    padding: 10px 0;
    /* Top/Bottom padding only, side handled by flex and center text */
    font-size: 0.8rem;
    /* Larger font since we only have 3 items now */
    min-width: 0;
    /* Allow shrink */
    text-align: center;
    white-space: nowrap;
    /* Prevent wrap */
    overflow: hidden;
    /* safety */
}

.faq-tab.active-tab {
    background: #209cee !important;
    /* Leaderboard Blue */
    color: #fff !important;
    border-color: #fff !important;
}

/* Specific overwrite to match Leaderboard Blue */
.faq-tab.active-tab {
    background: #209cee !important;
    /* Leaderboard Blue */
    color: #fff !important;
    border-color: #fff !important;
}

/* Global Hidden Helper - strengthened */
.hidden {
    display: none !important;
}