/* Global */
body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a;
    color: #fff;
    overflow: hidden;
    /* Prevent scroll on display */
    box-sizing: border-box;
}

.admin-page {
    overflow-y: auto;
}

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

/* Display Layout */
.display-body {
    height: 100vh;
    width: 100vw;
}

.display-container {
    display: flex;
    height: 100%;
}

.sidebar {
    width: 250px;
    background-color: #252525;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #333;
}

.logo {
    padding: 20px;
    font-size: 1.5em;
    font-weight: bold;
    text-align: center;
    background-color: #e60012;
    /* NES Red */
}

.input-log {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    font-family: monospace;
    font-size: 0.9em;
}

.log-entry {
    margin-bottom: 5px;
    border-bottom: 1px solid #333;
    padding-bottom: 2px;
    animation: fadeIn 0.2s;
}

.log-entry .player {
    color: #4caf50;
    font-weight: bold;
}

.log-entry .input {
    color: #aaa;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #000;
}

.header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background-color: #252525;
}

.game-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    /* Prevent expansion */
    min-height: 0;
    /* Allow shrinking in flex column */
}

canvas {
    image-rendering: pixelated;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    display: block;
}

/* Controller Layout */
.controller-body {
    background-color: #202020;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.login-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-screen input {
    padding: 10px;
    font-size: 1.2em;
    margin-bottom: 20px;
    border-radius: 5px;
    border: none;
}

.login-screen button {
    padding: 10px 20px;
    font-size: 1.2em;
    background-color: #e60012;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.controller-container {
    display: none;
    /* Hidden by default */
    height: 100vh;
    width: 100vw;
    display: flex;
    /* Override previous display:none when active via JS */
    flex-direction: row;
    /* Landscape */
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    box-sizing: border-box;
    background: #202020;
}

/* Force landscape hint ONLY for controller */
@media (orientation: portrait) {
    .controller-container::before {
        content: "Please rotate your device";
        position: fixed;
        /* Changed from absolute to fixed to cover full screen */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.95);
        color: white;
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 9999;
        /* Ensure it's on top of everything */
        font-size: 1.5em;
        pointer-events: all;
        /* Block interactions */
    }

    /* Ensure login screen is visible in portrait */
    .login-screen {
        display: flex !important;
    }
}

.dpad-area {
    flex: 1;
    display: flex;
    justify-content: flex-start;
    /* Left align */
    align-items: center;
    padding-left: 20px;
}

.dpad {
    width: 240px;
    height: 240px;
    position: relative;
    /* Visual separators for hitboxes */
    background:
        linear-gradient(to top right, transparent calc(50% - 1px), rgba(255, 255, 255, 0.3) 50%, transparent calc(50% + 1px)),
        linear-gradient(to top left, transparent calc(50% - 1px), rgba(255, 255, 255, 0.3) 50%, transparent calc(50% + 1px));
}

.dpad-btn {
    position: absolute;
    /* Hitbox styles */
    background-color: transparent;
    border: 1px dotted rgba(255, 255, 255, 0.3);
    z-index: 10;
}

/* Visual representation */
.dpad-btn::after {
    content: '';
    position: absolute;
    background-color: #333;
    border: 2px solid #555;
    border-radius: 4px;
    z-index: -1;
    /* Center the visual part */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.dpad-btn:active::after,
.dpad-btn.active::after {
    background-color: #555;
}

/* Cross shape logic with hitboxes */
/* UP: Trapezoid pointing up */
.dpad-up {
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.dpad-up::after {
    width: 60px;
    height: 60px;
    border-radius: 4px 4px 0 0;
    /* Offset for visual placement relative to center of hitbox */
    transform: translate(-50%, -50%);
}

/* DOWN: Trapezoid pointing down */
.dpad-down {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    clip-path: polygon(0 100%, 100% 100%, 50% 0);
}

.dpad-down::after {
    width: 60px;
    height: 60px;
    border-radius: 0 0 4px 4px;
    transform: translate(-50%, -50%);
}

/* LEFT: Trapezoid pointing left */
.dpad-left {
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    clip-path: polygon(0 0, 0 100%, 100% 50%);
}

.dpad-left::after {
    width: 60px;
    height: 60px;
    border-radius: 4px 0 0 4px;
    transform: translate(-50%, -50%);
}

/* RIGHT: Trapezoid pointing right */
.dpad-right {
    top: 0;
    right: 0;
    width: 50%;
    height: 100%;
    clip-path: polygon(100% 0, 100% 100%, 0 50%);
}

.dpad-right::after {
    width: 60px;
    height: 60px;
    border-radius: 0 4px 4px 0;
    transform: translate(-50%, -50%);
}

/* Center filler */
.dpad::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background-color: #333;
    z-index: 1;
    /* Below hitboxes but above background */
    pointer-events: none;
    /* Non-interactive */
}

.meta-area {
    flex: 0.5;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    /* Lower down like real NES */
    gap: 20px;
    padding-bottom: 20px;
}

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

.meta-label {
    font-size: 0.8em;
    color: #e60012;
    font-weight: bold;
    text-transform: uppercase;
}

.meta-btn {
    width: 100px;
    /* Larger hitbox */
    height: 60px;
    /* Larger hitbox */
    background-color: transparent;
    border: 1px dotted rgba(255, 255, 255, 0.3);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.meta-btn::after {
    content: '';
    width: 60px;
    height: 20px;
    background-color: #333;
    border: 2px solid #555;
    border-radius: 10px;
    position: absolute;
}

.meta-btn:active::after,
.meta-btn.active::after {
    background-color: #555;
}

.action-area {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    /* Right align */
    align-items: center;
    gap: 20px;
    padding-right: 20px;
}

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

.action-btn {
    width: 130px;
    /* Larger hitbox, nearly tangent */
    height: 130px;
    /* Larger hitbox, nearly tangent */
    background-color: transparent;
    border: 1px dotted rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: none;
}

.action-btn::after {
    content: '';
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: #e60012;
    /* NES Red */
    border: none;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
    position: absolute;
}

.action-btn:active::after,
.action-btn.active::after {
    background-color: #b3000e;
    transform: translateY(2px);
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.action-label {
    font-size: 1.2em;
    font-weight: bold;
    color: #e60012;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* SNES Controller Styles */
.snes-controller {
    flex-direction: column !important;
    background-color: #d0d0d0;
    /* Light grey body */
    border-radius: 30px;
    padding: 10px !important;
    position: relative;
    box-shadow: inset 0 -5px 10px rgba(0, 0, 0, 0.2), 0 10px 20px rgba(0, 0, 0, 0.5);
    height: auto !important;
    min-height: 90vh;
    /* Occupy most of the screen */
    margin: 20px;
    width: calc(100vw - 40px) !important;
    max-width: 800px;
    /* Limit width on large screens */
}

.shoulder-area {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.shoulder-btn-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.shoulder-label {
    display: none;
    /* Hide label, text is on button */
}

.shoulder-btn {
    width: 140px;
    height: 40px;
    background-color: #e0e0e0;
    border: 2px solid #a0a0a0;
    border-radius: 20px 20px 0 0;
    /* Rounded top */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #888;
    font-weight: bold;
    font-family: sans-serif;
    box-shadow: 0 4px 0 #a0a0a0;
    transition: transform 0.1s, box-shadow 0.1s;
}

.shoulder-btn::after {
    content: attr(data-key);
    /* Show L/R text */
}

.shoulder-btn:active,
.shoulder-btn.active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #a0a0a0;
    background-color: #d0d0d0;
}

.main-controller-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    width: 100%;
    background-color: #c0c0c0;
    /* Slightly darker grey for main area */
    border-radius: 20px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
}

/* SNES D-Pad - Reuse NES structure but adjust colors */
.snes-controller .dpad {
    width: 180px;
    height: 180px;
    background: none;
    /* Remove gradients */
}

.snes-controller .dpad-btn {
    border: none;
    /* Remove dotted border */
}

.snes-controller .dpad-btn::after {
    background-color: #404040;
    /* Darker grey */
    border: none;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
}

.snes-controller .dpad::before {
    background-color: #404040;
    /* Center piece */
}

.snes-controller .dpad-btn:active::after,
.snes-controller .dpad-btn.active::after {
    background-color: #202020;
}

/* SNES Select/Start */
.snes-controller .meta-area {
    gap: 15px;
}

.snes-controller .meta-btn {
    width: 60px;
    height: 60px;
    border: none;
    transform: rotate(-25deg);
    /* Angled */
}

.snes-controller .meta-btn::after {
    width: 50px;
    height: 18px;
    background-color: #505050;
    border: none;
    border-radius: 9px;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.snes-controller .meta-btn:active::after,
.snes-controller .meta-btn.active::after {
    background-color: #303030;
    transform: scale(0.95);
}

.snes-controller .meta-label {
    color: #505050;
    font-style: italic;
    margin-top: 5px;
    transform: rotate(-25deg);
}

/* SNES Action Area - Diamond Layout */
.snes-action-area {
    position: relative;
    background-color: #b0b0b0;
    /* Circle background */
    border-radius: 50%;
    width: 240px;
    height: 240px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.action-diamond {
    position: relative;
    width: 100%;
    height: 100%;
}

.snes-top,
.snes-bottom,
.snes-left,
.snes-right {
    position: absolute;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.snes-top {
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.snes-bottom {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.snes-left {
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
}

.snes-right {
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

.snes-controller .action-btn {
    width: 60px;
    height: 60px;
    border: none;
    background-color: transparent;
    box-shadow: none;
}

.snes-controller .action-btn::after {
    width: 56px;
    height: 56px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
    transition: transform 0.05s;
}

.snes-controller .action-btn:active::after,
.snes-controller .action-btn.active::after {
    transform: scale(0.95);
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.snes-controller .action-label {
    display: none;
    /* Hide labels, buttons are colored */
}

/* SNES Button Colors (EU/JP Style) */
.snes-x::after {
    background-color: #0074D9 !important;
}

/* Blue */
.snes-y::after {
    background-color: #2ECC40 !important;
}

/* Green */
.snes-a::after {
    background-color: #FF4136 !important;
}

/* Red */
.snes-b::after {
    background-color: #FFDC00 !important;
}

/* Yellow */