/* ===========================
   MARIO MENU + MOBILE STYLES
   =========================== */

/* ---- Disable tap highlights and selection on mobile ---- */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html, body {
    overflow: hidden;
    touch-action: none;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ---- Main Menu Overlay ---- */
#main-menu {
    position: fixed;
    inset: 0;
    background: #000080;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    font-family: 'Press Start 2P', 'Press Start', monospace;
    overflow: hidden;
}

#menu-bg-stars {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle, #fff 1px, transparent 1px),
        radial-gradient(circle, #fff 1px, transparent 1px),
        radial-gradient(circle, #ffe 1px, transparent 1px);
    background-size: 150px 150px, 250px 250px, 350px 350px;
    background-position: 0 0, 75px 50px, 30px 100px;
    opacity: 0.3;
    animation: starsTwinkle 4s infinite linear;
}

@keyframes starsTwinkle {
    0%   { opacity: 0.2; }
    50%  { opacity: 0.4; }
    100% { opacity: 0.2; }
}

#menu-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 640px;
    padding: 20px;
}

/* ---- Logo ---- */
#menu-logo {
    text-align: center;
    margin-bottom: 24px;
    text-shadow: 3px 3px 0 #a00, 6px 6px 0 #600;
}
.logo-line-1 {
    font-size: clamp(22px, 6vw, 40px);
    color: #fff;
    letter-spacing: 0.25em;
    line-height: 1.4;
}
.logo-line-2 {
    font-size: clamp(16px, 4.5vw, 30px);
    color: #ffcc00;
    letter-spacing: 0.1em;
    line-height: 1.6;
}
.logo-sub {
    font-size: clamp(7px, 1.8vw, 12px);
    color: #aaffaa;
    letter-spacing: 0.2em;
    margin-top: 8px;
}

/* ---- Mario Sprite ---- */
#menu-mario-sprite {
    width: 48px;
    height: 48px;
    margin: 0 auto 20px;
    image-rendering: pixelated;
    background-image: url('Theme/Mario.gif');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    animation: marioBounce 0.8s infinite alternate ease-in-out;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6));
}
@keyframes marioBounce {
    from { transform: translateY(0); }
    to   { transform: translateY(-8px); }
}

/* ---- Menu Items ---- */
#menu-options {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 32px;
    text-align: left;
    min-width: 300px;
}
.menu-item {
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(12px, 3vw, 16px);
    color: #ddd;
    cursor: pointer;
    padding: 6px 0;
    letter-spacing: 0.05em;
    transition: color 0.15s;
    user-select: none;
    white-space: nowrap;
}
.menu-item .cursor {
    display: inline-block;
    margin-right: 12px;
    opacity: 0;
    color: #ffcc00;
}
.menu-item.selected { color: #fff; }
.menu-item.selected .cursor {
    opacity: 1;
    animation: cursorBlink 0.7s infinite;
}
.menu-item:hover { color: #fff; }
.menu-item:hover .cursor { opacity: 1; }
@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

#menu-copyright {
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(6px, 1.5vw, 9px);
    color: #888;
    letter-spacing: 0.1em;
    text-align: center;
}

/* ---- Menu Fade Out ---- */
#main-menu.fade-out {
    animation: menuFadeOut 0.6s forwards;
}
@keyframes menuFadeOut {
    0%   { opacity: 1; transform: scale(1); }
    60%  { opacity: 0.8; transform: scale(1.04); }
    100% { opacity: 0; transform: scale(1.08); pointer-events: none; }
}

/* ============================
   CONTROL SELECT OVERLAY
   ============================ */
#control-select {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.90);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    font-family: 'Press Start 2P', 'Press Start', monospace;
}

#control-select-box {
    background: #0d0d2e;
    border: 3px solid #ffcc00;
    border-radius: 6px;
    padding: 32px 24px 24px;
    max-width: 480px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 40px rgba(255,204,0,0.3);
}

#control-select-box h2 {
    color: #ffcc00;
    font-size: clamp(13px, 2.5vw, 18px);
    margin: 0 0 28px;
    letter-spacing: 0.15em;
}

.ctrl-option {
    background: #1a1a4a;
    border: 2px solid #555;
    border-radius: 6px;
    padding: 14px 20px;
    margin-bottom: 14px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}
.ctrl-option:hover, .ctrl-option:active {
    border-color: #ffcc00;
    background: #22224a;
    transform: scale(1.02);
}

.ctrl-icon {
    font-size: 28px;
    min-width: 36px;
    text-align: center;
    line-height: 1;
}

.ctrl-label {
    font-size: clamp(11px, 2vw, 14px);
    color: #fff;
    margin-bottom: 4px;
    letter-spacing: 0.05em;
}

.ctrl-desc {
    font-size: clamp(7px, 1.3vw, 10px);
    color: #aaa;
    font-family: sans-serif;
    margin-top: 4px;
    letter-spacing: normal;
}

.ctrl-option > div:first-child { flex-shrink: 0; }
.ctrl-option .ctrl-label-wrap { display: flex; flex-direction: column; }

#ctrl-back {
    display: inline-block;
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(9px, 1.5vw, 11px);
    color: #aaa;
    cursor: pointer;
    margin-top: 8px;
    padding: 8px 12px;
    transition: color 0.15s;
}
#ctrl-back:hover { color: #fff; }

/* ============================
   HOW TO PLAY OVERLAY
   ============================ */
#howto-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    font-family: 'Press Start 2P', 'Press Start', monospace;
}

#howto-box {
    background: #1a1a3e;
    border: 3px solid #ffcc00;
    border-radius: 4px;
    padding: 28px 32px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 40px rgba(255,204,0,0.3);
}
#howto-box h2 {
    color: #ffcc00;
    font-size: clamp(13px, 2.5vw, 18px);
    margin: 0 0 24px;
    letter-spacing: 0.15em;
}
.howto-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    text-align: left;
}
.howto-table tr { border-bottom: 1px solid #333; }
.howto-table td {
    padding: 9px 6px;
    font-size: clamp(7px, 1.5vw, 10px);
    color: #ccc;
    vertical-align: middle;
}
.howto-table td.key {
    color: #7df;
    min-width: 140px;
    white-space: nowrap;
}
.howto-tips {
    margin: 12px 0 24px;
    font-size: clamp(6px, 1.2vw, 9px);
    color: #afa;
    line-height: 2.4;
    text-align: left;
}
#howto-back {
    display: inline-block;
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(9px, 1.5vw, 12px);
    color: #fff;
    background: #cc4400;
    border: 3px solid #ff6600;
    padding: 10px 20px;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: background 0.15s;
}
#howto-back:hover { background: #ee5500; }

.menu-btn {
    display: inline-block;
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(9px, 1.5vw, 12px);
    color: #fff;
    background: #cc4400;
    border: 3px solid #ff6600;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 0.15s;
}

/* ============================
   GAME WRAPPER
   ============================ */
#game-wrapper {
    position: fixed;
    inset: 0;
    background: black;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
}

#game-wrapper section#game {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Scale canvas to fill mobile screen properly */
#game-wrapper section#game .EightBitter {
    max-width: 100% !important;
    max-height: 100% !important;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Override the engine's inline pixel dimensions with CSS scaling */
    width: auto !important;
    height: auto !important;
    transform-origin: top left;
}

#game-wrapper section#game canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    /* Override the engine's inline pixel dimensions */
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
}

#game-wrapper section#controls {
    display: none !important;
}

/* When touch controls are active, game area must not overlap them */
body.touch-active #game-wrapper {
    bottom: 140px;
    height: calc(100vh - 140px);
}
body.touch-active #game-wrapper section#game {
    height: 100%;
    max-height: 100%;
}

/* ============================
   TOUCH CONTROLS
   ============================ */
#touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px 8px;
    z-index: 5000;
    pointer-events: none; /* children opt-in */
    /* slight dark gradient at bottom so canvas is still visible */
    background: linear-gradient(transparent, rgba(0,0,0,0.45));
}

/* ---- Left side (dpad) ---- */
#touch-left {
    pointer-events: all;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 160px;
    height: 120px;
}

/* ---- Right side (action buttons) ---- */
#touch-right {
    pointer-events: all;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ---- Generic touch button ---- */
.touch-btn {
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    border: none;
    outline: none;
    cursor: pointer;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    transition: opacity 0.05s, transform 0.05s;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
}
.touch-btn:active { opacity: 1; transform: scale(0.92); }

.btn-a {
    background: radial-gradient(circle at 40% 35%, #ff5555, #cc0000);
    box-shadow: 0 4px 0 #880000, 0 6px 12px rgba(0,0,0,0.5);
    width: 66px;
    height: 66px;
    font-size: 18px;
}
.btn-b {
    background: radial-gradient(circle at 40% 35%, #dd9900, #aa6600);
    box-shadow: 0 4px 0 #664400, 0 6px 12px rgba(0,0,0,0.5);
}
.btn-start {
    background: rgba(80,80,80,0.7);
    border: 2px solid rgba(255,255,255,0.3);
    width: 44px;
    height: 44px;
    font-size: 10px;
    border-radius: 22px;
    align-self: center;
    margin-bottom: 10px;
}

/* ============================
   DPAD STYLES
   ============================ */
.dpad-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.dpad {
    display: grid;
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
    gap: 2px;
}

.dpad-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.25);
    border-radius: 6px;
    color: rgba(255,255,255,0.85);
    font-size: 18px;
    cursor: pointer;
    user-select: none;
    transition: background 0.06s;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}
.dpad-btn:active { background: rgba(255,255,255,0.35); }

/* Position the 5 buttons in grid */
.dpad-up     { grid-column: 2; grid-row: 1; border-radius: 8px 8px 4px 4px; }
.dpad-left   { grid-column: 1; grid-row: 2; border-radius: 8px 4px 4px 8px; }
.dpad-center { grid-column: 2; grid-row: 2; background: rgba(0,0,0,0.3); border-color: transparent; }
.dpad-right  { grid-column: 3; grid-row: 2; border-radius: 4px 8px 8px 4px; }
.dpad-down   { grid-column: 2; grid-row: 3; border-radius: 4px 4px 8px 8px; }

/* ============================
   JOYSTICK STYLES
   ============================ */
.joystick-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.joystick-base {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, rgba(0,0,0,0.4) 100%);
    border: 3px solid rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    touch-action: none;
    cursor: grab;
}

.joystick-stick {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 38% 35%, rgba(255,255,255,0.8), rgba(180,180,180,0.5) 50%, rgba(100,100,100,0.7));
    box-shadow: 0 4px 10px rgba(0,0,0,0.6), inset 0 2px 4px rgba(255,255,255,0.3);
    border: 2px solid rgba(255,255,255,0.4);
    position: absolute;
    transition: transform 0.0s; /* no delay needed */
    will-change: transform;
    pointer-events: none;
}

/* ============================
   RESPONSIVE TWEAKS
   ============================ */
@media (max-width: 480px) {
    #menu-options { min-width: auto; width: 85%; }
    #howto-box    { padding: 20px 16px; }
    #touch-controls { height: 130px; padding: 0 10px 6px; }
    #touch-left   { width: 140px; height: 110px; }
    .btn-a        { width: 54px; height: 54px; font-size: 16px; }
    .touch-btn    { width: 50px; height: 50px; font-size: 14px; }
    .dpad         { grid-template-columns: 40px 40px 40px; grid-template-rows: 40px 40px 40px; }
}

/* ---- Landscape phone: compact touch controls ---- */
@media (max-height: 500px) {
    #touch-controls { height: 110px; padding: 0 10px 4px; }
    .touch-btn   { width: 48px; height: 48px; font-size: 14px; }
    .btn-a       { width: 52px; height: 52px; font-size: 16px; }
    .btn-b       { width: 48px; height: 48px; }
    .btn-start   { width: 36px; height: 36px; font-size: 8px; }
    #touch-left  { width: 130px; height: 100px; }
    .dpad        { grid-template-columns: 38px 38px 38px; grid-template-rows: 38px 38px 38px; gap: 1px; }
    .dpad-btn    { font-size: 14px; }

    body.touch-active #game-wrapper {
        bottom: 110px;
        height: calc(100vh - 110px);
    }
}

@media (max-height: 400px) {
    #touch-controls { height: 90px; padding: 0 8px 2px; }
    .touch-btn   { width: 40px; height: 40px; font-size: 12px; }
    .btn-a       { width: 44px; height: 44px; font-size: 14px; }
    .btn-b       { width: 40px; height: 40px; }
    .btn-start   { width: 30px; height: 30px; font-size: 7px; }
    #touch-left  { width: 110px; height: 85px; }
    .dpad        { grid-template-columns: 32px 32px 32px; grid-template-rows: 32px 32px 32px; gap: 1px; }
    .dpad-btn    { font-size: 12px; }

    body.touch-active #game-wrapper {
        bottom: 90px;
        height: calc(100vh - 90px);
    }
}

/* ============================
   ONLINE OVERLAY
   ============================ */
#online-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    font-family: 'Press Start 2P', 'Press Start', monospace;
}

#online-box {
    background: #0a0a2e;
    border: 3px solid #00ccff;
    border-radius: 6px;
    padding: 28px 24px 24px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 40px rgba(0,204,255,0.3);
}

#online-box h2 {
    color: #00ccff;
    font-size: clamp(13px, 2.5vw, 18px);
    margin: 0 0 16px;
    letter-spacing: 0.15em;
}

.online-status {
    font-size: clamp(7px, 1.4vw, 10px);
    color: #888;
    margin-bottom: 16px;
    font-family: sans-serif;
    letter-spacing: normal;
}
.online-status.connected { color: #66ff66; }
.online-status.error { color: #ff6666; }
.online-status.connecting { color: #ffcc00; animation: statusBlink 1s infinite; }

@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.online-field {
    margin-bottom: 14px;
    text-align: left;
}

.online-field label {
    display: block;
    font-size: clamp(8px, 1.5vw, 10px);
    color: #00aadd;
    margin-bottom: 6px;
    letter-spacing: 0.1em;
}

.online-field input {
    width: 100%;
    background: #111144;
    border: 2px solid #335;
    border-radius: 4px;
    padding: 10px 12px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(9px, 1.6vw, 12px);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s;
}

.online-field input:focus {
    border-color: #00ccff;
}

.online-field input::placeholder {
    color: #446;
}

.online-players-info {
    font-size: clamp(8px, 1.5vw, 10px);
    color: #aaa;
    font-family: sans-serif;
    margin-bottom: 16px;
    letter-spacing: normal;
}

#online-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.online-btn {
    display: inline-block;
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(9px, 1.5vw, 12px);
    color: #fff;
    background: #0066aa;
    border: 3px solid #00ccff;
    padding: 10px 20px;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: background 0.15s;
    flex: 1;
    text-align: center;
}
.online-btn:hover { background: #0088cc; }
.online-btn:disabled { background: #334; border-color: #556; cursor: default; color: #666; }

.online-btn-text {
    display: inline-block;
    font-family: 'Press Start 2P', 'Press Start', monospace;
    font-size: clamp(8px, 1.3vw, 10px);
    color: #aaa;
    cursor: pointer;
    transition: color 0.15s;
    white-space: nowrap;
}
.online-btn-text:hover { color: #fff; }

/* ============================
   ONLINE LOBBY
   ============================ */
#online-lobby {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    font-family: 'Press Start 2P', 'Press Start', monospace;
}

#online-lobby-box {
    background: #0a0a2e;
    border: 3px solid #00ff88;
    border-radius: 6px;
    padding: 28px 24px 24px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 40px rgba(0,255,136,0.3);
}

#online-lobby-box h2 {
    color: #00ff88;
    font-size: clamp(14px, 2.5vw, 18px);
    margin: 0 0 12px;
    letter-spacing: 0.15em;
}

#lobby-room-info {
    font-size: clamp(7px, 1.3vw, 10px);
    color: #aaa;
    font-family: sans-serif;
    margin-bottom: 16px;
    letter-spacing: normal;
}

#lobby-player-list {
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.lobby-player-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 4px;
    background: #111144;
    border-radius: 4px;
    font-size: clamp(8px, 1.4vw, 11px);
    color: #ddd;
    font-family: sans-serif;
    letter-spacing: normal;
}

.lobby-player-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00ff88;
    flex-shrink: 0;
}

#lobby-start-area {
    margin-bottom: 16px;
}

#lobby-waiting {
    font-size: clamp(7px, 1.3vw, 10px);
    color: #ffcc00;
    font-family: sans-serif;
    letter-spacing: normal;
}

#lobby-start {
    background: #00aa44;
    border-color: #00ff88;
}
#lobby-start:hover { background: #00cc55; }

/* ============================
   ONLINE HUD (in-game)
   ============================ */
#online-hud {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 5001;
    pointer-events: none;
}

#online-hud-content {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.7);
    padding: 4px 10px;
    border-radius: 4px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #fff;
}

#hud-name { color: #00ccff; }
#hud-ping { color: #888; }
#hud-players { color: #00ff88; }

/* Lobby control selection buttons */
.lobby-ctrl-btn {
    flex: 1;
    padding: 10px 4px;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 10px;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.lobby-ctrl-btn div:first-child {
    font-size: 22px;
    margin-bottom: 4px;
}
.lobby-ctrl-btn.selected {
    border-color: #00ccff;
    color: #fff;
    background: rgba(0,204,255,0.12);
}
.lobby-ctrl-btn:active {
    transform: scale(0.95);
}
