/* =========================================
   BASE LAYOUT & TYPOGRAPHY
   ========================================= */
body {
    font-family: 'Press Start 2P', cursive;
    background-image: 
        url('../images/brickLeft.png'), 
        url('../images/brickRight.png'),
        url('../images/bgwallpaper.png');
    background-position: 
        left top, 
        right top,
        center var(--bg-y, 0px);
    background-repeat: 
        repeat-y, 
        repeat-y,
        repeat;
    background-attachment: 
        fixed, 
        fixed,
        fixed;
    background-size:
        128px auto,
	128px auto,
	auto auto;
    image-rendering: pixelated;
    background-color: #212529;
    padding: 2rem;
}

/* =========================================
   HEADER & NAVIGATION
   ========================================= */
.retro-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #fff;
    z-index: 1000;
    box-sizing: border-box;
    border-bottom: 4px solid #212529;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.2rem;

  /* 1. Stack the images (Mountains in front, Sky in back) */
    /* I added a fallback sky-blue color (#87CEEB) at the very end just in case the sky image has transparent spots */
    background-image: 
        url('../images/mountains.png'), 
        url('../images/sky.png');
    background-color: #87CEEB; 
    
    /* 2. Anchor Mountains to the bottom of the header, Sky to the top */
    background-position: 0px -40px, 0px -20px;
        
    /* 3. Make them repeat infinitely horizontally */
    background-repeat: 
        repeat-x, 
        repeat-x;
        
    /* 4. Keep retro chunky pixels if the images are small */
    image-rendering: pixelated;
    
    /* 5. Trigger the animation! (30 seconds, constant speed, infinite loop) */
    animation: parallaxScroll 120s linear infinite;
}

/* =========================================
   IMAGE UTILITIES (FLOATS)
   ========================================= */
.img-float-right {
    float: right;
    width: 50%;
    /* margin: top right bottom left */
    margin: 0 0 1rem 1.5rem; 
}

.img-float-left {
    float: left;
    width: 50%;
    /* margin: top right bottom left */
    margin: 0 1.5rem 1rem 0; 
}

/* Clearfix: Add this to the parent container if a floating image pokes out the bottom */
.clearfix::after {
    content: "";
    clear: both;
    display: table;
}

.button-stack {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    margin-top: 1.5rem;
    justify-content: center;
}

.retro-header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.social-buttons {
    display: flex;
    gap: 1rem;
}

/* =========================================
   CAPTIONED IMAGES
   ========================================= */
.caption-wrapper {
    position: relative;
    display: inline-block; /* Shrinks the wrapper to perfectly hug the image */
    max-width: 100%;       /* Keeps it from blowing out on mobile */
}

.caption-wrapper img {
    display: block; /* Removes the invisible 4px gap browsers put under images */
    width: 100%;
}

.caption-box {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Black with 50% opacity */
    color: #fff;
    text-align: center;
    box-sizing: border-box;
    
    /* 8-bit text adjustments */
    font-size: 0.5rem; 
    padding: 5px; 
}

/* =========================================
   CUSTOM COMPONENTS (Blog, Comments, Containers)
   ========================================= */
.nes-container.is-light {
    background-color: #f1f5f9;
    color: #212529;
    border-color: #212529;
}

.nes-container.is-light.with-title > .title {
    background-color: #f1f5f9;
    color: #212529;
}

.post-date { font-size: 0.7rem; color: #666; margin-bottom: 1rem; }
.pagination { display: flex; justify-content: space-between; margin-top: 2rem; }
.comment-section { margin-top: 2rem; padding-top: 2rem; border-top: 4px dashed #212529; }

/* =========================================
   CUSTOM TEXT UTILITIES
   ========================================= */
/* Option A: Just dark text */
.nes-text.is-dark {
    color: #212529 !important;
}

/* Option B: A dark background highlight with white text */
.nes-text.is-dark-highlight {
    color: #fff !important;
    background-color: #212529;
    padding: 0.2rem 0.4rem;
    box-shadow: 2px 2px 0px #000; /* Adds a tiny drop shadow to make it pop */
}

/* =========================================
   CUSTOM ICONS (Box-Shadow Pixel Art)
   ========================================= */
.nes-icon.earth::before {
  /* Set up the 1x1 pixel canvas */
  width: 1px;
  height: 1px;
  color: #000;

  /* Paint the globe pixel by pixel */
  box-shadow:
    /* Row 1 */
    6px 1px, 7px 1px, 8px 1px, 9px 1px, 10px 1px,
    /* Row 2 */
    4px 2px, 5px 2px, 6px 2px #55a8ff, 7px 2px #55a8ff, 8px 2px #55a8ff, 9px 2px #55a8ff, 10px 2px #55a8ff, 11px 2px, 12px 2px,
    /* Row 3 */
    3px 3px, 4px 3px #3b8fd7, 5px 3px #55a8ff, 6px 3px #55a8ff, 7px 3px #55a8ff, 8px 3px #55a8ff, 9px 3px #c5d45d, 10px 3px #c5d45d, 11px 3px #c5d45d, 12px 3px #c5d45d, 13px 3px,
    /* Row 4 */
    2px 4px, 3px 4px #3b8fd7, 4px 4px #55a8ff, 5px 4px #55a8ff, 6px 4px #55a8ff, 7px 4px #55a8ff, 8px 4px #c5d45d, 9px 4px #c5d45d, 10px 4px #c5d45d, 11px 4px #c5d45d, 12px 4px #c5d45d, 13px 4px #acbd4b, 14px 4px,
    /* Row 5 */
    2px 5px, 3px 5px #3b8fd7, 4px 5px #55a8ff, 5px 5px #55a8ff, 6px 5px #55a8ff, 7px 5px #55a8ff, 8px 5px #acbd4b, 9px 5px #c5d45d, 10px 5px #c5d45d, 11px 5px #acbd4b, 12px 5px #acbd4b, 13px 5px #acbd4b, 14px 5px,
    /* Row 6 */
    1px 6px, 2px 6px #3b8fd7, 3px 6px #55a8ff, 4px 6px #55a8ff, 5px 6px #55a8ff, 6px 6px #55a8ff, 7px 6px #acbd4b, 8px 6px #55a8ff, 9px 6px #55a8ff, 10px 6px #acbd4b, 11px 6px #acbd4b, 12px 6px #acbd4b, 13px 6px #acbd4b, 14px 6px #8b984b, 15px 6px,
    /* Row 7 */
    1px 7px, 2px 7px #3b8fd7, 3px 7px #55a8ff, 4px 7px #55a8ff, 5px 7px #55a8ff, 6px 7px #c5d45d, 7px 7px #c5d45d, 8px 7px #c5d45d, 9px 7px #55a8ff, 10px 7px #3b8fd7, 11px 7px #3b8fd7, 12px 7px #8b984b, 13px 7px #8b984b, 14px 7px #8b984b, 15px 7px,
    /* Row 8 */
    1px 8px, 2px 8px #3b8fd7, 3px 8px #55a8ff, 4px 8px #55a8ff, 5px 8px #c5d45d, 6px 8px #c5d45d, 7px 8px #c5d45d, 8px 8px #c5d45d, 9px 8px #c5d45d, 10px 8px #acbd4b, 11px 8px #acbd4b, 12px 8px #2763a1, 13px 8px #8b984b, 14px 8px #8b984b, 15px 8px,
    /* Row 9 */
    1px 9px, 2px 9px #3b8fd7, 3px 9px #3b8fd7, 4px 9px #55a8ff, 5px 9px #c5d45d, 6px 9px #c5d45d, 7px 9px #8b984b, 8px 9px #c5d45d, 9px 9px #acbd4b, 10px 9px #acbd4b, 11px 9px #8b984b, 12px 9px #8b984b, 13px 9px #2763a1, 14px 9px #8b984b, 15px 9px,
    /* Row 10 */
    1px 10px, 2px 10px #c5d45d, 3px 10px #3b8fd7, 4px 10px #3b8fd7, 5px 10px #8b984b, 6px 10px #8b984b, 7px 10px #8b984b, 8px 10px #8b984b, 9px 10px #acbd4b, 10px 10px #acbd4b, 11px 10px #8b984b, 12px 10px #8b984b, 13px 10px #2763a1, 14px 10px #2763a1, 15px 10px,
    /* Row 11 */
    2px 11px, 3px 11px #c5d45d, 4px 11px #3b8fd7, 5px 11px #3b8fd7, 6px 11px #3b8fd7, 7px 11px #3b8fd7, 8px 11px #acbd4b, 9px 11px #acbd4b, 10px 11px #8b984b, 11px 11px #8b984b, 12px 11px #2763a1, 13px 11px #2763a1, 14px 11px,
    /* Row 12 */
    2px 12px, 3px 12px #8b984b, 4px 12px #c5d45d, 5px 12px #3b8fd7, 6px 12px #3b8fd7, 7px 12px #3b8fd7, 8px 12px #8b984b, 9px 12px #8b984b, 10px 12px #8b984b, 11px 12px #2763a1, 12px 12px #2763a1, 13px 12px #2763a1, 14px 12px,
    /* Row 13 */
    3px 13px, 4px 13px #8b984b, 5px 13px #8b984b, 6px 13px #3b8fd7, 7px 13px #3b8fd7, 8px 13px #8b984b, 9px 13px #8b984b, 10px 13px #2763a1, 11px 13px #2763a1, 12px 13px #2763a1, 13px 13px,
    /* Row 14 */
    4px 14px, 5px 14px, 6px 14px #2763a1, 7px 14px #2763a1, 8px 14px #2763a1, 9px 14px #2763a1, 10px 14px #2763a1, 11px 14px, 12px 14px,
    /* Row 15 */
    6px 15px, 7px 15px, 8px 15px, 9px 15px, 10px 15px;
}

/* =========================================
   GLOBAL RESPONSIVENESS & QOL
   ========================================= */
/* Fix #2: Force all images to resize to their container, and keep them crispy */
img {
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
}

/* Prevent long unbroken strings (like URLs) from blowing out the borders */
.nes-container, .nes-balloon, p {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* =========================================
   RETINA & HIGH-DPI BORDER FIX (V2)
   ========================================= */
.nes-btn, .nes-container, .nes-balloon, .nes-input, .nes-textarea {
    border-image-repeat: stretch !important;
    #background-clip: padding-box !important;
}

/* =========================================
   MOBILE SPECIFIC RULES
   ========================================= */
@media (max-width: 768px) {
    /* Fix #1: Shrink the base font size. 
       Default is 16px. Dropping to 12px yields ~35% more characters per line! */
    body {
        font-size: 12px; 
        background-image: url('../images/bgwallpaper.png');
        background-position: center var(--bg-y, 0px);
	background-repeat: repeat;
        background-attachment: fixed;
    }

    /* Shrink the header elements further to save vertical space */
    .retro-header { gap: 1rem; padding: 1rem; }
    .retro-header h1 { font-size: 0.9rem; }
    
    .retro-header .nes-icon.earth {
        transform: scale(1.5) !important;
        margin: 0 5px !important; 
    }
    
    /* Allow navigation buttons to wrap to a new line if you add more later */
    .social-buttons { 
        gap: 0.5rem; 
        flex-wrap: wrap; 
        justify-content: center; 
    }
    .social-buttons .nes-btn {
        font-size: 0.6rem;
        padding: 0.4rem 0.6rem;
    }

    /* Reduce the margins so the content fills more of the phone screen */
    .wrapper { 
        margin-top: 130px; 
        padding: 0 0.5rem; 
    }
    .nes-container { padding: 1rem 0.8rem; }

    /* Fix #3: Stack inline forms (like the chat room) vertically! */
    /* The !important tags override the inline styles we put in the HTML */
    #chat-form {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    #chat-form .nes-field {
        width: 100% !important;
    }
    
    /* Make submit buttons massive and easy to tap on mobile */
    #chat-form button, .nes-container form button {
        width: 100%;
        margin-top: 1rem;
        padding: 0.8rem;
        font-size: 0.8rem;
    }

    /* Mobile View: Stack buttons vertically and make them massive to tap */
    .button-stack {
        flex-direction: column;
        gap: 1rem;
    }
    
    .button-stack .nes-btn {
        width: 100%;
        display: block;
        text-align: center;
        box-sizing: border-box; /* Prevents the border from breaking the 100% width */
        font-size: 0.7rem; /* Shrinks the text slightly so long titles fit on one line */
        padding: 0.8rem;
    }
    /* Mobile View: Break the floats so text doesn't get squished! */
    .img-float-right, 
    .img-float-left {
        float: none;
        width: 100%;
        margin: 0 0 1.5rem 0; /* Only keep the bottom margin */
        display: block;
    }
}

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes parallaxScroll {
    0% {
        background-position: 0px -40px, 0px -20px;
    }
    100% {
        /* Mountains still move 1 width (-634px) but over 120s (Very slow!) */
        /* Sky moves 8 widths (-2240px) over 120s (Same fast speed as before!) */
        background-position: -634px -40px, -2240px -20px;
    }
}
