/* CSS Reset - START */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
/* CSS Reset - END */

*, *::before, *::after {
    box-sizing: border-box;
}

@font-face {
    font-family: "earlyGameBoy";
    src: url(./files/Early_GameBoy.ttf);
    font-display: swap;
}

html, body {
    cursor: url("./img/Rainbow-Paintbrush.gif"), default;
    background-image: url("./img/galaxy.webp");
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
    margin: 0;
}

body {
    background-color: rgb(0, 23, 62);
    /* sticky footer: content grows, footer always sits at the bottom */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url(./img/header.webp);
    background-repeat: repeat;
    background-size: 35%;
    height: 120px;
    border: 2px solid black;
    flex: none;
}

.gameboy {
    font-family: "earlyGameboy", Arial;
    text-shadow: black 0.1em 0.17em 0.1em;
    text-align: center;
    color: white;
}

header {
    color: white;
    font-size: 40px;
}

button {
    font-family: "earlyGameboy", Arial;
    cursor: pointer;
    padding: 6px 10px;
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/************************ Layout ************************/

.app {
    display: grid;
    /* the middle column needs a definite width, otherwise the canvas
       shrink-wraps and the fr-sized pixel cells collapse to nothing */
    grid-template-columns: minmax(160px, 1fr) minmax(0, 740px) minmax(160px, 1fr);
    align-items: start;
    justify-items: center;
    gap: 18px;
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 20px;
    flex: 1 0 auto;
}

.panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
}

/* Retro "menu box" — the NES/GameBoy dialog frame that groups each toolset */
.box {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 225px;
    padding: 10px;
    background: rgba(0, 18, 52, 0.82);
    border: 2px solid #7fb2ff;
    box-shadow: 0 0 0 2px #00102a, 4px 4px 0 rgba(0, 0, 0, 0.45);
}

.box-title {
    font-size: 9px;
    letter-spacing: 1px;
    padding-bottom: 6px;
    margin-bottom: 9px;
    border-bottom: 2px dotted rgba(127, 178, 255, 0.55);
}

.box-body {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    /* fill the box and sit centred, so boxes stretched to a shared row
       height don't leave all their slack at the bottom */
    flex: 1 1 auto;
    align-content: center;
    gap: 10px;
}

.field {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.field-full {
    width: 100%;
}

.field-label {
    font-size: 8px;
    line-height: 1.3;
    color: #cfe1ff;
    text-shadow: black 0.1em 0.15em 0.1em;
}

.mascot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/************************ Canvas ************************/

.canvas {
    padding: 20px;
    width: 100%;
    max-width: 740px;
    justify-self: stretch;
    min-height: 480px;
    position: relative;
    flex-direction: column;
    background-color: rgb(0, 36, 126);
}

.flex {
    justify-content: center;
    align-items: center;
    display: flex;
}

.canvas h3 {
    font-size: 30px;
    text-align: center;
}

#pixelCanvas {
    width: 100%;
    /* --cols is set by main.js based on the viewport when the grid is built */
    display: grid;
    grid-template-columns: repeat(var(--cols, 58), 1fr);
    /* let a finger draw instead of scrolling the page */
    touch-action: none;
}

.pixel {
    aspect-ratio: 1 / 1;
    background-color: white;
    border: 1px solid rgb(135, 135, 135);
    -webkit-user-select: none;
    user-select: none;
}

#startButton,
#instructions {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: "earlyGameboy", Arial;
    min-height: 50px;
    padding: 25px;
    cursor: inherit;
    text-align: center;
}

#startButton {
    margin: 30px;
}

/************************ Tools ************************/

/* same footprint as the picker beside it, so their labels line up */
#selectedColor {
    width: 60px;
    height: 60px;
    background-color: black;
    border: 3px dotted white;
}

#colorPicker {
    width: 60px;
    height: 60px;
    cursor: pointer;
}

#bgColor,
#gridColor {
    width: 35px;
    height: 35px;
    cursor: pointer;
}

/* Palette */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 5px 12px;
}

.palette-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.swatch {
    width: 22px;
    height: 22px;
    border: 2px dotted black;
    background-color: white;
    cursor: pointer;
    flex: none;
}

.palette-row button {
    font-size: 7px;
    padding: 4px 6px;
}

/* Music */
#musicNotes {
    width: 34px;
    height: 34px;
}

/* notes sit above the transport row, not beside it */
.music-box .box-body {
    flex-direction: column;
    align-items: center;
}

.transport {
    gap: 8px;
}

.transport button {
    font-weight: 900;
    min-width: 40px;
}

input[type="range"] {
    width: 100%;
    accent-color: #7fb2ff;
    cursor: pointer;
}

#energy {
    height: 20px;
    width: 15px;
    cursor: pointer;
    align-self: flex-end;
    opacity: 0.85;
}

/* Left panel bits */
#disk {
    width: 100px;
    height: 100px;
    cursor: pointer;
}

#megaman {
    height: 92px;
    width: 77px;
}

#mega-life {
    height: 45px;
    width: 45px;
    display: none;
}

/* Easter egg */
.easter-egg {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 20px;
    flex: none;
}

#hidden-mega {
    height: 85px;
    width: 85px;
    cursor: pointer;
    display: none;
}

#hidden-text {
    display: none;
}

footer {
    width: 100%;
    display: flex;
    background-color: #002041;
    align-items: center;
    justify-content: center;
    height: 40px;
    flex: none;
}

/************************ Responsive ************************/

/* Tablet and below: canvas on top, tool boxes reflow beneath it */
@media (max-width: 1023px) {
    /* Dissolve the two panels so every box can be ordered on its own,
       independent of which column it sits in on desktop. A grid (rather than
       wrapping flex) keeps every box the same width and gives each row a
       shared height, so short boxes no longer sit ragged next to tall ones. */
    .app {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
        justify-items: stretch;
        align-items: stretch;
        gap: 16px;
    }

    .panel {
        display: contents;
    }

    .canvas {
        order: 0;
        grid-column: 1 / -1;
        justify-self: center;
    }

    .box {
        width: auto;
        max-width: none;
    }

    /* MegaMan spans the full row rather than eating a box-sized cell */
    .mascot {
        grid-column: 1 / -1;
    }

    #energy {
        grid-column: 1 / -1;
        justify-self: end;
    }

    /* Ordered by what you reach for while drawing: colour constantly,
       erase often, canvas setup occasionally, save at the end of a
       session, music once and forget. */
    .mascot     { order: 1; }
    .box-color  { order: 2; }
    .box-edit   { order: 3; }
    .box-canvas { order: 4; }
    .box-save   { order: 5; }
    .music-box  { order: 6; }
    #energy     { order: 7; }
}

/* Phones */
@media (max-width: 639px) {
    .header-container {
        height: 80px;
        background-size: 60%;
    }

    header {
        font-size: 24px;
    }

    .app {
        padding: 10px;
        gap: 14px;
    }

    .canvas {
        padding: 10px;
        min-height: 0;
    }

    .canvas h3 {
        font-size: 20px;
    }

    #startButton,
    #instructions {
        padding: 18px;
        margin: 12px;
    }

    /* one tidy centred column: every box the same width as the canvas,
       edges aligned, mascot on its own line */
    .app {
        grid-template-columns: 1fr;
    }

    /* bigger tap targets */
    button {
        min-height: 40px;
        padding: 8px 12px;
    }

    .palette-row button {
        min-height: 32px;
    }

    #disk {
        width: 70px;
        height: 70px;
    }

    #colorPicker,
    #selectedColor {
        width: 56px;
        height: 56px;
    }
}
