/*-----------------------------------*\
  #CHIP-8 EMULATOR STYLES
\*-----------------------------------*/

/* ===== RESET & BASE STYLES ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

a {
    text-decoration: none;
}

li {
    list-style: none;
}

img,
ion-icon,
a,
button,
time,
span {
    display: block;
}

button {
    font: inherit;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
}

input,
textarea {
    display: block;
    width: 100%;
    background: none;
    font: inherit;
}

::selection {
    background: var(--orange-yellow-crayola);
    color: var(--smoky-black);
}

:focus {
    outline-color: var(--orange-yellow-crayola);
}

html {
    font-family: var(--ff-poppins);
}

/* ===== CSS VARIABLES ===== */
:root {
    --bg-gradient-onyx: linear-gradient(to bottom right, hsl(240, 1%, 25%) 3%, hsl(0, 0%, 19%) 97%);
    --bg-gradient-jet: linear-gradient(to bottom right, hsla(240, 1%, 18%, 0.251) 0%, hsla(240, 2%, 11%, 0) 100%), hsl(240, 2%, 13%);
    --bg-gradient-yellow-1: linear-gradient(to bottom right, hsl(45, 100%, 71%) 0%, hsla(36, 100%, 69%, 0) 50%);
    --bg-gradient-yellow-2: linear-gradient(135deg, hsla(45, 100%, 71%, 0.251) 0%, hsla(35, 100%, 68%, 0) 59.86%), hsl(240, 2%, 13%);
    --border-gradient-onyx: linear-gradient(to bottom right, hsl(0, 0%, 25%) 0%, hsla(0, 0%, 25%, 0) 50%);
    --text-gradient-yellow: linear-gradient(to right, hsl(45, 100%, 72%), hsl(35, 100%, 68%));
    --jet: hsl(0, 0%, 22%);
    --onyx: hsl(240, 1%, 17%);
    --eerie-black-1: hsl(240, 2%, 13%);
    --eerie-black-2: hsl(240, 2%, 12%);
    --smoky-black: hsl(0, 0%, 7%);
    --white-1: hsl(0, 0%, 100%);
    --white-2: hsl(0, 0%, 98%);
    --orange-yellow-crayola: hsl(45, 100%, 72%);
    --vegas-gold: hsl(45, 54%, 58%);
    --light-gray: hsl(0, 0%, 84%);
    --light-gray-70: hsla(0, 0%, 84%, 0.7);
    --bittersweet-shimmer: hsl(0, 43%, 51%);
    --shadow-1: -4px 8px 24px hsla(0, 0%, 0%, 0.25);
    --shadow-2: 0 16px 30px hsla(0, 0%, 0%, 0.25);
    --shadow-3: 0 16px 40px hsla(0, 0%, 0%, 0.25);
    --shadow-4: 0 25px 50px hsla(0, 0%, 0%, 0.15);
    --shadow-5: 0 24px 80px hsla(0, 0%, 0%, 0.25);
    --transition-1: 0.25s ease;
    --transition-2: 0.5s ease-in-out;
    --ff-poppins: 'Poppins', sans-serif;
    --fs-1: 24px;
    --fs-2: 18px;
    --fs-3: 17px;
    --fs-4: 16px;
    --fs-5: 15px;
    --fs-6: 14px;
    --fs-7: 13px;
    --fs-8: 11px;
    --fw-300: 300;
    --fw-400: 400;
    --fw-500: 500;
    --fw-600: 600;
}

body {
    font-family: var(--ff-poppins);
    width: 95%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 60px;
    background: var(--smoky-black);
    color: #fff;
}

/* ===== MAIN LAYOUT ===== */
main {
    margin: 15px 12px;
    margin-bottom: 75px;
    min-width: 259px;
}

/* ===== SIDEBAR STYLES ===== */
.sidebar,
article {
    background: var(--eerie-black-2);
    border: 1px solid var(--jet);
    border-radius: 20px;
    padding: 15px;
    box-shadow: var(--shadow-1);
    z-index: 1;
}

.sidebar {
    margin-bottom: 15px;
    max-height: 112px;
    overflow: hidden;
    transition: var(--transition-2);
}

.sidebar.active {
    max-height: 405px;
}

.sidebar-info {
    position: relative;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
}

.avatar-box {
    background: var(--bg-gradient-onyx);
    border-radius: 20px;
}

.info-content .name {
    color: var(--white-2);
    font-size: var(--fs-3);
    font-weight: var(--fw-500);
    letter-spacing: -0.25px;
    margin-bottom: 10px;
}

.info-content .title {
    color: var(--white-1);
    background: var(--onyx);
    font-size: var(--fs-8);
    font-weight: var(--fw-300);
    width: max-content;
    padding: 3px 12px;
    border-radius: 8px;
}

.info_more-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    border-radius: 0 15px;
    font-size: 13px;
    color: var(--orange-yellow-crayola);
    background: var(--border-gradient-onyx);
    padding: 10px;
    box-shadow: var(--shadow-2);
    transition: var(--transition-1);
    z-index: 1;
}

.info_more-btn::before {
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: inherit;
    background: var(--bg-gradient-jet);
    transition: var(--transition-1);
    z-index: -1;
}

.info_more-btn:hover,
.info_more-btn:focus {
    background: var(--bg-gradient-yellow-1);
}

.info_more-btn:hover::before,
.info_more-btn:focus::before {
    background: var(--bg-gradient-yellow-2);
}

.info_more-btn span {
    display: none;
}

.sidebar-info_more {
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-2);
}

.sidebar.active .sidebar-info_more {
    opacity: 1;
    visibility: visible;
}

.separator {
    width: 100%;
    height: 1px;
    background: var(--jet);
    margin: 16px 0;
}

.icon-box {
    position: relative;
    background: var(--border-gradient-onyx);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    color: var(--orange-yellow-crayola);
    box-shadow: var(--shadow-1);
    z-index: 1;
}

.icon-box::before {
    content: "";
    position: absolute;
    inset: 1px;
    background: var(--eerie-black-1);
    border-radius: inherit;
    z-index: -1;
}

.icon-box ion-icon {
    --ionicon-stroke-width: 35px;
}

.contacts-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.contact-item {
    min-width: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
}

.contact-info {
    max-width: calc(100% - 46px);
    width: calc(100% - 46px);
}

.contact-title {
    color: var(--light-gray-70);
    font-size: var(--fs-8);
    text-transform: uppercase;
    margin-bottom: 2px;
}

.contact-info :is(.contact-link, time, address) {
    color: var(--white-2);
    font-size: var(--fs-7);
}

.contact-info address {
    font-style: normal;
}


.social-list {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
    padding-bottom: 4px;
    padding-left: 7px;
}

.social-item .social-link {
    color: var(--light-gray-70);
    font-size: 18px;
}

.social-item .social-link:hover {
    color: var(--light-gray);
}

/* For regular img icons (Bluesky, Dev.to) */
.social-item .social-link img {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    transition: var(--transition-1);
}

.social-item .social-link:hover img {
    opacity: 1;
}

/* For inline SVG (GitHub rainbow) */
.social-item .social-link svg {
    width: 18px;
    height: 18px;
    transition: var(--transition-1);
}

.social-item .social-link:hover svg {
    opacity: 0.9;
}


/* ===== ARTICLE STYLES ===== */
article {
    width: 100%;
    box-sizing: border-box;
}

article {
    display: none;
}

article.active {
    display: block;
    animation: fade 0.5s ease backwards;
}

@keyframes fade {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.emulator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 12px;
    position: relative;
    border-bottom: 1px solid var(--jet);
}

.emulator-header::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 40px;
    height: 5px;
    background: var(--text-gradient-yellow);
    border-radius: 3px;
    z-index: 1;
}

.emulator-header h1 {
    text-align: left;
    margin: 0;
    padding: 0;
    color: var(--white-2);
    font-size: var(--fs-1);
}

.back-home-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-gradient-onyx);
    border: 1px solid var(--jet);
    color: var(--white-2);
    padding: 8px 16px;
    border-radius: 12px;
    font-size: var(--fs-7);
    text-decoration: none;
    box-shadow: var(--shadow-1);
    transition: var(--transition-1);
    white-space: nowrap;
}

.back-home-btn ion-icon {
    font-size: 18px;
    color: var(--orange-yellow-crayola);
}

.back-home-btn:hover {
    background: var(--bg-gradient-jet);
    border-color: var(--orange-yellow-crayola);
    transform: translateY(-2px);
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.control-card {
    background: var(--border-gradient-onyx);
    padding: 20px;
    border-radius: 14px;
    box-shadow: var(--shadow-2);
    position: relative;
    z-index: 1;
}

.control-card::before {
    content: "";
    position: absolute;
    inset: 1px;
    background: var(--bg-gradient-jet);
    border-radius: inherit;
    z-index: -1;
}

.control-card label {
    color: var(--white-2);
    font-size: var(--fs-6);
    font-weight: var(--fw-500);
    display: block;
    margin-bottom: 10px;
}

.control-card select,
.control-card input[type="file"] {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--jet);
    background: var(--eerie-black-1);
    color: var(--white-2);
    font-size: var(--fs-6);
    font-family: var(--ff-poppins);
    cursor: pointer;
    transition: var(--transition-1);
}

.control-card select:focus,
.control-card input[type="file"]:focus {
    border-color: var(--orange-yellow-crayola);
    outline: none;
}

.control-card small {
    display: block;
    color: var(--light-gray-70);
    font-size: var(--fs-8);
    margin-top: 8px;
}

.sound-toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: var(--fs-6);
}

.sound-toggle-label input[type="checkbox"] {
    width: auto;
    cursor: pointer;
    accent-color: var(--orange-yellow-crayola);
}

.sound-toggle-label span {
    color: var(--white-2);
}

input[type=file]::file-selector-button {
    background: var(--jet);
    color: var(--white-2);
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    margin-right: 10px;
    transition: var(--transition-1);
}

input[type=file]::file-selector-button:hover {
    background: var(--orange-yellow-crayola);
    color: var(--smoky-black);
}

#gamedescription {
    grid-column: 1 / -1;
    background: var(--bg-gradient-jet);
    border: 1px solid var(--jet);
    padding: 20px;
    border-radius: 14px;
    white-space: pre-line;
    color: var(--light-gray);
    font-size: var(--fs-6);
    line-height: 1.6;
    box-shadow: var(--shadow-2);
}

#canvas {
    border-radius: 12px;
    border: 2px solid var(--jet);
    box-shadow: var(--shadow-3);
    background-color: #000;
    margin: 20px auto;
    display: block;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 2 / 1;
    image-rendering: pixelated;
}

.debugger-title {
    background: var(--text-gradient-yellow);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: var(--fs-2);
    font-weight: var(--fw-600);
    padding-bottom: 15px;
    border-bottom: 1px solid var(--jet);
    margin-bottom: 10px;
    text-align: center;
}

.debugger h3 {
    color: var(--orange-yellow-crayola);
    text-transform: uppercase;
    font-size: var(--fs-8);
    letter-spacing: 1px;
    margin: 20px 0 10px;
}

.debug-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.data-item {
    background: var(--bg-gradient-jet);
    border: 1px solid var(--jet);
    padding: 8px;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow-1);
}

.data-item .label {
    display: block;
    color: var(--light-gray-70);
    font-size: 10px;
    margin-bottom: 2px;
}

.data-item .value {
    color: var(--white-1);
    font-family: 'Courier New', monospace;
    font-weight: var(--fw-600);
    font-size: var(--fs-6);
}

.register-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--light-gray);
}

.debug-box {
    background: var(--eerie-black-1);
    border: 1px solid var(--jet);
    border-radius: 10px;
    padding: 12px;
    font-family: 'Courier New', monospace;
    color: var(--orange-yellow-crayola);
    line-height: 1.6;
    max-height: 120px;
    overflow-y: auto;
    font-size: var(--fs-7);
}

.debug-box::-webkit-scrollbar {
    width: 5px;
}

.debug-box::-webkit-scrollbar-track {
    background: var(--eerie-black-2);
}

.debug-box::-webkit-scrollbar-thumb {
    background: var(--jet);
    border-radius: 10px;
}

#mobile-keyboard {
    display: none;
    background: var(--bg-gradient-jet);
    border: 1px solid var(--jet);
    padding: 20px;
    border-radius: 20px;
    margin-top: 30px;
    box-shadow: var(--shadow-2);
}

.keyboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.key-btn {
    aspect-ratio: 1 / 1;
    background: var(--bg-gradient-onyx);
    color: var(--orange-yellow-crayola);
    border: 1px solid var(--jet);
    border-radius: 12px;
    font-family: var(--ff-poppins);
    font-size: var(--fs-4);
    font-weight: var(--fw-600);
    cursor: pointer;
    transition: var(--transition-1);
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.key-btn:active,
.key-btn.pressed {
    background: var(--text-gradient-yellow);
    color: var(--smoky-black);
    transform: scale(0.92);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 450px) {
    .emulator-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }
}

@media (max-width: 767px) {
    #mobile-keyboard {
        display: block !important;
    }

    body {
        width: 95% !important;
        padding: 10px !important;
    }

    article {
        padding: 10px !important;
    }

    .debug-box {
        max-height: 150px !important;
        font-size: 13px !important;
    }

    /* Fix for sidebar on mobile */
    .sidebar {
        margin-bottom: 15px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .sidebar.debug-sidebar {
        max-height: none !important;
        overflow: visible !important;
    }

    .debugger {
        width: 100%;
    }

    .debugger-title {
        font-size: var(--fs-4) !important;
    }

    .debug-grid {
        gap: 8px !important;
    }

    .data-item {
        padding: 6px !important;
    }

    .data-item .label {
        font-size: 9px !important;
    }

    .data-item .value {
        font-size: 14px !important;
    }

    .register-grid {
        gap: 5px !important;
        font-size: 10px !important;
    }

    .debugger h3 {
        font-size: 10px !important;
        margin: 15px 0 8px !important;
    }

    main {
        display: block !important;
        margin: 10px !important;
    }
}

@media (min-width: 768px) and (max-width: 1249px) {

    /* Mid-sized screens: stack sidebars and content vertically */
    main {
        display: block !important;
    }

    .sidebar {
        margin-bottom: 15px;
        width: 100%;
        max-width: 100%;
    }

    .sidebar.debug-sidebar {
        max-height: none !important;
        overflow: visible !important;
    }

    .main-content {
        width: 100%;
        max-width: 100%;
    }
}

@media (min-width: 1024px) {
    :root {
        --shadow-1: -4px 8px 24px hsla(0, 0%, 0%, 0.125);
        --shadow-2: 0 16px 30px hsla(0, 0%, 0%, 0.125);
        --shadow-3: 0 16px 40px hsla(0, 0%, 0%, 0.125);
    }

    .sidebar,
    article {
        position: relative;
        max-width: 1200px;
        width: 100%;
        box-shadow: var(--shadow-5);
    }

    main {
        width: 100%;
        max-width: min(1200px, 95vw);
        margin-inline: auto;
        margin-bottom: 60px;
    }

    .main-content {
        position: relative;
        width: 100%;
        max-width: 1100px;
        margin: 0 auto;
    }
}

@media (min-width: 1250px) {
    body::-webkit-scrollbar {
        width: 20px;
    }

    body::-webkit-scrollbar-track {
        background: var(--smoky-black);
    }

    body::-webkit-scrollbar-thumb {
        border: 5px solid var(--smoky-black);
        background: hsla(0, 0%, 100%, 0.1);
        border-radius: 20px;
        box-shadow: inset 1px 1px 0 hsla(0, 0%, 100%, 0.11),
            inset -1px -1px 0 hsla(0, 0%, 100%, 0.11);
    }

    body::-webkit-scrollbar-thumb:hover {
        background: hsla(0, 0%, 100%, 0.15);
    }

    body::-webkit-scrollbar-button {
        height: 60px;
    }

    .sidebar,
    article {
        width: auto;
    }

    article {
        min-height: 100%;
    }

    main {
        max-width: 1400px;
        margin-inline: auto;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        gap: 25px;
    }

    .main-content {
        flex: 1;
        min-width: 0;
        margin: 0;
        max-width: none;
    }

    .sidebar {
        flex: 0 0 240px;
        position: sticky;
        top: 60px;
        max-height: max-content;
        height: auto;
        margin-bottom: 0;
        padding-top: 60px;
    }

    .sidebar-info {
        flex-direction: column;
    }

    .avatar-box img {
        width: 150px;
    }

    .info-content .name {
        white-space: nowrap;
        text-align: center;
    }

    .info-content .title {
        margin: auto;
    }

    .info_more-btn {
        display: none;
    }

    .sidebar-info_more {
        opacity: 1;
        visibility: visible;
    }

    .contacts-list {
        grid-template-columns: 1fr;
    }

    .contact-info :is(.contact-link) {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .contact-info :is(.contact-link, time, address) {
        --fs-7: 14px;
        font-weight: var(--fw-300);
    }

    .separator:last-of-type {
        margin: 15px 0;
        opacity: 0;
    }

    .social-list {
        justify-content: center;
    }

    .debugger {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
    }

    #dbg-stack {
        flex-grow: 1;
        max-height: none;
        min-height: 150px;
    }
}
